Removed redundant "final" keywords at variables and parameters.

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