From 9d151d2ce86e01d9de56cbe777c37083e266e9b8 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 31 Mar 2015 17:17:14 +0300 Subject: [PATCH] Add ability to configure set of tools with in file --- .../checkers/KotlinAndJavaCheckerTest.java | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java b/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java index fc846a87877..2ad48bb3427 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java @@ -17,21 +17,66 @@ package org.jetbrains.kotlin.checkers; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.codeInspection.nullable.NullableStuffInspection; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.ArrayUtil; import com.siyeh.ig.bugs.StaticCallOnSubclassInspection; import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection; +import kotlin.Function1; +import kotlin.KotlinPackage; import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase; import org.jetbrains.kotlin.idea.PluginTestCaseBase; +import org.jetbrains.kotlin.test.InTextDirectivesUtils; +import org.jetbrains.kotlin.utils.UtilsPackage; + +import java.io.File; +import java.io.IOException; +import java.util.List; public class KotlinAndJavaCheckerTest extends KotlinDaemonAnalyzerTestCase { + private static final LocalInspectionTool[] DEFAULT_TOOLS = new LocalInspectionTool[] { + new StaticCallOnSubclassInspection(), + new StaticFieldReferenceOnSubclassInspection(), + new NullableStuffInspection() + }; + + private static LocalInspectionTool mapStringToTool(String toolString) { + if ("StaticCallOnSubclassInspection".equals(toolString)) + return new StaticCallOnSubclassInspection(); + if ("StaticFieldReferenceOnSubclassInspection".equals(toolString)) + return new StaticFieldReferenceOnSubclassInspection(); + if ("NullableStuffInspection".equals(toolString)) + return new NullableStuffInspection(); + if ("DataFlowInspection".equals(toolString)) + return new DataFlowInspection(); + + throw new IllegalArgumentException("Can't find inspection tool with identifier: " + toolString); + } + @Override protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[] { - new StaticCallOnSubclassInspection(), - new StaticFieldReferenceOnSubclassInspection(), - new NullableStuffInspection() - }; + File configureFile = new File(getTestDataPath(), getTestName(false) + ".txt"); + + if (!configureFile.exists()) return DEFAULT_TOOLS; + + try { + String configureText = FileUtil.loadFile(configureFile, true); + + InTextDirectivesUtils.assertHasUnknownPrefixes(configureText, KotlinPackage.listOf("TOOL:")); + List toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configureText, "TOOL:"); + + return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1() { + @Override + public LocalInspectionTool invoke(String toolString) { + return mapStringToTool(toolString); + } + }), LocalInspectionTool.class); + } + catch (IOException e) { + throw UtilsPackage.rethrow(e); + } } @Override