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; override val dialogTitle: String
get() = JavaRuntimeLibraryDescription.DIALOG_TITLE
override val libraryCaption: String
get() = JavaRuntimeLibraryDescription.LIBRARY_CAPTION
override val messageForOverrideDialog: String
get() = JavaRuntimeLibraryDescription.JAVA_RUNTIME_LIBRARY_CREATION
override val presentableText: String
get() = "Java"
override val name: String
get() = NAME
override val targetPlatform: TargetPlatform
get() = JvmPlatform
override val existingJarFiles: RuntimeLibraryFiles
get() {
val paths = PathUtil.getKotlinPathsForIdeaPlugin()
return RuntimeLibraryFiles(
assertFileExists(paths.runtimePath),
assertFileExists(paths.reflectPath),
assertFileExists(paths.runtimeSourcesPath)
)
} }
@NotNull override fun getOldSourceRootUrl(library: Library): String? {
@Override val runtimeJarPath = getRuntimeJar(library)
protected String getDialogTitle() { return if (runtimeJarPath != null) runtimeJarPath.url + "src" else null
return JavaRuntimeLibraryDescription.DIALOG_TITLE;
} }
@NotNull override fun isKotlinLibrary(project: Project, library: Library): Boolean {
@Override
protected String getLibraryCaption() {
return JavaRuntimeLibraryDescription.LIBRARY_CAPTION;
}
@NotNull
@Override
protected String getMessageForOverrideDialog() {
return JavaRuntimeLibraryDescription.JAVA_RUNTIME_LIBRARY_CREATION;
}
@NotNull
@Override
public String getPresentableText() {
return "Java";
}
@NotNull
@Override
public String getName() {
return NAME;
}
@NotNull
@Override
public TargetPlatform getTargetPlatform() {
return JvmPlatform.INSTANCE;
}
@NotNull
@Override
public RuntimeLibraryFiles getExistingJarFiles() {
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
return new RuntimeLibraryFiles(
assertFileExists(paths.getRuntimePath()),
assertFileExists(paths.getReflectPath()),
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)) { if (super.isKotlinLibrary(project, library)) {
return true; return true
} }
LibraryScope scope = new LibraryScope(project, library); val scope = LibraryScope(project, library)
return KotlinRuntimeLibraryUtilKt.getKotlinJvmRuntimeMarkerClass(project, scope) != null; return getKotlinJvmRuntimeMarkerClass(project, scope) != null
} }
KotlinJavaModuleConfigurator() { companion object {
} val NAME = "java"
public static KotlinJavaModuleConfigurator getInstance() { val instance: KotlinJavaModuleConfigurator
return Extensions.findExtension(KotlinProjectConfigurator.Companion.getEP_NAME(), KotlinJavaModuleConfigurator.class); 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);
} }
} }