Field names pushed into Diagnostic factories
This commit is contained in:
+16
@@ -8,6 +8,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class AbstractDiagnosticFactory implements DiagnosticFactory {
|
||||
|
||||
private String name = null;
|
||||
|
||||
/*package*/ void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getTextRange(@NotNull Diagnostic diagnostic) {
|
||||
@@ -18,6 +30,10 @@ public class AbstractDiagnosticFactory implements DiagnosticFactory {
|
||||
@Override
|
||||
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
|
||||
return ((DiagnosticWithTextRange) diagnostic).getPsiFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ public interface DiagnosticFactory {
|
||||
|
||||
@NotNull
|
||||
PsiFile getPsiFile(@NotNull Diagnostic diagnostic);
|
||||
|
||||
@NotNull
|
||||
String getName();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -282,5 +284,27 @@ public interface Errors {
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 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()) {
|
||||
if ((field.getModifiers() & Modifier.STATIC) != 0) {
|
||||
try {
|
||||
Object value = field.get(null);
|
||||
if (value instanceof AbstractDiagnosticFactory) {
|
||||
AbstractDiagnosticFactory factory = (AbstractDiagnosticFactory) value;
|
||||
factory.setName(field.getName());
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final Initializer INSTANCE = new Initializer();
|
||||
private Initializer() {};
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -29,4 +29,15 @@ public class RedeclarationDiagnosticFactory implements DiagnosticFactory {
|
||||
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "REDECLARATION";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,61 +45,7 @@ public class JetPsiChecker implements Annotator {
|
||||
try {
|
||||
final BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(file);
|
||||
|
||||
// ErrorHandler errorHandler = new ErrorHandler() {
|
||||
// private final Set<DeclarationDescriptor> redeclarations = new HashSet<DeclarationDescriptor>();
|
||||
//
|
||||
// @Override
|
||||
// public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
|
||||
// PsiReference reference = referenceExpression.getReference();
|
||||
// if (reference instanceof MultiRangeReference) {
|
||||
// MultiRangeReference mrr = (MultiRangeReference) reference;
|
||||
// for (TextRange range : mrr.getRanges()) {
|
||||
// holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
|
||||
// holder.createErrorAnnotation(expression, "Type mismatch: inferred type is " + actualType + " but " + expectedType + " was expected");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
|
||||
// markRedeclaration(existingDescriptor);
|
||||
// markRedeclaration(redeclaredDescriptor);
|
||||
// }
|
||||
//
|
||||
// private void markRedeclaration(DeclarationDescriptor redeclaration) {
|
||||
// if (!redeclarations.add(redeclaration)) return;
|
||||
// PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration);
|
||||
// if (declarationPsiElement instanceof JetNamedDeclaration) {
|
||||
// PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier();
|
||||
// if (nameIdentifier != null) {
|
||||
// holder.createErrorAnnotation(nameIdentifier, "Redeclaration");
|
||||
// }
|
||||
// }
|
||||
// else if (declarationPsiElement != null) {
|
||||
// holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
|
||||
// holder.createErrorAnnotation(node, errorMessage);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void genericWarning(@NotNull ASTNode node, @NotNull String message) {
|
||||
// holder.createWarningAnnotation(node, message);
|
||||
// }
|
||||
// };
|
||||
|
||||
if (errorReportingEnabled) {
|
||||
// ErrorHandler.applyHandler(errorHandler, bindingContext);
|
||||
Collection<Diagnostic> diagnostics = bindingContext.getDiagnostics();
|
||||
Set<DeclarationDescriptor> redeclarations = new HashSet<DeclarationDescriptor>();
|
||||
for (Diagnostic diagnostic : diagnostics) {
|
||||
|
||||
Reference in New Issue
Block a user