check debug info errors in diagnostic tests
This commit is contained in:
@@ -16,33 +16,19 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.highlighter;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.checkers.DebugInfoUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
/**
|
||||
* Quick showing possible problems with jet internals in IDEA with a tooltips
|
||||
*
|
||||
@@ -50,8 +36,6 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
*/
|
||||
public class DebugInfoAnnotator implements Annotator {
|
||||
|
||||
public static final TokenSet EXCLUDED = TokenSet.create(COLON, AS_KEYWORD, AS_SAFE, IS_KEYWORD, NOT_IS, OROR, ANDAND, EQ, EQEQEQ, EXCLEQEQEQ, ELVIS, EXCLEXCL);
|
||||
|
||||
public static boolean isDebugInfoEnabled() {
|
||||
return ApplicationManager.getApplication().isInternal();
|
||||
}
|
||||
@@ -69,67 +53,24 @@ public class DebugInfoAnnotator implements Annotator {
|
||||
JetFile file = (JetFile) element;
|
||||
try {
|
||||
final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file).getBindingContext();
|
||||
|
||||
final Set<JetReferenceExpression> unresolvedReferences = Sets.newHashSet();
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
if (diagnostic.getFactory() instanceof UnresolvedReferenceDiagnosticFactory) {
|
||||
unresolvedReferences.add((JetReferenceExpression)diagnostic.getPsiElement());
|
||||
}
|
||||
}
|
||||
|
||||
file.acceptChildren(new JetVisitorVoid() {
|
||||
|
||||
DebugInfoUtil.markDebugAnnotations(file, bindingContext, new DebugInfoUtil.DebugInfoReporter() {
|
||||
@Override
|
||||
public void visitReferenceExpression(JetReferenceExpression expression) {
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) expression;
|
||||
IElementType elementType = expression.getNode().getElementType();
|
||||
if (elementType == JetNodeTypes.OPERATION_REFERENCE) {
|
||||
IElementType referencedNameElementType = nameExpression.getReferencedNameElementType();
|
||||
if (EXCLUDED.contains(referencedNameElementType)) {
|
||||
return;
|
||||
}
|
||||
if (JetTokens.LABELS.contains(referencedNameElementType)) return;
|
||||
}
|
||||
else if (nameExpression.getReferencedNameElementType() == JetTokens.THIS_KEYWORD) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String target = null;
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, expression);
|
||||
if (declarationDescriptor != null) {
|
||||
target = declarationDescriptor.toString();
|
||||
}
|
||||
else {
|
||||
PsiElement labelTarget = bindingContext.get(LABEL_TARGET, expression);
|
||||
if (labelTarget != null) {
|
||||
target = labelTarget.getText();
|
||||
}
|
||||
else {
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, expression);
|
||||
if (declarationDescriptors != null) {
|
||||
target = "[" + declarationDescriptors.size() + " descriptors]";
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean resolved = target != null;
|
||||
boolean unresolved = unresolvedReferences.contains(expression);
|
||||
JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression);
|
||||
if (declarationDescriptor != null && !ApplicationManager.getApplication().isUnitTestMode() && (ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(JetHighlightingColors.RESOLVED_TO_ERROR);
|
||||
}
|
||||
if (resolved && unresolved) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target).setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
else if (!resolved && !unresolved) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Reference is not resolved to anything, but is not marked unresolved").setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
public void reportErrorElement(@NotNull JetReferenceExpression expression) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element")
|
||||
.setTextAttributes(JetHighlightingColors.RESOLVED_TO_ERROR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement element) {
|
||||
element.acceptChildren(this);
|
||||
public void reportMissingUnresolved(@NotNull JetReferenceExpression expression) {
|
||||
holder.createErrorAnnotation(expression,
|
||||
"[DEBUG] Reference is not resolved to anything, but is not marked unresolved")
|
||||
.setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportUnresolvedWithTarget(@NotNull JetReferenceExpression expression, @NotNull String target) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target)
|
||||
.setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -144,4 +85,5 @@ public class DebugInfoAnnotator implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user