Factories moved out of Errors.java
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class AbstractDiagnosticFactory implements DiagnosticFactory {
|
||||||
|
protected final MessageFormat messageFormat;
|
||||||
|
protected final Severity severity;
|
||||||
|
|
||||||
|
public AbstractDiagnosticFactory(Severity severity, String message) {
|
||||||
|
this.severity = severity;
|
||||||
|
this.messageFormat = new MessageFormat(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
||||||
|
return ((DiagnosticWithTextRange) diagnostic).getTextRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class AmbiguousDescriptorDiagnosticFactory extends ParameterizedDiagnosticFactory1<Collection<? extends CallableDescriptor>> {
|
||||||
|
public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) {
|
||||||
|
return new AmbiguousDescriptorDiagnosticFactory(messageTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AmbiguousDescriptorDiagnosticFactory(String messageTemplate) {
|
||||||
|
super(Severity.ERROR, messageTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String makeMessageFor(@NotNull Collection<? extends CallableDescriptor> argument) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder("\n");
|
||||||
|
for (CallableDescriptor descriptor : argument) {
|
||||||
|
stringBuilder.append(DescriptorRenderer.TEXT.render(descriptor)).append("\n");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics;
|
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;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@@ -21,204 +17,7 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
|
|||||||
*/
|
*/
|
||||||
public interface Errors {
|
public interface Errors {
|
||||||
|
|
||||||
public class AbstractDiagnosticFactory implements DiagnosticFactory {
|
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.INSTANCE;
|
||||||
protected final MessageFormat messageFormat;
|
|
||||||
protected final Severity severity;
|
|
||||||
|
|
||||||
public AbstractDiagnosticFactory(Severity severity, String message) {
|
|
||||||
this.severity = severity;
|
|
||||||
this.messageFormat = new MessageFormat(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
|
||||||
return ((DiagnosticWithTextRange) diagnostic).getTextRange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SimpleDiagnosticFactory implements DiagnosticFactory {
|
|
||||||
|
|
||||||
public static SimpleDiagnosticFactory create(Severity severity, String message) {
|
|
||||||
return new SimpleDiagnosticFactory(severity, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final String message;
|
|
||||||
protected final Severity severity;
|
|
||||||
|
|
||||||
public SimpleDiagnosticFactory(Severity severity, String message) {
|
|
||||||
this.message = message;
|
|
||||||
this.severity = severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull TextRange range) {
|
|
||||||
return new GenericDiagnostic(this, severity, message, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull ASTNode node) {
|
|
||||||
return on(node.getTextRange());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull PsiElement element) {
|
|
||||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, message, element);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
|
||||||
return ((DiagnosticWithTextRange) diagnostic).getTextRange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ParameterizedDiagnosticFactory1<T> extends AbstractDiagnosticFactory {
|
|
||||||
public static <T> ParameterizedDiagnosticFactory1<T> create(Severity severity, String messageStub) {
|
|
||||||
return new ParameterizedDiagnosticFactory1<T>(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ParameterizedDiagnosticFactory1(Severity severity, String messageStub) {
|
|
||||||
super(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeMessage(@NotNull T argument) {
|
|
||||||
return messageFormat.format(new Object[]{makeMessageFor(argument)});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeMessageFor(T argument) {
|
|
||||||
return argument.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull TextRange range, @NotNull T argument) {
|
|
||||||
return new GenericDiagnostic(this, severity, makeMessage(argument), range);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull ASTNode node, @NotNull T argument) {
|
|
||||||
return on(node.getTextRange(), argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull PsiElement element, @NotNull T argument) {
|
|
||||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(argument), element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ParameterizedDiagnosticFactory2<A, B> extends AbstractDiagnosticFactory {
|
|
||||||
public static <A, B> ParameterizedDiagnosticFactory2<A, B> create(Severity severity, String messageStub) {
|
|
||||||
return new ParameterizedDiagnosticFactory2<A, B>(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ParameterizedDiagnosticFactory2(Severity severity, String messageStub) {
|
|
||||||
super(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 a.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeMessageForB(@NotNull B b) {
|
|
||||||
return b.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull TextRange range, @NotNull A a, @NotNull B b) {
|
|
||||||
return new GenericDiagnostic(this, severity, makeMessage(a, b), range);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull ASTNode node, @NotNull A a, @NotNull B b) {
|
|
||||||
return on(node.getTextRange(), a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b) {
|
|
||||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b), element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ParameterizedDiagnosticFactory3<A, B, C> extends AbstractDiagnosticFactory {
|
|
||||||
public static <A, B, C> ParameterizedDiagnosticFactory3<A, B, C> create(Severity severity, String messageStub) {
|
|
||||||
return new ParameterizedDiagnosticFactory3<A, B, C>(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ParameterizedDiagnosticFactory3(Severity severity, String messageStub) {
|
|
||||||
super(severity, messageStub);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 a.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeMessageForB(@NotNull B b) {
|
|
||||||
return b.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeMessageForC(@NotNull C c) {
|
|
||||||
return c.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull TextRange range, @NotNull A a, @NotNull B b, @NotNull C c) {
|
|
||||||
return new GenericDiagnostic(this, severity, makeMessage(a, b, c), range);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull ASTNode node, @NotNull A a, @NotNull B b, @NotNull C c) {
|
|
||||||
return on(node.getTextRange(), a, b, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
|
||||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b, c), element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UnresolvedReferenceDiagnosticFactory implements DiagnosticFactory {
|
|
||||||
private UnresolvedReferenceDiagnosticFactory() {}
|
|
||||||
|
|
||||||
public UnresolvedReferenceDiagnostic on(@NotNull JetReferenceExpression reference) {
|
|
||||||
return new UnresolvedReferenceDiagnostic(reference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
|
||||||
return ((UnresolvedReferenceDiagnostic) diagnostic).getTextRange();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AmbiguousDescriptorDiagnosticFactory extends ParameterizedDiagnosticFactory1<Collection<? extends CallableDescriptor>> {
|
|
||||||
public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) {
|
|
||||||
return new AmbiguousDescriptorDiagnosticFactory(messageTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AmbiguousDescriptorDiagnosticFactory(String messageTemplate) {
|
|
||||||
super(Severity.ERROR, messageTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String makeMessageFor(@NotNull Collection<? extends CallableDescriptor> argument) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder("\n");
|
|
||||||
for (CallableDescriptor descriptor : argument) {
|
|
||||||
stringBuilder.append(DescriptorRenderer.TEXT.render(descriptor)).append("\n");
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = new UnresolvedReferenceDiagnosticFactory();
|
|
||||||
SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces");
|
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"); // TODO: message
|
SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem"); // TODO: message
|
||||||
SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "'return' is not allowed here");
|
SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "'return' is not allowed here");
|
||||||
@@ -481,60 +280,6 @@ public interface Errors {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class RedeclarationDiagnosticFactory implements DiagnosticFactory {
|
|
||||||
|
|
||||||
public static final RedeclarationDiagnosticFactory INSTANCE = new RedeclarationDiagnosticFactory();
|
|
||||||
|
|
||||||
private RedeclarationDiagnosticFactory() {}
|
|
||||||
|
|
||||||
public RedeclarationDiagnostic on(DeclarationDescriptor a, DeclarationDescriptor b) {
|
|
||||||
return new RedeclarationDiagnostic(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
|
||||||
throw new UnsupportedOperationException(); // TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RedeclarationDiagnostic implements Diagnostic {
|
|
||||||
|
|
||||||
private final DeclarationDescriptor a;
|
|
||||||
private final DeclarationDescriptor b;
|
|
||||||
|
|
||||||
public RedeclarationDiagnostic(DeclarationDescriptor a, DeclarationDescriptor b) {
|
|
||||||
this.a = a;
|
|
||||||
this.b = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeclarationDescriptor getA() {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeclarationDescriptor getB() {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public DiagnosticFactory getFactory() {
|
|
||||||
return RedeclarationDiagnosticFactory.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return "Redeclaration";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Severity getSeverity() {
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE;
|
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE;
|
||||||
|
|
||||||
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElement<JetReferenceExpression> {
|
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElement<JetReferenceExpression> {
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
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 abreslav
|
||||||
|
*/
|
||||||
|
public class ParameterizedDiagnosticFactory1<T> extends AbstractDiagnosticFactory {
|
||||||
|
public static <T> ParameterizedDiagnosticFactory1<T> create(Severity severity, String messageStub) {
|
||||||
|
return new ParameterizedDiagnosticFactory1<T>(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterizedDiagnosticFactory1(Severity severity, String messageStub) {
|
||||||
|
super(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String makeMessage(@NotNull T argument) {
|
||||||
|
return messageFormat.format(new Object[]{makeMessageFor(argument)});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String makeMessageFor(T argument) {
|
||||||
|
return argument.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull TextRange range, @NotNull T argument) {
|
||||||
|
return new GenericDiagnostic(this, severity, makeMessage(argument), range);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull ASTNode node, @NotNull T argument) {
|
||||||
|
return on(node.getTextRange(), argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull PsiElement element, @NotNull T argument) {
|
||||||
|
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(argument), element);
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
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 abreslav
|
||||||
|
*/
|
||||||
|
public class ParameterizedDiagnosticFactory2<A, B> extends AbstractDiagnosticFactory {
|
||||||
|
public static <A, B> ParameterizedDiagnosticFactory2<A, B> create(Severity severity, String messageStub) {
|
||||||
|
return new ParameterizedDiagnosticFactory2<A, B>(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterizedDiagnosticFactory2(Severity severity, String messageStub) {
|
||||||
|
super(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 a.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String makeMessageForB(@NotNull B b) {
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull TextRange range, @NotNull A a, @NotNull B b) {
|
||||||
|
return new GenericDiagnostic(this, severity, makeMessage(a, b), range);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull ASTNode node, @NotNull A a, @NotNull B b) {
|
||||||
|
return on(node.getTextRange(), a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b) {
|
||||||
|
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b), element);
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
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 abreslav
|
||||||
|
*/
|
||||||
|
public class ParameterizedDiagnosticFactory3<A, B, C> extends AbstractDiagnosticFactory {
|
||||||
|
public static <A, B, C> ParameterizedDiagnosticFactory3<A, B, C> create(Severity severity, String messageStub) {
|
||||||
|
return new ParameterizedDiagnosticFactory3<A, B, C>(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterizedDiagnosticFactory3(Severity severity, String messageStub) {
|
||||||
|
super(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 a.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String makeMessageForB(@NotNull B b) {
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String makeMessageForC(@NotNull C c) {
|
||||||
|
return c.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull TextRange range, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||||
|
return new GenericDiagnostic(this, severity, makeMessage(a, b, c), range);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull ASTNode node, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||||
|
return on(node.getTextRange(), a, b, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||||
|
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b, c), element);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class RedeclarationDiagnostic implements Diagnostic {
|
||||||
|
|
||||||
|
private final DeclarationDescriptor a;
|
||||||
|
private final DeclarationDescriptor b;
|
||||||
|
|
||||||
|
public RedeclarationDiagnostic(DeclarationDescriptor a, DeclarationDescriptor b) {
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeclarationDescriptor getA() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeclarationDescriptor getB() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DiagnosticFactory getFactory() {
|
||||||
|
return RedeclarationDiagnosticFactory.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return "Redeclaration";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Severity getSeverity() {
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class RedeclarationDiagnosticFactory implements DiagnosticFactory {
|
||||||
|
|
||||||
|
public static final RedeclarationDiagnosticFactory INSTANCE = new RedeclarationDiagnosticFactory();
|
||||||
|
|
||||||
|
public RedeclarationDiagnosticFactory() {}
|
||||||
|
|
||||||
|
public RedeclarationDiagnostic on(DeclarationDescriptor a, DeclarationDescriptor b) {
|
||||||
|
return new RedeclarationDiagnostic(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
||||||
|
throw new UnsupportedOperationException(); // TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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 abreslav
|
||||||
|
*/
|
||||||
|
public class SimpleDiagnosticFactory implements DiagnosticFactory {
|
||||||
|
|
||||||
|
public static SimpleDiagnosticFactory create(Severity severity, String message) {
|
||||||
|
return new SimpleDiagnosticFactory(severity, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String message;
|
||||||
|
protected final Severity severity;
|
||||||
|
|
||||||
|
public SimpleDiagnosticFactory(Severity severity, String message) {
|
||||||
|
this.message = message;
|
||||||
|
this.severity = severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull TextRange range) {
|
||||||
|
return new GenericDiagnostic(this, severity, message, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull ASTNode node) {
|
||||||
|
return on(node.getTextRange());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Diagnostic on(@NotNull PsiElement element) {
|
||||||
|
return new DiagnosticWithPsiElement<PsiElement>(this, severity, message, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
||||||
|
return ((DiagnosticWithTextRange) diagnostic).getTextRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class UnresolvedReferenceDiagnosticFactory implements DiagnosticFactory {
|
||||||
|
public static final UnresolvedReferenceDiagnosticFactory INSTANCE = new UnresolvedReferenceDiagnosticFactory();
|
||||||
|
|
||||||
|
public UnresolvedReferenceDiagnosticFactory() {}
|
||||||
|
|
||||||
|
public Errors.UnresolvedReferenceDiagnostic on(@NotNull JetReferenceExpression reference) {
|
||||||
|
return new Errors.UnresolvedReferenceDiagnostic(reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) {
|
||||||
|
return ((Errors.UnresolvedReferenceDiagnostic) diagnostic).getTextRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.RedeclarationDiagnostic;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
@@ -120,8 +121,8 @@ public class JetPsiChecker implements Annotator {
|
|||||||
holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (diagnostic instanceof Errors.RedeclarationDiagnostic) {
|
else if (diagnostic instanceof RedeclarationDiagnostic) {
|
||||||
Errors.RedeclarationDiagnostic redeclarationDiagnostic = (Errors.RedeclarationDiagnostic) diagnostic;
|
RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic;
|
||||||
markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder);
|
markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder);
|
||||||
markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder);
|
markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user