diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddItemPopupAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddItemPopupAction.java index a6aa3092a96f..d8a23887bf60 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddItemPopupAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddItemPopupAction.java @@ -15,6 +15,9 @@ */ package com.intellij.openapi.roots.ui.configuration.classpath; +import com.intellij.openapi.ui.popup.PopupStep; +import org.jetbrains.annotations.Nullable; + import javax.swing.*; /** @@ -32,6 +35,15 @@ abstract class AddItemPopupAction extends ChooseAndAddAction myIndex = index; } + public boolean hasSubStep() { + return false; + } + + @Nullable + public PopupStep createSubStep() { + return null; + } + public String getTitle() { return myTitle; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java index c392afa1df99..09711c05fd54 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java @@ -23,8 +23,10 @@ import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil; +import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.util.Icons; import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog; import org.jetbrains.annotations.Nullable; @@ -36,13 +38,21 @@ import java.util.List; */ class AddLibraryAction extends AddItemPopupAction { private StructureConfigurableContext myContext; - private AddNewLibraryItemAction myNewLibraryAction; public AddLibraryAction(ClasspathPanel classpathPanel, final int index, final String title, final StructureConfigurableContext context) { super(classpathPanel, index, title, Icons.LIBRARY_ICON); myContext = context; - myNewLibraryAction = new AddNewLibraryItemAction(classpathPanel, context); + } + + @Override + public boolean hasSubStep() { + return !hasLibraries() && AddNewLibraryItemAction.hasSuitableTypes(myClasspathPanel); + } + + @Override + public PopupStep createSubStep() { + return AddNewLibraryItemAction.createChooseTypeStep(myClasspathPanel, myContext, null); } @Override @@ -51,16 +61,19 @@ class AddLibraryAction extends AddItemPopupAction { super.run(); } else { - myNewLibraryAction.run(); + new AddNewLibraryItemAction(myClasspathPanel, myContext, null).run(); } } private boolean hasLibraries() { final Predicate condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel()); for (LibraryTable table : ChooseLibrariesFromTablesDialog.getLibraryTables(myClasspathPanel.getProject(), true)) { - for (Library library : table.getLibraries()) { - if (condition.apply(library)) { - return true; + final LibrariesModifiableModel model = myContext.myLevel2Providers.get(table.getTableLevel()); + if (model != null) { + for (Library library : model.getLibraries()) { + if (condition.apply(library)) { + return true; + } } } } @@ -101,8 +114,8 @@ class AddLibraryAction extends AddItemPopupAction { public void doChoose() { final Predicate condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel()); - ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel.getComponent(), myClasspathPanel.getProject(), myContext, - condition, myNewLibraryAction); + ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel, myContext, + condition); dialog.show(); mySelectedLibraries = dialog.getSelectedLibraries(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java index 0242fe83344c..fb55db139762 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java @@ -15,21 +15,37 @@ */ package com.intellij.openapi.roots.ui.configuration.classpath; +import com.intellij.ide.IdeBundle; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.ListPopup; +import com.intellij.openapi.ui.popup.PopupStep; +import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.util.Icons; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; /** * @author nik */ class AddNewLibraryItemAction extends ChooseAndAddAction { private final StructureConfigurableContext myContext; + private LibraryType myLibraryType; public AddNewLibraryItemAction(final ClasspathPanel classpathPanel, - StructureConfigurableContext context) { + StructureConfigurableContext context, LibraryType libraryType) { super(classpathPanel); myContext = context; + myLibraryType = libraryType; } protected ClasspathTableItem createTableItem(final Library item) { @@ -46,6 +62,64 @@ class AddNewLibraryItemAction extends ChooseAndAddAction { } protected ClasspathElementChooser createChooser() { - return new NewLibraryChooser(myClasspathPanel.getProject(), myClasspathPanel.getRootModel(), myContext, myClasspathPanel.getComponent()); + return new NewLibraryChooser(myClasspathPanel.getProject(), myClasspathPanel.getRootModel(), myLibraryType, myContext, myClasspathPanel.getComponent()); + } + + public static void chooseTypeAndExecute(final ClasspathPanel classpathPanel, + final StructureConfigurableContext context, + final DialogWrapper parentDialog, + JButton contextButton) { + if (hasSuitableTypes(classpathPanel)) { + final ListPopup popup = JBPopupFactory.getInstance().createListPopup(createChooseTypeStep(classpathPanel, context, parentDialog)); + popup.showUnderneathOf(contextButton); + } + else { + if (parentDialog != null) parentDialog.close(DialogWrapper.CANCEL_EXIT_CODE); + new AddNewLibraryItemAction(classpathPanel, context, null).execute(); + } + } + + public static BaseListPopupStep createChooseTypeStep(final ClasspathPanel classpathPanel, + final StructureConfigurableContext context, + final DialogWrapper parentDialog) { + return new BaseListPopupStep("Select Library Type", getSuitableTypes(classpathPanel)) { + @NotNull + @Override + public String getTextFor(LibraryType value) { + return value != null ? value.getCreateActionName() : IdeBundle.message("create.default.library.type.action.name"); + } + + @Override + public Icon getIconFor(LibraryType aValue) { + return aValue != null ? aValue.getIcon() : Icons.LIBRARY_ICON; + } + + @Override + public PopupStep onChosen(final LibraryType selectedValue, boolean finalChoice) { + return doFinalStep(new Runnable() { + @Override + public void run() { + if (parentDialog != null) parentDialog.close(DialogWrapper.CANCEL_EXIT_CODE); + new AddNewLibraryItemAction(classpathPanel, context, selectedValue).execute(); + } + }); + } + }; + } + + public static boolean hasSuitableTypes(ClasspathPanel panel) { + return getSuitableTypes(panel).size() > 1; + } + + private static List getSuitableTypes(ClasspathPanel classpathPanel) { + List suitableTypes = new ArrayList(); + suitableTypes.add(null); + final ModuleType moduleType = classpathPanel.getRootModel().getModule().getModuleType(); + for (LibraryType libraryType : LibraryType.EP_NAME.getExtensions()) { + if (libraryType.isSuitableModuleType(moduleType)) { + suitableTypes.add(libraryType); + } + } + return suitableTypes; } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index 623523a41471..fe9bb3a0fea8 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -312,10 +312,18 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { return aValue.getIcon(); } + @Override + public boolean hasSubstep(AddItemPopupAction selectedValue) { + return selectedValue.hasSubStep(); + } + public boolean isMnemonicsNavigationEnabled() { return true; } public PopupStep onChosen(final AddItemPopupAction selectedValue, final boolean finalChoice) { + if (selectedValue.hasSubStep()) { + return selectedValue.createSubStep(); + } return doFinalStep(new Runnable() { public void run() { selectedValue.execute(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java index b892182b9bd9..9f8e6e30069f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java @@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; +import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; @@ -42,11 +43,13 @@ class NewLibraryChooser implements ClasspathElementChooser { private StructureConfigurableContext myContext; private final JComponent myParentComponent; private final Project myProject; + private LibraryType myLibraryType; public NewLibraryChooser(final Project project, - final ModifiableRootModel rootModel, - StructureConfigurableContext context, final JComponent parentComponent) { + final ModifiableRootModel rootModel, + LibraryType libraryType, StructureConfigurableContext context, final JComponent parentComponent) { myRootModel = rootModel; + myLibraryType = libraryType; myContext = context; myParentComponent = parentComponent; myProject = project; @@ -57,11 +60,20 @@ class NewLibraryChooser implements ClasspathElementChooser { } public void doChoose() { + final NewLibraryEditor libraryEditor; + if (myLibraryType == null) { + libraryEditor = new NewLibraryEditor(); + } + else { + libraryEditor = new NewLibraryEditor(myLibraryType, myLibraryType.createDefaultProperties()); + } + final LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance(); List tables = Arrays.asList(myRootModel.getModuleLibraryTable(), registrar.getLibraryTable(myProject), registrar.getLibraryTable()); - CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myParentComponent, myContext, new NewLibraryEditor(), tables, 1); + + CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myParentComponent, myContext, libraryEditor, tables, 1); final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myParentComponent)); dialog.setContextModule(contextModule); dialog.show(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java index 33d4d136749b..44485486b5c5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java @@ -27,7 +27,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigur import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.event.ActionEvent; @@ -37,18 +36,18 @@ import java.awt.event.KeyEvent; * @author nik */ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTablesDialog { + private final ClasspathPanel myClasspathPanel; private StructureConfigurableContext myContext; private Predicate myAcceptedLibraries; - private AddNewLibraryItemAction myNewLibraryAction; + private JButton myCreateLibraryButton; - public ProjectStructureChooseLibrariesDialog(JComponent parentComponent, - @Nullable Project project, + public ProjectStructureChooseLibrariesDialog(ClasspathPanel classpathPanel, StructureConfigurableContext context, - Predicate acceptedLibraries, AddNewLibraryItemAction newLibraryAction) { - super(parentComponent, "Choose Libraries", project, true); + Predicate acceptedLibraries) { + super(classpathPanel.getComponent(), "Choose Libraries", classpathPanel.getProject(), true); + myClasspathPanel = classpathPanel; myContext = context; myAcceptedLibraries = acceptedLibraries; - myNewLibraryAction = newLibraryAction; setOKButtonText("Add Selected"); init(); } @@ -95,6 +94,15 @@ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTa return new Action[]{getOKAction(), new CreateNewLibraryAction()}; } + @Override + protected JButton createJButtonForAction(Action action) { + final JButton button = super.createJButtonForAction(action); + if (action instanceof CreateNewLibraryAction) { + myCreateLibraryButton = button; + } + return button; + } + @Override protected LibrariesTreeNodeBase createLibraryDescriptor(NodeDescriptor parentDescriptor, Library library) { @@ -121,8 +129,7 @@ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTa @Override protected void doAction(ActionEvent e) { - close(CANCEL_EXIT_CODE); - myNewLibraryAction.execute(); + AddNewLibraryItemAction.chooseTypeAndExecute(myClasspathPanel, myContext, ProjectStructureChooseLibrariesDialog.this, myCreateLibraryButton); } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java index 8d374c5ea6f1..52e0a641aa03 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.roots.ui.configuration.libraryEditor; +import com.intellij.ide.IdeBundle; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; @@ -30,7 +31,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiab import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.openapi.ui.MasterDetailsComponent; import com.intellij.util.Icons; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -78,7 +78,11 @@ public class CreateNewLibraryAction extends AnAction { private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) { final List modules = new ArrayList(); - ContainerUtil.addAll(modules, rootConfigurable.getModules()); + for (Module module : rootConfigurable.getModules()) { + if (myType == null || myType.isSuitableModuleType(module.getModuleType())) { + modules.add(module); + } + } if (modules.isEmpty()) return; final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject, modules, ProjectBundle.message("choose.modules.dialog.title"), @@ -99,7 +103,7 @@ public class CreateNewLibraryAction extends AnAction { return new AnAction[]{new CreateNewLibraryAction(text, Icons.LIBRARY_ICON, null, librariesConfigurable, project)}; } List actions = new ArrayList(); - actions.add(new CreateNewLibraryAction("Java", Icons.LIBRARY_ICON, null, librariesConfigurable, project)); + actions.add(new CreateNewLibraryAction(IdeBundle.message("create.default.library.type.action.name"), Icons.LIBRARY_ICON, null, librariesConfigurable, project)); for (LibraryType type : extensions) { actions.add(new CreateNewLibraryAction(type.getCreateActionName(), type.getIcon(), type, librariesConfigurable, project)); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java index c953df9490ed..e085da3d4450 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; @@ -67,8 +68,8 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase { } public Library createLibrary() { - final LibraryTable.ModifiableModel modifiableModel = getTableModifiableModel(); - final Library library = modifiableModel.createLibrary(myLibraryEditor.getName()); + final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel(); + final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), myLibraryEditor.getType()); final Library.ModifiableModel model = library.getModifiableModel(); myLibraryEditor.apply(model); new WriteAction() { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java index f0b622d4329d..d00b6c7bb8a6 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryType.java @@ -16,6 +16,7 @@ package com.intellij.openapi.roots.libraries; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor; import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; @@ -50,6 +51,13 @@ public abstract class LibraryType

extends LibraryPr @NotNull public abstract P createDefaultProperties(); + /** + * @return {@code true} if library of this type can be added as a dependency to a module of type {@code moduleType} + */ + public boolean isSuitableModuleType(@NotNull ModuleType moduleType) { + return true; + } + /** * Override this method to customize the library roots editor * @return {@link com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor} instance diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index 57af041c825f..3e6c16b5e48d 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -92,6 +92,7 @@ public class VfsUtil { * @param separator character to use as files separator * @return the relative path */ + @Nullable public static String getRelativePath(@NotNull VirtualFile file, @NotNull VirtualFile ancestor, char separator) { if (!file.getFileSystem().equals(ancestor.getFileSystem())) return null; diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 4b04dd00875b..9d3e74a5e995 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -984,6 +984,9 @@ setup.library.dialog.title=Setup Library label.library.will.be.created.description.text={0} level library {1} with {2} file(s) will be created new.library.file.chooser.title=New Library Files new.library.file.chooser.description=Select jar files in which library classes are located + +create.default.library.type.action.name=Java + file.chooser.show.path=Show path file.chooser.hide.path=Hide path file.chooser.hide.path.tooltip.text=Show/Hide path text field diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 3346592ec74c..60470401e53b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -225,12 +225,12 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { Annotation annotation = myHolder.createInfoAnnotation(elt, null); final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null) { - if (!(parent instanceof GrCall)) { - registerCreateClassByTypeFix(referenceExpression, annotation); - registerAddImportFixes(referenceExpression, annotation); + if (parent instanceof GrMethodCall) { + registerStaticImportFix(referenceExpression, annotation); } else { - registerStaticImportFix(referenceExpression, annotation); + registerCreateClassByTypeFix(referenceExpression, annotation); + registerAddImportFixes(referenceExpression, annotation); } } else { @@ -380,7 +380,9 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { PsiElement typeDef = parent.getParent(); if (typeDef != null && typeDef instanceof GrTypeDefinition) { PsiModifierList modifiersList = variableDeclaration.getModifierList(); - final GrMember member = variableDeclaration.getMembers()[0]; + final GrMember[] members = variableDeclaration.getMembers(); + if (members.length == 0) return; + final GrMember member = members[0]; checkAccessModifiers(myHolder, modifiersList, member); checkDuplicateModifiers(myHolder, variableDeclaration.getModifierList(), member); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java index 76964a7a145e..2f450f234a6d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java @@ -17,8 +17,10 @@ package org.jetbrains.plugins.groovy.codeInspection.unusedDef; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; +import com.intellij.psi.impl.DebugUtil; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; @@ -56,6 +58,8 @@ import java.util.ArrayList; & @author ven */ public class UnusedDefInspection extends GroovyLocalInspectionBase { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection"); + @Nls @NotNull public String getGroupDisplayName() { @@ -152,7 +156,7 @@ public class UnusedDefInspection extends GroovyLocalInspectionBase { if (var != null) { final GroovyPsiElement scope = getScope(var); - assert scope != null; + LOG.assertTrue(scope != null, DebugUtil.psiToString(var.getContainingFile(), true, false)); return ReferencesSearch.search(var, new LocalSearchScope(scope)).forEach(new Processor() { public boolean process(PsiReference ref) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppClosureParameterTypeProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppClosureParameterTypeProvider.java index 2e0a8e35d979..584c88117360 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppClosureParameterTypeProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppClosureParameterTypeProvider.java @@ -49,20 +49,19 @@ public class GppClosureParameterTypeProvider extends AbstractClosureParameterEnh assert argIndex >= 0; if (listType instanceof GrTupleType) { for (PsiType type : GroovyExpectedTypesProvider.getDefaultExpectedTypes(list)) { - if (type instanceof PsiClassType) { - for (GroovyResolveResult resolveResult : PsiUtil - .getConstructorCandidates((PsiClassType)type, ((GrTupleType)listType).getComponentTypes(), closure)) { - final PsiElement method = resolveResult.getElement(); - if (method instanceof PsiMethod && ((PsiMethod)method).isConstructor()) { - final PsiType toCastTo = - resolveResult.getSubstitutor().substitute(((PsiMethod)method).getParameterList().getParameters()[argIndex].getType()); - final PsiType suggestion = getSingleMethodParameterType(toCastTo, index, closure); - if (suggestion != null) { - return suggestion; - } - } + if (!(type instanceof PsiClassType)) continue; - } + final GroovyResolveResult[] candidates = PsiUtil.getConstructorCandidates((PsiClassType)type,((GrTupleType)listType).getComponentTypes(),closure); + for (GroovyResolveResult resolveResult : candidates) { + final PsiElement method = resolveResult.getElement(); + if (!(method instanceof PsiMethod) || !((PsiMethod)method).isConstructor()) continue; + + final PsiParameter[] parameters = ((PsiMethod)method).getParameterList().getParameters(); + if (parameters.length <= argIndex) continue; + + final PsiType toCastTo = resolveResult.getSubstitutor().substitute(parameters[argIndex].getType()); + final PsiType suggestion = getSingleMethodParameterType(toCastTo, index, closure); + if (suggestion != null) return suggestion; } } } diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariableValidator/loop3.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariableValidator/loop3.test index 15961a8f7033..bda46ec8ffa8 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariableValidator/loop3.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariableValidator/loop3.test @@ -15,5 +15,5 @@ class A{ } } ----- +Introduced variable will conflict with local variable preved Introduced variable will conflict with parameter preved -Introduced variable will conflict with local variable preved \ No newline at end of file diff --git a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/CustomArtifact.java b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/CustomArtifact.java index 3c80a16be25b..85f24315ba74 100644 --- a/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/CustomArtifact.java +++ b/plugins/maven/facade-impl/src/org/jetbrains/idea/maven/facade/embedder/CustomArtifact.java @@ -172,7 +172,19 @@ public class CustomArtifact implements Artifact { } public String getId() { - return myWrapee.getId(); + try { + return myWrapee.getId(); + } + catch (NullPointerException e) { + if (e.getMessage() != null && e.getMessage().contains("version was null")) { + VersionRange range = getVersionRange(); + if (range != null) { + setBaseVersion(range.toString()); + return myWrapee.getId(); + } + } + throw e; + } } public String getDependencyConflictId() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/RemoteObjectWrapper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/RemoteObjectWrapper.java index 56a6eb5b3807..8183ce4089fb 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/RemoteObjectWrapper.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/facade/RemoteObjectWrapper.java @@ -56,7 +56,7 @@ public abstract class RemoteObjectWrapper { } protected synchronized void handleRemoteError(RemoteException e) { - MavenLog.LOG.info("Connection failed. Will be reconnected on the next request.", e); + MavenLog.LOG.debug("Connection failed. Will be reconnected on the next request.", e); onError(); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java index 7d04d8dba13b..0460ba1e7e04 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenConsoleImpl.java @@ -40,7 +40,7 @@ public class MavenConsoleImpl extends MavenConsole { private static final Key CONSOLE_KEY = Key.create("MAVEN_CONSOLE_KEY"); private static final String CONSOLE_FILTER_REGEXP = - RegexpFilter.FILE_PATH_MACROS + ":\\[" + RegexpFilter.LINE_MACROS + "," + RegexpFilter.COLUMN_MACROS + "]"; + "(?:^|(?:\\[\\w+\\]\\s*))" + RegexpFilter.FILE_PATH_MACROS + ":\\[" + RegexpFilter.LINE_MACROS + "," + RegexpFilter.COLUMN_MACROS + "]"; private final String myTitle; private final Project myProject; @@ -153,9 +153,9 @@ public class MavenConsoleImpl extends MavenConsole { } ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW); - if (!toolWindow.isActive()) { + if (!toolWindow.isActive()) { toolWindow.activate(null, false); - } + } } }); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index 431dd346a238..c9d4b98d32f4 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -343,18 +343,20 @@ public class MavenProjectsManager extends SimpleProjectComponent @Override public void projectResolved(Pair projectWithChanges, @Nullable NativeMavenProjectHolder nativeMavenProject) { - if (nativeMavenProject != null && shouldScheduleProject(projectWithChanges)) { - scheduleForNextImport(projectWithChanges); + if (nativeMavenProject != null) { + if (shouldScheduleProject(projectWithChanges)) { + scheduleForNextImport(projectWithChanges); - if (projectWithChanges.first.hasUnresolvedPlugins()) { - schedulePluginsResolve(projectWithChanges.first, nativeMavenProject); + scheduleArtifactsDownloading(Collections.singleton(projectWithChanges.first), + null, + getImportingSettings().isDownloadSourcesAutomatically(), + getImportingSettings().isDownloadDocsAutomatically(), + null); } - scheduleArtifactsDownloading(Collections.singleton(projectWithChanges.first), - null, - getImportingSettings().isDownloadSourcesAutomatically(), - getImportingSettings().isDownloadDocsAutomatically(), - null); + if (!projectWithChanges.first.hasReadingProblems() && projectWithChanges.first.hasUnresolvedPlugins()) { + schedulePluginsResolve(projectWithChanges.first, nativeMavenProject); + } } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java index 66e08718b44a..d3d536e81003 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java @@ -1640,7 +1640,7 @@ public class DependenciesImportingTest extends MavenImportingTestCase { public void testCustomSourcesAndJavadocPaths() throws Exception { if (!checkUltimate()) return; - + importProject("test" + "project" + "1" + @@ -2041,4 +2041,101 @@ public class DependenciesImportingTest extends MavenImportingTestCase { assertModuleLibDep("project", "Maven: junit:junit:3.8.2", "jar://" + repoPath + "/junit/junit/3.8.2/junit-3.8.2.jar!/"); } + + //public void testVersionRangeDoesntBreakIndirectDependency() throws Exception { + // createProjectPom("test" + + // "project" + + // "1" + + // "pom" + + // + // "" + + // " m1" + + // " m2" + + // ""); + // + // createModulePom("m1", "test" + + // "m1" + + // "1" + + // + // "" + + // " " + + // " asm" + + // " asm" + + // " 2.2.3" + + // " " + + // ""); + // + // createModulePom("m2", "test" + + // "m2" + + // "1" + + // + // "" + + // " " + + // " test" + + // " m1" + + // " 1" + + // " " + + // " " + + // " asm" + + // " asm" + + // " [2.2.3]" + + // " " + + // ""); + // + // importProject(); + // + // assertModuleModuleDeps("m2", "m1"); + // assertModuleLibDeps("m1", "Maven: asm:asm:2.2.3"); + // assertModuleLibDeps("m2", "Maven: asm:asm:2.2.3"); + //} + // + public void testVersionRangeInDependencyManagementDoesntBreakIndirectDependency() throws Exception { + createProjectPom("test" + + "project" + + "1" + + "pom" + + + "" + + " m" + + "" + + + " \n" + + " \n" + + " \n" + + " asm\n" + + " asm\n" + + " [2.2.1]\n" + + " runtime\n" + + " \n" + + " \n" + + " asm-attrs\n" + + " asm\n" + + " [2.2.1]\n" + + " runtime\n" + + " \n" + + " \n" + + " "); + + createModulePom("m", "test" + + "m" + + "1" + + "" + + " \n" + + " test\n" + + " project\n" + + " 1\n" + + " " + + + "" + + " " + + " asm-attrs\n" + + " asm\n" + + " test" + + " " + + ""); + + importProject(); + + assertModuleLibDeps("m", "Maven: asm:asm-attrs:2.2.1", "Maven: asm:asm:2.2.1"); + } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java index c886494cc88c..e7a135848e8a 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java @@ -74,7 +74,7 @@ public class DependenciesManagementTest extends MavenImportingTestCase { public void testImportingNotInstalledDependencies() throws Exception { if (ignore()) return; - + setRepositoryPath(new File(myDir, "/repo").getPath()); updateSettingsXml("" + getRepositoryPath() + ""); @@ -144,20 +144,20 @@ public class DependenciesManagementTest extends MavenImportingTestCase { updateSettingsXml("" + getRepositoryPath() + ""); VirtualFile parent = createModulePom("parent", - "test" + - "parent" + - "pom" + - "1" + + "test" + + "parent" + + "pom" + + "1" + - "" + - " " + - " " + - " junit" + - " junit" + - " 4.0" + - " " + - " " + - ""); + "" + + " " + + " " + + " junit" + + " junit" + + " 4.0" + + " " + + " " + + ""); VirtualFile project = createModulePom("project", "test" +