Check module is already configured with Kotlin framework of other type

This commit is contained in:
Nikolay Krasko
2013-02-20 17:56:46 +04:00
parent ac1f7aa9bc
commit 833b5d2548
7 changed files with 86 additions and 10 deletions
@@ -0,0 +1,65 @@
/*
* 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.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FrameworksCompatibilityUtils {
private FrameworksCompatibilityUtils() {
}
public static void suggestRemoveIncompatibleFramework(
@NotNull ModifiableRootModel rootModel,
@NotNull LibraryKind kind,
String message,
String title
) {
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
existingEntries.add(entry);
}
}
if (!existingEntries.isEmpty()) {
int result = Messages.showYesNoDialog(message, title, Messages.getWarningIcon());
if (result == 0) {
for (OrderEntry entry : existingEntries) {
rootModel.removeOrderEntry(entry);
}
}
}
}
}
@@ -24,6 +24,10 @@ import org.jetbrains.jet.plugin.JetIcons;
import javax.swing.*;
public class JavaScriptFrameworkType extends FrameworkTypeEx {
public static JavaScriptFrameworkType getInstance() {
return FrameworkTypeEx.EP_NAME.findExtension(JavaScriptFrameworkType.class);
}
public JavaScriptFrameworkType() {
super("kotlin-js-framework-id");
}
@@ -36,7 +36,7 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
@NotNull
@Override
public FrameworkTypeEx getFrameworkType() {
return FrameworkTypeEx.EP_NAME.findExtension(JetJavaFrameworkType.class);
return JetJavaFrameworkType.getInstance();
}
@NotNull
@@ -72,6 +72,11 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
@NotNull Module module,
@NotNull ModifiableRootModel rootModel,
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
rootModel,
JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_KIND,
"Current module is already configured as JavaScript Kotlin module.\nDo you want to remove JavaScript support?",
"Configure Kotlin Java Support");
}
private FrameworkSourcePanel getConfigurationPanel() {
@@ -24,6 +24,10 @@ import org.jetbrains.jet.plugin.JetIcons;
import javax.swing.*;
public class JetJavaFrameworkType extends FrameworkTypeEx {
public static JetJavaFrameworkType getInstance() {
return FrameworkTypeEx.EP_NAME.findExtension(JetJavaFrameworkType.class);
}
public JetJavaFrameworkType() {
super("kotlin-java-framework-id");
}
@@ -50,7 +50,6 @@ public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription {
this.frameworkSourcePanel = frameworkSourcePanel;
}
@NotNull
@Override
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
@@ -36,7 +36,7 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
@NotNull
@Override
public FrameworkTypeEx getFrameworkType() {
return FrameworkTypeEx.EP_NAME.findExtension(JavaScriptFrameworkType.class);
return JavaScriptFrameworkType.getInstance();
}
@NotNull
@@ -62,17 +62,16 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
getConfigurationPanel().onFrameworkSelectionChanged(selected);
}
@Override
public boolean isOnlyLibraryAdded() {
return true;
}
@Override
public void addSupport(
@NotNull Module module,
@NotNull ModifiableRootModel rootModel,
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
rootModel,
JetJavaRuntimeLibraryDescription.KOTLIN_JAVA_RUNTIME_KIND,
"Current module is already configured as Java Kotlin module.\nDo you want to remove Java support?",
"Configure Kotlin JavaScript Support");
}
private FrameworkSourcePanel getConfigurationPanel() {
@@ -29,7 +29,7 @@ import java.util.List;
public class KotlinJavaScriptHeadersPresentationProvider extends LibraryPresentationProvider<LibraryVersionProperties> {
protected KotlinJavaScriptHeadersPresentationProvider() {
super(JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_HEADERS_KIND);
super(JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_KIND);
}
@Nullable