diff --git a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java index 0eba8704826..b7d156c1825 100644 --- a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java @@ -11,6 +11,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange; import org.jetbrains.jet.lang.diagnostics.Severity; +import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -50,6 +51,7 @@ public class CheckerTestUtil { } public interface DiagnosticDiffCallbacks { + @NotNull PsiFile getFile(); void missingDiagnostic(String type, int expectedStart, int expectedEnd); void unexpectedDiagnostic(String type, int actualStart, int actualEnd); } @@ -129,6 +131,7 @@ public class CheckerTestUtil { private static void unexpectedDiagnostics(List actual, DiagnosticDiffCallbacks callbacks) { for (Diagnostic diagnostic : actual) { + if (!diagnostic.getFactory().getPsiFile(diagnostic).equals(callbacks.getFile())) continue; TextRange textRange = getTextRange(diagnostic); callbacks.unexpectedDiagnostic(diagnostic.getFactory().getName(), textRange.getStartOffset(), textRange.getEndOffset()); } @@ -136,6 +139,7 @@ public class CheckerTestUtil { private static void missingDiagnostics(DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) { for (String type : currentExpected.getDiagnostics()) { + if (!currentExpected.getFile().equals(callbacks.getFile())) return; callbacks.missingDiagnostic(type, currentExpected.getStart(), currentExpected.getEnd()); } } @@ -393,6 +397,7 @@ public class CheckerTestUtil { private final int start; private int end; private final Multiset diagnostics = HashMultiset.create(); + private PsiFile file; private DiagnosedRange(int start) { this.start = start; @@ -417,5 +422,14 @@ public class CheckerTestUtil { public void addDiagnostic(String diagnostic) { diagnostics.add(diagnostic); } + + public void setFile(@NotNull PsiFile file) { + this.file = file; + } + + @NotNull + public PsiFile getFile() { + return file; + } } } diff --git a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java index eb1e3267d9f..f9e7eba1c9b 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java @@ -2,6 +2,7 @@ package org.jetbrains.jet.checkers; import com.google.common.collect.Lists; import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.diagnostics.Diagnostic; @@ -79,7 +80,7 @@ public class CheckerTestUtilTest extends JetLiteFixture { this.expected = expectedMessages; } - public void test(PsiFile psiFile) { + public void test(final @NotNull PsiFile psiFile) { BindingContext bindingContext = AnalyzerFacade.analyzeOneNamespaceWithJavaIntegration( ((JetFile) psiFile).getRootNamespace(), JetControlFlowDataTraceFactory.EMPTY); @@ -88,6 +89,9 @@ public class CheckerTestUtilTest extends JetLiteFixture { List diagnosedRanges = Lists.newArrayList(); CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); + for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) { + diagnosedRange.setFile(psiFile); + } List diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile); Collections.sort(diagnostics, CheckerTestUtil.DIAGNOSTIC_COMPARATOR); @@ -98,6 +102,12 @@ public class CheckerTestUtilTest extends JetLiteFixture { final List actualMessages = Lists.newArrayList(); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, new CheckerTestUtil.DiagnosticDiffCallbacks() { + @NotNull + @Override + public PsiFile getFile() { + return psiFile; + } + @Override public void missingDiagnostic(String type, int expectedStart, int expectedEnd) { String message = "Missing " + type + " at " + expectedStart + " to " + expectedEnd; diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java index 464e7e6de8b..9cabe8bdd66 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java @@ -52,10 +52,19 @@ public class JetDiagnosticsTest extends JetLiteFixture { expectedText = textWithMarkers; clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); jetFile = createCheckAndReturnPsiFile(fileName, clearText); + for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) { + diagnosedRange.setFile(jetFile); + } } public void getActualText(BindingContext bindingContext, StringBuilder actualText) { CheckerTestUtil.diagnosticsDiff(diagnosedRanges, CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, jetFile), new CheckerTestUtil.DiagnosticDiffCallbacks() { + @NotNull + @Override + public PsiFile getFile() { + return jetFile; + } + @Override public void missingDiagnostic(String type, int expectedStart, int expectedEnd) { String message = "Missing " + type + DiagnosticUtils.atLocation(jetFile, new TextRange(expectedStart, expectedEnd)); @@ -95,7 +104,7 @@ public class JetDiagnosticsTest extends JetLiteFixture { bindingContext = AnalyzerFacade.analyzeNamespacesWithJavaIntegration(getProject(), namespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); } else { - bindingContext = AnalyzingUtils.analyzeNamespaces(getProject(), Configuration.EMPTY, namespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, JetSemanticServices.createSemanticServices(getProject())); + bindingContext = AnalyzingUtils.analyzeNamespaces(getProject(), Configuration.EMPTY, namespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); } StringBuilder actualText = new StringBuilder();