From 42e00102f83fc529138488aab07db4de1620d573 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 27 Jul 2012 17:57:02 +0400 Subject: [PATCH] Removed redundant "final" keywords at variables and parameters. --- .../jet/cli/common/util/CompilerPathUtil.java | 6 +- .../src/org/jetbrains/jet/utils/PathUtil.java | 24 +++---- .../jetbrains/jet/plugin/JetPluginUtil.java | 2 +- .../OutdatedKotlinRuntimeNotification.java | 6 +- ...gureKotlinLibraryNotificationProvider.java | 14 ++-- .../sdk/BundledKotlinSdkLibraryCreator.java | 16 ++--- .../KotlinFrameworkSupportConfigurable.java | 6 +- .../sdk/KotlinFrameworkSupportProvider.java | 4 +- .../jet/plugin/sdk/KotlinSdkDescription.java | 28 ++++---- ...nSdkNotConfiguredNotificationProvider.java | 18 ++--- .../sdk/KotlinSdkPresentationProvider.java | 8 +-- .../jet/plugin/sdk/KotlinSdkProperties.java | 4 +- .../jet/plugin/sdk/KotlinSdkUtil.java | 70 +++++++++---------- .../jet/plugin/util/PluginPathUtil.java | 10 +-- .../IDECompilerMessagingTest.java | 8 +-- 15 files changed, 112 insertions(+), 112 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/util/CompilerPathUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/common/util/CompilerPathUtil.java index 1d2e60f0391..13d4d171b8c 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/util/CompilerPathUtil.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/util/CompilerPathUtil.java @@ -30,12 +30,12 @@ public class CompilerPathUtil { @Nullable public static File getSDKHome() { - final File compilerJar = new File(PathUtil.getJarPathForClass(CompilerPathUtil.class)); + File compilerJar = new File(PathUtil.getJarPathForClass(CompilerPathUtil.class)); if (!compilerJar.exists()) return null; if (compilerJar.getName().equals(PathUtil.KOTLIN_COMPILER_JAR)) { - final File lib = compilerJar.getParentFile(); - final File answer = lib.getParentFile(); + File lib = compilerJar.getParentFile(); + File answer = lib.getParentFile(); return answer.exists() ? answer : null; } diff --git a/compiler/util/src/org/jetbrains/jet/utils/PathUtil.java b/compiler/util/src/org/jetbrains/jet/utils/PathUtil.java index be6eadbb0c2..8a72c01f9c2 100644 --- a/compiler/util/src/org/jetbrains/jet/utils/PathUtil.java +++ b/compiler/util/src/org/jetbrains/jet/utils/PathUtil.java @@ -39,43 +39,43 @@ public class PathUtil { private PathUtil() {} @Nullable - public static File getRuntimePath(@Nullable final File sdkHome) { + public static File getRuntimePath(@Nullable File sdkHome) { return getFilePackedIntoLib(sdkHome, KOTLIN_RUNTIME_JAR); } @Nullable - public static File getCompilerPath(@Nullable final File sdkHome) { + public static File getCompilerPath(@Nullable File sdkHome) { return getFilePackedIntoLib(sdkHome, KOTLIN_COMPILER_JAR); } @Nullable - public static File getJsLibJsPath(@Nullable final File sdkHome) { + public static File getJsLibJsPath(@Nullable File sdkHome) { return getFilePackedIntoLib(sdkHome, JS_LIB_JS_NAME); } @Nullable - public static File getJsLibJarPath(@Nullable final File sdkHome) { + public static File getJsLibJarPath(@Nullable File sdkHome) { return getFilePackedIntoLib(sdkHome, JS_LIB_JAR_NAME); } @Nullable - public static File getJdkAnnotationsPath(@Nullable final File sdkHome) { + public static File getJdkAnnotationsPath(@Nullable File sdkHome) { return getFilePackedIntoLib(sdkHome, JDK_ANNOTATIONS_JAR); } @Nullable - private static File getFilePackedIntoLib(@Nullable final File sdkHome, @NotNull final String filePathFromLib) { + private static File getFilePackedIntoLib(@Nullable File sdkHome, @NotNull String filePathFromLib) { if (sdkHome == null) return null; - final File answer = new File(sdkHome, "lib/" + filePathFromLib); + File answer = new File(sdkHome, "lib/" + filePathFromLib); return answer.exists() ? answer : null; } @Nullable - public static File getSDKHomeByCompilerPath(@Nullable final File compilerPath) { + public static File getSDKHomeByCompilerPath(@Nullable File compilerPath) { if (compilerPath == null) return null; - final File libDir = compilerPath.getParentFile(); + File libDir = compilerPath.getParentFile(); if (libDir == null) return null; - final File sdkHome = libDir.getParentFile(); + File sdkHome = libDir.getParentFile(); return sdkHome != null && sdkHome.exists() ? sdkHome : null; } @@ -96,8 +96,8 @@ public class PathUtil { } @NotNull - public static String getJarPathForClass(@NotNull final Class aClass) { - final String resourceRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class"); + public static String getJarPathForClass(@NotNull Class aClass) { + String resourceRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class"); return new File(resourceRoot).getAbsoluteFile().getAbsolutePath(); } diff --git a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java index 08d83d420ba..5b178e0bf21 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java @@ -85,7 +85,7 @@ public class JetPluginUtil { } @Nullable - public static Module getModuleForKotlinFile(@NotNull final VirtualFile file, @NotNull final Project project) { + public static Module getModuleForKotlinFile(@NotNull VirtualFile file, @NotNull Project project) { if (file.getFileType() != JetFileType.INSTANCE) return null; if (CompilerManager.getInstance(project).isExcludedFromCompilation(file)) return null; return ModuleUtil.findModuleForFile(file, project); diff --git a/idea/src/org/jetbrains/jet/plugin/OutdatedKotlinRuntimeNotification.java b/idea/src/org/jetbrains/jet/plugin/OutdatedKotlinRuntimeNotification.java index a2606b733f5..1bf828f8664 100644 --- a/idea/src/org/jetbrains/jet/plugin/OutdatedKotlinRuntimeNotification.java +++ b/idea/src/org/jetbrains/jet/plugin/OutdatedKotlinRuntimeNotification.java @@ -55,7 +55,7 @@ public class OutdatedKotlinRuntimeNotification implements ModuleComponent { private final Module myModule; private final String mySuppressedPropertyName; - public OutdatedKotlinRuntimeNotification(final Module module) { + public OutdatedKotlinRuntimeNotification(Module module) { myModule = module; mySuppressedPropertyName = String.format(SUPPRESSED_PROPERTY_NAME_PATTERN, module.getName()); } @@ -133,7 +133,7 @@ public class OutdatedKotlinRuntimeNotification implements ModuleComponent { } @Nullable - private static String getRuntimeVersion(@Nullable final VirtualFile kotlinRuntimeJar) { + private static String getRuntimeVersion(@Nullable VirtualFile kotlinRuntimeJar) { if (kotlinRuntimeJar == null) return null; VirtualFile manifestFile = kotlinRuntimeJar.findFileByRelativePath(JarFile.MANIFEST_NAME); if (manifestFile != null) { @@ -161,7 +161,7 @@ public class OutdatedKotlinRuntimeNotification implements ModuleComponent { @Nullable private VirtualFile getRuntimeFromSdk() { - final File runtimePath = PluginPathUtil.getRuntimePath(myModule); + File runtimePath = PluginPathUtil.getRuntimePath(myModule); return runtimePath == null ? null : PathUtil.jarFileOrDirectoryToVirtualFile(runtimePath); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java index 42eddad4558..1e7a3128eeb 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java @@ -65,9 +65,9 @@ import java.io.IOException; import static org.jetbrains.jet.plugin.project.JsModuleDetector.isJsModule; public class ConfigureKotlinLibraryNotificationProvider implements EditorNotifications.Provider { - private static final Key KEY = Key.create("configure.kotlin.library"); - public static final String LIBRARY_NAME = "KotlinRuntime"; - private final Project myProject; + private static Key KEY = Key.create("configure.kotlin.library"); + public static String LIBRARY_NAME = "KotlinRuntime"; + private Project myProject; @Override public Key getKey() { @@ -82,7 +82,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific @Override public EditorNotificationPanel createNotificationPanel(VirtualFile file) { try { - final Module module = JetPluginUtil.getModuleForKotlinFile(file, myProject); + Module module = JetPluginUtil.getModuleForKotlinFile(file, myProject); if (module == null) return null; if (isMavenModule(module) || isJsModule(module)) return null; @@ -159,7 +159,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific } private EditorNotificationPanel createNotificationPanel(final Module module) { - final EditorNotificationPanel answer = new EditorNotificationPanel(); + EditorNotificationPanel answer = new EditorNotificationPanel(); answer.setText("Kotlin is not configured for module '" + module.getName() + "'"); answer.createActionLabel("Set up module '" + module.getName() + "' as JVM Kotlin module", new Runnable() { @@ -247,8 +247,8 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific }); } - private static boolean isMavenModule(@NotNull final Module module) { - for (final VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { + private static boolean isMavenModule(@NotNull Module module) { + for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { if (root.findChild("pom.xml") != null) { return true; } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/BundledKotlinSdkLibraryCreator.java b/idea/src/org/jetbrains/jet/plugin/sdk/BundledKotlinSdkLibraryCreator.java index 2e9fa83bde7..94d3b780176 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/BundledKotlinSdkLibraryCreator.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/BundledKotlinSdkLibraryCreator.java @@ -44,13 +44,13 @@ public class BundledKotlinSdkLibraryCreator implements ApplicationComponent { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - final LibrariesContainer librariesContainer = LibrariesContainerFactory.createContainer((Project) null); + LibrariesContainer librariesContainer = LibrariesContainerFactory.createContainer((Project) null); if (!bundledSdkLibraryExists(librariesContainer)) { - final File bundledSDKHome = PluginPathUtil.getBundledSDKHome(); + File bundledSDKHome = PluginPathUtil.getBundledSDKHome(); if (bundledSDKHome != null) { - final String version = KotlinSdkUtil.getSDKVersion(bundledSDKHome); + String version = KotlinSdkUtil.getSDKVersion(bundledSDKHome); if (version != null) { - final NewLibraryEditor editor = new NewLibraryEditor(); + NewLibraryEditor editor = new NewLibraryEditor(); editor.setName(KotlinSdkUtil.getSDKName(bundledSDKHome, version)); KotlinSdkDescription.addSDKRoots(editor, bundledSDKHome); librariesContainer.createLibrary(editor, LibrariesContainer.LibraryLevel.GLOBAL); @@ -61,10 +61,10 @@ public class BundledKotlinSdkLibraryCreator implements ApplicationComponent { }); } - private static boolean bundledSdkLibraryExists(@NotNull final LibrariesContainer librariesContainer) { - final Library[] globalLibraries = librariesContainer.getLibraries(LibrariesContainer.LibraryLevel.GLOBAL); - for (final Library library : globalLibraries) { - final File sdkHome = KotlinSdkUtil.detectSDKHome(Arrays.asList(library.getFiles(OrderRootType.CLASSES))); + private static boolean bundledSdkLibraryExists(@NotNull LibrariesContainer librariesContainer) { + Library[] globalLibraries = librariesContainer.getLibraries(LibrariesContainer.LibraryLevel.GLOBAL); + for (Library library : globalLibraries) { + File sdkHome = KotlinSdkUtil.detectSDKHome(Arrays.asList(library.getFiles(OrderRootType.CLASSES))); if (sdkHome != null && KotlinSdkUtil.isBundledSDK(sdkHome)) { return true; } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportConfigurable.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportConfigurable.java index fb0838c4038..de634f27b08 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportConfigurable.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportConfigurable.java @@ -49,8 +49,8 @@ public class KotlinFrameworkSupportConfigurable extends FrameworkSupportInModule } @Override - public void addSupport(@NotNull final Module module, - @NotNull final ModifiableRootModel rootModel, - @NotNull final ModifiableModelsProvider modifiableModelsProvider) { + public void addSupport(@NotNull Module module, + @NotNull ModifiableRootModel rootModel, + @NotNull ModifiableModelsProvider modifiableModelsProvider) { } } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportProvider.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportProvider.java index 7a328448a38..fffdde351ed 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinFrameworkSupportProvider.java @@ -40,12 +40,12 @@ public class KotlinFrameworkSupportProvider extends FrameworkSupportInModuleProv @NotNull @Override - public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull final FrameworkSupportModel model) { + public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) { return new KotlinFrameworkSupportConfigurable(); } @Override - public boolean isEnabledForModuleType(@NotNull final ModuleType type) { + public boolean isEnabledForModuleType(@NotNull ModuleType type) { return type instanceof JavaModuleType || PLUGIN_MODULE_ID.equals(type.getId()) || ANDROID_MODULE_ID.equals(type.getId()); } } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkDescription.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkDescription.java index c20591fc0bc..ef4eae64954 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkDescription.java @@ -53,26 +53,26 @@ public class KotlinSdkDescription extends CustomLibraryDescription { @Nullable @Override - public NewLibraryConfiguration createNewLibrary(@NotNull final JComponent parentComponent, @Nullable final VirtualFile contextDirectory) { + public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) { VirtualFile initial = findFile(System.getenv("KOTLIN_HOME")); if (initial == null) { initial = findFile(System.getProperty("kotlinHome")); } - final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { + FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override - public boolean isFileSelectable(@Nullable final VirtualFile file) { + public boolean isFileSelectable(@Nullable VirtualFile file) { return super.isFileSelectable(file) && KotlinSdkUtil.isSDKHome(file); } }; descriptor.setTitle("Kotlin SDK"); descriptor.setDescription("Choose a directory containing Kotlin distribution"); - final VirtualFile sdkHomeVFile = FileChooser.chooseFile(parentComponent, descriptor, initial); + VirtualFile sdkHomeVFile = FileChooser.chooseFile(parentComponent, descriptor, initial); if (sdkHomeVFile == null) return null; final File sdkHome = new File(sdkHomeVFile.getPath()); - final String sdkVersion = KotlinSdkUtil.getSDKVersion(sdkHome); + String sdkVersion = KotlinSdkUtil.getSDKVersion(sdkHome); if (sdkVersion == null) { Messages.showErrorDialog(parentComponent, "Failed to find Kotlin SDK in the specified path: cannot determine Kotlin version.", @@ -82,36 +82,36 @@ public class KotlinSdkDescription extends CustomLibraryDescription { return new NewLibraryConfiguration(KotlinSdkUtil.getSDKName(sdkHome, sdkVersion)) { @Override - public void addRoots(@NotNull final LibraryEditor editor) { + public void addRoots(@NotNull LibraryEditor editor) { addSDKRoots(editor, sdkHome); } }; } @Nullable - private static VirtualFile findFile(@Nullable final String path) { + private static VirtualFile findFile(@Nullable String path) { if (StringUtil.isEmptyOrSpaces(path)) return null; //noinspection ConstantConditions return LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(path)); } - public static void addSDKRoots(@NotNull final LibraryEditor editor, @NotNull final File sdkHome) { - final File libDir = new File(sdkHome, "lib"); + public static void addSDKRoots(@NotNull LibraryEditor editor, @NotNull File sdkHome) { + File libDir = new File(sdkHome, "lib"); if (!libDir.isDirectory()) return; - final List jars = new ArrayList(); + List jars = new ArrayList(); collectJars(libDir, jars); - for (final File jar : jars) { + for (File jar : jars) { editor.addRoot(VfsUtil.getUrlForLibraryRoot(jar), OrderRootType.CLASSES); } } - private static void collectJars(@NotNull final File dir, @NotNull final List jars) { - final File[] children = dir.listFiles(); + private static void collectJars(@NotNull File dir, @NotNull List jars) { + File[] children = dir.listFiles(); if (children == null) return; - for (final File child : children) { + for (File child : children) { if (child.isDirectory()) { collectJars(child, jars); } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkNotConfiguredNotificationProvider.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkNotConfiguredNotificationProvider.java index f5dc2552156..4d6e1be72d4 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkNotConfiguredNotificationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkNotConfiguredNotificationProvider.java @@ -41,14 +41,14 @@ public class KotlinSdkNotConfiguredNotificationProvider implements EditorNotific @NotNull private final Project myProject; - public KotlinSdkNotConfiguredNotificationProvider(@NotNull final Project project, @NotNull final EditorNotifications notifications) { + public KotlinSdkNotConfiguredNotificationProvider(@NotNull Project project, @NotNull final EditorNotifications notifications) { myProject = project; project.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override - public void beforeRootsChange(final ModuleRootEvent event) {} + public void beforeRootsChange(ModuleRootEvent event) {} @Override - public void rootsChanged(final ModuleRootEvent event) { + public void rootsChanged(ModuleRootEvent event) { notifications.updateAllNotifications(); } }); @@ -62,29 +62,29 @@ public class KotlinSdkNotConfiguredNotificationProvider implements EditorNotific @Nullable @Override - public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file) { + public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file) { try { - final Module module = JetPluginUtil.getModuleForKotlinFile(file, myProject); + Module module = JetPluginUtil.getModuleForKotlinFile(file, myProject); if (module == null) return null; if (!KotlinSdkUtil.isSDKConfiguredFor(module)) { return createNotificationPanel(module); } } - catch (final ProcessCanceledException ignore) {} - catch (final IndexNotReadyException ignore) {} + catch (ProcessCanceledException ignore) {} + catch (IndexNotReadyException ignore) {} return null; } @NotNull private static EditorNotificationPanel createNotificationPanel(@NotNull final Module module) { - final EditorNotificationPanel panel = new EditorNotificationPanel(); + EditorNotificationPanel panel = new EditorNotificationPanel(); panel.setText("Kotlin SDK is not configured for module \"" + module.getName() + "\""); panel.createActionLabel("Configure Kotlin SDK", new Runnable() { @Override public void run() { - final AddFrameworkSupportDialog dialog = AddFrameworkSupportDialog.createDialog(module); + AddFrameworkSupportDialog dialog = AddFrameworkSupportDialog.createDialog(module); if (dialog != null) { dialog.show(); } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkPresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkPresentationProvider.java index 435bb60623c..8ef9f0e946e 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkPresentationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkPresentationProvider.java @@ -43,16 +43,16 @@ public class KotlinSdkPresentationProvider extends LibraryPresentationProvider classesRoots) { - final File sdkHome = KotlinSdkUtil.detectSDKHome(classesRoots); + public KotlinSdkProperties detect(@NotNull List classesRoots) { + File sdkHome = KotlinSdkUtil.detectSDKHome(classesRoots); if (sdkHome == null) return null; - final String sdkVersion = KotlinSdkUtil.getSDKVersion(sdkHome); + String sdkVersion = KotlinSdkUtil.getSDKVersion(sdkHome); return sdkVersion == null ? null : new KotlinSdkProperties(sdkHome, sdkVersion); } } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkProperties.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkProperties.java index 935260464ee..16d7947ae04 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkProperties.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkProperties.java @@ -29,7 +29,7 @@ public class KotlinSdkProperties extends LibraryProperties @NotNull private File mySdkHome; @NotNull private String myVersion; - public KotlinSdkProperties(@NotNull final File sdkHome, @NotNull final String version) { + public KotlinSdkProperties(@NotNull File sdkHome, @NotNull String version) { mySdkHome = sdkHome; myVersion = version; } @@ -50,7 +50,7 @@ public class KotlinSdkProperties extends LibraryProperties } @Override - public void loadState(@NotNull final KotlinSdkProperties state) { + public void loadState(@NotNull KotlinSdkProperties state) { mySdkHome = state.mySdkHome; myVersion = state.myVersion; } diff --git a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkUtil.java b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkUtil.java index 5eba0b14344..3a58e3dd1a2 100644 --- a/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/sdk/KotlinSdkUtil.java @@ -42,7 +42,7 @@ import java.util.jar.Manifest; * Date: 19.05.12 */ public class KotlinSdkUtil { - @NotNull private static final PersistentLibraryKind KOTLIN_SDK_KIND = + @NotNull private static PersistentLibraryKind KOTLIN_SDK_KIND = new PersistentLibraryKind("KotlinSDK", false) { @NotNull @Override @@ -50,50 +50,50 @@ public class KotlinSdkUtil { return new KotlinSdkProperties(new File(""), ""); } }; - @NotNull private static final String[] KOTLIN_COMPILER_JAR_ENTRY_NAMES = { + @NotNull private static String[] KOTLIN_COMPILER_JAR_ENTRY_NAMES = { "org/jetbrains/jet/cli/KotlinCompiler.class", "org/jetbrains/jet/cli/jvm/K2JVMCompiler.class" }; private KotlinSdkUtil() {} - public static boolean isSDKHome(@Nullable final VirtualFile dir) { + public static boolean isSDKHome(@Nullable VirtualFile dir) { return dir != null && isSDKHome(new File(dir.getPath())); } - private static boolean isSDKHome(@NotNull final File dir) { + private static boolean isSDKHome(@NotNull File dir) { return dir.isDirectory() && isKotlinCompilerJar(PathUtil.getCompilerPath(dir)); } @Nullable - public static String getSDKVersion(@NotNull final File sdkHome) { - final String buildNumber = getSDKBuildNumber(sdkHome); + public static String getSDKVersion(@NotNull File sdkHome) { + String buildNumber = getSDKBuildNumber(sdkHome); if (buildNumber == null) return null; - final int lastDotPos = buildNumber.lastIndexOf('.'); + int lastDotPos = buildNumber.lastIndexOf('.'); return lastDotPos == -1 ? buildNumber : buildNumber.substring(0, lastDotPos); } @Nullable - private static String getSDKBuildNumber(@NotNull final File sdkHome) { + private static String getSDKBuildNumber(@NotNull File sdkHome) { try { return FileUtil.loadFile(new File(sdkHome, "build.txt")).trim(); } - catch (final IOException e) { + catch (IOException e) { try { - final File compilerJar = PathUtil.getCompilerPath(sdkHome); + File compilerJar = PathUtil.getCompilerPath(sdkHome); return compilerJar == null ? null : getJarImplementationVersion(compilerJar); } - catch (final IOException e1) { + catch (IOException e1) { return null; } } } @Nullable - private static String getJarImplementationVersion(@NotNull final File jar) throws IOException { - final JarFile jarFile = new JarFile(jar); + private static String getJarImplementationVersion(@NotNull File jar) throws IOException { + JarFile jarFile = new JarFile(jar); try { - final Manifest manifest = jarFile.getManifest(); + Manifest manifest = jarFile.getManifest(); return manifest == null ? null : manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION); } finally { @@ -102,13 +102,13 @@ public class KotlinSdkUtil { } @Nullable - public static File detectSDKHome(@NotNull final List jars) { + public static File detectSDKHome(@NotNull List jars) { for (VirtualFile jar : jars) { jar = prepare(jar); if (jar == null) continue; - final File file = new File(jar.getPath()); + File file = new File(jar.getPath()); if (file.getName().equals(PathUtil.KOTLIN_COMPILER_JAR) && isKotlinCompilerJar(file)) { - final File sdkHome = PathUtil.getSDKHomeByCompilerPath(file); + File sdkHome = PathUtil.getSDKHomeByCompilerPath(file); if (sdkHome != null) { return sdkHome; } @@ -118,40 +118,40 @@ public class KotlinSdkUtil { } @Nullable - private static VirtualFile prepare(@NotNull final VirtualFile jar) { + private static VirtualFile prepare(@NotNull VirtualFile jar) { if (jar.getFileSystem() instanceof JarFileSystem) { return JarFileSystem.getInstance().getVirtualFileForJar(jar); } return jar; } - public static boolean isSDKConfiguredFor(@NotNull final Module module) { + public static boolean isSDKConfiguredFor(@NotNull Module module) { return getSDKHomeFor(module) != null; } @Nullable - public static File getSDKHomeFor(@NotNull final Module module) { + public static File getSDKHomeFor(@NotNull Module module) { return findSDKHome(module, new HashSet(), false); } @Nullable - public static File findSDKHome(@NotNull final Module module, @NotNull final Set checkedModuleNames, final boolean isDependency) { + public static File findSDKHome(@NotNull Module module, @NotNull Set checkedModuleNames, boolean isDependency) { checkedModuleNames.add(module.getName()); - for (final OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { + for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { if (orderEntry instanceof ModuleOrderEntry) { - final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; - final Module depModule = moduleOrderEntry.getModule(); + ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; + Module depModule = moduleOrderEntry.getModule(); if (depModule != null && !checkedModuleNames.contains(depModule.getName()) && isAvailable(moduleOrderEntry, isDependency)) { - final File sdkHome = findSDKHome(depModule, checkedModuleNames, true); + File sdkHome = findSDKHome(depModule, checkedModuleNames, true); if (sdkHome != null) { return sdkHome; } } } else if (orderEntry instanceof LibraryOrderEntry) { - final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; + LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; if (isAvailable(libraryOrderEntry, isDependency)) { - final File sdkHome = detectSDKHome(Arrays.asList(libraryOrderEntry.getRootFiles(OrderRootType.CLASSES))); + File sdkHome = detectSDKHome(Arrays.asList(libraryOrderEntry.getRootFiles(OrderRootType.CLASSES))); if (sdkHome != null) { return sdkHome; } @@ -161,23 +161,23 @@ public class KotlinSdkUtil { return null; } - private static boolean isAvailable(@NotNull final ExportableOrderEntry orderEntry, final boolean isDependency) { + private static boolean isAvailable(@NotNull ExportableOrderEntry orderEntry, boolean isDependency) { return !isDependency || orderEntry.isExported(); } - private static boolean isKotlinCompilerJar(@Nullable final File jar) { + private static boolean isKotlinCompilerJar(@Nullable File jar) { try { return jar != null && doIsKotlinCompilerJar(jar); } - catch (final IOException e) { + catch (IOException e) { return false; } } - private static boolean doIsKotlinCompilerJar(@NotNull final File jar) throws IOException { - final JarFile jarFile = new JarFile(jar); + private static boolean doIsKotlinCompilerJar(@NotNull File jar) throws IOException { + JarFile jarFile = new JarFile(jar); try { - for (final String entryName : KOTLIN_COMPILER_JAR_ENTRY_NAMES) { + for (String entryName : KOTLIN_COMPILER_JAR_ENTRY_NAMES) { if (jarFile.getJarEntry(entryName) != null) { return true; } @@ -189,12 +189,12 @@ public class KotlinSdkUtil { } } - public static boolean isBundledSDK(@NotNull final File sdkHome) { + public static boolean isBundledSDK(@NotNull File sdkHome) { return sdkHome.equals(PluginPathUtil.getBundledSDKHome()); } @NotNull - public static String getSDKName(@NotNull final File sdkHome, @NotNull final String version) { + public static String getSDKName(@NotNull File sdkHome, @NotNull String version) { return "Kotlin " + version + (isBundledSDK(sdkHome) ? " (bundled)" : ""); } diff --git a/idea/src/org/jetbrains/jet/plugin/util/PluginPathUtil.java b/idea/src/org/jetbrains/jet/plugin/util/PluginPathUtil.java index d51eff4c422..6ff60f8fa31 100644 --- a/idea/src/org/jetbrains/jet/plugin/util/PluginPathUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/util/PluginPathUtil.java @@ -33,7 +33,7 @@ public class PluginPathUtil { @Nullable public static File getBundledSDKHome() { - final File plugin_jar_path = new File(PathUtil.getJarPathForClass(PathUtil.class)); + File plugin_jar_path = new File(PathUtil.getJarPathForClass(PathUtil.class)); if (!plugin_jar_path.exists()) return null; if (plugin_jar_path.getName().equals("kotlin-plugin.jar")) { @@ -49,22 +49,22 @@ public class PluginPathUtil { } @Nullable - public static File getRuntimePath(@NotNull final Module module) { + public static File getRuntimePath(@NotNull Module module) { return PathUtil.getRuntimePath(KotlinSdkUtil.getSDKHomeFor(module)); } @Nullable - public static File getJsLibJsPath(@NotNull final Module module) { + public static File getJsLibJsPath(@NotNull Module module) { return PathUtil.getJsLibJsPath(KotlinSdkUtil.getSDKHomeFor(module)); } @Nullable - public static File getJsLibJarPath(@NotNull final Module module) { + public static File getJsLibJarPath(@NotNull Module module) { return PathUtil.getJsLibJarPath(KotlinSdkUtil.getSDKHomeFor(module)); } @Nullable - public static File getJdkAnnotationsPath(@NotNull final Module module) { + public static File getJdkAnnotationsPath(@NotNull Module module) { return PathUtil.getJdkAnnotationsPath(KotlinSdkUtil.getSDKHomeFor(module)); } } diff --git a/idea/tests/org/jetbrains/jet/plugin/compilerMessages/IDECompilerMessagingTest.java b/idea/tests/org/jetbrains/jet/plugin/compilerMessages/IDECompilerMessagingTest.java index 17a6c285764..ed4ca655053 100644 --- a/idea/tests/org/jetbrains/jet/plugin/compilerMessages/IDECompilerMessagingTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/compilerMessages/IDECompilerMessagingTest.java @@ -44,12 +44,12 @@ public abstract class IDECompilerMessagingTest extends PlatformTestCase { protected void performTest(@NotNull Function1 whatToExpect, @NotNull TranslatingCompiler compiler, @NotNull String testDataPath) { - final String pathToTestDir = testDataPath + "/" + getTestName(true); + String pathToTestDir = testDataPath + "/" + getTestName(true); VirtualFile testDir = LocalFileSystem.getInstance().findFileByPath(pathToTestDir); Assert.assertNotNull(testDir); VirtualFile sampleFile = LocalFileSystem.getInstance().findFileByPath(pathToTestDir + "/src/test.kt"); VirtualFile outDirectory = getOutDirectory(pathToTestDir, testDir); - final String pathToSrc = pathToTestDir + "/src/"; + String pathToSrc = pathToTestDir + "/src/"; VirtualFile root = LocalFileSystem.getInstance().findFileByPath(pathToSrc); Assert.assertNotNull(root); MockCompileContext mockCompileContext = new MockCompileContext(myModule, outDirectory, root); @@ -91,7 +91,7 @@ public abstract class IDECompilerMessagingTest extends PlatformTestCase { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel(); + ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel(); model.addLibraryEntry(createKotlinSdkLibrary()); model.commit(); } @@ -100,7 +100,7 @@ public abstract class IDECompilerMessagingTest extends PlatformTestCase { @NotNull private Library createKotlinSdkLibrary() { - final NewLibraryEditor editor = new NewLibraryEditor(); + NewLibraryEditor editor = new NewLibraryEditor(); editor.setName("Kotlin SDK"); KotlinSdkDescription.addSDKRoots(editor, new File("dist/kotlinc")); return LibrariesContainerFactory.createContainer(myModule).createLibrary(editor, LibrariesContainer.LibraryLevel.GLOBAL);