Mark dynamic calls in tests

This commit is contained in:
Andrey Breslav
2014-11-13 21:03:37 +03:00
parent c8029307fa
commit 4f3158abb3
8 changed files with 102 additions and 7 deletions
@@ -82,7 +82,12 @@ public class CheckerTestUtil {
private static final Pattern INDIVIDUAL_DIAGNOSTIC_PATTERN = Pattern.compile(INDIVIDUAL_DIAGNOSTIC);
private static final Pattern INDIVIDUAL_PARAMETER_PATTERN = Pattern.compile(DIAGNOSTIC_PARAMETER);
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(BindingContext bindingContext, final PsiElement root) {
@NotNull
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(
@NotNull BindingContext bindingContext,
@NotNull final PsiElement root,
boolean markDynamicCalls
) {
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics().all(),
new Predicate<Diagnostic>() {
@@ -94,12 +99,17 @@ public class CheckerTestUtil {
for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) {
diagnostics.add(new SyntaxErrorDiagnostic(errorElement));
}
List<Diagnostic> debugAnnotations = getDebugInfoDiagnostics(root, bindingContext);
List<Diagnostic> debugAnnotations = getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls);
diagnostics.addAll(debugAnnotations);
return diagnostics;
}
public static List<Diagnostic> getDebugInfoDiagnostics(@NotNull PsiElement root, @NotNull BindingContext bindingContext) {
@NotNull
public static List<Diagnostic> getDebugInfoDiagnostics(
@NotNull PsiElement root,
@NotNull BindingContext bindingContext,
final boolean markDynamicCalls
) {
final List<Diagnostic> debugAnnotations = Lists.newArrayList();
DebugInfoUtil.markDebugAnnotations(root, bindingContext, new DebugInfoUtil.DebugInfoReporter() {
@Override
@@ -117,6 +127,13 @@ public class CheckerTestUtil {
newDiagnostic(expression, DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET);
}
@Override
public void reportDynamicCall(@NotNull JetReferenceExpression expression) {
if (markDynamicCalls) {
newDiagnostic(expression, DebugInfoDiagnosticFactory.DYNAMIC);
}
}
private void newDiagnostic(JetReferenceExpression expression, DebugInfoDiagnosticFactory factory) {
debugAnnotations.add(new DebugInfoDiagnostic(expression, factory));
}
@@ -486,6 +503,7 @@ public class CheckerTestUtil {
public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE");
public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET");
public static final DebugInfoDiagnosticFactory MISSING_UNRESOLVED = new DebugInfoDiagnosticFactory("MISSING_UNRESOLVED");
public static final DebugInfoDiagnosticFactory DYNAMIC = new DebugInfoDiagnosticFactory("DYNAMIC");
private final String name;
private DebugInfoDiagnosticFactory(String name, Severity severity) {
@@ -23,7 +23,9 @@ import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Errors;
@@ -32,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypesPackage;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collection;
@@ -55,6 +58,8 @@ public class DebugInfoUtil {
public abstract void reportMissingUnresolved(@NotNull JetReferenceExpression expression);
public abstract void reportUnresolvedWithTarget(@NotNull JetReferenceExpression expression, @NotNull String target);
public void reportDynamicCall(@NotNull JetReferenceExpression expression) { }
}
public static void markDebugAnnotations(
@@ -113,6 +118,14 @@ public class DebugInfoUtil {
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, expression);
if (declarationDescriptor != null) {
target = declarationDescriptor.toString();
if (declarationDescriptor instanceof CallableDescriptor) {
CallableDescriptor callableDescriptor = (CallableDescriptor) declarationDescriptor;
ReceiverParameterDescriptor dispatchReceiverParameter = callableDescriptor.getDispatchReceiverParameter();
if (dispatchReceiverParameter != null && TypesPackage.isDynamic(dispatchReceiverParameter.getReturnType())) {
debugInfoReporter.reportDynamicCall(expression);
}
}
}
if (target == null) {
PsiElement labelTarget = bindingContext.get(LABEL_TARGET, expression);