Diagnostics & diagnostic factories refactoring

This commit is contained in:
Svetlana Isakova
2012-02-27 21:35:00 +04:00
parent 4c70d341b1
commit 631961e761
81 changed files with 1486 additions and 1999 deletions
@@ -35,8 +35,8 @@ import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.diagnostics.SimpleDiagnosticFactory;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
@@ -190,7 +190,7 @@ public class CompileSession {
public void visitErrorElement(PsiErrorElement element) {
String description = element.getErrorDescription();
String message = StringUtil.isEmpty(description) ? "Syntax error" : description;
Diagnostic diagnostic = SimpleDiagnosticFactory.create(Severity.ERROR, message).on(element);
Diagnostic diagnostic = DiagnosticFactory.create(Severity.ERROR, message).on(element);
errorCollector.report(diagnostic);
}
});
@@ -39,7 +39,7 @@ class ErrorCollector {
public void report(Diagnostic diagnostic) {
hasErrors |= diagnostic.getSeverity() == Severity.ERROR;
maps.put(diagnostic.getFactory().getPsiFile(diagnostic), diagnostic);
maps.put(diagnostic.getPsiFile(), diagnostic);
}
public void flushTo(final PrintStream out) {
@@ -23,12 +23,12 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange;
import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -72,8 +72,8 @@ public class CheckerTestUtil {
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(BindingContext bindingContext, PsiElement root) {
ArrayList<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
diagnostics.addAll(bindingContext.getDiagnostics());
for (TextRange textRange : AnalyzingUtils.getSyntaxErrorRanges(root)) {
diagnostics.add(new SyntaxErrorDiagnostic(textRange, root.getContainingFile()));
for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) {
diagnostics.add(new SyntaxErrorDiagnostic(errorElement));
}
return diagnostics;
}
@@ -159,7 +159,7 @@ public class CheckerTestUtil {
private static void unexpectedDiagnostics(List<Diagnostic> actual, DiagnosticDiffCallbacks callbacks) {
for (Diagnostic diagnostic : actual) {
if (!diagnostic.getFactory().getPsiFile(diagnostic).equals(callbacks.getFile())) continue;
if (!diagnostic.getPsiFile().equals(callbacks.getFile())) continue;
List<TextRange> textRanges = getTextRanges(diagnostic);
for (TextRange textRange : textRanges) {
callbacks.unexpectedDiagnostic(diagnostic.getFactory().getName(), textRange.getStartOffset(), textRange.getEndOffset());
@@ -209,11 +209,11 @@ public class CheckerTestUtil {
return matcher.replaceAll("");
}
public static StringBuffer addDiagnosticMarkersToText(PsiFile psiFile, BindingContext bindingContext, List<TextRange> syntaxErrors) {
public static StringBuffer addDiagnosticMarkersToText(PsiFile psiFile, BindingContext bindingContext, List<PsiErrorElement> syntaxErrors) {
Collection<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
diagnostics.addAll(bindingContext.getDiagnostics());
for (TextRange syntaxError : syntaxErrors) {
diagnostics.add(new SyntaxErrorDiagnostic(syntaxError, psiFile));
for (PsiErrorElement syntaxError : syntaxErrors) {
diagnostics.add(new SyntaxErrorDiagnostic(syntaxError));
}
return addDiagnosticMarkersToText(psiFile, diagnostics);
@@ -225,7 +225,7 @@ public class CheckerTestUtil {
diagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() {
@Override
public boolean apply(@Nullable Diagnostic diagnostic) {
if (diagnostic == null || !psiFile.equals(diagnostic.getFactory().getPsiFile(diagnostic))) return false;
if (diagnostic == null || !psiFile.equals(diagnostic.getPsiFile())) return false;
return true;
}
});
@@ -297,21 +297,9 @@ public class CheckerTestUtil {
result.append("<!>");
}
private static class SyntaxErrorDiagnosticFactory implements DiagnosticFactory {
private static class SyntaxErrorDiagnosticFactory extends AbstractDiagnosticFactory {
private static final SyntaxErrorDiagnosticFactory instance = new SyntaxErrorDiagnosticFactory();
@NotNull
@Override
public List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic) {
return Collections.singletonList(((SyntaxErrorDiagnostic) diagnostic).textRange);
}
@NotNull
@Override
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
return ((SyntaxErrorDiagnostic)diagnostic).getPsiFile();
}
@NotNull
@Override
public String getName() {
@@ -319,19 +307,16 @@ public class CheckerTestUtil {
}
}
public static class SyntaxErrorDiagnostic implements DiagnosticWithTextRange {
public static class SyntaxErrorDiagnostic implements Diagnostic {
private final PsiErrorElement errorElement;
private final TextRange textRange;
private final PsiFile psiFile;
public SyntaxErrorDiagnostic(@NotNull TextRange textRange, @NotNull PsiFile psiFile) {
this.textRange = textRange;
this.psiFile = psiFile;
public SyntaxErrorDiagnostic(@NotNull PsiErrorElement errorElement) {
this.errorElement = errorElement;
}
@NotNull
@Override
public DiagnosticFactory getFactory() {
public AbstractDiagnosticFactory getFactory() {
return SyntaxErrorDiagnosticFactory.instance;
}
@@ -349,14 +334,20 @@ public class CheckerTestUtil {
@NotNull
@Override
public TextRange getTextRange() {
return textRange;
public PsiErrorElement getPsiElement() {
return errorElement;
}
@NotNull
@Override
public List<TextRange> getTextRanges() {
return Collections.singletonList(errorElement.getTextRange());
}
@NotNull
@Override
public PsiFile getPsiFile() {
return psiFile;
return errorElement.getContainingFile();
}
}
@@ -380,7 +371,7 @@ public class CheckerTestUtil {
}
private static List<TextRange> getTextRanges(Diagnostic currentDiagnostic) {
return currentDiagnostic.getFactory().getTextRanges(currentDiagnostic);
return currentDiagnostic.getTextRanges();
}
private static class DiagnosticDescriptor {
@@ -371,10 +371,10 @@ public class JetFlowInformationProvider {
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) variable;
if (simpleNameExpression.getReferencedNameElementType() != JetTokens.FIELD_IDENTIFIER) {
if (((PropertyDescriptor) variableDescriptor).getModality() != Modality.FINAL) {
trace.report(Errors.INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER.on(simpleNameExpression, expression, variableDescriptor));
trace.report(Errors.INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER.on(expression, variableDescriptor));
}
else {
trace.report(Errors.INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER.on(simpleNameExpression, expression, variableDescriptor));
trace.report(Errors.INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER.on(expression, variableDescriptor));
}
return true;
}
@@ -620,7 +620,7 @@ public class JetFlowInformationProvider {
if (nameIdentifier == null) return;
if (variableStatus == null || variableStatus == VariableStatus.UNUSED) {
if (element instanceof JetProperty) {
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty) element, nameIdentifier, variableDescriptor));
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty) element, variableDescriptor));
}
else if (element instanceof JetParameter) {
PsiElement psiElement = element.getParent().getParent();
@@ -630,18 +630,18 @@ public class JetFlowInformationProvider {
assert descriptor instanceof FunctionDescriptor;
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
if (!isMain && !functionDescriptor.getModality().isOverridable() && functionDescriptor.getOverriddenDescriptors().isEmpty()) {
trace.report(Errors.UNUSED_PARAMETER.on((JetParameter) element, nameIdentifier, variableDescriptor));
trace.report(Errors.UNUSED_PARAMETER.on((JetParameter) element, variableDescriptor));
}
}
}
}
else if (variableStatus == VariableStatus.ONLY_WRITTEN && element instanceof JetProperty) {
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, nameIdentifier, variableDescriptor));
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, variableDescriptor));
}
else if (variableStatus == VariableStatus.WRITTEN && element instanceof JetProperty) {
JetExpression initializer = ((JetProperty) element).getInitializer();
if (initializer != null) {
trace.report(Errors.VARIABLE_WITH_REDUNDANT_INITIALIZER.on((JetNamedDeclaration) element, initializer, variableDescriptor));
trace.report(Errors.VARIABLE_WITH_REDUNDANT_INITIALIZER.on(initializer, variableDescriptor));
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,44 +16,36 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class GenericDiagnostic implements DiagnosticWithTextRange {
private final TextRange textRange;
* @author svtk
*/
public abstract class AbstractDiagnostic<P extends PsiElement> implements Diagnostic<P> {
private final P psiElement;
private final String message;
private final DiagnosticFactory factory;
private final AbstractDiagnosticFactory factory;
private final Severity severity;
private final PsiFile psiFile;
public GenericDiagnostic(DiagnosticFactory factory, Severity severity, String message, @NotNull PsiFile psiFile, @NotNull TextRange textRange) {
public AbstractDiagnostic(@NotNull P psiElement, @NotNull AbstractDiagnosticFactory factory, @NotNull Severity severity, @NotNull String message) {
this.psiElement = psiElement;
this.factory = factory;
this.textRange = textRange;
this.severity = severity;
this.message = message;
this.psiFile = psiFile;
}
@NotNull
@Override
public DiagnosticFactory getFactory() {
public AbstractDiagnosticFactory getFactory() {
return factory;
}
@NotNull
public TextRange getTextRange() {
return textRange;
}
@NotNull
@Override
public PsiFile getPsiFile() {
return psiFile;
return psiElement.getContainingFile();
}
@NotNull
@@ -67,4 +59,11 @@ public class GenericDiagnostic implements DiagnosticWithTextRange {
public Severity getSeverity() {
return severity;
}
@Override
@NotNull
public P getPsiElement() {
return psiElement;
}
}
@@ -16,41 +16,21 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
/**
* @author abreslav
*/
public class AbstractDiagnosticFactory implements DiagnosticFactory {
public class AbstractDiagnosticFactory {
private String name = null;
/*package*/ void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@NotNull
@Override
public List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic) {
return Collections.singletonList(((DiagnosticWithTextRange) diagnostic).getTextRange());
}
@NotNull
@Override
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
return ((DiagnosticWithTextRange) diagnostic).getPsiFile();
}
@Override
public String toString() {
return getName();
@@ -16,7 +16,9 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.resolve.DescriptorRenderer;
@@ -24,23 +26,27 @@ import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.util.Collection;
/**
* @author abreslav
*/
public class AmbiguousDescriptorDiagnosticFactory extends ParameterizedDiagnosticFactory1<Collection<? extends ResolvedCall<? extends CallableDescriptor>>> {
* @author abreslav
*/
public class AmbiguousDescriptorDiagnosticFactory extends DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<? extends CallableDescriptor>>> {
public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) {
return new AmbiguousDescriptorDiagnosticFactory(messageTemplate);
}
public AmbiguousDescriptorDiagnosticFactory(String messageTemplate) {
super(Severity.ERROR, messageTemplate);
super(Severity.ERROR, messageTemplate, PositioningStrategies.DEFAULT, AMBIGUOUS_DESCRIPTOR_RENDERER);
}
@Override
protected String makeMessageFor(@NotNull Collection<? extends ResolvedCall<? extends CallableDescriptor>> argument) {
StringBuilder stringBuilder = new StringBuilder("\n");
for (ResolvedCall<? extends CallableDescriptor> call : argument) {
stringBuilder.append(DescriptorRenderer.TEXT.render(call.getResultingDescriptor())).append("\n");
private static Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>> AMBIGUOUS_DESCRIPTOR_RENDERER =
new Renderer<Collection<? extends ResolvedCall<? extends CallableDescriptor>>>() {
@NotNull
@Override
public String render(@Nullable Collection<? extends ResolvedCall<? extends CallableDescriptor>> argument) {
StringBuilder stringBuilder = new StringBuilder("\n");
for (ResolvedCall<? extends CallableDescriptor> call : argument) {
stringBuilder.append(DescriptorRenderer.TEXT.render(call.getResultingDescriptor())).append("\n");
}
return stringBuilder.toString();
}
return stringBuilder.toString();
}
};
}
@@ -16,19 +16,33 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author abreslav
*/
public interface Diagnostic {
* @author abreslav
*/
public interface Diagnostic<E extends PsiElement> {//todo
@NotNull
DiagnosticFactory getFactory();
AbstractDiagnosticFactory getFactory();
@NotNull
String getMessage();
@NotNull
Severity getSeverity();
@NotNull
E getPsiElement();
@NotNull
List<TextRange> getTextRanges();
@NotNull
PsiFile getPsiFile();
}
@@ -16,22 +16,30 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author abreslav
*/
public interface DiagnosticFactory {
@NotNull
List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic);
* @author svtk
*/
public class DiagnosticFactory<P extends PsiElement> extends DiagnosticFactoryWithPsiElement<P> {
protected final String message;
protected DiagnosticFactory(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy) {
super(severity, positioningStrategy);
this.message = message;
}
public static <T extends PsiElement> DiagnosticFactory<T> create(Severity severity, String message) {
return create(severity, message, PositioningStrategies.DEFAULT);
}
public static <T extends PsiElement> DiagnosticFactory<T> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
return new DiagnosticFactory<T>(severity, message, positioningStrategy);
}
@NotNull
PsiFile getPsiFile(@NotNull Diagnostic diagnostic);
@NotNull
String getName();
}
public Diagnostic<P> on(@NotNull P element) {
return new DiagnosticWithPsiElement<P>(element, this, severity, message);
}
}
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public class DiagnosticFactory1<P extends PsiElement, A> extends DiagnosticFactoryWithMessageFormat<P> {
private final Renderer<? super A> renderer;
protected String makeMessage(@NotNull A argument) {
return messageFormat.format(new Object[]{makeMessageFor(argument)});
}
protected String makeMessageFor(@NotNull A argument) {
return renderer.render(argument);
}
@NotNull
public DiagnosticWithPsiElement<P> on(@NotNull P element, @NotNull A argument) {
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(argument));
}
protected DiagnosticFactory1(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> renderer) {
super(severity, message, positioningStrategy);
this.renderer = renderer;
}
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
return new DiagnosticFactory1<T, A>(severity, message, positioningStrategy, renderer);
}
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
return create(severity, message, positioningStrategy, Renderers.TO_STRING);
}
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message, Renderer<? super A> renderer) {
return create(severity, message, PositioningStrategies.DEFAULT, renderer);
}
public static <T extends PsiElement, A> DiagnosticFactory1<T, A> create(Severity severity, String message) {
return create(severity, message, PositioningStrategies.DEFAULT, Renderers.TO_STRING);
}
}
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class DiagnosticFactory2<P extends PsiElement, A, B> extends DiagnosticFactoryWithMessageFormat<P> {
private final Renderer<? super A> rendererForA;
private final Renderer<? super B> rendererForB;
private String makeMessage(@NotNull A a, @NotNull B b) {
return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)});
}
private String makeMessageForA(@NotNull A a) {
return rendererForA.render(a);
}
private String makeMessageForB(@NotNull B b) {
return rendererForB.render(b);
}
@NotNull
public Diagnostic<P> on(@NotNull P element, @NotNull A a, @NotNull B b) {
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(a, b));
}
private DiagnosticFactory2(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
super(severity, message, positioningStrategy);
this.rendererForA = rendererForA;
this.rendererForB = rendererForB;
}
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
return new DiagnosticFactory2<T, A, B>(severity, messageStub, positioningStrategy, rendererForA, rendererForB);
}
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy) {
return new DiagnosticFactory2<T, A, B>(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING);
}
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
return new DiagnosticFactory2<T, A, B>(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB);
}
public static <T extends PsiElement, A, B> DiagnosticFactory2<T, A, B> create(Severity severity, String messageStub) {
return new DiagnosticFactory2<T, A, B>(severity, messageStub, PositioningStrategies.DEFAULT, Renderers.TO_STRING, Renderers.TO_STRING);
}
}
@@ -0,0 +1,72 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public class DiagnosticFactory3<P extends PsiElement, A, B, C> extends DiagnosticFactoryWithMessageFormat<P> {
private final Renderer<? super A> rendererForA;
private final Renderer<? super B> rendererForB;
private final Renderer<? super C> rendererForC;
protected DiagnosticFactory3(Severity severity, String messageStub, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
super(severity, messageStub, positioningStrategy);
this.rendererForA = rendererForA;
this.rendererForB = rendererForB;
this.rendererForC = rendererForC;
}
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub) {
return create(severity, messageStub, PositioningStrategies.DEFAULT);
}
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy) {
return create(severity, messageStub, positioningStrategy, Renderers.TO_STRING, Renderers.TO_STRING, Renderers.TO_STRING);
}
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
return create(severity, messageStub, PositioningStrategies.DEFAULT, rendererForA, rendererForB, rendererForC);
}
public static <T extends PsiElement, A, B, C> DiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
return new DiagnosticFactory3<T, A, B, C>(severity, messageStub, positioningStrategy, rendererForA, rendererForB, rendererForC);
}
private String makeMessage(@NotNull A a, @NotNull B b, @NotNull C c) {
return messageFormat.format(new Object[]{makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)});
}
private String makeMessageForA(@NotNull A a) {
return rendererForA.render(a);
}
private String makeMessageForB(@NotNull B b) {
return rendererForB.render(b);
}
private String makeMessageForC(@NotNull C c) {
return rendererForC.render(c);
}
@NotNull
public DiagnosticWithPsiElement<P> on(@NotNull P element, @NotNull A a, @NotNull B b, @NotNull C c) {
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(a, b, c));
}
}
@@ -16,23 +16,22 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import java.text.MessageFormat;
/**
* @author abreslav
*/
public abstract class DiagnosticFactoryWithMessageFormat extends DiagnosticFactoryWithSeverity {
public abstract class DiagnosticFactoryWithMessageFormat<P extends PsiElement> extends DiagnosticFactoryWithPsiElement<P> {
protected final MessageFormat messageFormat;
protected final Renderer renderer;
public DiagnosticFactoryWithMessageFormat(Severity severity, String message) {
this(severity, message, Renderer.TO_STRING);
this(severity, message, PositioningStrategies.DEFAULT);
}
public DiagnosticFactoryWithMessageFormat(Severity severity, String message, Renderer renderer) {
super(severity);
public DiagnosticFactoryWithMessageFormat(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy) {
super(severity, positioningStrategy);
this.messageFormat = new MessageFormat(message);
this.renderer = renderer;
}
}
@@ -16,14 +16,24 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import java.util.List;
/**
* @author abreslav
*/
public abstract class DiagnosticFactoryWithSeverity extends AbstractDiagnosticFactory {
public abstract class DiagnosticFactoryWithPsiElement<P extends PsiElement> extends AbstractDiagnosticFactory {
protected final Severity severity;
protected final PositioningStrategy<? super P> positioningStrategy;
public DiagnosticFactoryWithSeverity(Severity severity) {
public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super P> positioningStrategy) {
this.severity = severity;
this.positioningStrategy = positioningStrategy;
}
protected List<TextRange> getTextRanges(Diagnostic<P> diagnostic) {
return positioningStrategy.mark(diagnostic.getPsiElement());
}
}
@@ -1,64 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public abstract class DiagnosticFactoryWithPsiElement1<T extends PsiElement, A> extends DiagnosticFactoryWithMessageFormat {
protected DiagnosticFactoryWithPsiElement1(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
protected DiagnosticFactoryWithPsiElement1(Severity severity, String message) {
super(severity, message);
}
protected String makeMessage(@NotNull A argument) {
return messageFormat.format(new Object[]{makeMessageFor(argument)});
}
protected String makeMessageFor(A argument) {
return renderer.render(argument);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToMark, @NotNull A argument) {
return on(elementToMark, elementToMark.getTextRange(), argument);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A argument) {
return on(elementToBlame, nodeToMark.getTextRange(), argument);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark, @NotNull A argument) {
return on(elementToBlame, elementToMark.getTextRange(), argument);
}
@NotNull
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A argument) {
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), elementToBlame, textRangeToMark);
}
}
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public abstract class DiagnosticFactoryWithPsiElement2<T extends PsiElement, A, B> extends DiagnosticFactoryWithMessageFormat {
protected DiagnosticFactoryWithPsiElement2(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
protected DiagnosticFactoryWithPsiElement2(Severity severity, String message) {
super(severity, message);
}
protected String makeMessage(@NotNull A a, @NotNull B b) {
return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)});
}
protected String makeMessageForA(@NotNull A a) {
return renderer.render(a);
}
protected String makeMessageForB(@NotNull B b) {
return renderer.render(b);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToMark, @NotNull A a, @NotNull B b) {
return on(elementToMark, elementToMark.getNode(), a, b);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b) {
return makeDiagnostic(new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b), elementToBlame, nodeToMark.getTextRange()));
}
public DiagnosticWithPsiElement<T> makeDiagnostic(DiagnosticWithPsiElement<T> diagnostic) {
return diagnostic;
}
}
@@ -1,72 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public abstract class DiagnosticFactoryWithPsiElement3<T extends PsiElement, A, B, C> extends DiagnosticFactoryWithMessageFormat {
protected DiagnosticFactoryWithPsiElement3(Severity severity, String messageStub, Renderer renderer) {
super(severity, messageStub, renderer);
}
protected DiagnosticFactoryWithPsiElement3(Severity severity, String message) {
super(severity, message);
}
protected String makeMessage(@NotNull A a, @NotNull B b, @NotNull C c) {
return messageFormat.format(new Object[]{makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)});
}
protected String makeMessageForA(@NotNull A a) {
return renderer.render(a);
}
protected String makeMessageForB(@NotNull B b) {
return renderer.render(b);
}
protected String makeMessageForC(@NotNull C c) {
return renderer.render(c);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return on(elementToMark, elementToMark, a, b, c);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return on(elementToBlame, elementToMark.getTextRange(), a, b, c);
}
@NotNull
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return on(elementToBlame, nodeToMark.getTextRange(), a, b, c);
}
@NotNull
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b, c), elementToBlame, textRangeToMark);
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
@@ -35,8 +36,8 @@ public interface DiagnosticHolder {
@Override
public void report(@NotNull Diagnostic diagnostic) {
if (diagnostic.getSeverity() == Severity.ERROR) {
PsiFile psiFile = diagnostic.getFactory().getPsiFile(diagnostic);
List<TextRange> textRanges = diagnostic.getFactory().getTextRanges(diagnostic);
PsiFile psiFile = diagnostic.getPsiFile();
List<TextRange> textRanges = diagnostic.getTextRanges();
throw new IllegalStateException(diagnostic.getMessage() + DiagnosticUtils.atLocation(psiFile, textRanges.get(0)));
}
}
@@ -84,10 +84,10 @@ public class DiagnosticUtils {
}
}
public static String formatPosition(Diagnostic diagnostic) {
PsiFile file = diagnostic.getFactory().getPsiFile(diagnostic);
public static String formatPosition(Diagnostic<PsiElement> diagnostic) {
PsiFile file = diagnostic.getPsiFile();
Document document = file.getViewProvider().getDocument();
TextRange firstRange = diagnostic.getFactory().getTextRanges(diagnostic).iterator().next();
TextRange firstRange = diagnostic.getTextRanges().iterator().next();
int offset = firstRange.getStartOffset();
if (document != null) {
int lineNumber = document.getLineNumber(offset);
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public class DiagnosticWithParameterFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
public static <T extends PsiElement, A> DiagnosticWithParameterFactory<T, A> create(Severity severity, String messageStub, DiagnosticParameter<A> diagnosticParameter) {
return new DiagnosticWithParameterFactory<T, A>(severity, messageStub, diagnosticParameter);
}
private final DiagnosticParameter<A> diagnosticParameter;
protected DiagnosticWithParameterFactory(Severity severity, String message, DiagnosticParameter<A> diagnosticParameter) {
super(severity, message);
this.diagnosticParameter = diagnosticParameter;
}
@NotNull
@Override
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A argument) {
return super.on(elementToBlame, textRangeToMark, argument).add(diagnosticParameter, argument);
}
}
@@ -1,48 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.google.common.collect.Maps;
import com.intellij.psi.PsiElement;
import java.util.Map;
/**
* @author svtk
*/
public class DiagnosticWithParameters<T extends PsiElement> extends DiagnosticWithPsiElementImpl<T> {
private final Map<DiagnosticParameter, Object> map = Maps.newHashMap();
public DiagnosticWithParameters(DiagnosticWithPsiElement<T> diagnostic) {
super(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), diagnostic.getPsiElement(), diagnostic.getTextRange());
}
@Override
public <P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter) {
map.put(parameterType, parameter);
return this;
}
public <P> P getParameter(DiagnosticParameter<P> parameterType) {
return (P) map.get(parameterType);
}
public <P> boolean hasParameter(DiagnosticParameter<P> parameterType) {
return getParameter(parameterType) != null;
}
}
@@ -16,15 +16,28 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public interface DiagnosticWithPsiElement<T extends PsiElement> extends DiagnosticWithTextRange {
@NotNull
T getPsiElement();
import java.util.List;
<P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter);
/**
* @author svtk
*/
public class DiagnosticWithPsiElement<P extends PsiElement> extends AbstractDiagnostic<P> {
public DiagnosticWithPsiElement(@NotNull P psiElement, @NotNull DiagnosticFactoryWithPsiElement<P> factory, @NotNull Severity severity, @NotNull String message) {
super(psiElement, factory, severity, message);
}
@NotNull
@Override
public DiagnosticFactoryWithPsiElement<P> getFactory() {
return (DiagnosticFactoryWithPsiElement<P>)super.getFactory();
}
@NotNull
public List<TextRange> getTextRanges() {
return getFactory().getTextRanges(this);
}
}
@@ -1,48 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public class DiagnosticWithPsiElementImpl<T extends PsiElement> extends GenericDiagnostic implements DiagnosticWithPsiElement<T> {
private final T psiElement;
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
this(factory, severity, message, psiElement, psiElement.getTextRange());
}
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
super(factory, severity, message, psiElement.getContainingFile(), textRange);
this.psiElement = psiElement;
}
@Override
@NotNull
public T getPsiElement() {
return psiElement;
}
@Override
public <P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter) {
return (new DiagnosticWithParameters<T>(this)).add(parameterType, parameter);
}
}
@@ -1,33 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public interface DiagnosticWithTextRange extends Diagnostic {
@NotNull
TextRange getTextRange();
@NotNull
PsiFile getPsiFile();
}
@@ -16,9 +16,9 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
@@ -26,475 +26,430 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.inference.SolutionStatus;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
import static org.jetbrains.jet.lang.diagnostics.Renderers.*;
/**
* @author abreslav
*/
public interface Errors {
Renderer NAME = new Renderer() {
DiagnosticFactory1<JetFile, Throwable> EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR, "{0}", new Renderer<Throwable>() {
@NotNull
@Override
public String render(@Nullable Object object) {
if (object == null) return "null";
if (object instanceof Named) {
return ((Named) object).getName();
}
return object.toString();
}
};
ParameterizedDiagnosticFactory1<Throwable> EXCEPTION_WHILE_ANALYZING = new ParameterizedDiagnosticFactory1<Throwable>(ERROR, "{0}") {
@Override
protected String makeMessageFor(@NotNull Throwable e) {
public String render(@Nullable Throwable e) {
return e.getClass().getSimpleName() + ": " + e.getMessage();
}
};
});
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = new UnresolvedReferenceDiagnosticFactory("Unresolved reference");
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create("Unresolved reference");
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
PsiElementOnlyDiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = PsiElementOnlyDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected");
ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS = new ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>>(ERROR, "Incompatible modifiers: ''{0}''") {
@Override
protected String makeMessageFor(Collection<JetKeywordToken> argument) {
StringBuilder sb = new StringBuilder();
for (Iterator<JetKeywordToken> iterator = argument.iterator(); iterator.hasNext(); ) {
JetKeywordToken modifier = iterator.next();
sb.append(modifier.getValue());
if (iterator.hasNext()) {
sb.append(" ");
}
}
return sb.toString();
}
};
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> ILLEGAL_MODIFIER = DiagnosticWithParameterFactory.create(ERROR, "Illegal modifier ''{0}''", DiagnosticParameters.MODIFIER);
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = DiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected");
DiagnosticFactory1<PsiElement, Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS =
DiagnosticFactory1.create(ERROR, "Incompatible modifiers: ''{0}''",
new Renderer<Collection<JetKeywordToken>>() {
@NotNull
@Override
public String render(@Nullable Collection<JetKeywordToken> element) {
assert element != null;
StringBuilder sb = new StringBuilder();
for (Iterator<JetKeywordToken> iterator = element.iterator(); iterator.hasNext(); ) {
JetKeywordToken modifier = iterator.next();
sb.append(modifier.getValue());
if (iterator.hasNext()) {
sb.append(" ");
}
}
return sb.toString();
}
});
DiagnosticFactory1<PsiElement, JetKeywordToken> ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR, "Illegal modifier ''{0}''");
PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = new PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken>(Severity.WARNING, "Modifier {0} is redundant because {1} is present") {
DiagnosticFactory2<PsiElement, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING, "Modifier {0} is redundant because {1} is present");
DiagnosticFactory<JetModifierListOwner> ABSTRACT_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory<JetModifierListOwner> OPEN_MODIFIER_IN_TRAIT = DiagnosticFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD));
DiagnosticFactory<PsiElement> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticFactory.create(WARNING, "Visibility modifiers are redundant in getter");
DiagnosticFactory<PsiElement> TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory.create(ERROR, "Trait can not be final");
DiagnosticFactory<JetExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
DiagnosticFactory<JetReturnExpression> RETURN_NOT_ALLOWED = DiagnosticFactory.create(ERROR, "'return' is not allowed here");
DiagnosticFactory<JetTypeProjection> PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE = DiagnosticFactory.create(ERROR, "Projections are not allowed for immediate arguments of a supertype", new PositioningStrategy<JetTypeProjection>() {
@NotNull
@Override
public DiagnosticWithPsiElement<JetModifierList> on(@NotNull JetModifierList elementToBlame, @NotNull ASTNode nodeToMark, @NotNull JetKeywordToken redundantModifier, @NotNull JetKeywordToken presentModifier) {
return super.on(elementToBlame, nodeToMark, redundantModifier, presentModifier).add(DiagnosticParameters.MODIFIER, redundantModifier);
public List<TextRange> mark(@NotNull JetTypeProjection element) {
return markNode(element.getProjectionNode());
}
};
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> REDUNDANT_MODIFIER_IN_TRAIT = DiagnosticWithParameterFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", DiagnosticParameters.MODIFIER);
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticWithParameterFactory.create(WARNING, "Visibility modifiers are redundant in getter", DiagnosticParameters.MODIFIER);
SimplePsiElementOnlyDiagnosticFactory<JetClass> TRAIT_CAN_NOT_BE_FINAL = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Trait can not be final");
SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces");
SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message
SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "'return' is not allowed here");
SimpleDiagnosticFactory PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed for immediate arguments of a supertype");
SimpleDiagnosticFactory LABEL_NAME_CLASH = SimpleDiagnosticFactory.create(WARNING, "There is more than one label with such a name in this scope");
SimpleDiagnosticFactory EXPRESSION_EXPECTED_NAMESPACE_FOUND = SimpleDiagnosticFactory.create(ERROR, "Expression expected, but a namespace name found");
});
DiagnosticFactory<JetSimpleNameExpression> LABEL_NAME_CLASH = DiagnosticFactory.create(WARNING, "There is more than one label with such a name in this scope");
DiagnosticFactory<JetSimpleNameExpression> EXPRESSION_EXPECTED_NAMESPACE_FOUND = DiagnosticFactory.create(ERROR, "Expression expected, but a namespace name found");
ParameterizedDiagnosticFactory1<DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot import from ''{0}''", NAME);
ParameterizedDiagnosticFactory1<DeclarationDescriptor> CANNOT_BE_IMPORTED = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
SimpleDiagnosticFactory USELESS_HIDDEN_IMPORT = SimpleDiagnosticFactory.create(WARNING, "Useless import, it is hidden further");
SimpleDiagnosticFactory USELESS_SIMPLE_IMPORT = SimpleDiagnosticFactory.create(WARNING, "Useless import, does nothing");
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR, "Cannot import from ''{0}''", NAME);
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
DiagnosticFactory<JetExpression> USELESS_HIDDEN_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, it is hidden further");
DiagnosticFactory<JetExpression> USELESS_SIMPLE_IMPORT = DiagnosticFactory.create(WARNING, "Useless import, does nothing");
SimpleDiagnosticFactory CANNOT_INFER_PARAMETER_TYPE = SimpleDiagnosticFactory.create(ERROR, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
DiagnosticFactory<JetParameter> CANNOT_INFER_PARAMETER_TYPE = DiagnosticFactory.create(ERROR, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
SimpleDiagnosticFactory NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it's abstract");
SimpleDiagnosticFactory NO_BACKING_FIELD_CUSTOM_ACCESSORS = SimpleDiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it has custom accessors without reference to the backing field");
SimpleDiagnosticFactory INACCESSIBLE_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "The backing field is not accessible here");
SimpleDiagnosticFactory NOT_PROPERTY_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "The referenced variable is not a property and doesn't have backing field");
DiagnosticFactory<JetElement> NO_BACKING_FIELD_ABSTRACT_PROPERTY = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it's abstract");
DiagnosticFactory<JetElement> NO_BACKING_FIELD_CUSTOM_ACCESSORS = DiagnosticFactory.create(ERROR, "This property doesn't have a backing field, because it has custom accessors without reference to the backing field");
DiagnosticFactory<JetElement> INACCESSIBLE_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The backing field is not accessible here");
DiagnosticFactory<JetElement> NOT_PROPERTY_BACKING_FIELD = DiagnosticFactory.create(ERROR, "The referenced variable is not a property and doesn't have backing field");
SimpleDiagnosticFactory MIXING_NAMED_AND_POSITIONED_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Mixing named and positioned arguments in not allowed");
SimpleDiagnosticFactory ARGUMENT_PASSED_TWICE = SimpleDiagnosticFactory.create(ERROR, "An argument is already passed for this parameter");
UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = new UnresolvedReferenceDiagnosticFactory("Cannot find a parameter with this name");//SimpleDiagnosticFactory.create(ERROR, "Cannot find a parameter with this name");
SimpleDiagnosticFactory VARARG_OUTSIDE_PARENTHESES = SimpleDiagnosticFactory.create(ERROR, "Passing value as a vararg is only allowed inside a parenthesized argument list");
DiagnosticFactory<PsiElement> MIXING_NAMED_AND_POSITIONED_ARGUMENTS = DiagnosticFactory.create(ERROR, "Mixing named and positioned arguments in not allowed");
DiagnosticFactory<JetReferenceExpression> ARGUMENT_PASSED_TWICE = DiagnosticFactory.create(ERROR, "An argument is already passed for this parameter");
UnresolvedReferenceDiagnosticFactory NAMED_PARAMETER_NOT_FOUND = UnresolvedReferenceDiagnosticFactory.create("Cannot find a parameter with this name");
DiagnosticFactory<JetExpression> VARARG_OUTSIDE_PARENTHESES = DiagnosticFactory.create(ERROR, "Passing value as a vararg is only allowed inside a parenthesized argument list");
SimpleDiagnosticFactory MANY_FUNCTION_LITERAL_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Only one function literal is allowed outside a parenthesized argument list");
SimpleDiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR, "This property must either have a type annotation or be initialized");
DiagnosticFactory<JetExpression> MANY_FUNCTION_LITERAL_ARGUMENTS = DiagnosticFactory.create(ERROR, "Only one function literal is allowed outside a parenthesized argument list");
DiagnosticFactory<PsiElement> PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory.create(ERROR, "This property must either have a type annotation or be initialized");
SimpleDiagnosticFactory FUNCTION_WITH_NO_TYPE_NO_BODY = SimpleDiagnosticFactory.create(ERROR, "This function must either declare a return type or have a body element");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "This property cannot be declared abstract");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_NOT_IN_CLASS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait");
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParameterFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticFactory<JetElement> FUNCTION_WITH_NO_TYPE_NO_BODY = DiagnosticFactory.create(ERROR, "This function must either declare a return type or have a body element");
DiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory.create(ERROR, "This property cannot be declared abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory<JetProperty> ABSTRACT_PROPERTY_NOT_IN_CLASS = DiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory<JetExpression> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticFactory.create(ERROR, "Property with initializer cannot be abstract");
DiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticFactory.create(ERROR, "Property with getter implementation cannot be abstract");
DiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticFactory.create(ERROR, "Property with setter implementation cannot be abstract");
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticWithParameterFactory.create(ERROR, "Getter visibility must be the same as property visibility", DiagnosticParameters.MODIFIER);
SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field");
SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "Property must be initialized");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
DiagnosticFactory<PsiElement> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticFactory.create(ERROR, "Getter visibility must be the same as property visibility");
DiagnosticFactory BACKING_FIELD_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field");
DiagnosticFactory MUST_BE_INITIALIZED = DiagnosticFactory.create(ERROR, "Property must be initialized");
DiagnosticFactory<PsiElement> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
DiagnosticFactory<JetExpression> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits");
DiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
DiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract property {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = DiagnosticFactory3.create(ERROR, "Abstract function {0} in non-abstract class {1}", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory1<PsiElement, NamedFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = DiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
DiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = DiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract", PositioningStrategies.POSITION_NAME_IDENTIFIER);
DiagnosticFactory1<JetModifierListOwner, NamedFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = DiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract", PositioningStrategies.POSITION_ABSTRACT_MODIFIER);
DiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = DiagnosticFactory1.create(ERROR, "Function {0} must have a body", PositioningStrategies.POSITION_NAME_IDENTIFIER);
DiagnosticFactory<PsiElement> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticFactory.create(ERROR, "Non final member in a final class");
DiagnosticFactory<PsiElement> PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = DiagnosticFactory.create(ERROR, "Public or protected member should specify a type");
DiagnosticFactory<JetTypeProjection> PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = DiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
DiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED = DiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
DiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED_DEFAULT = DiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
DiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = DiagnosticFactory.create(ERROR, "A secondary constructor may appear only in a class that has a primary constructor");
DiagnosticFactory<PsiElement> SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = DiagnosticFactory.create(ERROR, "Secondary constructors must have an initializer list");
DiagnosticFactory<JetDelegatorByExpressionSpecifier> BY_IN_SECONDARY_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
DiagnosticFactory<JetDelegatorToSuperClass> INITIALIZER_WITH_NO_ARGUMENTS = DiagnosticFactory.create(ERROR, "Constructor arguments required");
DiagnosticFactory<JetDelegationSpecifier> MANY_CALLS_TO_THIS = DiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
DiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, "{0} overrides nothing", PositioningStrategies.positionModifier(JetTokens.OVERRIDE_KEYWORD), DescriptorRenderer.TEXT);
DiagnosticFactory3<PsiNameIdentifierOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = DiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", PositioningStrategies.POSITION_NAME_IDENTIFIER, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory1<JetClass, ClassDescriptor> ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, "Missing delegation specifier ''{0}''", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR, "The type constructor of enum entry should be ''{0}''", NAME);
DiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
DiagnosticFactory1<JetSimpleNameExpression, ValueParameterDescriptor> UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR, "Parameter ''{0}'' is uninitialized here", NAME);
UnusedElementDiagnosticFactory<JetProperty, VariableDescriptor> UNUSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is never used", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
UnusedElementDiagnosticFactory<JetParameter, VariableDescriptor> UNUSED_PARAMETER = UnusedElementDiagnosticFactory.create(WARNING, "Parameter ''{0}'' is never used", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
UnusedElementDiagnosticFactory<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is assigned but never accessed", PositioningStrategies.POSITION_NAME_IDENTIFIER, NAME);
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING, "Variable ''{0}'' initializer is redundant", NAME);
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, TO_STRING);
DiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
DiagnosticFactory<JetElement> UNUSED_EXPRESSION = DiagnosticFactory.create(WARNING, "The expression is unused");
DiagnosticFactory<JetFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = DiagnosticFactory.create(WARNING, "The function literal is unused. If you mean block, you can use 'run { ... }'");
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VAL_REASSIGNMENT = DiagnosticFactory1.create(ERROR, "Val can not be reassigned", NAME);
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_BEFORE_DECLARATION = DiagnosticFactory1.create(ERROR, "Variable cannot be initialized before declaration", NAME);
DiagnosticFactory<JetExpression> VARIABLE_EXPECTED = DiagnosticFactory.create(ERROR, "Variable expected");
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER = DiagnosticFactory1.create(ERROR, "This property has a custom setter, so initialization using backing field required", NAME);
DiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER = DiagnosticFactory1.create(ERROR, "Setter of this property can be overridden, so initialization using backing field required", NAME);
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> FUNCTION_PARAMETERS_OF_INLINE_FUNCTION = DiagnosticFactory1.create(ERROR, "Function parameters of inline function can only be invoked", NAME);
DiagnosticFactory<JetElement> UNREACHABLE_CODE = DiagnosticFactory.create(ERROR, "Unreachable code");
DiagnosticFactory<JetClassObject> MANY_CLASS_OBJECTS = DiagnosticFactory.create(ERROR, "Only one class object is allowed per class");
DiagnosticFactory<JetClassObject> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory.create(ERROR, "A class object is not allowed here");
DiagnosticFactory<JetDelegatorByExpressionSpecifier> DELEGATION_IN_TRAIT = DiagnosticFactory.create(ERROR, "Traits cannot use delegation");
DiagnosticFactory<JetTypeReference> DELEGATION_NOT_TO_TRAIT = DiagnosticFactory.create(ERROR, "Only traits can be delegated to");
DiagnosticFactory<PsiElement> NO_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "This class does not have a constructor");
DiagnosticFactory<JetExpression> NOT_A_CLASS = DiagnosticFactory.create(ERROR, "Not a class");
DiagnosticFactory<JetEscapeStringTemplateEntry> ILLEGAL_ESCAPE_SEQUENCE = DiagnosticFactory.create(ERROR, "Illegal escape sequence");
DiagnosticFactory<JetTypeReference> LOCAL_EXTENSION_PROPERTY = DiagnosticFactory.create(ERROR, "Local extension properties are not allowed");
DiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_GETTER = DiagnosticFactory.create(ERROR, "Local variables are not allowed to have getters");
DiagnosticFactory<JetPropertyAccessor> LOCAL_VARIABLE_WITH_SETTER = DiagnosticFactory.create(ERROR, "Local variables are not allowed to have setters");
DiagnosticFactory<JetPropertyAccessor> VAL_WITH_SETTER = DiagnosticFactory.create(ERROR, "A 'val'-property cannot have a setter");
DiagnosticFactory<JetArrayAccessExpression> NO_GET_METHOD = DiagnosticFactory.create(ERROR, "No get method providing array access", new PositioningStrategy<JetArrayAccessExpression>() {
@NotNull
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) {
return super.on(elementToBlame, textRangeToMark, s, classDescriptor, aClass).add(DiagnosticParameters.CLASS, aClass);
@Override
public List<TextRange> mark(@NotNull JetArrayAccessExpression element) {
return markElement(element.getIndicesNode());
}
};
PsiElementOnlyDiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass>(ERROR, "Abstract function {0} in non-abstract class {1}") {
});
DiagnosticFactory<JetArrayAccessExpression> NO_SET_METHOD = DiagnosticFactory.create(ERROR, "No set method providing array access", new PositioningStrategy<JetArrayAccessExpression>() {
@NotNull
public DiagnosticWithPsiElement<JetFunction> on(@NotNull JetFunction elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass modifierListOwner) {
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
}
};
PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract");
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, SimpleFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract");
PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body");
DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS);
DiagnosticWithParameterFactory<JetNamedDeclaration, JetType> PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Public or protected member should specify a type", DiagnosticParameters.TYPE);
SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
SimplePsiElementOnlyDiagnosticFactory<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = SimpleDiagnosticFactory.create(ERROR, "A secondary constructor may appear only in a class that has a primary constructor");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = SimpleDiagnosticFactory.create(ERROR, "Secondary constructors must have an initializer list");
SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required");
SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
PsiElementOnlyDiagnosticFactory1<JetModifierList, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT);
ParameterizedDiagnosticFactory1<ClassDescriptor> ENUM_ENTRY_SHOULD_BE_INITIALIZED = ParameterizedDiagnosticFactory1.create(ERROR, "Missing delegation specifier ''{0}''", NAME);
ParameterizedDiagnosticFactory1<ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = ParameterizedDiagnosticFactory1.create(ERROR, "The type constructor of enum entry should be ''{0}''", NAME);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, ValueParameterDescriptor> UNINITIALIZED_PARAMETER = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Parameter ''{0}'' is uninitialized here", NAME);
UnusedElementDiagnosticFactory<JetProperty, VariableDescriptor> UNUSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is never used", NAME);
UnusedElementDiagnosticFactory<JetParameter, VariableDescriptor> UNUSED_PARAMETER = UnusedElementDiagnosticFactory.create(WARNING, "Parameter ''{0}'' is never used", NAME);
UnusedElementDiagnosticFactory<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is assigned but never accessed", NAME);
PsiElementOnlyDiagnosticFactory1<JetNamedDeclaration, DeclarationDescriptor> VARIABLE_WITH_REDUNDANT_INITIALIZER = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Variable ''{0}'' initializer is redundant", NAME);
PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = new PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor>(WARNING, "The value ''{0}'' assigned to ''{1}'' is never used", NAME) {
@Override
protected String makeMessageForA(@NotNull JetElement element) {
return element.getText();
public List<TextRange> mark(@NotNull JetArrayAccessExpression element) {
return markElement(element.getIndicesNode());
}
};
PsiElementOnlyDiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = new PsiElementOnlyDiagnosticFactory1<JetElement, JetElement>(WARNING, "The value changed at ''{0}'' is never used", NAME) {
@Override
protected String makeMessageFor(JetElement argument) {
return argument.getText();
}
};
SimpleDiagnosticFactory UNUSED_EXPRESSION = SimpleDiagnosticFactory.create(WARNING, "The expression is unused");
SimplePsiElementOnlyDiagnosticFactory<JetFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "The function literal is unused. If you mean block, you can use 'run { ... }'");
});
PsiElementOnlyDiagnosticFactory1<JetExpression, DeclarationDescriptor> VAL_REASSIGNMENT = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Val can not be reassigned", NAME);
PsiElementOnlyDiagnosticFactory1<JetExpression, DeclarationDescriptor> INITIALIZATION_BEFORE_DECLARATION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable cannot be initialized before declaration", NAME);
SimplePsiElementOnlyDiagnosticFactory<JetExpression> VARIABLE_EXPECTED = new SimplePsiElementOnlyDiagnosticFactory<JetExpression>(ERROR, "Variable expected");
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This property has a custom setter, so initialization using backing field required", NAME);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Setter of this property can be overridden, so initialization using backing field required", NAME);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> FUNCTION_PARAMETERS_OF_INLINE_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function parameters of inline function can only be invoked", NAME);
SimpleDiagnosticFactory UNREACHABLE_CODE = SimpleDiagnosticFactory.create(ERROR, "Unreachable code");
SimpleDiagnosticFactory MANY_CLASS_OBJECTS = SimpleDiagnosticFactory.create(ERROR, "Only one class object is allowed per class");
SimpleDiagnosticFactory CLASS_OBJECT_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "A class object is not allowed here");
SimpleDiagnosticFactory DELEGATION_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Traits cannot use delegation");
SimpleDiagnosticFactory DELEGATION_NOT_TO_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Only traits can be delegated to");
SimpleDiagnosticFactory NO_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "This class does not have a constructor");
SimpleDiagnosticFactory NOT_A_CLASS = SimpleDiagnosticFactory.create(ERROR, "Not a class");
SimpleDiagnosticFactory ILLEGAL_ESCAPE_SEQUENCE = SimpleDiagnosticFactory.create(ERROR, "Illegal escape sequence");
SimpleDiagnosticFactory LOCAL_EXTENSION_PROPERTY = SimpleDiagnosticFactory.create(ERROR, "Local extension properties are not allowed");
SimpleDiagnosticFactory LOCAL_VARIABLE_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR, "Local variables are not allowed to have getters");
SimpleDiagnosticFactory LOCAL_VARIABLE_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR, "Local variables are not allowed to have setters");
SimplePsiElementOnlyDiagnosticFactory<JetProperty> VAL_WITH_SETTER = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "A 'val'-property cannot have a setter");
SimpleDiagnosticFactory NO_GET_METHOD = SimpleDiagnosticFactory.create(ERROR, "No get method providing array access");
SimpleDiagnosticFactory NO_SET_METHOD = SimpleDiagnosticFactory.create(ERROR, "No set method providing array access");
SimpleDiagnosticFactory INC_DEC_SHOULD_NOT_RETURN_UNIT = SimpleDiagnosticFactory.create(ERROR, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --");
ParameterizedDiagnosticFactory2<DeclarationDescriptor, JetSimpleNameExpression> ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT = new ParameterizedDiagnosticFactory2<DeclarationDescriptor, JetSimpleNameExpression>(ERROR, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", NAME) {
@Override
protected String makeMessageForB(@NotNull JetSimpleNameExpression expression) {
return expression.getText();
}
};
DiagnosticFactory<JetSimpleNameExpression> INC_DEC_SHOULD_NOT_RETURN_UNIT = DiagnosticFactory.create(ERROR, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --");
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, JetSimpleNameExpression> ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT =
DiagnosticFactory2.create(ERROR, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", NAME, ELEMENT_TEXT);
AmbiguousDescriptorDiagnosticFactory ASSIGN_OPERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create("Assignment operators ambiguity: {0}");
SimpleDiagnosticFactory EQUALS_MISSING = SimpleDiagnosticFactory.create(ERROR, "No method 'equals(Any?) : Boolean' available");
SimpleDiagnosticFactory ASSIGNMENT_IN_EXPRESSION_CONTEXT = SimpleDiagnosticFactory.create(ERROR, "Assignments are not expressions, and only expressions are allowed in this context");
SimpleDiagnosticFactory NAMESPACE_IS_NOT_AN_EXPRESSION = SimpleDiagnosticFactory.create(ERROR, "'namespace' is not an expression, it can only be used on the left-hand side of a dot ('.')");
ParameterizedDiagnosticFactory1<String> SUPER_IS_NOT_AN_EXPRESSION = ParameterizedDiagnosticFactory1.create(ERROR, "{0} is not an expression, it can only be used on the left-hand side of a dot ('.')");
SimpleDiagnosticFactory DECLARATION_IN_ILLEGAL_CONTEXT = SimpleDiagnosticFactory.create(ERROR, "Declarations are not allowed in this position");
SimpleDiagnosticFactory SETTER_PARAMETER_WITH_DEFAULT_VALUE = SimpleDiagnosticFactory.create(ERROR, "Setter parameters can not have default values");
SimpleDiagnosticFactory NO_THIS = SimpleDiagnosticFactory.create(ERROR, "'this' is not defined in this context");
SimpleDiagnosticFactory SUPER_NOT_AVAILABLE = SimpleDiagnosticFactory.create(ERROR, "No supertypes are accessible in this context");
SimpleDiagnosticFactory AMBIGUOUS_SUPER = SimpleDiagnosticFactory.create(ERROR, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'");
SimpleDiagnosticFactory ABSTRACT_SUPER_CALL = SimpleDiagnosticFactory.create(ERROR, "Abstarct member cannot be accessed directly");
SimpleDiagnosticFactory NOT_A_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, "Not a supertype");
SimpleDiagnosticFactory TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER = SimpleDiagnosticFactory.create(WARNING, "Type arguments do not need to be specified in a 'super' qualifier");
SimpleDiagnosticFactory NO_WHEN_ENTRIES = SimpleDiagnosticFactory.create(ERROR, "Entries are required for when-expression"); // TODO : Scope, and maybe this should not be an error
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST_STATIC_ASSERT_IS_FINE = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed, use ':' instead");
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed");
SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed");
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Please specify constructor invocation; classifier {0} does not have a class object", NAME);
SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
DiagnosticFactory<JetSimpleNameExpression> EQUALS_MISSING = DiagnosticFactory.create(ERROR, "No method 'equals(Any?) : Boolean' available");
DiagnosticFactory<JetBinaryExpression> ASSIGNMENT_IN_EXPRESSION_CONTEXT = DiagnosticFactory.create(ERROR, "Assignments are not expressions, and only expressions are allowed in this context");
DiagnosticFactory<JetRootNamespaceExpression> NAMESPACE_IS_NOT_AN_EXPRESSION = DiagnosticFactory.create(ERROR, "'namespace' is not an expression, it can only be used on the left-hand side of a dot ('.')");
DiagnosticFactory1<JetSuperExpression, String> SUPER_IS_NOT_AN_EXPRESSION = DiagnosticFactory1.create(ERROR, "{0} is not an expression, it can only be used on the left-hand side of a dot ('.')");
DiagnosticFactory<JetDeclaration> DECLARATION_IN_ILLEGAL_CONTEXT = DiagnosticFactory.create(ERROR, "Declarations are not allowed in this position");
DiagnosticFactory<JetExpression> SETTER_PARAMETER_WITH_DEFAULT_VALUE = DiagnosticFactory.create(ERROR, "Setter parameters can not have default values");
DiagnosticFactory<JetThisExpression> NO_THIS = DiagnosticFactory.create(ERROR, "'this' is not defined in this context");
DiagnosticFactory<JetSuperExpression> SUPER_NOT_AVAILABLE = DiagnosticFactory.create(ERROR, "No supertypes are accessible in this context");
DiagnosticFactory<JetSuperExpression> AMBIGUOUS_SUPER = DiagnosticFactory.create(ERROR, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'");
DiagnosticFactory<JetExpression> ABSTRACT_SUPER_CALL = DiagnosticFactory.create(ERROR, "Abstarct member cannot be accessed directly");
DiagnosticFactory<JetTypeReference> NOT_A_SUPERTYPE = DiagnosticFactory.create(ERROR, "Not a supertype");
DiagnosticFactory<PsiElement> TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER = DiagnosticFactory.create(WARNING, "Type arguments do not need to be specified in a 'super' qualifier");
DiagnosticFactory<JetWhenExpression> NO_WHEN_ENTRIES = DiagnosticFactory.create(ERROR, "Entries are required for when-expression"); // TODO : Scope, and maybe this should not be an error
DiagnosticFactory<JetSimpleNameExpression> USELESS_CAST_STATIC_ASSERT_IS_FINE = DiagnosticFactory.create(WARNING, "No cast needed, use ':' instead");
DiagnosticFactory<JetSimpleNameExpression> USELESS_CAST = DiagnosticFactory.create(WARNING, "No cast needed");
DiagnosticFactory<JetSimpleNameExpression> CAST_NEVER_SUCCEEDS = DiagnosticFactory.create(WARNING, "This cast can never succeed");
DiagnosticFactory1<JetTypeReference, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticFactory1.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}");//, DiagnosticParameters.TYPE);
DiagnosticFactory1<JetTypeReference, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory1.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}");//, DiagnosticParameters.TYPE);
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_CLASS_OBJECT = DiagnosticFactory1.create(ERROR, "Please specify constructor invocation; classifier {0} does not have a class object", NAME);
DiagnosticFactory<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = DiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
SimpleDiagnosticFactory HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
SimpleDiagnosticFactory HAS_NEXT_MISSING = SimpleDiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
SimpleDiagnosticFactory HAS_NEXT_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "Function 'iterator().hasNext()' is ambiguous for this expression");
SimpleDiagnosticFactory HAS_NEXT_MUST_BE_READABLE = SimpleDiagnosticFactory.create(ERROR, "The 'iterator().hasNext' property of the loop range must be readable");
ParameterizedDiagnosticFactory1<JetType> HAS_NEXT_PROPERTY_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns {0}");
ParameterizedDiagnosticFactory1<JetType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "The 'iterator().hasNext()' function of the loop range must return Boolean, but returns {0}");
SimpleDiagnosticFactory NEXT_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "Function 'iterator().next()' is ambiguous for this expression");
SimpleDiagnosticFactory NEXT_MISSING = SimpleDiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().next()' function");
SimpleDiagnosticFactory ITERATOR_MISSING = SimpleDiagnosticFactory.create(ERROR, "For-loop range must have an iterator() method");
DiagnosticFactory<JetExpression> HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = DiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
DiagnosticFactory<JetExpression> HAS_NEXT_MISSING = DiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
DiagnosticFactory<JetExpression> HAS_NEXT_FUNCTION_AMBIGUITY = DiagnosticFactory.create(ERROR, "Function 'iterator().hasNext()' is ambiguous for this expression");
DiagnosticFactory<JetExpression> HAS_NEXT_MUST_BE_READABLE = DiagnosticFactory.create(ERROR, "The 'iterator().hasNext' property of the loop range must be readable");
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_PROPERTY_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns {0}");
DiagnosticFactory1<JetExpression, JetType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "The 'iterator().hasNext()' function of the loop range must return Boolean, but returns {0}");
DiagnosticFactory<JetExpression> NEXT_AMBIGUITY = DiagnosticFactory.create(ERROR, "Function 'iterator().next()' is ambiguous for this expression");
DiagnosticFactory<JetExpression> NEXT_MISSING = DiagnosticFactory.create(ERROR, "Loop range must have an 'iterator().next()' function");
DiagnosticFactory<JetExpression> ITERATOR_MISSING = DiagnosticFactory.create(ERROR, "For-loop range must have an iterator() method");
AmbiguousDescriptorDiagnosticFactory ITERATOR_AMBIGUITY = AmbiguousDescriptorDiagnosticFactory.create("Method 'iterator()' is ambiguous for this expression: {0}");
ParameterizedDiagnosticFactory1<JetType> COMPARE_TO_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "compareTo() must return Int, but returns {0}");
ParameterizedDiagnosticFactory1<JetType> CALLEE_NOT_A_FUNCTION = ParameterizedDiagnosticFactory1.create(ERROR, "Expecting a function type, but found {0}");
DiagnosticFactory1<JetSimpleNameExpression, JetType> COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "compareTo() must return Int, but returns {0}");
DiagnosticFactory1<JetExpression, JetType> CALLEE_NOT_A_FUNCTION = DiagnosticFactory1.create(ERROR, "Expecting a function type, but found {0}");
SimpleDiagnosticFactory RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = SimpleDiagnosticFactory.create(ERROR, "Returns are not allowed for functions with expression body. Use block body in '{...}'");
SimpleDiagnosticFactory NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = SimpleDiagnosticFactory.create(ERROR, "A 'return' expression required in a function with a block body ('{...}')");
ParameterizedDiagnosticFactory1<JetType> RETURN_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "This function must return a value of type {0}");
ParameterizedDiagnosticFactory1<JetType> EXPECTED_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "Expected a value of type {0}");
ParameterizedDiagnosticFactory1<JetType> ASSIGNMENT_TYPE_MISMATCH = ParameterizedDiagnosticFactory1.create(ERROR, "Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value");
ParameterizedDiagnosticFactory1<JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = ParameterizedDiagnosticFactory1.create(WARNING, "Type was casted to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast");
ParameterizedDiagnosticFactory1<JetExpression> EXPRESSION_EXPECTED = new ParameterizedDiagnosticFactory1<JetExpression>(ERROR, "{0} is not an expression, and only expression are allowed here") {
DiagnosticFactory<JetReturnExpression> RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = DiagnosticFactory.create(ERROR, "Returns are not allowed for functions with expression body. Use block body in '{...}'");
DiagnosticFactory<JetExpression> NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory.create(ERROR, "A 'return' expression required in a function with a block body ('{...}')");
DiagnosticFactory1<JetExpression, JetType> RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "This function must return a value of type {0}");
DiagnosticFactory1<JetExpression, JetType> EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "Expected a value of type {0}");
DiagnosticFactory1<JetBinaryExpression, JetType> ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR, "Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value");
DiagnosticFactory1<JetExpression, JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING, "Type was casted to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast");
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR, "{0} is not an expression, and only expression are allowed here", new Renderer<JetExpression>() {
@NotNull
@Override
protected String makeMessageFor(JetExpression expression) {
public String render(@Nullable JetExpression expression) {
assert expression != null;
String expressionType = expression.toString();
return expressionType.substring(0, 1) + expressionType.substring(1).toLowerCase();
}
};
});
ParameterizedDiagnosticFactory1<JetType> UPPER_BOUND_VIOLATED = ParameterizedDiagnosticFactory1.create(ERROR, "An upper bound {0} is violated"); // TODO : Message
ParameterizedDiagnosticFactory1<JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = ParameterizedDiagnosticFactory1.create(ERROR, "{0} is a final type, and thus a class object cannot extend it");
ParameterizedDiagnosticFactory1<JetType> FINAL_UPPER_BOUND = ParameterizedDiagnosticFactory1.create(WARNING, "{0} is a final type, and thus a value of the type parameter is predetermined");
PsiElementOnlyDiagnosticFactory1<JetBinaryExpression, JetType> USELESS_ELVIS = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Elvis operator (?:) always returns the left operand of non-nullable type {0}");
ParameterizedDiagnosticFactory1<TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS = new ParameterizedDiagnosticFactory1<TypeParameterDescriptor>(ERROR, "Upper bounds of {0} have empty intersection") {
@Override
protected String makeMessageFor(@NotNull TypeParameterDescriptor argument) {
return argument.getName();
}
};
ParameterizedDiagnosticFactory1<TypeParameterDescriptor> CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS = ParameterizedDiagnosticFactory1.create(ERROR, "Class object upper bounds of {0} have empty intersection", NAME);
DiagnosticFactory1<JetTypeReference, JetType> UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR, "An upper bound {0} is violated"); // TODO : Message
DiagnosticFactory1<JetTypeReference, JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR, "{0} is a final type, and thus a class object cannot extend it");
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING, "{0} is a final type, and thus a value of the type parameter is predetermined");
DiagnosticFactory1<JetExpression, JetType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING, "Elvis operator (?:) always returns the left operand of non-nullable type {0}");
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR, "Upper bounds of {0} have empty intersection", NAME);
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS = DiagnosticFactory1.create(ERROR, "Class object upper bounds of {0} have empty intersection", NAME);
ParameterizedDiagnosticFactory1<CallableDescriptor> TOO_MANY_ARGUMENTS = ParameterizedDiagnosticFactory1.create(ERROR, "Too many arguments for {0}");
ParameterizedDiagnosticFactory1<String> ERROR_COMPILE_TIME_VALUE = ParameterizedDiagnosticFactory1.create(ERROR, "{0}");
DiagnosticFactory1<PsiElement, CallableDescriptor> TOO_MANY_ARGUMENTS = DiagnosticFactory1.create(ERROR, "Too many arguments for {0}");
DiagnosticFactory1<PsiElement, String> ERROR_COMPILE_TIME_VALUE = DiagnosticFactory1.create(ERROR, "{0}");
SimpleDiagnosticFactoryWithPsiElement<JetWhenEntry> ELSE_MISPLACED_IN_WHEN = new SimpleDiagnosticFactoryWithPsiElement<JetWhenEntry>(ERROR, "'else' entry must be the last one in a when-expression") {
DiagnosticFactory<JetWhenEntry> ELSE_MISPLACED_IN_WHEN = DiagnosticFactory.create(
ERROR, "'else' entry must be the last one in a when-expression", new PositioningStrategy<JetWhenEntry>() {
@NotNull
@Override
public TextRange getTextRange(@NotNull JetWhenEntry entry) {
public List<TextRange> mark(@NotNull JetWhenEntry entry) {
PsiElement elseKeywordElement = entry.getElseKeywordElement();
assert elseKeywordElement != null;
return elseKeywordElement.getTextRange();
return markElement(elseKeywordElement);
}
};
SimpleDiagnosticFactoryWithPsiElement<JetWhenExpression> NO_ELSE_IN_WHEN = new SimpleDiagnosticFactoryWithPsiElement<JetWhenExpression>(ERROR, "'when' expression must contain 'else' branch") {
});
DiagnosticFactory<JetWhenExpression> NO_ELSE_IN_WHEN = new DiagnosticFactory<JetWhenExpression>(ERROR, "'when' expression must contain 'else' branch", new PositioningStrategy<JetWhenExpression>() {
@NotNull
@Override
public TextRange getTextRange(@NotNull JetWhenExpression element) {
return element.getWhenKeywordElement().getTextRange();
public List<TextRange> mark(@NotNull JetWhenExpression element) {
return markElement(element.getWhenKeywordElement());
}
};
SimpleDiagnosticFactoryWithPsiElement<JetWhenConditionInRange> TYPE_MISMATCH_IN_RANGE = new SimpleDiagnosticFactoryWithPsiElement<JetWhenConditionInRange>(ERROR, "Type mismatch: incompatible types of range and element checked in it") {
});
DiagnosticFactory<JetWhenConditionInRange> TYPE_MISMATCH_IN_RANGE = new DiagnosticFactory<JetWhenConditionInRange>(ERROR, "Type mismatch: incompatible types of range and element checked in it", new PositioningStrategy<JetWhenConditionInRange>() {
@NotNull
@Override
public TextRange getTextRange(@NotNull JetWhenConditionInRange condition) {
return condition.getOperationReference().getTextRange();
public List<TextRange> mark(@NotNull JetWhenConditionInRange condition) {
return markElement(condition.getOperationReference());
}
};
SimpleDiagnosticFactory CYCLIC_INHERITANCE_HIERARCHY = SimpleDiagnosticFactory.create(ERROR, "There's a cycle in the inheritance hierarchy for this type");
});
DiagnosticFactory<PsiElement> CYCLIC_INHERITANCE_HIERARCHY = DiagnosticFactory.create(ERROR, "There's a cycle in the inheritance hierarchy for this type");
SimpleDiagnosticFactory MANY_CLASSES_IN_SUPERTYPE_LIST = SimpleDiagnosticFactory.create(ERROR, "Only one class may appear in a supertype list");
SimpleDiagnosticFactory SUPERTYPE_NOT_A_CLASS_OR_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Only classes and traits may serve as supertypes");
SimpleDiagnosticFactory SUPERTYPE_INITIALIZED_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Traits cannot initialize supertypes");
SimpleDiagnosticFactory CONSTRUCTOR_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "A trait may not have a constructor");
SimpleDiagnosticFactory SUPERTYPE_APPEARS_TWICE = SimpleDiagnosticFactory.create(ERROR, "A supertype appears twice");
SimpleDiagnosticFactory FINAL_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, "This type is final, so it cannot be inherited from");
DiagnosticFactory<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory.create(ERROR, "Only one class may appear in a supertype list");
DiagnosticFactory<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = DiagnosticFactory.create(ERROR, "Only classes and traits may serve as supertypes");
DiagnosticFactory<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = DiagnosticFactory.create(ERROR, "Traits cannot initialize supertypes");
DiagnosticFactory<PsiElement> CONSTRUCTOR_IN_TRAIT = DiagnosticFactory.create(ERROR, "A trait may not have a constructor");
DiagnosticFactory<JetTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory.create(ERROR, "A supertype appears twice");
DiagnosticFactory<JetTypeReference> FINAL_SUPERTYPE = DiagnosticFactory.create(ERROR, "This type is final, so it cannot be inherited from");
ParameterizedDiagnosticFactory1<String> ILLEGAL_SELECTOR = ParameterizedDiagnosticFactory1.create(ERROR, "Expression ''{0}'' cannot be a selector (occur after a dot)");
DiagnosticFactory1<JetExpression, String> ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR, "Expression ''{0}'' cannot be a selector (occur after a dot)");
SimpleDiagnosticFactory VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = SimpleDiagnosticFactory.create(ERROR, "A type annotation is required on a value parameter");
SimpleDiagnosticFactory BREAK_OR_CONTINUE_OUTSIDE_A_LOOP = SimpleDiagnosticFactory.create(ERROR, "'break' and 'continue' are only allowed inside a loop");
ParameterizedDiagnosticFactory1<String> NOT_A_LOOP_LABEL = ParameterizedDiagnosticFactory1.create(ERROR, "The label ''{0}'' does not denote a loop");
ParameterizedDiagnosticFactory1<String> NOT_A_RETURN_LABEL = ParameterizedDiagnosticFactory1.create(ERROR, "The label ''{0}'' does not reference to a context from which we can return");
DiagnosticFactory<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory.create(ERROR, "A type annotation is required on a value parameter");
DiagnosticFactory<JetLabelQualifiedExpression> BREAK_OR_CONTINUE_OUTSIDE_A_LOOP = DiagnosticFactory.create(ERROR, "'break' and 'continue' are only allowed inside a loop");
DiagnosticFactory1<JetLabelQualifiedExpression, String> NOT_A_LOOP_LABEL = DiagnosticFactory1.create(ERROR, "The label ''{0}'' does not denote a loop");
DiagnosticFactory1<JetReturnExpression, String> NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR, "The label ''{0}'' does not reference to a context from which we can return");
SimpleDiagnosticFactory ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "Anonymous initializers are only allowed in the presence of a primary constructor");
SimpleDiagnosticFactory NULLABLE_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, "A supertype cannot be nullable");
ParameterizedDiagnosticFactory1<JetType> UNSAFE_CALL = ParameterizedDiagnosticFactory1.create(ERROR, "Only safe calls (?.) are allowed on a nullable receiver of type {0}");
SimpleDiagnosticFactory AMBIGUOUS_LABEL = SimpleDiagnosticFactory.create(ERROR, "Ambiguous label");
ParameterizedDiagnosticFactory1<String> UNSUPPORTED = ParameterizedDiagnosticFactory1.create(ERROR, "Unsupported [{0}]");
ParameterizedDiagnosticFactory1<JetType> UNNECESSARY_SAFE_CALL = ParameterizedDiagnosticFactory1.create(WARNING, "Unnecessary safe call on a non-null receiver of type {0}");
ParameterizedDiagnosticFactory2<JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER = new ParameterizedDiagnosticFactory2<JetTypeConstraint, JetTypeParameterListOwner>(ERROR, "{0} does not refer to a type parameter of {1}") {
DiagnosticFactory<JetClassInitializer> ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = DiagnosticFactory.create(ERROR, "Anonymous initializers are only allowed in the presence of a primary constructor");
DiagnosticFactory<JetNullableType> NULLABLE_SUPERTYPE = DiagnosticFactory.create(ERROR, "A supertype cannot be nullable", new PositioningStrategy<JetNullableType>() {
@NotNull
@Override
protected String makeMessageForA(@NotNull JetTypeConstraint jetTypeConstraint) {
return jetTypeConstraint.getSubjectTypeParameterName().getReferencedName();
public List<TextRange> mark(@NotNull JetNullableType element) {
return markNode(element.getQuestionMarkNode());
}
});
DiagnosticFactory1<PsiElement, JetType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR, "Only safe calls (?.) are allowed on a nullable receiver of type {0}");
DiagnosticFactory<JetSimpleNameExpression> AMBIGUOUS_LABEL = DiagnosticFactory.create(ERROR, "Ambiguous label");
DiagnosticFactory1<PsiElement, String> UNSUPPORTED = DiagnosticFactory1.create(ERROR, "Unsupported [{0}]");
DiagnosticFactory1<PsiElement, JetType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING, "Unnecessary safe call on a non-null receiver of type {0}");
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER = DiagnosticFactory2.create(ERROR, "{0} does not refer to a type parameter of {1}", new Renderer<JetTypeConstraint>() {
@NotNull
@Override
protected String makeMessageForB(@NotNull JetTypeParameterListOwner constraintOwner) {
return constraintOwner.getName();
public String render(@Nullable JetTypeConstraint typeConstraint) {
assert typeConstraint != null;
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
}
};
ParameterizedDiagnosticFactory2<JetType, String> AUTOCAST_IMPOSSIBLE = ParameterizedDiagnosticFactory2.create(ERROR, "Automatic cast to {0} is impossible, because {1} could have changed since the is-check");
}, NAME);
DiagnosticFactory2<JetExpression, JetType, String> AUTOCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR, "Automatic cast to {0} is impossible, because {1} could have changed since the is-check");
ParameterizedDiagnosticFactory2<JetType, JetType> TYPE_MISMATCH_IN_FOR_LOOP = ParameterizedDiagnosticFactory2.create(ERROR, "The loop iterates over values of type {0} but the parameter is declared to be {1}");
ParameterizedDiagnosticFactory1<JetType> TYPE_MISMATCH_IN_CONDITION = ParameterizedDiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}");
ParameterizedDiagnosticFactory2<JetType, Integer> TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message
ParameterizedDiagnosticFactory2<JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}");
ParameterizedDiagnosticFactory2<JetType, JetType> INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}");
SimpleDiagnosticFactory EXPECTED_CONDITION = SimpleDiagnosticFactory.create(ERROR, "Expected condition of Boolean type");
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_FOR_LOOP = DiagnosticFactory2.create(ERROR, "The loop iterates over values of type {0} but the parameter is declared to be {1}");
DiagnosticFactory1<JetElement, JetType> TYPE_MISMATCH_IN_CONDITION = DiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}");
DiagnosticFactory2<JetTuplePattern, JetType, Integer> TYPE_MISMATCH_IN_TUPLE_PATTERN = DiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message
DiagnosticFactory2<JetTypeReference, JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = DiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}");
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}");
DiagnosticFactory<JetWhenCondition> EXPECTED_CONDITION = DiagnosticFactory.create(ERROR, "Expected condition of Boolean type");
ParameterizedDiagnosticFactory1<JetType> CANNOT_CHECK_FOR_ERASED = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}");
ParameterizedDiagnosticFactory2<JetType, JetType> UNCHECKED_CAST = ParameterizedDiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}");
DiagnosticFactory1<JetElement, JetType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}");
DiagnosticFactory2<JetBinaryExpressionWithTypeRHS, JetType, JetType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}");
ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") {
@Override
protected String makeMessageForA(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
return typeParameterDescriptor.getName();
}
@Override
protected String makeMessageForB(@NotNull ClassDescriptor classDescriptor) {
return DescriptorRenderer.TEXT.render(classDescriptor);
}
@Override
protected String makeMessageForC(@NotNull Collection<JetType> jetTypes) {
StringBuilder builder = new StringBuilder();
for (Iterator<JetType> iterator = jetTypes.iterator(); iterator.hasNext(); ) {
JetType jetType = iterator.next();
builder.append(jetType);
if (iterator.hasNext()) {
builder.append(", ");
DiagnosticFactory3<JetDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<JetType>> INCONSISTENT_TYPE_PARAMETER_VALUES =
DiagnosticFactory3.create(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}", NAME, DescriptorRenderer.TEXT, new Renderer<Collection<JetType>>() {
@NotNull
@Override
public String render(@Nullable Collection<JetType> types) {
StringBuilder builder = new StringBuilder();
for (Iterator<JetType> iterator = types.iterator(); iterator.hasNext(); ) {
JetType jetType = iterator.next();
builder.append(jetType);
if (iterator.hasNext()) {
builder.append(", ");
}
}
return builder.toString();
}
}
return builder.toString();
}
};
ParameterizedDiagnosticFactory3<JetSimpleNameExpression, JetType, JetType> EQUALITY_NOT_APPLICABLE = new ParameterizedDiagnosticFactory3<JetSimpleNameExpression, JetType, JetType>(ERROR, "Operator {0} cannot be applied to {1} and {2}") {
});
DiagnosticFactory3<JetBinaryExpression, JetSimpleNameExpression, JetType, JetType> EQUALITY_NOT_APPLICABLE = DiagnosticFactory3.create(ERROR, "Operator {0} cannot be applied to {1} and {2}", new Renderer<JetSimpleNameExpression>() {
@NotNull
@Override
protected String makeMessageForA(@NotNull JetSimpleNameExpression nameExpression) {
public String render(@Nullable JetSimpleNameExpression nameExpression) {
return nameExpression.getReferencedName();
}
};
ParameterizedDiagnosticFactory2<CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER = ParameterizedDiagnosticFactory2.create(ERROR, "{0} in {1} is final and cannot be overridden", NAME);
}, TO_STRING, TO_STRING);
ParameterizedDiagnosticFactory2<CallableMemberDescriptor, CallableMemberDescriptor> RETURN_TYPE_MISMATCH_ON_OVERRIDE = new ParameterizedDiagnosticFactory2<CallableMemberDescriptor, CallableMemberDescriptor>(ERROR, "Return type of {0} is not a subtype of the return type overridden member {1}") {
DiagnosticFactory2<PsiElement, CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER = DiagnosticFactory2.create(ERROR, "{0} in {1} is final and cannot be overridden", NAME, NAME);
DiagnosticFactory2<JetNamedDeclaration, CallableMemberDescriptor, CallableMemberDescriptor> RETURN_TYPE_MISMATCH_ON_OVERRIDE =
DiagnosticFactory2.create(ERROR, "Return type of {0} is not a subtype of the return type overridden member {1}", PositioningStrategies.POSITION_DECLARATION, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory2<JetProperty, PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL = DiagnosticFactory2.create(ERROR, "Var-property {0} cannot be overridden by val-property {1}", new PositioningStrategy<JetProperty>() {
@NotNull
@Override
public List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic) {
PsiElement psiElement = ((DiagnosticWithPsiElement) diagnostic).getPsiElement();
JetTypeReference returnTypeRef = null;
ASTNode nameNode = null;
if (psiElement instanceof JetNamedFunction) {
JetFunction function = (JetNamedFunction) psiElement;
returnTypeRef = function.getReturnTypeRef();
nameNode = getNameNode(function);
public List<TextRange> mark(@NotNull JetProperty property) {
return markNode(property.getValOrVarNode());
}
}, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT);
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> ABSTRACT_MEMBER_NOT_IMPLEMENTED = DiagnosticFactory2.create(ERROR, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
DiagnosticFactory2<PsiElement, JetClassOrObject, CallableMemberDescriptor> MANY_IMPL_MEMBER_NOT_IMPLEMENTED = DiagnosticFactory2.create(ERROR, "{0} must override {1} because it inherits many implementations of it", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
DiagnosticFactory2<JetDeclaration, CallableMemberDescriptor, String> CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, "{1} is already defined in ''{0}''", new PositioningStrategy<JetDeclaration>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull JetDeclaration jetDeclaration) {
if (jetDeclaration instanceof JetNamedFunction) {
JetNamedFunction functionElement = (JetNamedFunction) jetDeclaration;
return markRange(new TextRange(
functionElement.getStartOfSignatureElement().getTextRange().getStartOffset(),
functionElement.getEndOfSignatureElement().getTextRange().getEndOffset()
));
}
else if (psiElement instanceof JetProperty) {
JetProperty property = (JetProperty) psiElement;
returnTypeRef = property.getPropertyTypeRef();
nameNode = getNameNode(property);
else if (jetDeclaration instanceof JetClass) {
// primary constructor
JetClass klass = (JetClass) jetDeclaration;
PsiElement nameAsDeclaration = klass.getNameIdentifier();
if (nameAsDeclaration == null) {
return markRange(klass.getTextRange());
}
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) {
return markRange(nameAsDeclaration.getTextRange());
}
return markRange(new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
));
}
else if (psiElement instanceof JetPropertyAccessor) {
JetPropertyAccessor accessor = (JetPropertyAccessor) psiElement;
returnTypeRef = accessor.getReturnTypeReference();
nameNode = accessor.getNamePlaceholder().getNode();
else {
// safe way
return markRange(jetDeclaration.getTextRange());
}
if (returnTypeRef != null) return Collections.singletonList(returnTypeRef.getTextRange());
if (nameNode != null) return Collections.singletonList(nameNode.getTextRange());
return super.getTextRanges(diagnostic);
}
private ASTNode getNameNode(JetNamedDeclaration function) {
PsiElement nameIdentifier = function.getNameIdentifier();
return nameIdentifier == null ? null : nameIdentifier.getNode();
}
@Override
protected String makeMessageForA(@NotNull CallableMemberDescriptor callableMemberDescriptor) {
return DescriptorRenderer.TEXT.render(callableMemberDescriptor);
}
@Override
protected String makeMessageForB(@NotNull CallableMemberDescriptor callableMemberDescriptor) {
return DescriptorRenderer.TEXT.render(callableMemberDescriptor);
}
};
ParameterizedDiagnosticFactory2<PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL = new ParameterizedDiagnosticFactory2<PropertyDescriptor, PropertyDescriptor>(ERROR, "Var-property {0} cannot be overridden by val-property {1}", DescriptorRenderer.TEXT);
ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor> ABSTRACT_MEMBER_NOT_IMPLEMENTED = new ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor>(ERROR, "{0} must be declared abstract or implement abstract member {1}") {
@Override
protected String makeMessageForA(@NotNull JetClassOrObject jetClassOrObject) {
String name = jetClassOrObject.getName() != null ? " '" + jetClassOrObject.getName() + "'" : "";
if (jetClassOrObject instanceof JetClass) {
return "Class" + name;
}
return "Object" + name;
}
@Override
protected String makeMessageForB(@NotNull CallableMemberDescriptor memberDescriptor) {
return DescriptorRenderer.TEXT.render(memberDescriptor);
}
};
ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor> MANY_IMPL_MEMBER_NOT_IMPLEMENTED = new ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor>(ERROR, "Class ''{0}'' must override {1} because it inherits many implementations of it") {
@Override
protected String makeMessageForA(@NotNull JetClassOrObject jetClassOrObject) {
return jetClassOrObject.getName();
}
@Override
protected String makeMessageForB(@NotNull CallableMemberDescriptor memberDescriptor) {
return DescriptorRenderer.TEXT.render(memberDescriptor);
}
};
FunctionSignatureDiagnosticFactory CONFLICTING_OVERLOADS = new FunctionSignatureDiagnosticFactory(ERROR, "{1} is already defined in ''{0}''");
}, DescriptorRenderer.TEXT, TO_STRING);
ParameterizedDiagnosticFactory3<String, JetType, JetType> RESULT_TYPE_MISMATCH = ParameterizedDiagnosticFactory3.create(ERROR, "{0} must return {1} but returns {2}");
ParameterizedDiagnosticFactory3<String, String, String> UNSAFE_INFIX_CALL = ParameterizedDiagnosticFactory3.create(ERROR, "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. Use '?.'-qualified call instead");
DiagnosticFactory3<JetExpression, String, JetType, JetType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR, "{0} must return {1} but returns {2}");
DiagnosticFactory3<JetReferenceExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR, "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. Use '?.'-qualified call instead");
AmbiguousDescriptorDiagnosticFactory OVERLOAD_RESOLUTION_AMBIGUITY = new AmbiguousDescriptorDiagnosticFactory("Overload resolution ambiguity: {0}");
AmbiguousDescriptorDiagnosticFactory NONE_APPLICABLE = new AmbiguousDescriptorDiagnosticFactory("None of the following functions can be called with the arguments supplied: {0}");
ParameterizedDiagnosticFactory1<ValueParameterDescriptor> NO_VALUE_FOR_PARAMETER = ParameterizedDiagnosticFactory1.create(ERROR, "No value passed for parameter {0}", DescriptorRenderer.TEXT);
ParameterizedDiagnosticFactory1<JetType> MISSING_RECEIVER = ParameterizedDiagnosticFactory1.create(ERROR, "A receiver of type {0} is required");
SimpleDiagnosticFactory NO_RECEIVER_ADMITTED = SimpleDiagnosticFactory.create(ERROR, "No receiver can be passed to this function or property");
DiagnosticFactory1<PsiElement, ValueParameterDescriptor> NO_VALUE_FOR_PARAMETER = DiagnosticFactory1.create(ERROR, "No value passed for parameter {0}", DescriptorRenderer.TEXT);
DiagnosticFactory1<JetReferenceExpression, JetType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR, "A receiver of type {0} is required");
DiagnosticFactory<JetReferenceExpression> NO_RECEIVER_ADMITTED = DiagnosticFactory.create(ERROR, "No receiver can be passed to this function or property");
SimpleDiagnosticFactory CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS = SimpleDiagnosticFactory.create(ERROR, "Can not create an instance of an abstract class");
ParameterizedDiagnosticFactory1<SolutionStatus> TYPE_INFERENCE_FAILED = ParameterizedDiagnosticFactory1.create(ERROR, "Type inference failed: {0}");
ParameterizedDiagnosticFactory1<Integer> WRONG_NUMBER_OF_TYPE_ARGUMENTS = new ParameterizedDiagnosticFactory1<Integer>(ERROR, "{0} type arguments expected") {
DiagnosticFactory<PsiElement> CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS = DiagnosticFactory.create(ERROR, "Can not create an instance of an abstract class");
DiagnosticFactory1<PsiElement, SolutionStatus> TYPE_INFERENCE_FAILED = DiagnosticFactory1.create(ERROR, "Type inference failed: {0}");
DiagnosticFactory1<JetElement, Integer> WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory1.create(ERROR, "{0} type arguments expected", new Renderer<Integer>() {
@NotNull
@Override
protected String makeMessageFor(@NotNull Integer argument) {
public String render(@Nullable Integer argument) {
assert argument != null;
return argument == 0 ? "No" : argument.toString();
}
};
});
ParameterizedDiagnosticFactory1<String> UNRESOLVED_IDE_TEMPLATE = new ParameterizedDiagnosticFactory1<String>(ERROR, "Unresolved IDE template: {0}");
DiagnosticFactory1<JetIdeTemplateExpression, String> UNRESOLVED_IDE_TEMPLATE = DiagnosticFactory1.create(ERROR, "Unresolved IDE template: {0}");
SimpleDiagnosticFactory DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = SimpleDiagnosticFactory.create(WARNING, "This expression is treated as an argument to the function call on the previous line. " +
"Separate it with a semicolon (;) if it is not intended to be an argument.");
DiagnosticFactory<JetExpression> DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = DiagnosticFactory.create(WARNING, "This expression is treated as an argument to the function call on the previous line. " +
"Separate it with a semicolon (;) if it is not intended to be an argument.");
// This field is needed to make the Initializer class load (interfaces cannot have static initializers)
@SuppressWarnings("UnusedDeclaration")
Initializer __initializer = Initializer.INSTANCE;
class Initializer {
static {
for (Field field : Errors.class.getFields()) {
@@ -505,15 +460,16 @@ public interface Errors {
AbstractDiagnosticFactory factory = (AbstractDiagnosticFactory) value;
factory.setName(field.getName());
}
}
catch (IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
}
private static final Initializer INSTANCE = new Initializer();
private Initializer() {};
private Initializer() {
}
}
}
@@ -1,78 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.resolve.DescriptorRenderer;
/**
* @author Stepan Koltsov
*/
public class FunctionSignatureDiagnosticFactory extends DiagnosticFactoryWithMessageFormat {
public FunctionSignatureDiagnosticFactory(Severity severity, String messageTemplate) {
super(severity, messageTemplate);
}
private TextRange rangeToMark(JetDeclaration jetDeclaration) {
if (jetDeclaration instanceof JetNamedFunction) {
JetNamedFunction functionElement = (JetNamedFunction) jetDeclaration;
return new TextRange(
functionElement.getStartOfSignatureElement().getTextRange().getStartOffset(),
functionElement.getEndOfSignatureElement().getTextRange().getEndOffset()
);
} else if (jetDeclaration instanceof JetClass) {
// primary constructor
JetClass klass = (JetClass) jetDeclaration;
PsiElement nameAsDeclaration = klass.getNameIdentifier();
if (nameAsDeclaration == null){
return klass.getTextRange();
}
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) {
return nameAsDeclaration.getTextRange();
}
return new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
);
} else {
// safe way
return jetDeclaration.getTextRange();
}
}
@NotNull
public Diagnostic on(@NotNull JetDeclaration declaration, @NotNull CallableMemberDescriptor functionDescriptor,
@NotNull String functionContainer)
{
TextRange rangeToMark = rangeToMark(declaration);
String message = messageFormat.format(new Object[]{
functionContainer,
DescriptorRenderer.TEXT.render(functionDescriptor)});
return new GenericDiagnostic(this, severity, message, declaration.getContainingFile(), rangeToMark);
}
} //~
@@ -1,54 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class ParameterizedDiagnosticFactory1<A> extends DiagnosticFactoryWithPsiElement1<PsiElement, A> {
public static <T> ParameterizedDiagnosticFactory1<T> create(Severity severity, String messageStub) {
return new ParameterizedDiagnosticFactory1<T>(severity, messageStub);
}
public static <T> ParameterizedDiagnosticFactory1<T> create(Severity severity, String messageStub, Renderer renderer) {
return new ParameterizedDiagnosticFactory1<T>(severity, messageStub, renderer);
}
public ParameterizedDiagnosticFactory1(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
public ParameterizedDiagnosticFactory1(Severity severity, String message) {
super(severity, message);
}
@NotNull
public Diagnostic on(@NotNull PsiFile psiFile, @NotNull TextRange rangeToMark, @NotNull A argument) {
return new GenericDiagnostic(this, severity, makeMessage(argument), psiFile, rangeToMark);
}
@NotNull
public Diagnostic on(@NotNull ASTNode nodeToMark, @NotNull A argument) {
return on(DiagnosticUtils.getContainingFile(nodeToMark), nodeToMark.getTextRange(), argument);
}
}
@@ -1,55 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class ParameterizedDiagnosticFactory2<A, B> extends DiagnosticFactoryWithPsiElement2<PsiElement, A,B> {
public static <A, B> ParameterizedDiagnosticFactory2<A, B> create(Severity severity, String messageStub) {
return new ParameterizedDiagnosticFactory2<A, B>(severity, messageStub);
}
public static <A, B> ParameterizedDiagnosticFactory2<A, B> create(Severity severity, String messageStub, Renderer renderer) {
return new ParameterizedDiagnosticFactory2<A, B>(severity, messageStub, renderer);
}
public ParameterizedDiagnosticFactory2(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
public ParameterizedDiagnosticFactory2(Severity severity, String messageStub) {
super(severity, messageStub);
}
@NotNull
public Diagnostic on(@NotNull PsiFile psiFile, @NotNull TextRange rangeToMark, @NotNull A a, @NotNull B b) {
return new GenericDiagnostic(this, severity, makeMessage(a, b), psiFile, rangeToMark);
}
@NotNull
public Diagnostic on(@NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b) {
return on(DiagnosticUtils.getContainingFile(nodeToMark), nodeToMark.getTextRange(), a, b);
}
}
@@ -1,54 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class ParameterizedDiagnosticFactory3<A, B, C> extends DiagnosticFactoryWithPsiElement3<PsiElement, A, B, C> {
public static <A, B, C> ParameterizedDiagnosticFactory3<A, B, C> create(Severity severity, String messageStub) {
return new ParameterizedDiagnosticFactory3<A, B, C>(severity, messageStub);
}
public static <A, B, C> ParameterizedDiagnosticFactory3<A, B, C> create(Severity severity, String messageStub, Renderer renderer) {
return new ParameterizedDiagnosticFactory3<A, B, C>(severity, messageStub, renderer);
}
public ParameterizedDiagnosticFactory3(Severity severity, String messageStub, Renderer renderer) {
super(severity, messageStub, renderer);
}
protected ParameterizedDiagnosticFactory3(Severity severity, String messageStub) {
super(severity, messageStub);
}
@NotNull
public Diagnostic on(@NotNull PsiFile psiFile, @NotNull TextRange rangeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return new GenericDiagnostic(this, severity, makeMessage(a, b, c), psiFile, rangeToMark);
}
@NotNull
public Diagnostic on(@NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
return on(DiagnosticUtils.getContainingFile(nodeToMark), nodeToMark.getTextRange(), a, b, c);
}
}
@@ -0,0 +1,126 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collections;
import java.util.List;
/**
* @author svtk
*/
public class PositioningStrategies {
public static final PositioningStrategy<PsiElement> DEFAULT = new PositioningStrategy<PsiElement>();
public static final PositioningStrategy<JetFunction> MARK_FUNCTION = new PositioningStrategy<JetFunction>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull JetFunction function) {
TextRange textRange;
PsiElement nameIdentifier = function.getNameIdentifier();
JetTypeReference returnTypeRef = function.getReturnTypeRef();
JetParameterList valueParameterList = function.getValueParameterList();
if (nameIdentifier == null) {
textRange = TextRange.from(function.getTextRange().getEndOffset(), 0);
}
else if (returnTypeRef != null) {
textRange = TextRange.from(returnTypeRef.getTextRange().getEndOffset(), 1);
}
else if (valueParameterList != null) {
textRange = TextRange.from(valueParameterList.getTextRange().getEndOffset(), 1);
}
else {
textRange = TextRange.from(nameIdentifier.getTextRange().getEndOffset(), 1);
}
return markRange(textRange);
}
};
public static final PositioningStrategy<JetDeclaration> POSITION_DECLARATION = new PositioningStrategy<JetDeclaration>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull JetDeclaration declaration) {
JetTypeReference returnTypeRef = null;
ASTNode nameNode = null;
if (declaration instanceof JetNamedFunction) {
JetFunction function = (JetNamedFunction) declaration;
returnTypeRef = function.getReturnTypeRef();
nameNode = getNameNode(function);
}
else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration;
returnTypeRef = property.getPropertyTypeRef();
nameNode = getNameNode(property);
}
else if (declaration instanceof JetPropertyAccessor) {
JetPropertyAccessor accessor = (JetPropertyAccessor) declaration;
returnTypeRef = accessor.getReturnTypeReference();
nameNode = accessor.getNamePlaceholder().getNode();
}
if (returnTypeRef != null) return Collections.singletonList(returnTypeRef.getTextRange());
if (nameNode != null) return Collections.singletonList(nameNode.getTextRange());
return super.mark(declaration);
}
private ASTNode getNameNode(JetNamedDeclaration function) {
PsiElement nameIdentifier = function.getNameIdentifier();
return nameIdentifier == null ? null : nameIdentifier.getNode();
}
};
public static final PositioningStrategy<PsiNameIdentifierOwner> POSITION_NAME_IDENTIFIER = new PositioningStrategy<PsiNameIdentifierOwner>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull PsiNameIdentifierOwner element) {
PsiElement nameIdentifier = element.getNameIdentifier();
if (nameIdentifier != null) {
return markElement(nameIdentifier);
}
return Collections.emptyList();
}
};
public static final PositioningStrategy<JetModifierListOwner> POSITION_ABSTRACT_MODIFIER = positionModifier(JetTokens.ABSTRACT_KEYWORD);
public static PositioningStrategy<JetModifierListOwner> positionModifier(final JetKeywordToken token) {
return new PositioningStrategy<JetModifierListOwner>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull JetModifierListOwner modifierListOwner) {
if (modifierListOwner.hasModifier(token)) {
JetModifierList modifierList = modifierListOwner.getModifierList();
assert modifierList != null;
ASTNode node = modifierList.getModifierNode(token);
assert node != null;
return Collections.singletonList(node.getTextRange());
}
return Collections.emptyList();
}
};
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,28 +19,32 @@ package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
/**
* @author abreslav
* @author svtk
*/
public class SimpleDiagnosticFactory extends SimpleDiagnosticFactoryWithPsiElement<PsiElement> {
public static SimpleDiagnosticFactory create(Severity severity, String message) {
return new SimpleDiagnosticFactory(severity, message);
}
protected SimpleDiagnosticFactory(Severity severity, String message) {
super(severity, message);
public class PositioningStrategy<P extends PsiElement> {
@NotNull
public List<TextRange> mark(@NotNull P element) {
return markElement(element);
}
@NotNull
public Diagnostic on(@NotNull PsiFile psiFile, @NotNull TextRange range) {
return new GenericDiagnostic(this, severity, message, psiFile, range);
protected static List<TextRange> markElement(@NotNull PsiElement element) {
return Collections.singletonList(element.getTextRange());
}
@NotNull
public Diagnostic on(@NotNull ASTNode node) {
return on(DiagnosticUtils.getContainingFile(node), node.getTextRange());
protected static List<TextRange> markNode(@NotNull ASTNode node) {
return Collections.singletonList(node.getTextRange());
}
@NotNull
protected static List<TextRange> markRange(@NotNull TextRange range) {
return Collections.singletonList(range);
}
}
@@ -1,25 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public interface PsiElementOnlyDiagnosticFactory<T extends PsiElement> extends DiagnosticFactory {
}
@@ -1,39 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public class PsiElementOnlyDiagnosticFactory1<T extends PsiElement, A> extends DiagnosticFactoryWithPsiElement1<T, A> implements PsiElementOnlyDiagnosticFactory<T> {
public static <T extends PsiElement, A> PsiElementOnlyDiagnosticFactory1<T, A> create(Severity severity, String messageStub) {
return new PsiElementOnlyDiagnosticFactory1<T, A>(severity, messageStub);
}
public static <T extends PsiElement, A> PsiElementOnlyDiagnosticFactory1<T, A> create(Severity severity, String messageStub, Renderer renderer) {
return new PsiElementOnlyDiagnosticFactory1<T, A>(severity, messageStub, renderer);
}
public PsiElementOnlyDiagnosticFactory1(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
protected PsiElementOnlyDiagnosticFactory1(Severity severity, String message) {
super(severity, message);
}
}
@@ -1,40 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public class PsiElementOnlyDiagnosticFactory2<T extends PsiElement, A, B> extends DiagnosticFactoryWithPsiElement2<T, A, B> implements PsiElementOnlyDiagnosticFactory<T> {
public static <T extends PsiElement, A, B> PsiElementOnlyDiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, Renderer renderer) {
return new PsiElementOnlyDiagnosticFactory2<T, A, B>(severity, messageStub, renderer);
}
public static <T extends PsiElement, A, B> PsiElementOnlyDiagnosticFactory2<T, A, B> create(Severity severity, String messageStub) {
return new PsiElementOnlyDiagnosticFactory2<T, A, B>(severity, messageStub);
}
public PsiElementOnlyDiagnosticFactory2(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
}
protected PsiElementOnlyDiagnosticFactory2(Severity severity, String message) {
super(severity, message);
}
}
@@ -1,39 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public class PsiElementOnlyDiagnosticFactory3<T extends PsiElement, A, B, C> extends DiagnosticFactoryWithPsiElement3<T, A, B, C> implements PsiElementOnlyDiagnosticFactory<T> {
public static <T extends PsiElement, A, B, C> PsiElementOnlyDiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub) {
return new PsiElementOnlyDiagnosticFactory3<T, A, B, C>(severity, messageStub);
}
public static <T extends PsiElement, A, B, C> PsiElementOnlyDiagnosticFactory3<T, A, B, C> create(Severity severity, String messageStub, Renderer renderer) {
return new PsiElementOnlyDiagnosticFactory3<T, A, B, C>(severity, messageStub, renderer);
}
protected PsiElementOnlyDiagnosticFactory3(Severity severity, String messageStub) {
super(severity, messageStub);
}
public PsiElementOnlyDiagnosticFactory3(Severity severity, String messageStub, Renderer renderer) {
super(severity, messageStub, renderer);
}
}
@@ -21,21 +21,31 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
/**
* @author abreslav
*/
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
public interface RedeclarationDiagnostic extends Diagnostic<PsiElement> {
class SimpleRedeclarationDiagnostic extends AbstractDiagnostic<PsiElement> implements RedeclarationDiagnostic {
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name, RedeclarationDiagnosticFactory factory) {
super(factory, factory.severity, factory.makeMessage(name), psiElement);
super(psiElement, factory, factory.severity, factory.makeMessage(name));
}
@NotNull
@Override
public List<TextRange> getTextRanges() {
return POSITION_REDECLARATION.mark(getPsiElement());
}
}
public class RedeclarationDiagnosticWithDeferredResolution implements RedeclarationDiagnostic {
class RedeclarationDiagnosticWithDeferredResolution implements RedeclarationDiagnostic {
private final DeclarationDescriptor duplicatingDescriptor;
private final BindingContext contextToResolveToDeclaration;
private final RedeclarationDiagnosticFactory factory;
@@ -54,7 +64,7 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
}
return element;
}
@NotNull
@Override
public PsiElement getPsiElement() {
@@ -63,8 +73,8 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
@NotNull
@Override
public TextRange getTextRange() {
return resolve().getTextRange();
public List<TextRange> getTextRanges() {
return POSITION_REDECLARATION.mark(getPsiElement());
}
@NotNull
@@ -75,7 +85,7 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
@NotNull
@Override
public DiagnosticFactory getFactory() {
public AbstractDiagnosticFactory getFactory() {
return factory;
}
@@ -90,11 +100,26 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
public Severity getSeverity() {
return factory.severity;
}
@Override
public <P> DiagnosticWithPsiElement<PsiElement> add(DiagnosticParameter<P> parameterType, P parameter) {
throw new UnsupportedOperationException();
}
}
PositioningStrategy<PsiElement> POSITION_REDECLARATION = new PositioningStrategy<PsiElement>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull PsiElement element) {
if (element instanceof JetNamedDeclaration) {
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
if (nameIdentifier != null) {
return markElement(nameIdentifier);
}
}
else if (element instanceof JetFile) {
JetFile file = (JetFile) element;
PsiElement nameIdentifier = file.getNamespaceHeader().getNameIdentifier();
if (nameIdentifier != null) {
return markElement(nameIdentifier);
}
}
return markElement(element);
}
};
}
@@ -55,26 +55,6 @@ public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration, this);
}
@NotNull
@Override
public List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic) {
PsiElement redeclaration = ((RedeclarationDiagnostic) diagnostic).getPsiElement();
if (redeclaration instanceof JetNamedDeclaration) {
PsiElement nameIdentifier = ((JetNamedDeclaration) redeclaration).getNameIdentifier();
if (nameIdentifier != null) {
return Collections.singletonList(nameIdentifier.getTextRange());
}
}
else if (redeclaration instanceof JetFile) {
JetFile file = (JetFile) redeclaration;
PsiElement nameIdentifier = file.getNamespaceHeader().getNameIdentifier();
if (nameIdentifier != null) {
return Collections.singletonList(nameIdentifier.getTextRange());
}
}
return Collections.singletonList(redeclaration.getTextRange());
}
@NotNull
@Override
public String getName() {
@@ -16,26 +16,15 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author abreslav
*/
public interface Renderer {
Renderer TO_STRING = new Renderer() {
@NotNull
@Override
public String render(@Nullable Object object) {
return object == null ? "null" : object.toString();
}
@Override
public String toString() {
return "TO_STRING";
}
};
public interface Renderer<P> {
@NotNull
String render(@Nullable Object object);
String render(@Nullable P element);
}
@@ -0,0 +1,77 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Named;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
/**
* @author svtk
*/
public class Renderers {
public static final Renderer<Object> TO_STRING = new Renderer<Object>() {
@NotNull
@Override
public String render(@Nullable Object element) {
return element == null ? "null" : element.toString();
}
@Override
public String toString() {
return "TO_STRING";
}
};
public static final Renderer<Object> NAME = new Renderer<Object>() {
@NotNull
@Override
public String render(@Nullable Object element) {
if (element == null) return "null";
if (element instanceof Named) {
return ((Named) element).getName();
}
return element.toString();
}
};
public static final Renderer<PsiElement> ELEMENT_TEXT = new Renderer<PsiElement>() {
@NotNull
@Override
public String render(@Nullable PsiElement element) {
if (element == null) return "null";
return element.getText();
}
};
public static final Renderer<JetClassOrObject> RENDER_CLASS_OR_OBJECT = new Renderer<JetClassOrObject>() {
@NotNull
@Override
public String render(@Nullable JetClassOrObject classOrObject) {
assert classOrObject != null;
String name = classOrObject.getName() != null ? " '" + classOrObject.getName() + "'" : "";
if (classOrObject instanceof JetClass) {
return "Class" + name;
}
return "Object" + name;
}
};
}
@@ -1,59 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author svtk
*/
public abstract class SimpleDiagnosticFactoryWithPsiElement<T extends PsiElement> extends DiagnosticFactoryWithSeverity {
protected final String message;
protected SimpleDiagnosticFactoryWithPsiElement(Severity severity, String message) {
super(severity);
this.message = message;
}
private Diagnostic on(@NotNull T elementToBlame, @NotNull TextRange textRange) {
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, elementToBlame, textRange);
}
@NotNull
public Diagnostic on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark) {
return on(elementToBlame, nodeToMark.getTextRange());
}
@NotNull
public Diagnostic on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark) {
return on(elementToBlame, elementToMark.getTextRange());
}
@NotNull
public Diagnostic on(@NotNull T element) {
return on(element, getTextRange(element));
}
@NotNull
public TextRange getTextRange(@NotNull T element) {
return element.getTextRange();
}
}
@@ -1,33 +0,0 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public class SimplePsiElementOnlyDiagnosticFactory<T extends PsiElement> extends SimpleDiagnosticFactoryWithPsiElement<T> implements PsiElementOnlyDiagnosticFactory<T> {
public static <T extends PsiElement> SimplePsiElementOnlyDiagnosticFactory<T> create(Severity severity, String message) {
return new SimplePsiElementOnlyDiagnosticFactory<T>(severity, message);
}
protected SimplePsiElementOnlyDiagnosticFactory(Severity severity, String message) {
super(severity, message);
}
}
@@ -16,18 +16,23 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
/**
* @author abreslav
*/
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElementImpl<JetReferenceExpression> {
* @author abreslav
*/
public class UnresolvedReferenceDiagnostic extends AbstractDiagnostic<JetReferenceExpression> {
public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression, String message) {
super(Errors.UNRESOLVED_REFERENCE, ERROR, message, referenceExpression);
super(referenceExpression, Errors.UNRESOLVED_REFERENCE, ERROR, message);
}
@NotNull
@@ -35,4 +40,14 @@ public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElementImpl<
public String getMessage() {
return super.getMessage() + ": " + getPsiElement().getText();
}
@NotNull
@Override
public List<TextRange> getTextRanges() {
JetReferenceExpression element = getPsiElement();
if (element instanceof JetArrayAccessExpression) {
return ((JetArrayAccessExpression) element).getBracketRanges();
}
return Collections.singletonList(element.getTextRange());
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
@@ -27,12 +28,11 @@ import java.util.List;
/**
* @author abreslav
*/
public class UnresolvedReferenceDiagnosticFactory extends AbstractDiagnosticFactory
implements PsiElementOnlyDiagnosticFactory<JetSimpleNameExpression> {
public class UnresolvedReferenceDiagnosticFactory extends AbstractDiagnosticFactory {
private final String message;
public UnresolvedReferenceDiagnosticFactory(String message) {
private UnresolvedReferenceDiagnosticFactory(String message) {
this.message = message;
}
@@ -40,15 +40,7 @@ public class UnresolvedReferenceDiagnosticFactory extends AbstractDiagnosticFact
return new UnresolvedReferenceDiagnostic(reference, message);
}
@NotNull
@Override
public List<TextRange> getTextRanges(@NotNull Diagnostic diagnostic) {
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
JetReferenceExpression element = ((UnresolvedReferenceDiagnostic) diagnostic).getPsiElement();
if (element instanceof JetArrayAccessExpression) {
return ((JetArrayAccessExpression)element).getBracketRanges();
}
}
return super.getTextRanges(diagnostic);
public static UnresolvedReferenceDiagnosticFactory create(String message) {
return new UnresolvedReferenceDiagnosticFactory(message);
}
}
@@ -20,20 +20,24 @@ import com.intellij.psi.PsiElement;
/**
* @author svtk
*/
public class UnusedElementDiagnosticFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String messageStub) {
return new UnusedElementDiagnosticFactory<T, A>(severity, messageStub);
public class UnusedElementDiagnosticFactory<T extends PsiElement, A> extends DiagnosticFactory1<T, A> {
private UnusedElementDiagnosticFactory(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
super(severity, message, positioningStrategy, renderer);
}
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String messageStub, Renderer renderer) {
return new UnusedElementDiagnosticFactory<T, A>(severity, messageStub, renderer);
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy, Renderer<? super A> renderer) {
return new UnusedElementDiagnosticFactory<T, A>(severity, message, positioningStrategy, renderer);
}
public UnusedElementDiagnosticFactory(Severity severity, String message, Renderer renderer) {
super(severity, message, renderer);
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, PositioningStrategy<? super T> positioningStrategy) {
return create(severity, message, positioningStrategy, Renderers.TO_STRING);
}
protected UnusedElementDiagnosticFactory(Severity severity, String message) {
super(severity, message);
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message, Renderer<? super A> renderer) {
return create(severity, message, PositioningStrategies.DEFAULT, renderer);
}
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String message) {
return create(severity, message, PositioningStrategies.DEFAULT, Renderers.TO_STRING);
}
}
@@ -55,8 +55,5 @@ public interface Call {
JetTypeArgumentList getTypeArgumentList();
@NotNull
ASTNode getCallNode();
@Nullable
PsiElement getCallElement();
}
@@ -61,8 +61,8 @@ public class AnalyzingUtils {
});
}
public static List<TextRange> getSyntaxErrorRanges(@NotNull PsiElement root) {
final ArrayList<TextRange> r = new ArrayList<TextRange>();
public static List<PsiErrorElement> getSyntaxErrorRanges(@NotNull PsiElement root) {
final ArrayList<PsiErrorElement> r = new ArrayList<PsiErrorElement>();
root.acceptChildren(new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
@@ -71,7 +71,7 @@ public class AnalyzingUtils {
@Override
public void visitErrorElement(PsiErrorElement element) {
r.add(element.getTextRange());
r.add(element);
}
});
return r;
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.Queue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
@@ -130,9 +131,9 @@ public class BodyResolver {
@Override
public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
JetValueArgumentList valueArgumentList = call.getValueArgumentList();
ASTNode node = valueArgumentList == null ? call.getNode() : valueArgumentList.getNode();
PsiElement elementToMark = valueArgumentList == null ? call : valueArgumentList;
if (descriptor.getKind() == ClassKind.TRAIT) {
context.getTrace().report(SUPERTYPE_INITIALIZED_IN_TRAIT.on(node));
context.getTrace().report(SUPERTYPE_INITIALIZED_IN_TRAIT.on(elementToMark));
}
JetTypeReference typeReference = call.getTypeReference();
if (typeReference == null) return;
@@ -149,7 +150,7 @@ public class BodyResolver {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
if (classDescriptor != null) {
if (classDescriptor.getKind() == ClassKind.TRAIT) {
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(node));
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(elementToMark));
}
}
}
@@ -304,13 +305,14 @@ public class BodyResolver {
final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
PsiElement nameElement = declaration.getNameNode().getPsi();
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration.getNameNode()));
context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(nameElement));
}
else {
List<JetDelegationSpecifier> initializers = declaration.getInitializers();
if (initializers.isEmpty()) {
context.getTrace().report(SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST.on(declaration.getNameNode()));
context.getTrace().report(SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST.on(nameElement));
}
else {
initializers.get(0).accept(new JetVisitorVoid() {
@@ -189,8 +189,7 @@ public class DeclarationResolver {
private void processSecondaryConstructor(MutableClassDescriptor classDescriptor, JetSecondaryConstructor constructor) {
if (classDescriptor.getKind() == ClassKind.TRAIT) {
// context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A trait may not have a constructor");
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode()));
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode().getPsi()));
}
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor(
classDescriptor.getScopeForMemberResolution(),
@@ -33,7 +33,6 @@ import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetToken;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -104,13 +103,13 @@ public class DeclarationsChecker {
JetModifierList modifierList = aClass.getModifierList();
if (modifierList == null) return;
if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) {
context.getTrace().report(Errors.TRAIT_CAN_NOT_BE_FINAL.on(aClass, modifierList.getModifierNode(JetTokens.FINAL_KEYWORD)));
context.getTrace().report(Errors.TRAIT_CAN_NOT_BE_FINAL.on(modifierList.getModifierNode(JetTokens.FINAL_KEYWORD).getPsi()));
}
ArrayList<JetKeywordToken> redundantModifiers = Lists.newArrayList(JetTokens.OPEN_KEYWORD, JetTokens.ABSTRACT_KEYWORD);
for (JetKeywordToken modifier : redundantModifiers) {
if (modifierList.hasModifier(modifier)) {
context.getTrace().report(Errors.REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, modifierList.getModifierNode(modifier), modifier));
}
if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
context.getTrace().report(Errors.ABSTRACT_MODIFIER_IN_TRAIT.on(aClass));
}
if (modifierList.hasModifier(JetTokens.OPEN_KEYWORD)) {
context.getTrace().report(Errors.OPEN_MODIFIER_IN_TRAIT.on(aClass));
}
}
@@ -127,7 +126,7 @@ public class DeclarationsChecker {
JetModifierList modifierList = member.getModifierList();
assert modifierList != null;
ASTNode openModifierNode = modifierList.getModifierNode(JetTokens.OPEN_KEYWORD);
context.getTrace().report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member, openModifierNode, aClass));
context.getTrace().report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(openModifierNode.getPsi()));
}
}
}
@@ -161,7 +160,7 @@ public class DeclarationsChecker {
if (returnType instanceof DeferredType) {
returnType = ((DeferredType) returnType).getActualType();
}
context.getTrace().report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(member, nameIdentifier, returnType));
context.getTrace().report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(nameIdentifier));
}
}
@@ -173,18 +172,18 @@ public class DeclarationsChecker {
if (abstractNode != null) { //has abstract modifier
if (classDescriptor == null) {
context.getTrace().report(ABSTRACT_PROPERTY_NOT_IN_CLASS.on(property, abstractNode));
context.getTrace().report(ABSTRACT_PROPERTY_NOT_IN_CLASS.on(property));
return;
}
if (!(classDescriptor.getModality() == Modality.ABSTRACT) && classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
assert classElement instanceof JetClass;
String name = property.getName();
context.getTrace().report(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(property, abstractNode, name != null ? name : "", classDescriptor, (JetClass) classElement));
context.getTrace().report(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(property, name != null ? name : "", classDescriptor, (JetClass) classElement));
return;
}
if (classDescriptor.getKind() == ClassKind.TRAIT) {
context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD));
context.getTrace().report(ABSTRACT_MODIFIER_IN_TRAIT.on(property));
}
}
@@ -196,13 +195,13 @@ public class DeclarationsChecker {
JetExpression initializer = property.getInitializer();
if (initializer != null) {
context.getTrace().report(ABSTRACT_PROPERTY_WITH_INITIALIZER.on(property, initializer, returnType));
context.getTrace().report(ABSTRACT_PROPERTY_WITH_INITIALIZER.on(initializer));
}
if (getter != null && getter.getBodyExpression() != null) {
context.getTrace().report(ABSTRACT_PROPERTY_WITH_GETTER.on(property, getter, returnType));
context.getTrace().report(ABSTRACT_PROPERTY_WITH_GETTER.on(getter));
}
if (setter != null && setter.getBodyExpression() != null) {
context.getTrace().report(ABSTRACT_PROPERTY_WITH_SETTER.on(property, setter, returnType));
context.getTrace().report(ABSTRACT_PROPERTY_WITH_SETTER.on(setter));
}
}
}
@@ -229,7 +228,7 @@ public class DeclarationsChecker {
context.getTrace().report(MUST_BE_INITIALIZED.on(nameIdentifier));
}
else {
context.getTrace().report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property, nameIdentifier));
context.getTrace().report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(nameIdentifier));
}
}
return;
@@ -239,7 +238,7 @@ public class DeclarationsChecker {
if (returnType instanceof DeferredType) {
returnType = ((DeferredType) returnType).getActualType();
}
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(property, initializer, returnType));
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(initializer));
}
else if (!backingFieldRequired) {
context.getTrace().report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
@@ -261,24 +260,24 @@ public class DeclarationsChecker {
if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) {
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
assert classElement instanceof JetClass;
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, abstractNode, functionDescriptor.getName(), classDescriptor, (JetClass) classElement));
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName(), classDescriptor, (JetClass) classElement));
}
if (hasAbstractModifier && inTrait) {
context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD));
context.getTrace().report(ABSTRACT_MODIFIER_IN_TRAIT.on(function));
}
if (function.getBodyExpression() != null && hasAbstractModifier) {
context.getTrace().report(ABSTRACT_FUNCTION_WITH_BODY.on(function, abstractNode, functionDescriptor));
context.getTrace().report(ABSTRACT_FUNCTION_WITH_BODY.on(abstractNode.getPsi(), functionDescriptor));
}
if (function.getBodyExpression() == null && !hasAbstractModifier && !inTrait && nameIdentifier != null) {
context.getTrace().report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(function, nameIdentifier, functionDescriptor));
context.getTrace().report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(function, functionDescriptor));
}
return;
}
if (hasAbstractModifier) {
context.getTrace().report(NON_MEMBER_ABSTRACT_FUNCTION.on(function, abstractNode, functionDescriptor));
context.getTrace().report(NON_MEMBER_ABSTRACT_FUNCTION.on(function, functionDescriptor));
}
if (function.getBodyExpression() == null && !hasAbstractModifier && nameIdentifier != null) {
context.getTrace().report(NON_MEMBER_FUNCTION_NO_BODY.on(function, nameIdentifier, functionDescriptor));
context.getTrace().report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
}
}
@@ -292,13 +291,13 @@ public class DeclarationsChecker {
if (getterModifierList != null && getterDescriptor != null) {
Map<JetKeywordToken, ASTNode> nodes = getNodesCorrespondingToModifiers(getterModifierList, Sets.newHashSet(JetTokens.PUBLIC_KEYWORD, JetTokens.PROTECTED_KEYWORD, JetTokens.PRIVATE_KEYWORD, JetTokens.INTERNAL_KEYWORD));
if (getterDescriptor.getVisibility() != propertyDescriptor.getVisibility()) {
for (Map.Entry<JetKeywordToken, ASTNode> entry : nodes.entrySet()) {
context.getTrace().report(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.on(getterModifierList, entry.getValue(), entry.getKey()));
for (ASTNode node : nodes.values()) {
context.getTrace().report(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.on(node.getPsi()));
}
}
else {
for (Map.Entry<JetKeywordToken, ASTNode> entry : nodes.entrySet()) {
context.getTrace().report(Errors.REDUNDANT_MODIFIER_IN_GETTER.on(getterModifierList, entry.getValue(), entry.getKey()));
for (ASTNode node : nodes.values()) {
context.getTrace().report(Errors.REDUNDANT_MODIFIER_IN_GETTER.on(node.getPsi()));
}
}
}
@@ -341,7 +340,7 @@ public class DeclarationsChecker {
}
}
for (JetKeywordToken token : presentModifiers) {
context.getTrace().report(Errors.INCOMPATIBLE_MODIFIERS.on(modifierList.getModifierNode(token), presentModifiers));
context.getTrace().report(Errors.INCOMPATIBLE_MODIFIERS.on(modifierList.getModifierNode(token).getPsi(), presentModifiers));
}
}
@@ -350,7 +349,7 @@ public class DeclarationsChecker {
JetKeywordToken redundantModifier = tokenPair.getFirst();
JetKeywordToken sufficientModifier = tokenPair.getSecond();
if (modifierList.hasModifier(redundantModifier) && modifierList.hasModifier(sufficientModifier)) {
context.getTrace().report(Errors.REDUNDANT_MODIFIER.on(modifierList, modifierList.getModifierNode(redundantModifier), redundantModifier, sufficientModifier));
context.getTrace().report(Errors.REDUNDANT_MODIFIER.on(modifierList.getModifierNode(redundantModifier).getPsi(), redundantModifier, sufficientModifier));
}
}
}
@@ -359,7 +358,7 @@ public class DeclarationsChecker {
if (modifierList == null) return;
for (JetKeywordToken modifier : illegalModifiers) {
if (modifierList.hasModifier(modifier)) {
context.getTrace().report(Errors.ILLEGAL_MODIFIER.on(modifierList, modifierList.getModifierNode(modifier), modifier));
context.getTrace().report(Errors.ILLEGAL_MODIFIER.on(modifierList.getModifierNode(modifier).getPsi(), modifier));
}
}
}
@@ -387,8 +386,7 @@ public class DeclarationsChecker {
ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
assert constructor != null;
if (!constructor.getValueParameters().isEmpty() && delegationSpecifiers.isEmpty()) {
PsiElement nameIdentifier = aClass.getNameIdentifier();
context.getTrace().report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(nameIdentifier != null ? nameIdentifier : aClass, enumClass));
context.getTrace().report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(aClass, enumClass));
}
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
@@ -111,7 +111,6 @@ public class DescriptorResolver {
return parentDescriptor.getDefaultType();
}
else {
// trace.getErrorHandler().genericError(((JetEnumEntry) jetClass).getNameIdentifier().getNode(), "Generic arguments of the base type must be specified");
trace.report(NO_GENERICS_IN_SUPERTYPE_SPECIFIER.on(((JetEnumEntry) jetClass).getNameIdentifier()));
return ErrorUtils.createErrorType("Supertype not specified");
}
@@ -131,8 +130,7 @@ public class DescriptorResolver {
JetTypeElement typeElement = typeReference.getTypeElement();
while (typeElement instanceof JetNullableType) {
JetNullableType nullableType = (JetNullableType) typeElement;
// trace.getErrorHandler().genericError(nullableType.getQuestionMarkNode(), "A supertype cannot be nullable");
trace.report(NULLABLE_SUPERTYPE.on(nullableType.getQuestionMarkNode()));
trace.report(NULLABLE_SUPERTYPE.on(nullableType));
typeElement = nullableType.getInnerType();
}
if (typeElement instanceof JetUserType) {
@@ -140,8 +138,7 @@ public class DescriptorResolver {
List<JetTypeProjection> typeArguments = userType.getTypeArguments();
for (JetTypeProjection typeArgument : typeArguments) {
if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) {
// trace.getErrorHandler().genericError(typeArgument.getProjectionNode(), "Projections are not allowed for immediate arguments of a supertype");
trace.report(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE.on(typeArgument.getProjectionNode()));
trace.report(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE.on(typeArgument));
}
}
}
@@ -202,7 +199,6 @@ public class DescriptorResolver {
});
}
else {
// trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
trace.report(FUNCTION_WITH_NO_TYPE_NO_BODY.on(function.asElement()));
returnType = ErrorUtils.createErrorType("No type, no body");
}
@@ -247,7 +243,6 @@ public class DescriptorResolver {
JetType type;
if (typeReference == null) {
// trace.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter));
type = ErrorUtils.createErrorType("Type annotation was missing");
} else {
@@ -350,7 +345,6 @@ public class DescriptorResolver {
// To tell the user that we look only for locally defined type parameters
ClassifierDescriptor classifier = scope.getClassifier(referencedName);
if (classifier != null) {
// trace.getErrorHandler().genericError(subjectTypeParameterName.getNode(), referencedName + " does not refer to a type parameter of " + declaration.getName());
trace.report(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER.on(subjectTypeParameterName, constraint, declaration));
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, classifier);
}
@@ -379,7 +373,6 @@ public class DescriptorResolver {
if (JetStandardClasses.isNothing(parameter.getUpperBoundsAsType())) {
PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier();
if (nameIdentifier != null) {
// trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Upper bounds of " + parameter.getName() + " have empty intersection");
trace.report(CONFLICTING_UPPER_BOUNDS.on(nameIdentifier, parameter));
}
}
@@ -388,7 +381,6 @@ public class DescriptorResolver {
if (classObjectType != null && JetStandardClasses.isNothing(classObjectType)) {
PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier();
if (nameIdentifier != null) {
// trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Class object upper bounds of " + parameter.getName() + " have empty intersection");
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(nameIdentifier, parameter));
}
}
@@ -399,11 +391,9 @@ public class DescriptorResolver {
JetType jetType = typeResolverNotCheckingBounds.resolveType(scope, upperBound);
if (!TypeUtils.canHaveSubtypes(semanticServices.getTypeChecker(), jetType)) {
if (classObjectConstaint) {
// trace.getErrorHandler().genericError(upperBound.getNode(), jetType + " is a final type, and thus a class object cannot extend it");
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType));
}
else {
// trace.getErrorHandler().genericWarning(upperBound.getNode(), jetType + " is a final type, and thus a value of the type parameter is predetermined");
trace.report(FINAL_UPPER_BOUND.on(upperBound, jetType));
}
}
@@ -615,10 +605,9 @@ public class DescriptorResolver {
if (propertyTypeRef == null) {
final JetExpression initializer = property.getInitializer();
if (initializer == null) {
// trace.getErrorHandler().genericError(property.getNode(), "This property must either have a type annotation or be initialized");
PsiElement nameIdentifier = property.getNameIdentifier();
if (nameIdentifier != null) {
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(nameIdentifier.getNode()));
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(nameIdentifier));
}
return ErrorUtils.createErrorType("No type, no body");
} else {
@@ -715,7 +704,7 @@ public class DescriptorResolver {
JetType inType = propertyDescriptor.getType();
if (inType != null) {
if (!TypeUtils.equalTypes(type, inType)) {
trace.report(WRONG_SETTER_PARAMETER_TYPE.on(setter, typeReference, inType));
trace.report(WRONG_SETTER_PARAMETER_TYPE.on(typeReference, inType));
}
}
else {
@@ -739,7 +728,7 @@ public class DescriptorResolver {
if (! property.isVar()) {
if (setter != null) {
// trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
trace.report(VAL_WITH_SETTER.on(property, setter));
trace.report(VAL_WITH_SETTER.on(setter));
}
}
return setterDescriptor;
@@ -768,8 +757,7 @@ public class DescriptorResolver {
if (returnTypeReference != null) {
returnType = typeResolver.resolveType(scope, returnTypeReference);
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
// trace.getErrorHandler().genericError(returnTypeReference.getNode(), "Getter return type must be equal to the type of the property, i.e. " + propertyDescriptor.getReturnType());
trace.report(WRONG_GETTER_RETURN_TYPE.on(getter, returnTypeReference, propertyDescriptor.getReturnType()));
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType()));
}
}
@@ -851,8 +839,7 @@ public class DescriptorResolver {
if (modifierList != null) {
ASTNode abstractNode = modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD);
if (abstractNode != null) {
// trace.getErrorHandler().genericError(abstractNode, "This property cannot be declared abstract");
trace.report(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS.on(parameter, abstractNode));
trace.report(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS.on(parameter));
}
}
@@ -913,7 +900,6 @@ public class DescriptorResolver {
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
if (!semanticServices.getTypeChecker().isSubtypeOf(typeArgument, substitutedBound)) {
// trace.getErrorHandler().genericError(argumentTypeReference.getNode(), "An upper bound " + substitutedBound + " is violated");
trace.report(UPPER_BOUND_VIOLATED.on(argumentTypeReference, substitutedBound));
}
}
@@ -366,8 +366,7 @@ public class OverrideResolver {
if (overridden != null) {
if (hasOverrideModifier) {
if (!overridden.getModality().isOverridable() && !finalOverriddenError) {
// context.getTrace().getErrorHandler().genericError(overrideNode, "Method " + overridden.getName() + " in " + overridden.getContainingDeclaration().getName() + " is final and cannot be overridden");
context.getTrace().report(OVERRIDING_FINAL_MEMBER.on(overrideNode, overridden, overridden.getContainingDeclaration()));
context.getTrace().report(OVERRIDING_FINAL_MEMBER.on(overrideNode.getPsi(), overridden, overridden.getContainingDeclaration()));
finalOverriddenError = true;
}
@@ -377,23 +376,19 @@ public class OverrideResolver {
}
if (checkPropertyKind(overridden, true) && checkPropertyKind(declared, false) && !kindMismatchError) {
context.getTrace().report(VAR_OVERRIDDEN_BY_VAL.on(member, ((JetProperty) member).getValOrVarNode(), (PropertyDescriptor) declared, (PropertyDescriptor) overridden));
context.getTrace().report(VAR_OVERRIDDEN_BY_VAL.on((JetProperty) member, (PropertyDescriptor) declared, (PropertyDescriptor) overridden));
kindMismatchError = true;
}
}
}
}
if (hasOverrideModifier && declared.getOverriddenDescriptors().size() == 0) {
// context.getTrace().getErrorHandler().genericError(overrideNode, "Method " + declared.getName() + " overrides nothing");
context.getTrace().report(NOTHING_TO_OVERRIDE.on(modifierList, overrideNode, declared));
context.getTrace().report(NOTHING_TO_OVERRIDE.on(member, declared));
}
PsiElement nameIdentifier = member.getNameIdentifier();
if (!hasOverrideModifier && declared.getOverriddenDescriptors().size() > 0 && nameIdentifier != null) {
CallableMemberDescriptor overridden = declared.getOverriddenDescriptors().iterator().next();
// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(),
// "Method '" + declared.getName() + "' overrides method '" + overridden.getName() + "' in class " +
// overridden.getContainingDeclaration().getName() + " and needs 'override' modifier");
context.getTrace().report(VIRTUAL_MEMBER_HIDDEN.on(member, nameIdentifier, declared, overridden, overridden.getContainingDeclaration()));
context.getTrace().report(VIRTUAL_MEMBER_HIDDEN.on(member, declared, overridden, overridden.getContainingDeclaration()));
}
}
@@ -368,7 +368,7 @@ public class TypeHierarchyResolver {
ClassDescriptor superclass = (i < size - 1) ? currentPath.get(i + 1) : current;
PsiElement psiElement = context.getTrace().get(DESCRIPTOR_TO_DECLARATION, classDescriptor);
ASTNode node = null;
PsiElement elementToMark = null;
if (psiElement instanceof JetClassOrObject) {
JetClassOrObject classOrObject = (JetClassOrObject) psiElement;
for (JetDelegationSpecifier delegationSpecifier : classOrObject.getDelegationSpecifiers()) {
@@ -376,19 +376,19 @@ public class TypeHierarchyResolver {
if (typeReference == null) continue;
JetType supertype = context.getTrace().get(TYPE, typeReference);
if (supertype != null && supertype.getConstructor() == superclass.getTypeConstructor()) {
node = typeReference.getNode();
elementToMark = typeReference;
}
}
}
if (node == null && psiElement instanceof PsiNameIdentifierOwner) {
if (elementToMark == null && psiElement instanceof PsiNameIdentifierOwner) {
PsiNameIdentifierOwner namedElement = (PsiNameIdentifierOwner) psiElement;
PsiElement nameIdentifier = namedElement.getNameIdentifier();
if (nameIdentifier != null) {
node = nameIdentifier.getNode();
elementToMark = nameIdentifier;
}
}
if (node != null) {
context.getTrace().report(CYCLIC_INHERITANCE_HIERARCHY.on(node));
if (elementToMark != null) {
context.getTrace().report(CYCLIC_INHERITANCE_HIERARCHY.on(elementToMark));
}
}
}
@@ -71,15 +71,13 @@ public class CallMaker {
private static class CallImpl implements Call {
private final ASTNode callNode;
private final PsiElement callElement;
private final ReceiverDescriptor explicitReceiver;
private ASTNode callOperationNode;
private final JetExpression calleeExpression;
private final List<? extends ValueArgument> valueArguments;
protected CallImpl(@NotNull ASTNode callNode, @Nullable PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments) {
this.callNode = callNode;
protected CallImpl(@Nullable PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments) {
this.callElement = callElement;
this.explicitReceiver = explicitReceiver;
this.callOperationNode = callOperationNode;
@@ -87,10 +85,6 @@ public class CallMaker {
this.valueArguments = valueArguments;
}
protected CallImpl(@NotNull PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments) {
this(callElement.getNode(), callElement, explicitReceiver, callOperationNode, calleeExpression, valueArguments);
}
@Override
public ASTNode getCallOperationNode() {
return callOperationNode;
@@ -114,11 +108,6 @@ public class CallMaker {
}
@NotNull
@Override
public ASTNode getCallNode() {
return callNode;
}
@Override
public PsiElement getCallElement() {
return callElement;
@@ -147,7 +136,7 @@ public class CallMaker {
@Override
public String toString() {
return getCallNode().getText();
return getCallElement().getText();
}
}
@@ -237,11 +226,6 @@ public class CallMaker {
}
@NotNull
@Override
public ASTNode getCallNode() {
return callElement.getNode();
}
@Override
public PsiElement getCallElement() {
return callElement;
@@ -151,7 +151,7 @@ public class CallResolver {
}
else {
JetValueArgumentList valueArgumentList = call.getValueArgumentList();
ASTNode reportAbsenceOn = valueArgumentList == null ? call.getCallNode() : valueArgumentList.getNode();
PsiElement reportAbsenceOn = valueArgumentList == null ? call.getCallElement() : valueArgumentList;
if (calleeExpression instanceof JetConstructorCalleeExpression) {
assert !call.getExplicitReceiver().exists();
@@ -336,7 +336,7 @@ public class CallResolver {
@Override
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallNode(), descriptors));
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallElement(), descriptors));
}
@Override
@@ -346,20 +346,20 @@ public class CallResolver {
@Override
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {
trace.report(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS.on(call.getCallNode()));
trace.report(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS.on(call.getCallElement()));
}
@Override
public void typeInferenceFailed(@NotNull BindingTrace trace, SolutionStatus status) {
assert !status.isSuccessful();
trace.report(TYPE_INFERENCE_FAILED.on(call.getCallNode(), status));
trace.report(TYPE_INFERENCE_FAILED.on(call.getCallElement(), status));
}
@Override
public void unsafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
ASTNode callOperationNode = call.getCallOperationNode();
if (callOperationNode != null) {
trace.report(UNSAFE_CALL.on(callOperationNode, type));
trace.report(UNSAFE_CALL.on(callOperationNode.getPsi(), type));
}
else {
PsiElement callElement = call.getCallElement();
@@ -382,9 +382,7 @@ public class CallResolver {
public void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
ASTNode callOperationNode = call.getCallOperationNode();
assert callOperationNode != null;
PsiElement callElement = call.getCallElement();
assert callElement != null;
trace.report(UNNECESSARY_SAFE_CALL.on((JetElement) callOperationNode.getTreeParent().getPsi(), callOperationNode, type));
trace.report(UNNECESSARY_SAFE_CALL.on(callOperationNode.getPsi(), type));
}
@Override
@@ -84,12 +84,6 @@ public class DelegatingCall implements Call {
return delegate.getTypeArgumentList();
}
@Override
@NotNull
public ASTNode getCallNode() {
return delegate.getCallNode();
}
@Override
@Nullable
public PsiElement getCallElement() {
@@ -169,7 +169,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
if (value instanceof ErrorValue) {
ErrorValue errorValue = (ErrorValue) value;
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node, errorValue.getMessage()));
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node.getPsi(), errorValue.getMessage()));
return getDefaultType(context.semanticServices, elementType);
}
else {
@@ -243,7 +243,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetTypeChecker typeChecker = context.semanticServices.getTypeChecker();
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
if (typeChecker.isSubtypeOf(actualType, targetType)) {
context.trace.report(USELESS_CAST_STATIC_ASSERT_IS_FINE.on(expression, expression.getOperationSign()));
context.trace.report(USELESS_CAST_STATIC_ASSERT_IS_FINE.on(expression.getOperationSign()));
}
else {
// See JET-58 Make 'as never succeeds' a warning, or even never check for Java (external) types
@@ -252,7 +252,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
else {
if (typeChecker.isSubtypeOf(actualType, targetType)) {
context.trace.report(USELESS_CAST.on(expression, expression.getOperationSign()));
context.trace.report(USELESS_CAST.on(expression.getOperationSign()));
} else {
if (isCastErased(actualType, targetType, typeChecker)) {
context.trace.report(Errors.UNCHECKED_CAST.on(expression, actualType, targetType));
@@ -852,7 +852,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType rightType = right == null ? null : facade.getType(right, contextWithExpectedType.replaceScope(context.scope));
if (leftType != null) {
if (!leftType.isNullable()) {
context.trace.report(USELESS_ELVIS.on(expression, left, leftType));
context.trace.report(USELESS_ELVIS.on(left, leftType));
}
if (rightType != null) {
DataFlowUtils.checkType(TypeUtils.makeNullableAsSpecified(leftType, rightType.isNullable()), left, contextWithExpectedType);
@@ -1035,8 +1035,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
arrayAccessExpression,
isGet ? "get" : "set");
if (!functionResults.isSuccess()) {
JetContainerNode indicesNode = arrayAccessExpression.getIndicesNode();
traceForResolveResult.report(isGet ? NO_GET_METHOD.on(indicesNode) : NO_SET_METHOD.on(indicesNode));
traceForResolveResult.report(isGet ? NO_GET_METHOD.on(arrayAccessExpression) : NO_SET_METHOD.on(arrayAccessExpression));
return null;
}
traceForResolveResult.record(isGet ? INDEXED_LVALUE_GET : INDEXED_LVALUE_SET, arrayAccessExpression, functionResults.getResultingCall());
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
@@ -318,7 +317,7 @@ public class ExpressionTypingServices {
@Override
public void report(@NotNull Diagnostic diagnostic) {
if (diagnostic.getFactory() == TYPE_MISMATCH && ((DiagnosticWithPsiElement) diagnostic).getPsiElement() == expressionToWatch) {
if (diagnostic.getFactory() == TYPE_MISMATCH && diagnostic.getPsiElement() == expressionToWatch) {
mismatchFound[0] = true;
}
super.report(diagnostic);
@@ -89,7 +89,6 @@ public class ExpressionTypingUtils {
if (resultType != null) {
// TODO : Relax?
if (!isBoolean(context.semanticServices, resultType)) {
// context.trace.getErrorHandler().genericError(operationSign.getNode(), subjectName + " must return Boolean but returns " + resultType);
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, context.semanticServices.getStandardLibrary().getBooleanType(), resultType));
return false;
}
@@ -205,7 +205,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
ASTNode nameLabelNode = entry.getNameLabelNode();
if (nameLabelNode != null) {
// context.trace.getErrorHandler().genericError(nameLabelNode, "Unsupported [OperatorConventions]");
context.trace.report(UNSUPPORTED.on(nameLabelNode, getClass().getCanonicalName()));
context.trace.report(UNSUPPORTED.on(nameLabelNode.getPsi(), getClass().getCanonicalName()));
}
JetPattern entryPattern = entry.getPattern();
@@ -33,7 +33,7 @@ import java.util.List;
/**
* @author abreslav
*/
public class DescriptorRenderer implements Renderer {
public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
public static final DescriptorRenderer TEXT = new DescriptorRenderer();
@@ -97,11 +97,6 @@ public class DescriptorRenderer implements Renderer {
@NotNull
@Override
public String render(@Nullable Object object) {
assert object instanceof DeclarationDescriptor;
return render((DeclarationDescriptor) object);
}
public String render(DeclarationDescriptor declarationDescriptor) {
if (declarationDescriptor == null) return lt() + "null>";
StringBuilder stringBuilder = new StringBuilder();
@@ -4,29 +4,29 @@ trait MyTrait {
//properties
val a: Int
val a1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>1<!>
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val a2: Int
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> val a2: Int
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
var b: Int private set
var b1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; private set
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var b2: Int private set
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> var b2: Int private set
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
var <!BACKING_FIELD_IN_TRAIT!>c<!>: Int set(v: Int) { $c = v }
var <!BACKING_FIELD_IN_TRAIT!>c1<!>: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; set(v: Int) { $c1 = v }
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
val e: Int get() = a
val e1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = a
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
//methods
fun f()
fun g() {}
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> fun h()
<!REDUNDANT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
<!ABSTRACT_MODIFIER_IN_TRAIT!>abstract<!> fun h()
<!ABSTRACT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
@@ -42,5 +42,4 @@ trait MyTrait {
var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.jet.checkers.CheckerTestUtil;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -48,7 +49,7 @@ public class CopyAsDiagnosticTestAction extends AnAction {
assert editor != null && psiFile != null;
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile) psiFile);
List<TextRange> syntaxError = AnalyzingUtils.getSyntaxErrorRanges(psiFile);
List<PsiErrorElement> syntaxError = AnalyzingUtils.getSyntaxErrorRanges(psiFile);
String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, bindingContext, syntaxError).toString();
@@ -79,7 +79,7 @@ public class JetPsiChecker implements Annotator {
for (Diagnostic diagnostic : diagnostics) {
// This is needed because we have the same context for all files
if (diagnostic.getFactory().getPsiFile(diagnostic) != file) continue;
if (diagnostic.getPsiFile() != file) continue;
registerDiagnosticAnnotations(diagnostic, redeclarations, holder);
}
@@ -158,7 +158,7 @@ public class JetPsiChecker implements Annotator {
@NotNull Set<PsiElement> redeclarations,
@NotNull final AnnotationHolder holder
) {
List<TextRange> textRanges = diagnostic.getFactory().getTextRanges(diagnostic);
List<TextRange> textRanges = diagnostic.getTextRanges();
if (diagnostic.getSeverity() == Severity.ERROR) {
if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) {
return;
@@ -226,21 +226,18 @@ public class JetPsiChecker implements Annotator {
return null;
}
if (diagnostic instanceof DiagnosticWithPsiElementImpl && diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.get(factory);
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
IntentionAction action = null;
if (intentionActionFactory != null) {
action = intentionActionFactory.createAction((DiagnosticWithPsiElement) diagnostic);
}
if (action != null) {
annotation.registerFix(action);
}
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.getActionFactories(diagnostic.getFactory());
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
IntentionAction action = null;
if (intentionActionFactory != null) {
action = intentionActionFactory.createAction(diagnostic);
}
if (action != null) {
annotation.registerFix(action);
}
}
Collection<IntentionAction> actions = QuickFixes.get(diagnostic.getFactory());
Collection<IntentionAction> actions = QuickFixes.getActions(diagnostic.getFactory());
for (IntentionAction action : actions) {
annotation.registerFix(action);
}
@@ -259,7 +256,7 @@ public class JetPsiChecker implements Annotator {
@Nullable
private Annotation markRedeclaration(@NotNull Set<PsiElement> redeclarations, @NotNull RedeclarationDiagnostic diagnostic, @NotNull AnnotationHolder holder) {
if (!redeclarations.add(diagnostic.getPsiElement())) return null;
return holder.createErrorAnnotation(diagnostic.getFactory().getTextRanges(diagnostic).get(0), getMessage(diagnostic));
return holder.createErrorAnnotation(diagnostic.getTextRanges().get(0), getMessage(diagnostic));
}
@@ -18,11 +18,14 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
@@ -67,12 +70,15 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
element.replace(newElement);
}
public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunction>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunction;
return new AddFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
public JetIntentionAction createAction(Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
JetFunction function = PsiTreeUtil.getParentOfType(element, JetFunction.class, false);
if (function == null) return null;
return new AddFunctionBodyFix(function);
}
};
}
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
@@ -120,17 +120,14 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
return true;
}
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier, final JetToken[] modifiersThatCanBeReplaced) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
public static JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final JetToken[] modifiersThatCanBeReplaced) {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return new AddModifierFix((JetModifierListOwner) diagnostic.getPsiElement(), modifier, modifiersThatCanBeReplaced);
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, JetModifierListOwner.class);
if (modifierListOwner == null) return null;
return new AddModifierFix(modifierListOwner, modifier, modifiersThatCanBeReplaced);
}
};
}
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
return createFactory(modifier, new JetToken[0]);
}
}
@@ -23,23 +23,18 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
/**
* @author svtk
*/
* @author svtk
*/
public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
private JetType type;
public AddReturnTypeFix(@NotNull JetNamedDeclaration element, JetType type) {
public AddReturnTypeFix(@NotNull JetNamedDeclaration element) {
super(element);
this.type = type;
}
@NotNull
@@ -56,13 +51,16 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return super.isAvailable(project, editor, file) && !ErrorUtils.isErrorType(type);
JetType type = QuickFixUtil.getDeclarationReturnType(element);
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
if (!(file instanceof JetFile)) return;
PsiElement newElement;
JetType type = QuickFixUtil.getDeclarationReturnType(element);
if (type == null) return;
if (element instanceof JetProperty) {
newElement = addPropertyType(project, (JetProperty) element, type);
}
@@ -70,7 +68,7 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
assert element instanceof JetFunction;
newElement = addFunctionType(project, (JetFunction) element, type);
}
ImportClassHelper.addImportDirectiveIfNeeded(type, (JetFile)file);
ImportClassHelper.addImportDirectiveIfNeeded(type, (JetFile) file);
element.replace(newElement);
}
@@ -79,7 +77,7 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
return true;
}
public static JetProperty addPropertyType(Project project, JetProperty property, JetType type) {
public static JetProperty addPropertyType(@NotNull Project project, @NotNull JetProperty property, @NotNull JetType type) {
JetProperty newProperty = (JetProperty) property.copy();
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
@@ -88,7 +86,7 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
return newProperty;
}
public static JetFunction addFunctionType(Project project, JetFunction function, JetType type) {
public static JetFunction addFunctionType(@NotNull Project project, @NotNull JetFunction function, @NotNull JetType type) {
JetFunction newFunction = (JetFunction) function.copy();
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
@@ -103,14 +101,13 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
element.addRangeAfter(colon.getFirst(), colon.getSecond(), anchor);
}
public static JetIntentionActionFactory<JetNamedDeclaration> createFactory() {
return new JetIntentionActionFactory<JetNamedDeclaration>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetNamedDeclaration> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetNamedDeclaration;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
return new AddReturnTypeFix((JetNamedDeclaration) diagnostic.getPsiElement(), type);
public JetIntentionAction<JetNamedDeclaration> createAction(Diagnostic diagnostic) {
JetNamedDeclaration declaration = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedDeclaration.class);
if (declaration == null) return null;
return new AddReturnTypeFix(declaration);
}
};
}
@@ -18,18 +18,19 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.psi.JetTypeReference;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
@@ -37,17 +38,30 @@ import org.jetbrains.jet.plugin.JetBundle;
* @author svtk
*/
public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccessor> {
private final JetType type;
public ChangeAccessorTypeFix(@NotNull JetPropertyAccessor element, JetType type) {
public ChangeAccessorTypeFix(@NotNull JetPropertyAccessor element) {
super(element);
this.type = type;
}
@Nullable
private JetType getPropertyType() {
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
if (property == null) return null;
return QuickFixUtil.getDeclarationReturnType(property);
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
JetType type = getPropertyType();
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
}
@NotNull
@Override
public String getText() {
return element.isGetter() ? JetBundle.message("change.getter.type", type) : JetBundle.message("change.setter.type", type);
JetType type = getPropertyType();
return element.isGetter()
? JetBundle.message("change.getter.type", type)
: JetBundle.message("change.setter.type", type);
}
@NotNull
@@ -58,6 +72,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetType type = getPropertyType();
if (type == null) return;
JetPropertyAccessor newElement = (JetPropertyAccessor) element.copy();
JetTypeReference newTypeReference = JetPsiFactory.createType(project, type.toString());
@@ -75,15 +91,14 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
}
element.replace(newElement);
}
public static JetIntentionActionFactory<JetPropertyAccessor> createFactory() {
return new JetIntentionActionFactory<JetPropertyAccessor>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetPropertyAccessor;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
return new ChangeAccessorTypeFix((JetPropertyAccessor) diagnostic.getPsiElement(), type);
public JetIntentionAction<JetPropertyAccessor> createAction(Diagnostic diagnostic) {
JetPropertyAccessor accessor = QuickFixUtil.getParentElementOfType(diagnostic, JetPropertyAccessor.class);
if (accessor == null) return null;
return new ChangeAccessorTypeFix(accessor);
}
};
}
@@ -18,12 +18,12 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.plugin.JetBundle;
/**
@@ -52,12 +52,22 @@ public class ChangeToBackingFieldFix extends JetIntentionAction<JetSimpleNameExp
element.replace(backingField);
}
public static JetIntentionActionFactory<JetSimpleNameExpression> createFactory() {
return new JetIntentionActionFactory<JetSimpleNameExpression>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetSimpleNameExpression> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetSimpleNameExpression;
return new ChangeToBackingFieldFix((JetSimpleNameExpression) diagnostic.getPsiElement());
public JetIntentionAction<JetSimpleNameExpression> createAction(Diagnostic diagnostic) {
JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class);
if (expression == null) {
PsiElement element = diagnostic.getPsiElement();
if (element instanceof JetQualifiedExpression && ((JetQualifiedExpression) element).getReceiverExpression() instanceof JetThisExpression) {
JetExpression selector = ((JetQualifiedExpression) element).getSelectorExpression();
if (selector instanceof JetSimpleNameExpression) {
expression = (JetSimpleNameExpression) selector;
}
}
}
if (expression == null) return null;
return new ChangeToBackingFieldFix(expression);
}
};
}
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass;
@@ -61,12 +61,14 @@ public class ChangeToInvocationFix extends JetIntentionAction<JetDelegatorToSupe
element.replace(specifier);
}
public static JetIntentionActionFactory<JetDelegatorToSuperClass> createFactory() {
return new JetIntentionActionFactory<JetDelegatorToSuperClass>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetDelegatorToSuperClass> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass;
return new ChangeToInvocationFix((JetDelegatorToSuperClass) diagnostic.getPsiElement());
public JetIntentionAction<JetDelegatorToSuperClass> createAction(Diagnostic diagnostic) {
if (diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass) {
return new ChangeToInvocationFix((JetDelegatorToSuperClass) diagnostic.getPsiElement());
}
return null;
}
};
}
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.Severity;
import java.util.List;
/**
* @author svtk
*/
public class FakeDiagnosticForQuickFixes implements Diagnostic {
private final PsiElement element;
public FakeDiagnosticForQuickFixes(PsiElement element) {
this.element = element;
}
@NotNull
@Override
public AbstractDiagnosticFactory getFactory() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public String getMessage() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Severity getSeverity() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public PsiElement getPsiElement() {
return element;
}
@NotNull
@Override
public List<TextRange> getTextRanges() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public PsiFile getPsiFile() {
return element.getContainingFile();
}
}
@@ -38,7 +38,7 @@ import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
@@ -205,11 +205,11 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
}
@Nullable
public static JetIntentionActionFactory<JetSimpleNameExpression> createFactory() {
return new JetIntentionActionFactory<JetSimpleNameExpression>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetSimpleNameExpression> createAction(@NotNull DiagnosticWithPsiElement diagnostic) {
public JetIntentionAction<JetSimpleNameExpression> createAction(@NotNull Diagnostic diagnostic) {
// There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case
if (diagnostic.getPsiElement() instanceof JetSimpleNameExpression) {
JetSimpleNameExpression psiElement = (JetSimpleNameExpression) diagnostic.getPsiElement();
@@ -219,4 +219,5 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
return null;
}
};
}}
}
}
@@ -21,12 +21,10 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import java.util.Arrays;
/**
* @author svtk
@@ -47,16 +45,4 @@ public abstract class JetIntentionAction<T extends PsiElement> implements Intent
public boolean startInWriteAction() {
return true;
}
public static DiagnosticWithParameters<PsiElement> assertAndCastToDiagnosticWithParameters(Diagnostic diagnostic, DiagnosticParameter... parameters) {
assert diagnostic instanceof DiagnosticWithParameters :
"For this type of quick fix diagnostic with additional " +
(parameters.length == 1 ? "parameter '" + parameters[0] + "'" : "parameters " + Arrays.asList(parameters)) + " is expected";
for (DiagnosticParameter parameter : parameters) {
assert ((DiagnosticWithParameters) diagnostic).hasParameter(parameter) :
"For this type of quick fix diagnostic with additional parameter '" + parameter + "' is expected";
}
return (DiagnosticWithParameters<PsiElement>) diagnostic;
}
}
@@ -16,14 +16,16 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import com.intellij.codeInsight.intention.IntentionAction;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
/**
* @author svtk
*/
public interface JetIntentionActionFactory<T extends PsiElement> {
public interface JetIntentionActionFactory {
JetIntentionAction<T> createAction(DiagnosticWithPsiElement diagnostic);
@Nullable
IntentionAction createAction(Diagnostic diagnostic);
}
@@ -16,18 +16,22 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.extapi.psi.ASTDelegatePsiElement;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElementImpl;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author svtk
@@ -36,54 +40,12 @@ public class QuickFixUtil {
private QuickFixUtil() {
}
public static <T extends PsiElement, P extends T> JetIntentionActionFactory<PsiElement> createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<P> parameter) {
return new JetIntentionActionFactory<PsiElement>() {
public static <T extends PsiElement> JetIntentionActionFactory createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory factory, final Class<T> aClass) {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<PsiElement> createAction(DiagnosticWithPsiElement diagnostic) {
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, parameter);
P element = diagnosticWithParameters.getParameter(parameter);
return (JetIntentionAction<PsiElement>) factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
}
};
}
public static <T extends PsiElement, P extends T> JetIntentionActionFactory<PsiElement> createFactoryRedirectingAdditionalInfoIfAnyToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<P> parameter) {
return new JetIntentionActionFactory<PsiElement>() {
@Override
public JetIntentionAction<PsiElement> createAction(DiagnosticWithPsiElement diagnostic) {
if (diagnostic instanceof DiagnosticWithParameters && ((DiagnosticWithParameters<PsiElement>) diagnostic).hasParameter(parameter)) {
P element = ((DiagnosticWithParameters<PsiElement>) diagnostic).getParameter(parameter);
return (JetIntentionAction<PsiElement>) factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
}
return createDoNothingAction(diagnostic);
}
};
}
public static JetIntentionAction<PsiElement> createDoNothingAction(DiagnosticWithPsiElement diagnostic) {
return new JetIntentionAction<PsiElement>(diagnostic.getPsiElement()) {
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return false;
}
@NotNull
@Override
public String getText() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public String getFamilyName() {
throw new UnsupportedOperationException();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
throw new UnsupportedOperationException();
public IntentionAction createAction(Diagnostic diagnostic) {
T element = getParentElementOfType(diagnostic, aClass);
return factory.createAction(new FakeDiagnosticForQuickFixes(element));
}
};
}
@@ -95,4 +57,23 @@ public class QuickFixUtil {
}
return false;
}
@Nullable
public static <T extends PsiElement> T getParentElementOfType(Diagnostic diagnostic, Class<T> aClass) {
return PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), aClass, false);
}
@Nullable
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
PsiFile file = declaration.getContainingFile();
if (!(file instanceof JetFile)) return null;
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache((JetFile) file, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
if (!(descriptor instanceof CallableDescriptor)) return null;
JetType type = ((CallableDescriptor) descriptor).getReturnType();
if (type instanceof DeferredType) {
type = ((DeferredType) type).getActualType();
}
return type;
}
}
@@ -19,12 +19,9 @@ package org.jetbrains.jet.plugin.quickfix;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lexer.JetToken;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
@@ -35,109 +32,107 @@ import java.util.Collection;
* @author svtk
*/
public class QuickFixes {
private static final Multimap<PsiElementOnlyDiagnosticFactory, JetIntentionActionFactory> jetActionMap = HashMultimap.create();
private static final Multimap<DiagnosticFactory, IntentionAction> actionMap = HashMultimap.create();
public static Collection<JetIntentionActionFactory> get(PsiElementOnlyDiagnosticFactory diagnosticFactory) {
return jetActionMap.get(diagnosticFactory);
private static final Multimap<AbstractDiagnosticFactory, JetIntentionActionFactory> factories = HashMultimap.create();
private static final Multimap<AbstractDiagnosticFactory, IntentionAction> actions = HashMultimap.create();
public static Collection<JetIntentionActionFactory> getActionFactories(AbstractDiagnosticFactory diagnosticFactory) {
return factories.get(diagnosticFactory);
}
public static Collection<IntentionAction> get(DiagnosticFactory diagnosticFactory) {
return actionMap.get(diagnosticFactory);
public static Collection<IntentionAction> getActions(AbstractDiagnosticFactory diagnosticFactory) {
return actions.get(diagnosticFactory);
}
private QuickFixes() {}
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, JetIntentionActionFactory<T> actionFactory) {
jetActionMap.put(diagnosticFactory, actionFactory);
}
static {
JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD);
JetIntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD);
JetIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD});
add(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_NOT_IN_CLASS, removeAbstractModifierFactory);
JetIntentionActionFactory<JetProperty> removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
add(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removePartsFromPropertyFactory);
factories.put(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_PROPERTY_NOT_IN_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_WITH_GETTER, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_WITH_GETTER, removePartsFromPropertyFactory);
JetIntentionActionFactory removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
factories.put(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removePartsFromPropertyFactory);
add(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removePartsFromPropertyFactory);
factories.put(Errors.ABSTRACT_PROPERTY_WITH_GETTER, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_PROPERTY_WITH_GETTER, removePartsFromPropertyFactory);
add(Errors.PROPERTY_INITIALIZER_IN_TRAIT, removePartsFromPropertyFactory);
factories.put(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removePartsFromPropertyFactory);
add(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
factories.put(Errors.PROPERTY_INITIALIZER_IN_TRAIT, removePartsFromPropertyFactory);
JetIntentionActionFactory<PsiElement> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.CLASS);
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
factories.put(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
JetIntentionActionFactory<JetFunction> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
JetIntentionActionFactory addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, JetClass.class);
factories.put(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeFunctionBodyFactory);
JetIntentionActionFactory removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
factories.put(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
JetIntentionActionFactory<JetFunction> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
factories.put(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeAbstractModifierFactory);
factories.put(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeFunctionBodyFactory);
add(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory);
add(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
JetIntentionActionFactory addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
factories.put(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
factories.put(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListFactory(JetTokens.OVERRIDE_KEYWORD));
add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
factories.put(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory);
factories.put(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
add(Errors.USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
add(Errors.USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
factories.put(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OVERRIDE_KEYWORD));
factories.put(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
JetIntentionActionFactory<JetPropertyAccessor> changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
add(Errors.WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
add(Errors.WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
factories.put(Errors.USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
factories.put(Errors.USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
add(Errors.USELESS_ELVIS, RemoveRightPartOfBinaryExpressionFix.createRemoveElvisOperatorFactory());
JetIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
factories.put(Errors.WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
factories.put(Errors.WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory(true);
add(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
factories.put(Errors.USELESS_ELVIS, RemoveRightPartOfBinaryExpressionFix.createRemoveElvisOperatorFactory());
JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS));
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
JetIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
factories.put(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
factories.put(Errors.ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD, true));
factories.put(Errors.OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD, true));
factories.put(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
JetIntentionActionFactory<JetModifierList> removeModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory();
add(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
add(Errors.ILLEGAL_MODIFIER, removeModifierFactory);
JetIntentionActionFactory addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
factories.put(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, JetClass.class));
factories.put(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
add(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory());
JetIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
factories.put(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
factories.put(Errors.REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
factories.put(Errors.ILLEGAL_MODIFIER, removeModifierFactory);
JetIntentionActionFactory<JetSimpleNameExpression> changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
add(Errors.INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, changeToBackingFieldFactory);
add(Errors.INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, changeToBackingFieldFactory);
factories.put(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory());
JetIntentionActionFactory<JetSimpleNameExpression> unresolvedReferenceFactory = ImportClassAndFunFix.createFactory();
add(Errors.UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
JetIntentionActionFactory changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
factories.put(Errors.INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, changeToBackingFieldFactory);
factories.put(Errors.INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, changeToBackingFieldFactory);
JetIntentionActionFactory unresolvedReferenceFactory = ImportClassAndFunFix.createFactory();
factories.put(Errors.UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
factories.put(Errors.SUPERTYPE_NOT_INITIALIZED_DEFAULT, ChangeToInvocationFix.createFactory());
add(Errors.SUPERTYPE_NOT_INITIALIZED_DEFAULT, ChangeToInvocationFix.createFactory());
ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler();
actionMap.put(Errors.ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
actionMap.put(Errors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
actions.put(Errors.ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
actions.put(Errors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler);
ChangeVariableMutabilityFix changeVariableMutabilityFix = new ChangeVariableMutabilityFix();
actionMap.put(Errors.VAL_WITH_SETTER, changeVariableMutabilityFix);
actionMap.put(Errors.VAL_REASSIGNMENT, changeVariableMutabilityFix);
actions.put(Errors.VAL_WITH_SETTER, changeVariableMutabilityFix);
actions.put(Errors.VAL_REASSIGNMENT, changeVariableMutabilityFix);
actionMap.put(Errors.UNNECESSARY_SAFE_CALL, new ReplaceCallFix(false));
actionMap.put(Errors.UNSAFE_CALL, new ReplaceCallFix(true));
actions.put(Errors.UNNECESSARY_SAFE_CALL, new ReplaceCallFix(false));
actions.put(Errors.UNSAFE_CALL, new ReplaceCallFix(true));
}
}
}
@@ -24,7 +24,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunction;
@@ -88,12 +88,13 @@ public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunction> {
return false;
}
public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunction>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunction;
return new RemoveFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
public JetIntentionAction<JetFunction> createAction(Diagnostic diagnostic) {
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
if (function == null) return null;
return new RemoveFunctionBodyFix(function);
}
};
}
@@ -21,12 +21,11 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
@@ -36,13 +35,14 @@ import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.JetBundle;
/**
* @author svtk
*/
public class RemoveModifierFix {
* @author svtk
*/
public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner> {
private final JetKeywordToken modifier;
private final boolean isRedundant;
public RemoveModifierFix(JetKeywordToken modifier, boolean isRedundant) {
public RemoveModifierFix(@NotNull JetModifierListOwner element, @NotNull JetKeywordToken modifier, boolean isRedundant) {
super(element);
this.modifier = modifier;
this.isRedundant = isRedundant;
}
@@ -56,8 +56,10 @@ public class RemoveModifierFix {
}
return JetBundle.message("remove.modifier", modifier.getValue());
}
private static String getFamilyName() {
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("remove.modifier.family");
}
@@ -87,111 +89,53 @@ public class RemoveModifierFix {
}
return modifierList;
}
private class RemoveModifierFromListOwner extends JetIntentionAction<JetModifierListOwner> {
public RemoveModifierFromListOwner(@NotNull JetModifierListOwner element) {
super(element);
}
@NotNull
@Override
public String getText() {
return makeText(element, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
}
@NotNull
@Override
public String getText() {
return makeText(element, modifier, isRedundant);
}
private class RemoveModifierFromList extends JetIntentionAction<JetModifierList> {
public RemoveModifierFromList(@NotNull JetModifierList element) {
super(element);
}
@NotNull
@Override
public String getText() {
return makeText(null, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierList newElement = (JetModifierList) element.copy();
element.replace(RemoveModifierFix.removeModifierFromList(newElement, modifier));
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}
private static RemoveModifierFix createRemoveModifierFixFromDiagnostic(DiagnosticWithPsiElement diagnostic, boolean isRedundant) {
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
return new RemoveModifierFix(modifier, isRedundant);
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier) {
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListOwnerFactory(modifier, false);
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory() {
return createRemoveModifierFromListFactory(false);
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, JetModifierListOwner.class);
if (modifierListOwner == null) return null;
return new RemoveModifierFix(modifierListOwner, modifier, isRedundant);
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListFactory(modifier, false);
public static JetIntentionActionFactory createRemoveModifierFactory() {
return createRemoveModifierFactory(false);
}
public static JetIntentionActionFactory createRemoveModifierFactory(final boolean isRedundant) {
return new JetIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, JetModifierListOwner.class);
if (modifierListOwner == null) return null;
PsiElement psiElement = diagnostic.getPsiElement();
IElementType elementType = psiElement.getNode().getElementType();
if (!(elementType instanceof JetKeywordToken)) return null;
JetKeywordToken modifier = (JetKeywordToken) elementType;
return new RemoveModifierFix(modifierListOwner, modifier, isRedundant);
}
};
}
}
@@ -20,16 +20,12 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
@@ -37,29 +33,23 @@ import org.jetbrains.jet.plugin.JetBundle;
* @author svtk
*/
public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty> {
private final JetType type;
private final boolean removeInitializer;
private final boolean removeGetter;
private final boolean removeSetter;
private RemovePartsFromPropertyFix(@NotNull JetProperty element, @Nullable JetType type, boolean removeInitializer, boolean removeGetter, boolean removeSetter) {
private RemovePartsFromPropertyFix(@NotNull JetProperty element, boolean removeInitializer, boolean removeGetter, boolean removeSetter) {
super(element);
this.type = type;
this.removeInitializer = removeInitializer;
this.removeGetter = removeGetter;
this.removeSetter = removeSetter;
}
private RemovePartsFromPropertyFix(@NotNull JetProperty element, @Nullable JetType type) {
this(element, type, element.getInitializer() != null,
private RemovePartsFromPropertyFix(@NotNull JetProperty element) {
this(element, element.getInitializer() != null,
element.getGetter() != null && element.getGetter().getBodyExpression() != null,
element.getSetter() != null && element.getSetter().getBodyExpression() != null);
}
private RemovePartsFromPropertyFix(@NotNull JetProperty element, boolean removeInitializer, boolean removeGetter, boolean removeSetter) {
this(element, null, removeInitializer, removeGetter, removeSetter);
}
private static String partsToRemove(boolean getter, boolean setter, boolean initializer) {
StringBuilder sb = new StringBuilder();
if (getter) {
@@ -95,9 +85,16 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
return JetBundle.message("remove.parts.from.property.family");
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
JetType type = QuickFixUtil.getDeclarationReturnType(element);
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
if (!(file instanceof JetFile)) return;
JetType type = QuickFixUtil.getDeclarationReturnType(element);
JetProperty newElement = (JetProperty) element.copy();
JetPropertyAccessor getter = newElement.getGetter();
if (removeGetter && getter != null) {
@@ -127,24 +124,15 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
element.replace(newElement);
}
public static JetIntentionActionFactory<JetProperty> createFactory() {
return new JetIntentionActionFactory<JetProperty>() {
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetProperty;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
return new RemovePartsFromPropertyFix((JetProperty) diagnostic.getPsiElement(), type);
}
};
}
public static JetIntentionActionFactory<JetProperty> createRemoveInitializerFactory() {
return new JetIntentionActionFactory<JetProperty>() {
@Override
public JetIntentionAction<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetProperty;
return new RemovePartsFromPropertyFix((JetProperty) diagnostic.getPsiElement(), true, false, false);
public JetIntentionAction<JetProperty> createAction(Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
assert element instanceof JetElement;
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
if (property == null) return null;
return new RemovePartsFromPropertyFix(property);
}
};
}
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
import org.jetbrains.jet.lang.psi.JetBinaryExpressionWithTypeRHS;
import org.jetbrains.jet.lang.psi.JetExpression;
@@ -30,9 +30,16 @@ import org.jetbrains.jet.plugin.JetBundle;
/**
* @author svtk
*/
public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
public RemoveRightPartOfBinaryExpressionFix(@NotNull T element) {
public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
private final String message;
public RemoveRightPartOfBinaryExpressionFix(@NotNull T element, String message) {
super(element);
this.message = message;
}
public String getText() {
return message;
}
@NotNull
@@ -53,34 +60,24 @@ public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpressi
}
}
public static JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS> createRemoveCastFactory() {
return new JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
public static JetIntentionActionFactory createRemoveCastFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetBinaryExpressionWithTypeRHS;
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement()) {
@NotNull
@Override
public String getText() {
return JetBundle.message("remove.cast");
}
};
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
if (expression == null) return null;
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>(expression, JetBundle.message("remove.cast"));
}
};
}
public static JetIntentionActionFactory<JetBinaryExpression> createRemoveElvisOperatorFactory() {
return new JetIntentionActionFactory<JetBinaryExpression>() {
public static JetIntentionActionFactory createRemoveElvisOperatorFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpression> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetBinaryExpression;
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpression>((JetBinaryExpression) diagnostic.getPsiElement()) {
@NotNull
@Override
public String getText() {
return JetBundle.message("remove.elvis.operator");
}
};
public JetIntentionAction<JetBinaryExpression> createAction(Diagnostic diagnostic) {
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
if (expression == null) return null;
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpression>(expression, JetBundle.message("remove.elvis.operator"));
}
};
}
@@ -18,10 +18,11 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetBinaryExpressionWithTypeRHS;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
@@ -33,6 +34,7 @@ import org.jetbrains.jet.plugin.JetBundle;
*/
public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
private final String operation;
public ReplaceOperationInBinaryExpressionFix(@NotNull T element, String operation) {
super(element);
this.operation = operation;
@@ -56,12 +58,13 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
}
}
public static JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS> createChangeCastToStaticAssertFactory() {
return new JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
public static JetIntentionActionFactory createChangeCastToStaticAssertFactory() {
return new JetIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetBinaryExpressionWithTypeRHS;
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement(), " : ") {
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
if (expression == null) return null;
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>(expression, " : ") {
@NotNull
@Override
public String getText() {
@@ -4,5 +4,5 @@ abstract class B() {
}
abstract class A() : B() {
abstract override<caret> fun foo()
abstract override <caret>fun foo()
}