Minor. Cleanup code

This commit is contained in:
Mikhael Bogdanov
2017-04-13 15:01:37 +02:00
parent 3df32ad425
commit a6c9cf7d3f
5 changed files with 27 additions and 39 deletions
@@ -86,7 +86,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected GeneratedClassLoader initializedClassLoader; protected GeneratedClassLoader initializedClassLoader;
protected ConfigurationKind configurationKind = ConfigurationKind.JDK_ONLY; protected ConfigurationKind configurationKind = ConfigurationKind.JDK_ONLY;
public final String defaultJvmTarget = System.getProperty(DEFAULT_JVM_TARGET_FOR_TEST); private final String defaultJvmTarget = System.getProperty(DEFAULT_JVM_TARGET_FOR_TEST);
protected final void createEnvironmentWithMockJdkAndIdeaAnnotations( protected final void createEnvironmentWithMockJdkAndIdeaAnnotations(
@NotNull ConfigurationKind configurationKind, @NotNull ConfigurationKind configurationKind,
@@ -399,7 +399,8 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected ClassFileFactory generateClassesInFile() { protected ClassFileFactory generateClassesInFile() {
if (classFileFactory == null) { if (classFileFactory == null) {
try { try {
classFileFactory = generateFiles(myEnvironment, myFiles, getClassBuilderFactory()); classFileFactory =
GenerationUtils.compileFiles(myFiles.getPsiFiles(), myEnvironment, getClassBuilderFactory()).getFactory();
if (verifyWithDex() && DxChecker.RUN_DX_CHECKER) { if (verifyWithDex() && DxChecker.RUN_DX_CHECKER) {
DxChecker.check(classFileFactory); DxChecker.check(classFileFactory);
@@ -583,7 +584,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
} }
@NotNull @NotNull
protected List<String> extractJavacOptions(@NotNull List<TestFile> files) { protected static List<String> extractJavacOptions(@NotNull List<TestFile> files) {
List<String> javacOptions = new ArrayList<>(0); List<String> javacOptions = new ArrayList<>(0);
for (TestFile file : files) { for (TestFile file : files) {
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:")); javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"));
@@ -43,15 +43,6 @@ public class CodegenTestUtil {
return GenerationUtils.compileFiles(files.getPsiFiles(), environment).getFactory(); return GenerationUtils.compileFiles(files.getPsiFiles(), environment).getFactory();
} }
@NotNull
public static ClassFileFactory generateFiles(
@NotNull KotlinCoreEnvironment environment,
@NotNull CodegenTestFiles files,
@NotNull ClassBuilderFactory factory
) {
return GenerationUtils.compileFiles(files.getPsiFiles(), environment, factory).getFactory();
}
public static void assertThrows(@NotNull Method foo, @NotNull Class<? extends Throwable> exceptionClass, public static void assertThrows(@NotNull Method foo, @NotNull Class<? extends Throwable> exceptionClass,
@Nullable Object instance, @NotNull Object... args) throws IllegalAccessException { @Nullable Object instance, @NotNull Object... args) throws IllegalAccessException {
boolean caught = false; boolean caught = false;
@@ -141,17 +141,16 @@ public abstract class AbstractWriteFlagsTest extends CodegenTestCase {
} }
private static TestClassVisitor getClassVisitor(String visitorKind, String testedObjectName, boolean allowSynthetic) { private static TestClassVisitor getClassVisitor(String visitorKind, String testedObjectName, boolean allowSynthetic) {
if (visitorKind.equals("class")) { switch (visitorKind) {
return new ClassFlagsVisitor(); case "class":
} return new ClassFlagsVisitor();
else if (visitorKind.equals("function")) { case "function":
return new FunctionFlagsVisitor(testedObjectName, allowSynthetic); return new FunctionFlagsVisitor(testedObjectName, allowSynthetic);
} case "property":
else if (visitorKind.equals("property")) { return new PropertyFlagsVisitor(testedObjectName);
return new PropertyFlagsVisitor(testedObjectName); case "innerClass":
} return new InnerClassFlagsVisitor(testedObjectName);
else if (visitorKind.equals("innerClass")) { default:
return new InnerClassFlagsVisitor(testedObjectName);
} }
throw new IllegalArgumentException("Value of TESTED_OBJECT_KIND is incorrect: " + visitorKind); throw new IllegalArgumentException("Value of TESTED_OBJECT_KIND is incorrect: " + visitorKind);
@@ -32,7 +32,7 @@ abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenT
} }
override fun updateConfiguration(configuration: CompilerConfiguration) { override fun updateConfiguration(configuration: CompilerConfiguration) {
configuration.addJvmClasspathRoots(listOf(javaOutputDir!!)) configuration.addJvmClasspathRoots(listOf(javaOutputDir))
} }
override fun extractConfigurationKind(files: MutableList<TestFile>): ConfigurationKind { override fun extractConfigurationKind(files: MutableList<TestFile>): ConfigurationKind {
@@ -134,10 +134,10 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight
private void performTest() { private void performTest() {
Project project = getProject(); Project project = getProject();
List<KtFile> files = new ArrayList<KtFile>(PluginJetFilesProvider.allFilesInProject(project)); List<KtFile> files = new ArrayList<>(PluginJetFilesProvider.allFilesInProject(project));
if (files.isEmpty()) return; if (files.isEmpty()) return;
final List<Breakpoint> breakpoints = Lists.newArrayList(); List<Breakpoint> breakpoints = Lists.newArrayList();
for (KtFile file : files) { for (KtFile file : files) {
breakpoints.addAll(extractBreakpointsInfo(file, file.getText())); breakpoints.addAll(extractBreakpointsInfo(file, file.getText()));
} }
@@ -153,20 +153,17 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight
debugProcess = createDebugProcess(referencesByName); debugProcess = createDebugProcess(referencesByName);
final PositionManager positionManager = createPositionManager(debugProcess, files, state); PositionManager positionManager = createPositionManager(debugProcess, files, state);
ApplicationManager.getApplication().runReadAction(new Runnable() { ApplicationManager.getApplication().runReadAction(() -> {
@Override try {
public void run() { for (Breakpoint breakpoint : breakpoints) {
try { assertBreakpointIsHandledCorrectly(breakpoint, positionManager);
for (Breakpoint breakpoint : breakpoints) {
assertBreakpointIsHandledCorrectly(breakpoint, positionManager);
}
}
catch (NoDataException e) {
throw ExceptionUtilsKt.rethrow(e);
} }
} }
catch (NoDataException e) {
throw ExceptionUtilsKt.rethrow(e);
}
}); });
} }
@@ -199,7 +196,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight
return new SmartMockReferenceTypeContext(outputFiles).getReferenceTypesByName(); return new SmartMockReferenceTypeContext(outputFiles).getReferenceTypesByName();
} }
private DebugProcessEvents createDebugProcess(final Map<String, ReferenceType> referencesByName) { private DebugProcessEvents createDebugProcess(Map<String, ReferenceType> referencesByName) {
return new DebugProcessEvents(getProject()) { return new DebugProcessEvents(getProject()) {
private VirtualMachineProxyImpl virtualMachineProxy; private VirtualMachineProxyImpl virtualMachineProxy;
@@ -264,7 +261,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight
@Override @Override
public List<ReferenceType> allClasses() { public List<ReferenceType> allClasses() {
return new ArrayList<ReferenceType>(referencesByName.values()); return new ArrayList<>(referencesByName.values());
} }
@Override @Override