Frontend tests: serialize dynamic call descriptors and check them in diagnostic tests.

This commit is contained in:
Zalim Bashorov
2014-12-15 22:37:41 +03:00
parent d071c44126
commit 2484954e2f
26 changed files with 324 additions and 26 deletions
@@ -17,7 +17,9 @@
package org.jetbrains.jet.checkers;
import com.google.common.base.Predicate;
import com.google.common.collect.*;
import com.google.common.collect.Collections2;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
@@ -30,12 +32,12 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.diagnostics.rendering.AbstractDiagnosticWithParametersRenderer;
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap;
import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticRenderer;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
@@ -87,7 +89,8 @@ public class CheckerTestUtil {
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(
@NotNull BindingContext bindingContext,
@NotNull final PsiElement root,
boolean markDynamicCalls
boolean markDynamicCalls,
@Nullable List<DeclarationDescriptor> dynamicCallDescriptors
) {
List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics().all(),
@@ -100,16 +103,17 @@ public class CheckerTestUtil {
for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) {
diagnostics.add(new SyntaxErrorDiagnostic(errorElement));
}
List<Diagnostic> debugAnnotations = getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls);
List<Diagnostic> debugAnnotations = getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls, dynamicCallDescriptors);
diagnostics.addAll(debugAnnotations);
return diagnostics;
}
@NotNull
public static List<Diagnostic> getDebugInfoDiagnostics(
private static List<Diagnostic> getDebugInfoDiagnostics(
@NotNull PsiElement root,
@NotNull BindingContext bindingContext,
final boolean markDynamicCalls
final boolean markDynamicCalls,
@Nullable final List<DeclarationDescriptor> dynamicCallDescriptors
) {
final List<Diagnostic> debugAnnotations = Lists.newArrayList();
DebugInfoUtil.markDebugAnnotations(root, bindingContext, new DebugInfoUtil.DebugInfoReporter() {
@@ -129,7 +133,11 @@ public class CheckerTestUtil {
}
@Override
public void reportDynamicCall(@NotNull JetElement element) {
public void reportDynamicCall(@NotNull JetElement element, DeclarationDescriptor declarationDescriptor) {
if (dynamicCallDescriptors != null) {
dynamicCallDescriptors.add(declarationDescriptor);
}
if (markDynamicCalls) {
newDiagnostic(element, DebugInfoDiagnosticFactory.DYNAMIC);
}
@@ -64,7 +64,7 @@ public class DebugInfoUtil {
public abstract void reportUnresolvedWithTarget(@NotNull JetReferenceExpression expression, @NotNull String target);
public void reportDynamicCall(@NotNull JetElement element) { }
public void reportDynamicCall(@NotNull JetElement element, DeclarationDescriptor declarationDescriptor) { }
}
public static void markDebugAnnotations(
@@ -99,11 +99,9 @@ public class DebugInfoUtil {
@Override
public void visitForExpression(@NotNull JetForExpression expression) {
JetExpression range = expression.getLoopRange();
if (reportIfDynamicCall(range, range, LOOP_RANGE_ITERATOR_RESOLVED_CALL) ||
reportIfDynamicCall(range, range, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL) ||
reportIfDynamicCall(range, range, LOOP_RANGE_NEXT_RESOLVED_CALL)) {
// for side-effect of the condition only
}
reportIfDynamicCall(range, range, LOOP_RANGE_ITERATOR_RESOLVED_CALL);
reportIfDynamicCall(range, range, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL);
reportIfDynamicCall(range, range, LOOP_RANGE_NEXT_RESOLVED_CALL);
super.visitForExpression(expression);
}
@@ -120,11 +118,9 @@ public class DebugInfoUtil {
VariableDescriptor descriptor = bindingContext.get(VARIABLE, property);
if (descriptor instanceof PropertyDescriptor && property.getDelegate() != null) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
if (reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getGetter(), DELEGATED_PROPERTY_RESOLVED_CALL)
|| reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getSetter(), DELEGATED_PROPERTY_RESOLVED_CALL)
|| reportIfDynamicCall(property.getDelegate(), propertyDescriptor, DELEGATED_PROPERTY_PD_RESOLVED_CALL)) {
// for side-effect of the condition only
}
reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getGetter(), DELEGATED_PROPERTY_RESOLVED_CALL);
reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getSetter(), DELEGATED_PROPERTY_RESOLVED_CALL);
reportIfDynamicCall(property.getDelegate(), propertyDescriptor, DELEGATED_PROPERTY_PD_RESOLVED_CALL);
}
super.visitProperty(property);
}
@@ -230,7 +226,7 @@ public class DebugInfoUtil {
private static boolean reportIfDynamic(JetElement element, DeclarationDescriptor declarationDescriptor, DebugInfoReporter debugInfoReporter) {
if (declarationDescriptor != null && TasksPackage.isDynamic(declarationDescriptor)) {
debugInfoReporter.reportDynamicCall(element);
debugInfoReporter.reportDynamicCall(element, declarationDescriptor);
return true;
}
return false;