From 1e1cad92f0e9e090a48bbeb3b040b0ad7008828c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 15 Sep 2011 14:13:38 +0400 Subject: [PATCH] Factories moved out of Errors.java --- .../AbstractDiagnosticFactory.java | 25 ++ .../AmbiguousDescriptorDiagnosticFactory.java | 29 ++ .../jet/lang/diagnostics/Errors.java | 257 +----------------- .../ParameterizedDiagnosticFactory1.java | 42 +++ .../ParameterizedDiagnosticFactory2.java | 46 ++++ .../ParameterizedDiagnosticFactory3.java | 50 ++++ .../diagnostics/RedeclarationDiagnostic.java | 46 ++++ .../RedeclarationDiagnosticFactory.java | 25 ++ .../diagnostics/SimpleDiagnosticFactory.java | 45 +++ .../UnresolvedReferenceDiagnosticFactory.java | 25 ++ .../jet/plugin/annotations/JetPsiChecker.java | 5 +- 11 files changed, 337 insertions(+), 258 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory1.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory3.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnostic.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnosticFactory.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnosticFactory.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnosticFactory.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java new file mode 100644 index 00000000000..93deb0fd0f7 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnosticFactory.java @@ -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(); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java new file mode 100644 index 00000000000..f3cc1e2a67d --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AmbiguousDescriptorDiagnosticFactory.java @@ -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> { + public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) { + return new AmbiguousDescriptorDiagnosticFactory(messageTemplate); + } + + public AmbiguousDescriptorDiagnosticFactory(String messageTemplate) { + super(Severity.ERROR, messageTemplate); + } + + @Override + protected String makeMessageFor(@NotNull Collection argument) { + StringBuilder stringBuilder = new StringBuilder("\n"); + for (CallableDescriptor descriptor : argument) { + stringBuilder.append(DescriptorRenderer.TEXT.render(descriptor)).append("\n"); + } + return stringBuilder.toString(); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 9af5989bb43..8882cff414e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -1,15 +1,11 @@ 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.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.resolve.DescriptorRenderer; -import java.text.MessageFormat; import java.util.Collection; import java.util.Iterator; @@ -21,204 +17,7 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; */ public interface Errors { - 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(); - } - } - - 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(this, severity, message, element); - } - - @NotNull - @Override - public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) { - return ((DiagnosticWithTextRange) diagnostic).getTextRange(); - } - } - - public class ParameterizedDiagnosticFactory1 extends AbstractDiagnosticFactory { - public static ParameterizedDiagnosticFactory1 create(Severity severity, String messageStub) { - return new ParameterizedDiagnosticFactory1(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(this, severity, makeMessage(argument), element); - } - } - - public class ParameterizedDiagnosticFactory2 extends AbstractDiagnosticFactory { - public static ParameterizedDiagnosticFactory2 create(Severity severity, String messageStub) { - return new ParameterizedDiagnosticFactory2(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(this, severity, makeMessage(a, b), element); - } - } - - public class ParameterizedDiagnosticFactory3 extends AbstractDiagnosticFactory { - public static ParameterizedDiagnosticFactory3 create(Severity severity, String messageStub) { - return new ParameterizedDiagnosticFactory3(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(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> { - public static AmbiguousDescriptorDiagnosticFactory create(String messageTemplate) { - return new AmbiguousDescriptorDiagnosticFactory(messageTemplate); - } - - protected AmbiguousDescriptorDiagnosticFactory(String messageTemplate) { - super(Severity.ERROR, messageTemplate); - } - - @Override - protected String makeMessageFor(@NotNull Collection 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(); + UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.INSTANCE; 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 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; public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElement { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory1.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory1.java new file mode 100644 index 00000000000..748d4fc5b24 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory1.java @@ -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 extends AbstractDiagnosticFactory { + public static ParameterizedDiagnosticFactory1 create(Severity severity, String messageStub) { + return new ParameterizedDiagnosticFactory1(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(this, severity, makeMessage(argument), element); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java new file mode 100644 index 00000000000..81540baca6b --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java @@ -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 extends AbstractDiagnosticFactory { + public static ParameterizedDiagnosticFactory2 create(Severity severity, String messageStub) { + return new ParameterizedDiagnosticFactory2(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(this, severity, makeMessage(a, b), element); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory3.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory3.java new file mode 100644 index 00000000000..6df20171802 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory3.java @@ -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 extends AbstractDiagnosticFactory { + public static ParameterizedDiagnosticFactory3 create(Severity severity, String messageStub) { + return new ParameterizedDiagnosticFactory3(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(this, severity, makeMessage(a, b, c), element); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnostic.java new file mode 100644 index 00000000000..9fbb737d3b1 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnostic.java @@ -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; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnosticFactory.java new file mode 100644 index 00000000000..a4a790b62ed --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/RedeclarationDiagnosticFactory.java @@ -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 + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnosticFactory.java new file mode 100644 index 00000000000..a1a37fb1e8c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnosticFactory.java @@ -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(this, severity, message, element); + } + + @NotNull + @Override + public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) { + return ((DiagnosticWithTextRange) diagnostic).getTextRange(); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnosticFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnosticFactory.java new file mode 100644 index 00000000000..b1053f458e8 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/UnresolvedReferenceDiagnosticFactory.java @@ -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(); + } + +} diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java index 4b0f3d1ed48..2594bebdcf1 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java @@ -14,6 +14,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; 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.psi.*; 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); } } - else if (diagnostic instanceof Errors.RedeclarationDiagnostic) { - Errors.RedeclarationDiagnostic redeclarationDiagnostic = (Errors.RedeclarationDiagnostic) diagnostic; + else if (diagnostic instanceof RedeclarationDiagnostic) { + RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic; markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder); markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder); }