From 057bdb773108c18744eb51cb36d63b99ce92d8cd Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 19 Feb 2013 19:15:40 +0400 Subject: [PATCH] Library kinds detectors for Java and JavaScript --- idea/src/META-INF/plugin.xml | 2 + .../JetJavaRuntimeLibraryDescription.java | 4 +- ...KotlinJavaRuntimePresentationProvider.java | 55 +++++++++++++++++++ ...JavaScriptHeadersPresentationProvider.java | 54 ++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaRuntimePresentationProvider.java create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaScriptHeadersPresentationProvider.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index cd591fe9e9f..9d960956777 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -216,6 +216,8 @@ + + diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JetJavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JetJavaRuntimeLibraryDescription.java index 0ef1aac4ee0..9f4a99fe71e 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JetJavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JetJavaRuntimeLibraryDescription.java @@ -36,7 +36,7 @@ import javax.swing.*; import java.util.Set; public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription { - public static final LibraryKind KOTLIN_KIND = LibraryKind.create("kotlin-java-runtime"); + public static final LibraryKind KOTLIN_JAVA_RUNTIME_KIND = LibraryKind.create("kotlin-java-runtime"); private final FrameworkSourcePanel frameworkSourcePanel; public JetJavaRuntimeLibraryDescription(FrameworkSourcePanel frameworkSourcePanel) { @@ -47,7 +47,7 @@ public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription { @NotNull @Override public Set getSuitableLibraryKinds() { - return Sets.newHashSet(KOTLIN_KIND); + return Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND); } @Nullable diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaRuntimePresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaRuntimePresentationProvider.java new file mode 100644 index 00000000000..14f1851f0f6 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaRuntimePresentationProvider.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.framework; + +import com.intellij.framework.library.LibraryVersionProperties; +import com.intellij.openapi.roots.libraries.LibraryKind; +import com.intellij.openapi.roots.libraries.LibraryPresentationProvider; +import com.intellij.openapi.roots.libraries.LibraryProperties; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.JetIcons; +import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil; + +import javax.swing.*; +import java.util.List; + +public class KotlinJavaRuntimePresentationProvider extends LibraryPresentationProvider { + protected KotlinJavaRuntimePresentationProvider() { + super(JetJavaRuntimeLibraryDescription.KOTLIN_JAVA_RUNTIME_KIND); + } + + @Nullable + @Override + public Icon getIcon() { + return JetIcons.SMALL_LOGO_13; + } + + @Nullable + @Override + public LibraryVersionProperties detect(@NotNull List classesRoots) { + for (VirtualFile root : classesRoots) { + if (root.getName().equals(KotlinRuntimeLibraryUtil.KOTLIN_RUNTIME_JAR)) { + // TODO: Detect library version + return new LibraryVersionProperties("Unknown"); + } + } + + return null; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaScriptHeadersPresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaScriptHeadersPresentationProvider.java new file mode 100644 index 00000000000..12abb64278d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinJavaScriptHeadersPresentationProvider.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.framework; + +import com.intellij.framework.library.LibraryVersionProperties; +import com.intellij.openapi.roots.libraries.LibraryPresentationProvider; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.JetIcons; +import org.jetbrains.jet.utils.PathUtil; + +import javax.swing.*; +import java.util.List; + +public class KotlinJavaScriptHeadersPresentationProvider extends LibraryPresentationProvider { + protected KotlinJavaScriptHeadersPresentationProvider() { + super(JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_HEADERS_KIND); + } + + @Nullable + @Override + public Icon getIcon() { + return JetIcons.SMALL_LOGO_13; + } + + @Nullable + @Override + public LibraryVersionProperties detect(@NotNull List classesRoots) { + for (VirtualFile root : classesRoots) { + // TODO: Better detection for headers library + if (root.getName().equals(PathUtil.JS_LIB_JS_NAME)) { + // TODO: Detect library version + return new LibraryVersionProperties("Unknown"); + } + } + + return null; + } +}