KotlinJavaModuleConfigurator: J2K

This commit is contained in:
Dmitry Jemerov
2017-03-30 17:45:38 +02:00
parent 16c2dec60a
commit 344f372327
2 changed files with 53 additions and 84 deletions
@@ -14,106 +14,75 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.idea.configuration; package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.module.Module; import com.intellij.openapi.module.Module
import com.intellij.openapi.module.impl.scopes.LibraryScope; import com.intellij.openapi.module.impl.scopes.LibraryScope
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.framework.getRuntimeJar
import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.versions.getKotlinJvmRuntimeMarkerClass
import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription; import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.idea.framework.KotlinLibraryUtilKt; import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt; import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlin.resolve.TargetPlatform;
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
import org.jetbrains.kotlin.utils.KotlinPaths;
import org.jetbrains.kotlin.utils.PathUtil;
public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator { open class KotlinJavaModuleConfigurator internal constructor() : KotlinWithLibraryConfigurator() {
public static final String NAME = "java";
@Override override fun isConfigured(module: Module): Boolean {
public boolean isConfigured(@NotNull Module module) { return hasKotlinJvmRuntimeInScope(module)
return ConfigureKotlinInProjectUtilsKt.hasKotlinJvmRuntimeInScope(module);
} }
@NotNull override val libraryName: String
@Override get() = JavaRuntimeLibraryDescription.LIBRARY_NAME
protected String getLibraryName() {
return JavaRuntimeLibraryDescription.LIBRARY_NAME;
}
@NotNull override val dialogTitle: String
@Override get() = JavaRuntimeLibraryDescription.DIALOG_TITLE
protected String getDialogTitle() {
return JavaRuntimeLibraryDescription.DIALOG_TITLE;
}
@NotNull override val libraryCaption: String
@Override get() = JavaRuntimeLibraryDescription.LIBRARY_CAPTION
protected String getLibraryCaption() {
return JavaRuntimeLibraryDescription.LIBRARY_CAPTION;
}
@NotNull override val messageForOverrideDialog: String
@Override get() = JavaRuntimeLibraryDescription.JAVA_RUNTIME_LIBRARY_CREATION
protected String getMessageForOverrideDialog() {
return JavaRuntimeLibraryDescription.JAVA_RUNTIME_LIBRARY_CREATION;
}
@NotNull override val presentableText: String
@Override get() = "Java"
public String getPresentableText() {
return "Java";
}
@NotNull override val name: String
@Override get() = NAME
public String getName() {
return NAME;
}
@NotNull override val targetPlatform: TargetPlatform
@Override get() = JvmPlatform
public TargetPlatform getTargetPlatform() {
return JvmPlatform.INSTANCE;
}
@NotNull override val existingJarFiles: RuntimeLibraryFiles
@Override get() {
public RuntimeLibraryFiles getExistingJarFiles() { val paths = PathUtil.getKotlinPathsForIdeaPlugin()
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); return RuntimeLibraryFiles(
return new RuntimeLibraryFiles( assertFileExists(paths.runtimePath),
assertFileExists(paths.getRuntimePath()), assertFileExists(paths.reflectPath),
assertFileExists(paths.getReflectPath()), assertFileExists(paths.runtimeSourcesPath)
assertFileExists(paths.getRuntimeSourcesPath()) )
);
}
@Nullable
@Override
protected String getOldSourceRootUrl(@NotNull Library library) {
VirtualFile runtimeJarPath = KotlinLibraryUtilKt.getRuntimeJar(library);
return runtimeJarPath != null ? runtimeJarPath.getUrl() + "src" : null;
}
@Override
protected boolean isKotlinLibrary(@NotNull Project project, @NotNull Library library) {
if (super.isKotlinLibrary(project, library)) {
return true;
} }
LibraryScope scope = new LibraryScope(project, library); override fun getOldSourceRootUrl(library: Library): String? {
return KotlinRuntimeLibraryUtilKt.getKotlinJvmRuntimeMarkerClass(project, scope) != null; val runtimeJarPath = getRuntimeJar(library)
return if (runtimeJarPath != null) runtimeJarPath.url + "src" else null
} }
KotlinJavaModuleConfigurator() { override fun isKotlinLibrary(project: Project, library: Library): Boolean {
if (super.isKotlinLibrary(project, library)) {
return true
}
val scope = LibraryScope(project, library)
return getKotlinJvmRuntimeMarkerClass(project, scope) != null
} }
public static KotlinJavaModuleConfigurator getInstance() { companion object {
return Extensions.findExtension(KotlinProjectConfigurator.Companion.getEP_NAME(), KotlinJavaModuleConfigurator.class); val NAME = "java"
val instance: KotlinJavaModuleConfigurator
get() = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME, KotlinJavaModuleConfigurator::class.java)
} }
} }
@@ -37,6 +37,6 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDe
* @param project null when project doesn't exist yet (called from project wizard) * @param project null when project doesn't exist yet (called from project wizard)
*/ */
public JavaRuntimeLibraryDescription(@Nullable Project project) { public JavaRuntimeLibraryDescription(@Nullable Project project) {
super(project, KotlinJavaModuleConfigurator.NAME, LIBRARY_NAME, DIALOG_TITLE, LIBRARY_CAPTION, KOTLIN_JAVA_RUNTIME_KIND, SUITABLE_LIBRARY_KINDS); super(project, KotlinJavaModuleConfigurator.Companion.getNAME(), LIBRARY_NAME, DIALOG_TITLE, LIBRARY_CAPTION, KOTLIN_JAVA_RUNTIME_KIND, SUITABLE_LIBRARY_KINDS);
} }
} }