diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/CheckerTestUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/checkers/CheckerTestUtil.java index 89fccd0f117..3d7b9e29866 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/CheckerTestUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/CheckerTestUtil.java @@ -30,6 +30,8 @@ import com.intellij.util.Function; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; +import kotlin.Pair; +import kotlin.TuplesKt; import kotlin.collections.CollectionsKt; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; @@ -44,20 +46,20 @@ import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticRenderer; import org.jetbrains.kotlin.psi.KtElement; import org.jetbrains.kotlin.psi.KtExpression; import org.jetbrains.kotlin.psi.KtReferenceExpression; -import org.jetbrains.kotlin.psi.KtWhenExpression; import org.jetbrains.kotlin.resolve.AnalyzingUtils; import org.jetbrains.kotlin.resolve.BindingContext; +import org.jetbrains.kotlin.util.slicedMap.WritableSlice; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CheckerTestUtil { - public static final Comparator DIAGNOSTIC_COMPARATOR = new Comparator() { + public static final Comparator DIAGNOSTIC_COMPARATOR = new Comparator() { @Override - public int compare(@NotNull Diagnostic o1, @NotNull Diagnostic o2) { - List ranges1 = o1.getTextRanges(); - List ranges2 = o2.getTextRanges(); + public int compare(@NotNull ActualDiagnostic o1, @NotNull ActualDiagnostic o2) { + List ranges1 = o1.diagnostic.getTextRanges(); + List ranges2 = o2.diagnostic.getTextRanges(); int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size(); for (int i = 0; i < minNumberOfRanges; i++) { TextRange range1 = ranges1.get(i); @@ -90,37 +92,38 @@ public class CheckerTestUtil { private static final Pattern INDIVIDUAL_PARAMETER_PATTERN = Pattern.compile(DIAGNOSTIC_PARAMETER); @NotNull - public static List getDiagnosticsIncludingSyntaxErrors( + public static List getDiagnosticsIncludingSyntaxErrors( @NotNull BindingContext bindingContext, - @NotNull final PsiElement root, + @NotNull PsiElement root, boolean markDynamicCalls, @Nullable List dynamicCallDescriptors ) { - List diagnostics = new ArrayList(); - diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics().all(), - new Predicate() { - @Override - public boolean apply(Diagnostic diagnostic) { - return PsiTreeUtil.isAncestor(root, diagnostic.getPsiElement(), false); - } - })); - for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) { - diagnostics.add(new SyntaxErrorDiagnostic(errorElement)); + List diagnostics = new ArrayList(); + for (Diagnostic diagnostic : bindingContext.getDiagnostics().all()) { + if (PsiTreeUtil.isAncestor(root, diagnostic.getPsiElement(), false)) { + diagnostics.add(new ActualDiagnostic(diagnostic)); + } } - List debugAnnotations = getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls, dynamicCallDescriptors); + + for (PsiErrorElement errorElement : AnalyzingUtils.getSyntaxErrorRanges(root)) { + diagnostics.add(new ActualDiagnostic(new SyntaxErrorDiagnostic(errorElement))); + } + + List debugAnnotations = getDebugInfoDiagnostics(root, bindingContext, markDynamicCalls, dynamicCallDescriptors); diagnostics.addAll(debugAnnotations); return diagnostics; } @SuppressWarnings("TestOnlyProblems") @NotNull - private static List getDebugInfoDiagnostics( + private static List getDebugInfoDiagnostics( @NotNull PsiElement root, @NotNull BindingContext bindingContext, final boolean markDynamicCalls, @Nullable final List dynamicCallDescriptors ) { - final List debugAnnotations = Lists.newArrayList(); + final List debugAnnotations = new ArrayList(); + DebugInfoUtil.markDebugAnnotations(root, bindingContext, new DebugInfoUtil.DebugInfoReporter() { @Override public void reportElementWithErrorType(@NotNull KtReferenceExpression expression) { @@ -149,35 +152,26 @@ public class CheckerTestUtil { } private void newDiagnostic(KtElement element, DebugInfoDiagnosticFactory factory) { - debugAnnotations.add(new DebugInfoDiagnostic(element, factory)); + debugAnnotations.add(new ActualDiagnostic(new DebugInfoDiagnostic(element, factory))); } }); + // this code is used in tests and in internal action 'copy current file as diagnostic test' - for (KtExpression expression : bindingContext.getSliceContents(BindingContext.SMARTCAST).keySet()) { - if (PsiTreeUtil.isAncestor(root, expression, false)) { - debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.SMARTCAST)); - } - } - for (KtExpression expression : bindingContext.getSliceContents(BindingContext.IMPLICIT_RECEIVER_SMARTCAST).keySet()) { - if (PsiTreeUtil.isAncestor(root, expression, false)) { - debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.IMPLICIT_RECEIVER_SMARTCAST)); - } - } - for (KtExpression expression : bindingContext.getSliceContents(BindingContext.SMARTCAST_NULL).keySet()) { - if (PsiTreeUtil.isAncestor(root, expression, false)) { - debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.CONSTANT)); - } - } - for (KtExpression expression : bindingContext.getSliceContents(BindingContext.LEAKING_THIS).keySet()) { - if (PsiTreeUtil.isAncestor(root, expression, false)) { - debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.LEAKING_THIS)); - } - } - for (KtWhenExpression expression : bindingContext.getSliceContents(BindingContext.IMPLICIT_EXHAUSTIVE_WHEN).keySet()) { - if (PsiTreeUtil.isAncestor(root, expression, false)) { - debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.IMPLICIT_EXHAUSTIVE)); + //noinspection unchecked + for (Pair, DebugInfoDiagnosticFactory> factory : Arrays.asList( + TuplesKt.to(BindingContext.SMARTCAST, DebugInfoDiagnosticFactory.SMARTCAST), + TuplesKt.to(BindingContext.IMPLICIT_RECEIVER_SMARTCAST, DebugInfoDiagnosticFactory.IMPLICIT_RECEIVER_SMARTCAST), + TuplesKt.to(BindingContext.SMARTCAST_NULL, DebugInfoDiagnosticFactory.CONSTANT), + TuplesKt.to(BindingContext.LEAKING_THIS, DebugInfoDiagnosticFactory.LEAKING_THIS), + TuplesKt.to(BindingContext.IMPLICIT_EXHAUSTIVE_WHEN, DebugInfoDiagnosticFactory.IMPLICIT_EXHAUSTIVE) + )) { + for (KtExpression expression : bindingContext.getSliceContents(factory.getFirst()).keySet()) { + if (PsiTreeUtil.isAncestor(root, expression, false)) { + debugAnnotations.add(new ActualDiagnostic(new DebugInfoDiagnostic(expression, factory.getSecond()))); + } } } + return debugAnnotations; } @@ -189,12 +183,12 @@ public class CheckerTestUtil { void unexpectedDiagnostic(TextDiagnostic diagnostic, int actualStart, int actualEnd); } - public static Map diagnosticsDiff( + public static Map diagnosticsDiff( List expected, - Collection actual, + Collection actual, DiagnosticDiffCallbacks callbacks ) { - Map diagnosticToExpectedDiagnostic = new HashMap(); + Map diagnosticToExpectedDiagnostic = new HashMap(); assertSameFile(actual); @@ -256,7 +250,7 @@ public class CheckerTestUtil { @NotNull DiagnosticDiffCallbacks callbacks, @NotNull DiagnosedRange currentExpected, @NotNull DiagnosticDescriptor currentActual, - @NotNull Map diagnosticToInput + @NotNull Map diagnosticToInput ) { int expectedStart = currentExpected.getStart(); int expectedEnd = currentExpected.getEnd(); @@ -265,21 +259,21 @@ public class CheckerTestUtil { int actualEnd = currentActual.getEnd(); assert expectedStart == actualStart && expectedEnd == actualEnd; - Map actualDiagnostics = currentActual.getTextDiagnosticsMap(); + Map actualDiagnostics = currentActual.getTextDiagnosticsMap(); List expectedDiagnostics = currentExpected.getDiagnostics(); for (final TextDiagnostic expectedDiagnostic : expectedDiagnostics) { - Map.Entry actualDiagnosticEntry = CollectionsKt.firstOrNull( - actualDiagnostics.entrySet(), new Function1, Boolean>() { + Map.Entry actualDiagnosticEntry = CollectionsKt.firstOrNull( + actualDiagnostics.entrySet(), new Function1, Boolean>() { @Override - public Boolean invoke(Map.Entry entry) { + public Boolean invoke(Map.Entry entry) { return expectedDiagnostic.getName().equals(entry.getValue().getName()); } } ); if (actualDiagnosticEntry != null) { - Diagnostic actualDiagnostic = actualDiagnosticEntry.getKey(); + ActualDiagnostic actualDiagnostic = actualDiagnosticEntry.getKey(); TextDiagnostic actualTextDiagnostic = actualDiagnosticEntry.getValue(); if (!compareTextDiagnostic(expectedDiagnostic, actualTextDiagnostic)) { @@ -315,17 +309,17 @@ public class CheckerTestUtil { return true; } - private static void assertSameFile(Collection actual) { + private static void assertSameFile(Collection actual) { if (actual.isEmpty()) return; - PsiFile file = actual.iterator().next().getPsiElement().getContainingFile(); - for (Diagnostic diagnostic : actual) { - assert diagnostic.getPsiFile().equals(file) - : "All diagnostics should come from the same file: " + diagnostic.getPsiFile() + ", " + file; + PsiFile file = CollectionsKt.first(actual).getFile(); + for (ActualDiagnostic actualDiagnostic : actual) { + assert actualDiagnostic.getFile().equals(file) + : "All diagnostics should come from the same file: " + actualDiagnostic.getFile() + ", " + file; } } private static void unexpectedDiagnostics(DiagnosticDescriptor descriptor, DiagnosticDiffCallbacks callbacks) { - for (Diagnostic diagnostic : descriptor.diagnostics) { + for (ActualDiagnostic diagnostic : descriptor.diagnostics) { callbacks.unexpectedDiagnostic(TextDiagnostic.asTextDiagnostic(diagnostic), descriptor.start, descriptor.end); } } @@ -371,28 +365,30 @@ public class CheckerTestUtil { return matcher.replaceAll(""); } - public static StringBuffer addDiagnosticMarkersToText(@NotNull PsiFile psiFile, @NotNull Collection diagnostics) { - return addDiagnosticMarkersToText(psiFile, diagnostics, Collections.emptyMap(), - new Function() { - @Override - public String fun(PsiFile file) { - return file.getText(); - } - }); + public static StringBuffer addDiagnosticMarkersToText(@NotNull PsiFile psiFile, @NotNull Collection diagnostics) { + return addDiagnosticMarkersToText( + psiFile, diagnostics, Collections.emptyMap(), + new Function() { + @Override + public String fun(PsiFile file) { + return file.getText(); + } + } + ); } public static StringBuffer addDiagnosticMarkersToText( @NotNull final PsiFile psiFile, - @NotNull Collection diagnostics, - @NotNull Map diagnosticToExpectedDiagnostic, + @NotNull Collection diagnostics, + @NotNull Map diagnosticToExpectedDiagnostic, @NotNull Function getFileText ) { String text = getFileText.fun(psiFile); StringBuffer result = new StringBuffer(); - diagnostics = Collections2.filter(diagnostics, new Predicate() { + diagnostics = Collections2.filter(diagnostics, new Predicate() { @Override - public boolean apply(Diagnostic diagnostic) { - return psiFile.equals(diagnostic.getPsiFile()); + public boolean apply(ActualDiagnostic actualDiagnostic) { + return psiFile.equals(actualDiagnostic.getFile()); } }); if (!diagnostics.isEmpty()) { @@ -449,11 +445,11 @@ public class CheckerTestUtil { private static void openDiagnosticsString( StringBuffer result, DiagnosticDescriptor currentDescriptor, - Map diagnosticToExpectedDiagnostic + Map diagnosticToExpectedDiagnostic ) { result.append(" iterator = currentDescriptor.diagnostics.iterator(); iterator.hasNext(); ) { - Diagnostic diagnostic = iterator.next(); + for (Iterator iterator = currentDescriptor.diagnostics.iterator(); iterator.hasNext(); ) { + ActualDiagnostic diagnostic = iterator.next(); TextDiagnostic expectedDiagnostic = diagnosticToExpectedDiagnostic.get(diagnostic); if (expectedDiagnostic != null) { TextDiagnostic actualTextDiagnostic = TextDiagnostic.asTextDiagnostic(diagnostic); @@ -465,7 +461,7 @@ public class CheckerTestUtil { } } else { - result.append(diagnostic.getFactory().getName()); + result.append(diagnostic.getName()); } if (iterator.hasNext()) { result.append(", "); @@ -579,12 +575,13 @@ public class CheckerTestUtil { } @NotNull - private static List getSortedDiagnosticDescriptors(@NotNull Collection diagnostics) { - LinkedListMultimap diagnosticsGroupedByRanges = LinkedListMultimap.create(); - for (Diagnostic diagnostic : diagnostics) { + private static List getSortedDiagnosticDescriptors(@NotNull Collection diagnostics) { + LinkedListMultimap diagnosticsGroupedByRanges = LinkedListMultimap.create(); + for (ActualDiagnostic actualDiagnostic : diagnostics) { + Diagnostic diagnostic = actualDiagnostic.diagnostic; if (!diagnostic.isValid()) continue; for (TextRange textRange : diagnostic.getTextRanges()) { - diagnosticsGroupedByRanges.put(textRange, diagnostic); + diagnosticsGroupedByRanges.put(textRange, actualDiagnostic); } } List diagnosticDescriptors = Lists.newArrayList(); @@ -605,17 +602,17 @@ public class CheckerTestUtil { private static class DiagnosticDescriptor { private final int start; private final int end; - private final List diagnostics; + private final List diagnostics; - DiagnosticDescriptor(int start, int end, List diagnostics) { + DiagnosticDescriptor(int start, int end, List diagnostics) { this.start = start; this.end = end; this.diagnostics = diagnostics; } - public Map getTextDiagnosticsMap() { - Map diagnosticMap = new IdentityHashMap(); - for (Diagnostic diagnostic : diagnostics) { + public Map getTextDiagnosticsMap() { + Map diagnosticMap = new HashMap(); + for (ActualDiagnostic diagnostic : diagnostics) { diagnosticMap.put(diagnostic, TextDiagnostic.asTextDiagnostic(diagnostic)); } return diagnosticMap; @@ -634,6 +631,40 @@ public class CheckerTestUtil { } } + public static class ActualDiagnostic { + public final Diagnostic diagnostic; + + ActualDiagnostic(@NotNull Diagnostic diagnostic) { + this.diagnostic = diagnostic; + } + + @NotNull + public String getName() { + return diagnostic.getFactory().getName(); + } + + @NotNull + public PsiFile getFile() { + return diagnostic.getPsiFile(); + } + + @Override + public boolean equals(Object obj) { + // '==' on diagnostics is intentional here + return obj instanceof ActualDiagnostic && ((ActualDiagnostic) obj).diagnostic == diagnostic; + } + + @Override + public int hashCode() { + return System.identityHashCode(diagnostic); + } + + @Override + public String toString() { + return diagnostic.toString(); + } + } + public static class TextDiagnostic { @NotNull private static TextDiagnostic parseDiagnostic(String text) { @@ -663,9 +694,11 @@ public class CheckerTestUtil { } @NotNull - public static TextDiagnostic asTextDiagnostic(@NotNull Diagnostic diagnostic) { + public static TextDiagnostic asTextDiagnostic(@NotNull ActualDiagnostic actualDiagnostic) { + Diagnostic diagnostic = actualDiagnostic.diagnostic; + //noinspection TestOnlyProblems DiagnosticRenderer renderer = DefaultErrorMessages.getRendererForDiagnostic(diagnostic); - String diagnosticName = diagnostic.getFactory().getName(); + String diagnosticName = actualDiagnostic.getName(); if (renderer instanceof AbstractDiagnosticWithParametersRenderer) { //noinspection unchecked Object[] renderParameters = ((AbstractDiagnosticWithParametersRenderer) renderer).renderParameters(diagnostic); diff --git a/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt b/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt index 38049100090..7d16333c5f4 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt @@ -27,6 +27,7 @@ import com.intellij.util.containers.ContainerUtil import org.jetbrains.kotlin.asJava.getJvmSignatureDiagnostics import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.TestFile import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.TestModule +import org.jetbrains.kotlin.checkers.CheckerTestUtil.ActualDiagnostic import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.diagnostics.* @@ -201,7 +202,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() + emptySet() else computeJvmSignatureDiagnostics(bindingContext) @@ -210,7 +211,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava { - val jvmSignatureDiagnostics = HashSet() + private fun computeJvmSignatureDiagnostics(bindingContext: BindingContext): Set { + val jvmSignatureDiagnostics = HashSet() val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java) for (declaration in declarations) { val diagnostics = getJvmSignatureDiagnostics(declaration, bindingContext.diagnostics, GlobalSearchScope.allScope(project)) ?: continue - jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration)) + jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it) }) } return jvmSignatureDiagnostics } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/CheckerTestUtilTest.java b/compiler/tests/org/jetbrains/kotlin/checkers/CheckerTestUtilTest.java index 6cd03b4c637..e8c7dcc346d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/CheckerTestUtilTest.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/CheckerTestUtilTest.java @@ -20,9 +20,9 @@ import com.google.common.collect.Lists; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.checkers.CheckerTestUtil.ActualDiagnostic; import org.jetbrains.kotlin.checkers.CheckerTestUtil.DiagnosedRange; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; -import org.jetbrains.kotlin.diagnostics.Diagnostic; import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; @@ -53,7 +53,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { public void testEquals() throws Exception { doTest(new TheTest() { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { } }); } @@ -62,7 +62,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosticData typeMismatch1 = diagnostics.get(1); doTest(new TheTest(missing(typeMismatch1)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnostics.remove(typeMismatch1.index); } }); @@ -72,7 +72,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosticData typeMismatch1 = diagnostics.get(1); doTest(new TheTest(unexpected(typeMismatch1)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnosedRanges.remove(typeMismatch1.index); } }); @@ -83,7 +83,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosticData unresolvedReference = diagnostics.get(6); doTest(new TheTest(unexpected(typeMismatch1), missing(unresolvedReference)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnosedRanges.remove(typeMismatch1.rangeIndex); diagnostics.remove(unresolvedReference.index); } @@ -95,7 +95,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosticData typeMismatch3 = diagnostics.get(5); doTest(new TheTest(unexpected(noneApplicable), missing(typeMismatch3)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnosedRanges.remove(noneApplicable.rangeIndex); diagnostics.remove(typeMismatch3.index); } @@ -108,7 +108,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosedRange range = asDiagnosticRange(unused, unusedDiagnostic); doTest(new TheTest(wrongParameters(unusedDiagnostic, "UNUSED_VARIABLE(a)", unused.startOffset, unused.endOffset)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnosedRanges.set(unused.rangeIndex, range); } }); @@ -121,7 +121,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { final DiagnosedRange range = asDiagnosticRange(unresolvedReference, unusedDiagnostic, toManyArguments); doTest(new TheTest(wrongParameters(unusedDiagnostic, "UNRESOLVED_REFERENCE(xx)", unresolvedReference.startOffset, unresolvedReference.endOffset)) { @Override - protected void makeTestData(List diagnostics, List diagnosedRanges) { + protected void makeTestData(List diagnostics, List diagnosedRanges) { diagnosedRanges.set(unresolvedReference.rangeIndex, range); } }); @@ -153,15 +153,16 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { List diagnosedRanges = Lists.newArrayList(); CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); - List diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null); - Collections.sort(diagnostics, CheckerTestUtil.DIAGNOSTIC_COMPARATOR); + List actualDiagnostics = + CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null); + Collections.sort(actualDiagnostics, CheckerTestUtil.DIAGNOSTIC_COMPARATOR); - makeTestData(diagnostics, diagnosedRanges); + makeTestData(actualDiagnostics, diagnosedRanges); List expectedMessages = Lists.newArrayList(expected); final List actualMessages = Lists.newArrayList(); - CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, new CheckerTestUtil.DiagnosticDiffCallbacks() { + CheckerTestUtil.diagnosticsDiff(diagnosedRanges, actualDiagnostics, new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override public void missingDiagnostic(CheckerTestUtil.TextDiagnostic diagnostic, int expectedStart, int expectedEnd) { actualMessages.add(missing(diagnostic.getName(), expectedStart, expectedEnd)); @@ -194,7 +195,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment { return stringBuilder.toString(); } - protected abstract void makeTestData(List diagnostics, List diagnosedRanges); + protected abstract void makeTestData(List diagnostics, List diagnosedRanges); } private static String wrongParameters(String expected, String actual, int start, int end) { diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/internal/CopyAsDiagnosticTestAction.java b/idea/src/org/jetbrains/kotlin/idea/actions/internal/CopyAsDiagnosticTestAction.java index 571a40c651f..2d8ddbd5f36 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/internal/CopyAsDiagnosticTestAction.java +++ b/idea/src/org/jetbrains/kotlin/idea/actions/internal/CopyAsDiagnosticTestAction.java @@ -23,7 +23,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiFile; import org.jetbrains.kotlin.checkers.CheckerTestUtil; -import org.jetbrains.kotlin.diagnostics.Diagnostic; import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils; import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.resolve.BindingContext; @@ -44,7 +43,8 @@ public class CopyAsDiagnosticTestAction extends AnAction { BindingContext bindingContext = ResolutionUtils.analyzeFully((KtFile) psiFile); - List diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null); + List diagnostics = + CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null); String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, diagnostics).toString(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -54,7 +54,6 @@ public class CopyAsDiagnosticTestAction extends AnAction { }); } - @Override public void update(AnActionEvent e) { e.getPresentation().setVisible(ApplicationManager.getApplication().isInternal()); @@ -63,5 +62,4 @@ public class CopyAsDiagnosticTestAction extends AnAction { PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); e.getPresentation().setEnabled(editor != null && psiFile instanceof KtFile); } - }