diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index 0415ba8cc58..770298aa8c5 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -436,7 +436,7 @@ public class JetTestUtils { return testFiles; } - private static Map parseDirectives(String expectedText) { + public static Map parseDirectives(String expectedText) { Map directives = Maps.newHashMap(); Matcher directiveMatcher = DIRECTIVE_PATTERN.matcher(expectedText); int start = 0; diff --git a/idea/testData/diagnosticMessage/conflictingSubstitutions.kt b/idea/testData/diagnosticMessage/conflictingSubstitutions.kt index 6a86248dada..a3de9a1dab4 100644 --- a/idea/testData/diagnosticMessage/conflictingSubstitutions.kt +++ b/idea/testData/diagnosticMessage/conflictingSubstitutions.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS_NUMBER: 2 +// !DIAGNOSTICS: TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS // see org.jetbrains.jet.plugin.highlighter.DiagnosticMessageTest import java.io.Closeable diff --git a/idea/testData/diagnosticMessage/functionPlaceholder.kt b/idea/testData/diagnosticMessage/functionPlaceholder.kt index 7ea1effe1ff..f26da6266d6 100644 --- a/idea/testData/diagnosticMessage/functionPlaceholder.kt +++ b/idea/testData/diagnosticMessage/functionPlaceholder.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 3 +// !DIAGNOSTICS: TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH + class A fun foo(a: A) = a diff --git a/idea/testData/diagnosticMessage/inaccessibleOuterClassExpression.kt b/idea/testData/diagnosticMessage/inaccessibleOuterClassExpression.kt index 26519e93036..302b8b602a7 100644 --- a/idea/testData/diagnosticMessage/inaccessibleOuterClassExpression.kt +++ b/idea/testData/diagnosticMessage/inaccessibleOuterClassExpression.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: INACCESSIBLE_OUTER_CLASS_EXPRESSION + class A { class B { val r = object { diff --git a/idea/testData/diagnosticMessage/invisibleMember.kt b/idea/testData/diagnosticMessage/invisibleMember.kt index ef88596578b..d180bc6431e 100644 --- a/idea/testData/diagnosticMessage/invisibleMember.kt +++ b/idea/testData/diagnosticMessage/invisibleMember.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 3 +// !DIAGNOSTICS: INVISIBLE_MEMBER + package foo.bar class A { diff --git a/idea/testData/diagnosticMessage/numberValueTypes.kt b/idea/testData/diagnosticMessage/numberValueTypes.kt index cb67a188e8f..a5a7a2aefcf 100644 --- a/idea/testData/diagnosticMessage/numberValueTypes.kt +++ b/idea/testData/diagnosticMessage/numberValueTypes.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 4 +// !DIAGNOSTICS: TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS + package a fun id(t: T): T = t diff --git a/idea/testData/diagnosticMessage/renderCollectionOfTypes.kt b/idea/testData/diagnosticMessage/renderCollectionOfTypes.kt index 74dcf725102..f1c0685fe27 100644 --- a/idea/testData/diagnosticMessage/renderCollectionOfTypes.kt +++ b/idea/testData/diagnosticMessage/renderCollectionOfTypes.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: EXPECTED_PARAMETERS_NUMBER_MISMATCH + package aa import java.util.ArrayList diff --git a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt index d4664052421..6a98de49ace 100644 --- a/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt +++ b/idea/testData/diagnosticMessage/typeInferenceExpectedTypeMismatch.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 3 +// !DIAGNOSTICS: TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH + package s fun id(t: T): T = t diff --git a/idea/testData/diagnosticMessage/typeMismatchWithNothing.kt b/idea/testData/diagnosticMessage/typeMismatchWithNothing.kt index edd1a2b198c..cd0eb14154f 100644 --- a/idea/testData/diagnosticMessage/typeMismatchWithNothing.kt +++ b/idea/testData/diagnosticMessage/typeMismatchWithNothing.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: TYPE_MISMATCH + package b trait A diff --git a/idea/testData/diagnosticMessage/upperBoundViolated.kt b/idea/testData/diagnosticMessage/upperBoundViolated.kt index 19393027042..3edeb931709 100644 --- a/idea/testData/diagnosticMessage/upperBoundViolated.kt +++ b/idea/testData/diagnosticMessage/upperBoundViolated.kt @@ -1,3 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 3 +// !DIAGNOSTICS: TYPE_INFERENCE_UPPER_BOUND_VIOLATED + package i fun foo>(r: R, list: T) {} diff --git a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java index ea5c0273cf3..a904e4474a8 100644 --- a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTest.java @@ -18,9 +18,11 @@ package org.jetbrains.jet.plugin.highlighter; import com.google.common.collect.Sets; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.JetLiteFixture; +import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory; @@ -33,11 +35,17 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.plugin.PluginTestCaseBase; +import java.io.File; +import java.lang.reflect.Field; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; public class DiagnosticMessageTest extends JetLiteFixture { + private static final String DIAGNOSTICS_NUMBER_DIRECTIVE = "DIAGNOSTICS_NUMBER"; + private static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS"; + @Override protected JetCoreEnvironment createEnvironment() { return createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY); @@ -48,18 +56,22 @@ public class DiagnosticMessageTest extends JetLiteFixture { return PluginTestCaseBase.getTestDataPathBase() + "/diagnosticMessage/"; } - public void doTest(String name, int diagnosticNumber, DiagnosticFactory... diagnosticFactories) throws Exception { + public void doTest(String name) throws Exception { String fileName = name + ".kt"; JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName)); + String fileData = JetTestUtils.doLoadFile(new File(getTestDataPath() + fileName)); + Map directives = JetTestUtils.parseDirectives(fileData); + int diagnosticNumber = computeDiagnosticNumber(directives); + final Set diagnosticFactories = computeDiagnosticFactories(directives); + AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(psiFile, Collections.emptyList()); BindingContext bindingContext = analyzeExhaust.getBindingContext(); - final Set factoriesSet = Sets.newHashSet(diagnosticFactories); List diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition() { @Override public boolean value(Diagnostic diagnostic) { - return factoriesSet.contains(diagnostic.getFactory()); + return diagnosticFactories.contains(diagnostic.getFactory()); } }); @@ -86,40 +98,77 @@ public class DiagnosticMessageTest extends JetLiteFixture { } } + private int computeDiagnosticNumber(Map directives) { + String diagnosticsNumber = directives.get(DIAGNOSTICS_NUMBER_DIRECTIVE); + assert diagnosticsNumber != null : DIAGNOSTICS_NUMBER_DIRECTIVE + " should be present."; + try { + return Integer.parseInt(diagnosticsNumber); + } + catch (NumberFormatException e) { + throw new AssertionError(DIAGNOSTICS_NUMBER_DIRECTIVE + " should contain number as its value."); + } + } + + private Set computeDiagnosticFactories(Map directives) { + String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE); + assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present."; + Set diagnosticFactories = Sets.newHashSet(); + String[] diagnostics = diagnosticsData.split(" "); + for (String diagnosticName : diagnostics) { + String errorMessage = "Can't load diagnostic factory for " + diagnosticName; + try { + Field field = Errors.class.getField(diagnosticName); + Object value = field.get(null); + if (value instanceof DiagnosticFactory) { + diagnosticFactories.add((DiagnosticFactory)value); + } + else { + throw new AssertionError(errorMessage); + } + } + catch (NoSuchFieldException e) { + throw new AssertionError(errorMessage); + } + catch (IllegalAccessException e) { + throw new AssertionError(errorMessage); + } + } + return diagnosticFactories; + } + public void testConflictingSubstitutions() throws Exception { - doTest("conflictingSubstitutions", 2, Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS); + doTest("conflictingSubstitutions"); } public void testFunctionPlaceholder() throws Exception { - doTest("functionPlaceholder", 3, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH); + doTest("functionPlaceholder"); } public void testRenderCollectionOfTypes() throws Exception { - doTest("renderCollectionOfTypes", 1, Errors.EXPECTED_PARAMETERS_NUMBER_MISMATCH); + doTest("renderCollectionOfTypes"); } public void testInaccessibleOuterClassExpression() throws Exception { - doTest("inaccessibleOuterClassExpression", 1, Errors.INACCESSIBLE_OUTER_CLASS_EXPRESSION); + doTest("inaccessibleOuterClassExpression"); } public void testUpperBoundViolated() throws Exception { - doTest("upperBoundViolated", 3, Errors.TYPE_INFERENCE_UPPER_BOUND_VIOLATED); + doTest("upperBoundViolated"); } public void testTypeMismatchWithNothing() throws Exception { - doTest("typeMismatchWithNothing", 1, Errors.TYPE_MISMATCH); + doTest("typeMismatchWithNothing"); } public void testInvisibleMember() throws Exception { - doTest("invisibleMember", 3, Errors.INVISIBLE_MEMBER, Errors.INVISIBLE_MEMBER, Errors.INVISIBLE_MEMBER); + doTest("invisibleMember"); } public void testNumberValueTypes() throws Exception { - doTest("numberValueTypes", 4, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH, - Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS); + doTest("numberValueTypes"); } public void testTypeInferenceExpectedTypeMismatch() throws Exception { - doTest("typeInferenceExpectedTypeMismatch", 3, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH); + doTest("typeInferenceExpectedTypeMismatch"); } }