Add ability to configure set of tools with in file
This commit is contained in:
@@ -17,21 +17,66 @@
|
|||||||
package org.jetbrains.kotlin.checkers;
|
package org.jetbrains.kotlin.checkers;
|
||||||
|
|
||||||
import com.intellij.codeInspection.LocalInspectionTool;
|
import com.intellij.codeInspection.LocalInspectionTool;
|
||||||
|
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||||
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
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.StaticCallOnSubclassInspection;
|
||||||
import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection;
|
import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection;
|
||||||
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase;
|
import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase;
|
||||||
import org.jetbrains.kotlin.idea.PluginTestCaseBase;
|
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 {
|
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
|
@Override
|
||||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||||
return new LocalInspectionTool[] {
|
File configureFile = new File(getTestDataPath(), getTestName(false) + ".txt");
|
||||||
new StaticCallOnSubclassInspection(),
|
|
||||||
new StaticFieldReferenceOnSubclassInspection(),
|
if (!configureFile.exists()) return DEFAULT_TOOLS;
|
||||||
new NullableStuffInspection()
|
|
||||||
};
|
try {
|
||||||
|
String configureText = FileUtil.loadFile(configureFile, true);
|
||||||
|
|
||||||
|
InTextDirectivesUtils.assertHasUnknownPrefixes(configureText, KotlinPackage.listOf("TOOL:"));
|
||||||
|
List<String> toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configureText, "TOOL:");
|
||||||
|
|
||||||
|
return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1<String, LocalInspectionTool>() {
|
||||||
|
@Override
|
||||||
|
public LocalInspectionTool invoke(String toolString) {
|
||||||
|
return mapStringToTool(toolString);
|
||||||
|
}
|
||||||
|
}), LocalInspectionTool.class);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw UtilsPackage.rethrow(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user