From a6c9cf7d3f2936fd0176f1b4c18feb66320279c5 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 13 Apr 2017 15:01:37 +0200 Subject: [PATCH] Minor. Cleanup code --- .../kotlin/codegen/CodegenTestCase.java | 7 ++--- .../kotlin/codegen/CodegenTestUtil.java | 9 ------- .../codegen/flags/AbstractWriteFlagsTest.java | 21 +++++++-------- .../AbstractBlackBoxAgainstJavaCodegenTest.kt | 2 +- .../debugger/AbstractPositionManagerTest.java | 27 +++++++++---------- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 5e1f4cbcf9a..0f72edaec8a 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -86,7 +86,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { protected GeneratedClassLoader initializedClassLoader; 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( @NotNull ConfigurationKind configurationKind, @@ -399,7 +399,8 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { protected ClassFileFactory generateClassesInFile() { if (classFileFactory == null) { try { - classFileFactory = generateFiles(myEnvironment, myFiles, getClassBuilderFactory()); + classFileFactory = + GenerationUtils.compileFiles(myFiles.getPsiFiles(), myEnvironment, getClassBuilderFactory()).getFactory(); if (verifyWithDex() && DxChecker.RUN_DX_CHECKER) { DxChecker.check(classFileFactory); @@ -583,7 +584,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { } @NotNull - protected List extractJavacOptions(@NotNull List files) { + protected static List extractJavacOptions(@NotNull List files) { List javacOptions = new ArrayList<>(0); for (TestFile file : files) { javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:")); diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestUtil.java b/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestUtil.java index 5130f7a7576..e97555e0e5f 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestUtil.java +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/CodegenTestUtil.java @@ -43,15 +43,6 @@ public class CodegenTestUtil { 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 exceptionClass, @Nullable Object instance, @NotNull Object... args) throws IllegalAccessException { boolean caught = false; diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/flags/AbstractWriteFlagsTest.java b/compiler/tests-common/org/jetbrains/kotlin/codegen/flags/AbstractWriteFlagsTest.java index f59b52b02d2..70bf74a43e4 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/flags/AbstractWriteFlagsTest.java +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/flags/AbstractWriteFlagsTest.java @@ -141,17 +141,16 @@ public abstract class AbstractWriteFlagsTest extends CodegenTestCase { } private static TestClassVisitor getClassVisitor(String visitorKind, String testedObjectName, boolean allowSynthetic) { - if (visitorKind.equals("class")) { - return new ClassFlagsVisitor(); - } - else if (visitorKind.equals("function")) { - return new FunctionFlagsVisitor(testedObjectName, allowSynthetic); - } - else if (visitorKind.equals("property")) { - return new PropertyFlagsVisitor(testedObjectName); - } - else if (visitorKind.equals("innerClass")) { - return new InnerClassFlagsVisitor(testedObjectName); + switch (visitorKind) { + case "class": + return new ClassFlagsVisitor(); + case "function": + return new FunctionFlagsVisitor(testedObjectName, allowSynthetic); + case "property": + return new PropertyFlagsVisitor(testedObjectName); + case "innerClass": + return new InnerClassFlagsVisitor(testedObjectName); + default: } throw new IllegalArgumentException("Value of TESTED_OBJECT_KIND is incorrect: " + visitorKind); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt index 7b3a56f9d8f..3c302c6e6cc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt @@ -32,7 +32,7 @@ abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenT } override fun updateConfiguration(configuration: CompilerConfiguration) { - configuration.addJvmClasspathRoots(listOf(javaOutputDir!!)) + configuration.addJvmClasspathRoots(listOf(javaOutputDir)) } override fun extractConfigurationKind(files: MutableList): ConfigurationKind { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java index c3d4d663474..27f2e2351a0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java @@ -134,10 +134,10 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight private void performTest() { Project project = getProject(); - List files = new ArrayList(PluginJetFilesProvider.allFilesInProject(project)); + List files = new ArrayList<>(PluginJetFilesProvider.allFilesInProject(project)); if (files.isEmpty()) return; - final List breakpoints = Lists.newArrayList(); + List breakpoints = Lists.newArrayList(); for (KtFile file : files) { breakpoints.addAll(extractBreakpointsInfo(file, file.getText())); } @@ -153,20 +153,17 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight debugProcess = createDebugProcess(referencesByName); - final PositionManager positionManager = createPositionManager(debugProcess, files, state); + PositionManager positionManager = createPositionManager(debugProcess, files, state); - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - try { - for (Breakpoint breakpoint : breakpoints) { - assertBreakpointIsHandledCorrectly(breakpoint, positionManager); - } - } - catch (NoDataException e) { - throw ExceptionUtilsKt.rethrow(e); + ApplicationManager.getApplication().runReadAction(() -> { + try { + for (Breakpoint breakpoint : breakpoints) { + assertBreakpointIsHandledCorrectly(breakpoint, positionManager); } } + catch (NoDataException e) { + throw ExceptionUtilsKt.rethrow(e); + } }); } @@ -199,7 +196,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight return new SmartMockReferenceTypeContext(outputFiles).getReferenceTypesByName(); } - private DebugProcessEvents createDebugProcess(final Map referencesByName) { + private DebugProcessEvents createDebugProcess(Map referencesByName) { return new DebugProcessEvents(getProject()) { private VirtualMachineProxyImpl virtualMachineProxy; @@ -264,7 +261,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight @Override public List allClasses() { - return new ArrayList(referencesByName.values()); + return new ArrayList<>(referencesByName.values()); } @Override