JS: added js() diagnostics tests
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
val a = "1"
|
||||||
|
|
||||||
|
fun nonConst(): String = "1"
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val b = "b"
|
||||||
|
|
||||||
|
js(a)
|
||||||
|
js(b)
|
||||||
|
js("$a")
|
||||||
|
js("${1}")
|
||||||
|
js("$b;")
|
||||||
|
js("${b}bb")
|
||||||
|
js(a + a)
|
||||||
|
js("a" + "a")
|
||||||
|
js("ccc")
|
||||||
|
|
||||||
|
js(<!JSCODE_ARGUMENT_SHOULD_BE_CONSTANT!>nonConst()<!>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal val a: kotlin.String = "1"
|
||||||
|
internal fun nonConst(): kotlin.String
|
||||||
|
internal fun test(): kotlin.Unit
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
val code = """
|
||||||
|
var s = "hello"
|
||||||
|
+ );
|
||||||
|
"""
|
||||||
|
|
||||||
|
fun main(args: Array<String>): Unit {
|
||||||
|
js("var<!JSCODE_ERROR!> =<!> 10;")
|
||||||
|
|
||||||
|
js("""var<!JSCODE_ERROR!> =<!> 10;""")
|
||||||
|
|
||||||
|
js("""var<!JSCODE_ERROR!>
|
||||||
|
=<!> 777;
|
||||||
|
""")
|
||||||
|
|
||||||
|
js("""
|
||||||
|
var<!JSCODE_ERROR!> =<!> 777;
|
||||||
|
""")
|
||||||
|
|
||||||
|
js(<!JSCODE_ERROR!>"var " + " = " + "10;"<!>)
|
||||||
|
|
||||||
|
val n = 10
|
||||||
|
js(<!JSCODE_ERROR!>"var = $n;"<!>)
|
||||||
|
|
||||||
|
js(<!JSCODE_ERROR!>code<!>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal val code: kotlin.String = "
|
||||||
|
var s = "hello"
|
||||||
|
+ );
|
||||||
|
"
|
||||||
|
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun main(args: Array<String>): Unit {
|
||||||
|
js("var a =<!JSCODE_WARNING!> 08<!>;")
|
||||||
|
|
||||||
|
js("""var a =<!JSCODE_WARNING!>
|
||||||
|
|
||||||
|
08<!>;""")
|
||||||
|
|
||||||
|
val code = "var a = 08;"
|
||||||
|
js(<!JSCODE_WARNING!>code<!>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||||
+28
-1
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib")
|
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({JetDiagnosticsTestWithJsStdLibGenerated.DynamicTypes.class, JetDiagnosticsTestWithJsStdLibGenerated.Native.class})
|
@InnerTestClasses({JetDiagnosticsTestWithJsStdLibGenerated.DynamicTypes.class, JetDiagnosticsTestWithJsStdLibGenerated.JsCode.class, JetDiagnosticsTestWithJsStdLibGenerated.Native.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnosticsTestWithJsStdLib {
|
public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnosticsTestWithJsStdLib {
|
||||||
public void testAllFilesPresentInTestsWithJsStdLib() throws Exception {
|
public void testAllFilesPresentInTestsWithJsStdLib() throws Exception {
|
||||||
@@ -226,6 +226,33 @@ public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class JsCode extends AbstractJetDiagnosticsTestWithJsStdLib {
|
||||||
|
public void testAllFilesPresentInJsCode() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/jsCode"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("argumentIsLiteral.kt")
|
||||||
|
public void testArgumentIsLiteral() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/argumentIsLiteral.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("error.kt")
|
||||||
|
public void testError() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/error.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("warning.kt")
|
||||||
|
public void testWarning() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native")
|
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({Native.NativeGetter.class, Native.NativeInvoke.class, Native.NativeSetter.class, Native.OptionlBody.class, Native.UnusedParam.class})
|
@InnerTestClasses({Native.NativeGetter.class, Native.NativeInvoke.class, Native.NativeSetter.class, Native.OptionlBody.class, Native.UnusedParam.class})
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.completion.AbstractJvmBasicCompletionTest
|
|||||||
import org.jetbrains.kotlin.completion.AbstractJvmWithLibBasicCompletionTest
|
import org.jetbrains.kotlin.completion.AbstractJvmWithLibBasicCompletionTest
|
||||||
import org.jetbrains.kotlin.idea.navigation.AbstractGotoSuperTest
|
import org.jetbrains.kotlin.idea.navigation.AbstractGotoSuperTest
|
||||||
import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixMultiFileTest
|
import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixMultiFileTest
|
||||||
import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightingTest
|
|
||||||
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
|
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
|
||||||
import org.jetbrains.kotlin.idea.intentions.AbstractIntentionTest
|
import org.jetbrains.kotlin.idea.intentions.AbstractIntentionTest
|
||||||
@@ -66,7 +65,6 @@ import org.jetbrains.kotlin.idea.resolve.AbstractReferenceResolveWithLibTest
|
|||||||
import org.jetbrains.kotlin.findUsages.AbstractJetFindUsagesTest
|
import org.jetbrains.kotlin.findUsages.AbstractJetFindUsagesTest
|
||||||
import org.jetbrains.kotlin.idea.configuration.AbstractConfigureProjectByChangingFileTest
|
import org.jetbrains.kotlin.idea.configuration.AbstractConfigureProjectByChangingFileTest
|
||||||
import org.jetbrains.kotlin.formatter.AbstractJetFormatterTest
|
import org.jetbrains.kotlin.formatter.AbstractJetFormatterTest
|
||||||
import org.jetbrains.kotlin.idea.highlighter.AbstractDiagnosticMessageTest
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.AbstractOutOfBlockModificationTest
|
import org.jetbrains.kotlin.idea.codeInsight.AbstractOutOfBlockModificationTest
|
||||||
import org.jetbrains.kotlin.completion.AbstractDataFlowValueRenderingTest
|
import org.jetbrains.kotlin.completion.AbstractDataFlowValueRenderingTest
|
||||||
import org.jetbrains.kotlin.resolve.annotation.AbstractAnnotationParameterTest
|
import org.jetbrains.kotlin.resolve.annotation.AbstractAnnotationParameterTest
|
||||||
@@ -143,6 +141,7 @@ import org.jetbrains.kotlin.codegen.AbstractLineNumberTest
|
|||||||
import org.jetbrains.kotlin.completion.handlers.AbstractKeywordCompletionHandlerTest
|
import org.jetbrains.kotlin.completion.handlers.AbstractKeywordCompletionHandlerTest
|
||||||
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocHighlightingTest
|
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocHighlightingTest
|
||||||
import org.jetbrains.kotlin.addImport.AbstractAddImportTest
|
import org.jetbrains.kotlin.addImport.AbstractAddImportTest
|
||||||
|
import org.jetbrains.kotlin.idea.highlighter.*
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -570,7 +569,11 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractDiagnosticMessageTest>()) {
|
testClass(javaClass<AbstractDiagnosticMessageTest>()) {
|
||||||
model("diagnosticMessage")
|
model("diagnosticMessage", recursive = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractDiagnosticMessageJsTest>()) {
|
||||||
|
model("diagnosticMessage/js", recursive = false, targetBackend = TargetBackend.JS)
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractRenameTest>()) {
|
testClass(javaClass<AbstractRenameTest>()) {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// !DIAGNOSTICS_NUMBER: 4
|
||||||
|
// !DIAGNOSTICS: JSCODE_ERROR
|
||||||
|
// !MESSAGE_TYPE: HTML
|
||||||
|
|
||||||
|
fun box() {
|
||||||
|
val i = "i"
|
||||||
|
val n = 10
|
||||||
|
|
||||||
|
js("var = $n;")
|
||||||
|
|
||||||
|
js("""var a = 10;
|
||||||
|
var = $n;
|
||||||
|
var c = 15;""")
|
||||||
|
|
||||||
|
js("""for (var $i =
|
||||||
|
)""")
|
||||||
|
|
||||||
|
js("var = 10;")
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<!-- jsCodeErrorHtml1 -->
|
||||||
|
<html>
|
||||||
|
JavaScript: missing variable name in code:<br><pre>var<u> =</u> 10;</pre></html>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<!-- jsCodeErrorHtml2 -->
|
||||||
|
<html>
|
||||||
|
JavaScript: missing variable name in code:<br><pre>var a = 10;
|
||||||
|
var<u> =</u> 10;
|
||||||
|
var c = 15;</pre></html>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<!-- jsCodeErrorHtml3 -->
|
||||||
|
<html>
|
||||||
|
JavaScript: syntax error in code:<br><pre>for (var i =<u></u>
|
||||||
|
<u> )</pre></html>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<!-- jsCodeErrorHtml4 -->
|
||||||
|
<html>
|
||||||
|
JavaScript: missing variable name</html>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// !DIAGNOSTICS_NUMBER: 4
|
||||||
|
// !DIAGNOSTICS: JSCODE_ERROR
|
||||||
|
// !MESSAGE_TYPE: TEXT
|
||||||
|
|
||||||
|
fun box() {
|
||||||
|
val i = "i"
|
||||||
|
val n = 10
|
||||||
|
|
||||||
|
js("var = $n;")
|
||||||
|
|
||||||
|
js("""var a = 10;
|
||||||
|
var = $n;
|
||||||
|
var c = 15;""")
|
||||||
|
|
||||||
|
js("""for (var $i =
|
||||||
|
)""")
|
||||||
|
|
||||||
|
js("var = 10;")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<!-- jsCodeErrorText1 -->
|
||||||
|
JavaScript: missing variable name in code:
|
||||||
|
var = 10;
|
||||||
|
^^^^^^^^
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<!-- jsCodeErrorText2 -->
|
||||||
|
JavaScript: missing variable name in code:
|
||||||
|
var a = 10;
|
||||||
|
var = 10;
|
||||||
|
^^^^^^^^
|
||||||
|
var c = 15;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<!-- jsCodeErrorText3 -->
|
||||||
|
JavaScript: syntax error in code:
|
||||||
|
for (var i =
|
||||||
|
^
|
||||||
|
)
|
||||||
|
^^^^^
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<!-- jsCodeErrorText4 -->
|
||||||
|
JavaScript: missing variable name
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||||
|
import org.jetbrains.kotlin.idea.PluginTestCaseBase;
|
||||||
|
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS;
|
||||||
|
import org.jetbrains.kotlin.js.config.Config;
|
||||||
|
import org.jetbrains.kotlin.js.config.EcmaVersion;
|
||||||
|
import org.jetbrains.kotlin.js.config.LibrarySourcesConfigWithCaching;
|
||||||
|
import org.jetbrains.kotlin.js.resolve.diagnostics.ErrorsJs;
|
||||||
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
|
public abstract class AbstractDiagnosticMessageJsTest extends AbstractDiagnosticMessageTest {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected JetCoreEnvironment createEnvironment() {
|
||||||
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected AnalysisResult analyze(@NotNull JetFile file) {
|
||||||
|
return TopDownAnalyzerFacadeForJS.analyzeFiles(singletonList(file), Predicates.<PsiFile>alwaysTrue(), getConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getTestDataPath() {
|
||||||
|
return PluginTestCaseBase.getTestDataPathBase() + "/diagnosticMessage/js/";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
protected Field getPlatformSpecificDiagnosticField(@NotNull String diagnosticName) {
|
||||||
|
return getFieldOrNull(ErrorsJs.class, diagnosticName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Config getConfig() {
|
||||||
|
return new LibrarySourcesConfigWithCaching(getProject(),
|
||||||
|
"testModule",
|
||||||
|
EcmaVersion.defaultVersion(),
|
||||||
|
/* sourceMap = */ false,
|
||||||
|
/* inlineEnabled = */ false,
|
||||||
|
/* isUnitTestMode = */ true);
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-19
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.highlighter;
|
package org.jetbrains.kotlin.idea.highlighter;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
@@ -29,8 +30,10 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
|||||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages;
|
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages;
|
||||||
import org.jetbrains.kotlin.idea.PluginTestCaseBase;
|
import org.jetbrains.kotlin.idea.PluginTestCaseBase;
|
||||||
|
import org.jetbrains.kotlin.js.resolve.diagnostics.ErrorsJs;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
import org.jetbrains.kotlin.test.JetLiteFixture;
|
import org.jetbrains.kotlin.test.JetLiteFixture;
|
||||||
@@ -61,16 +64,23 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected JetCoreEnvironment createEnvironment() {
|
protected JetCoreEnvironment createEnvironment() {
|
||||||
return createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY);
|
return createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected String getTestDataPath() {
|
protected String getTestDataPath() {
|
||||||
return PluginTestCaseBase.getTestDataPathBase() + "/diagnosticMessage/";
|
return PluginTestCaseBase.getTestDataPathBase() + "/diagnosticMessage/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected AnalysisResult analyze(@NotNull JetFile file) {
|
||||||
|
return JvmResolveUtil.analyzeOneFileWithJavaIntegration(file);
|
||||||
|
}
|
||||||
|
|
||||||
public void doTest(String filePath) throws Exception {
|
public void doTest(String filePath) throws Exception {
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
@@ -82,7 +92,7 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
|
|||||||
MessageType messageType = getMessageTypeDirective(directives);
|
MessageType messageType = getMessageTypeDirective(directives);
|
||||||
|
|
||||||
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
|
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
|
||||||
AnalysisResult analysisResult = JvmResolveUtil.analyzeOneFileWithJavaIntegration(psiFile);
|
AnalysisResult analysisResult = analyze(psiFile);
|
||||||
BindingContext bindingContext = analysisResult.getBindingContext();
|
BindingContext bindingContext = analysisResult.getBindingContext();
|
||||||
|
|
||||||
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition<Diagnostic>() {
|
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition<Diagnostic>() {
|
||||||
@@ -128,33 +138,50 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Set<DiagnosticFactory<?>> getDiagnosticFactories(Map<String, String> directives) {
|
private Set<DiagnosticFactory<?>> getDiagnosticFactories(Map<String, String> directives) {
|
||||||
String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE);
|
String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE);
|
||||||
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
|
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
|
||||||
Set<DiagnosticFactory<?>> diagnosticFactories = Sets.newHashSet();
|
Set<DiagnosticFactory<?>> diagnosticFactories = Sets.newHashSet();
|
||||||
String[] diagnostics = diagnosticsData.split(" ");
|
String[] diagnostics = diagnosticsData.split(" ");
|
||||||
for (String diagnosticName : diagnostics) {
|
for (String diagnosticName : diagnostics) {
|
||||||
String errorMessage = "Can't load diagnostic factory for " + diagnosticName;
|
Object diagnostic = getDiagnostic(diagnosticName);
|
||||||
try {
|
assert diagnostic instanceof DiagnosticFactory: "Can't load diagnostic factory for " + diagnosticName;
|
||||||
Field field = Errors.class.getField(diagnosticName);
|
diagnosticFactories.add((DiagnosticFactory) diagnostic);
|
||||||
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;
|
return diagnosticFactories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Object getDiagnostic(@NotNull String diagnosticName) {
|
||||||
|
Field field = getPlatformSpecificDiagnosticField(diagnosticName);
|
||||||
|
|
||||||
|
if (field == null) {
|
||||||
|
field = getFieldOrNull(Errors.class, diagnosticName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field == null) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return field.get(null);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected Field getPlatformSpecificDiagnosticField(@NotNull String diagnosticName) {
|
||||||
|
return getFieldOrNull(ErrorsJvm.class, diagnosticName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected static Field getFieldOrNull(@NotNull Class<?> kind, @NotNull String field) {
|
||||||
|
try {
|
||||||
|
return kind.getField(field);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static MessageType getMessageTypeDirective(Map<String, String> directives) {
|
private static MessageType getMessageTypeDirective(Map<String, String> directives) {
|
||||||
String messageType = directives.get(MESSAGE_TYPE_DIRECTIVE);
|
String messageType = directives.get(MESSAGE_TYPE_DIRECTIVE);
|
||||||
|
|||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.InnerTestClasses;
|
||||||
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/diagnosticMessage/js")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public class DiagnosticMessageJsTestGenerated extends AbstractDiagnosticMessageJsTest {
|
||||||
|
public void testAllFilesPresentInJs() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/diagnosticMessage/js"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jsCodeErrorHtml.kt")
|
||||||
|
public void testJsCodeErrorHtml() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/diagnosticMessage/js/jsCodeErrorHtml.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jsCodeErrorText.kt")
|
||||||
|
public void testJsCodeErrorText() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/diagnosticMessage/js/jsCodeErrorText.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
|
|||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTest {
|
public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTest {
|
||||||
public void testAllFilesPresentInDiagnosticMessage() throws Exception {
|
public void testAllFilesPresentInDiagnosticMessage() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/diagnosticMessage"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/diagnosticMessage"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("assignedButNeverAccessedVariable.kt")
|
@TestMetadata("assignedButNeverAccessedVariable.kt")
|
||||||
|
|||||||
Reference in New Issue
Block a user