Merge branch 'master' of git@git.labs.intellij.net:idea/community
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Wed, 2 Dec 2009 18:56:36 +0000 (21:56 +0300)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Wed, 2 Dec 2009 18:56:36 +0000 (21:56 +0300)
52 files changed:
java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java
java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerManagerImpl.java
java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactManager.java
java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java
java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameStep.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContext.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTree.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/InlineArtifactAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/MovePackagingElementAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/RenamePackagingElementAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/nodes/PackagingNodeSource.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/SourceItemsTree.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java
java/idea-ui/src/com/intellij/projectImport/ProjectFormatPanel.form
java/idea-ui/src/com/intellij/projectImport/ProjectFormatPanel.java
java/java-impl/src/com/intellij/ide/todo/nodes/TodoJavaTreeHelper.java
java/java-impl/src/com/intellij/openapi/module/JavaModuleType.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/OldReferenceResolver.java
java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java
java/java-impl/src/com/intellij/refactoring/ui/ClassCellRenderer.java
java/java-tests/testData/refactoring/introduceParameter/afterIncompleteEnumDefinition.java [new file with mode: 0644]
java/java-tests/testData/refactoring/introduceParameter/beforeIncompleteEnumDefinition.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java
platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java
platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/RenameModuleHandler.java
platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java
platform/platform-api/src/com/intellij/openapi/ui/Messages.java
platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandler.java
platform/platform-resources-en/src/messages/RefactoringBundle.properties
platform/util/src/com/intellij/util/containers/SLRUCache.java
platform/util/src/com/intellij/util/io/PersistentHashMapValueStorage.java
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/AdvancedSettingsUI.form
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/AdvancedSettingsUI.java
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/pattern/PatternValidator.java
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/util/ContextComputationProcessor.java
plugins/IntelliLang/src/org/intellij/plugins/intelliLang/util/SubstitutedExpressionEvaluationHelper.java
plugins/IntentionPowerPak/src/com/siyeh/ipp/constant/ConstantSubexpressionIntention.java
plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/CommentTokenizer.java
plugins/spellchecker/testData/inspection/js/test.js
resources/src/META-INF/IdeaPlugin.xml
resources/src/ProductivityFeaturesRegistry.xml
resources/src/componentSets/Compiler.xml
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java

index e79a55ba907e5b49efe7ecdbf22d9f561c126c9a..b3c58b3a17be9335469135ce334d41523c35ad35 100644 (file)
@@ -65,11 +65,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
   };
   private Map<String, LocalFileSystem.WatchRequest> myWatchedOutputs = new HashMap<String, LocalFileSystem.WatchRequest>();
 
-  public ArtifactManagerImpl(Project project, VirtualFileManager virtualFileManager) {
+  public ArtifactManagerImpl(Project project) {
     myProject = project;
     myModel = new ArtifactManagerModel();
     myResolvingContext = new DefaultPackagingElementResolvingContext(myProject);
-    virtualFileManager.addVirtualFileListener(new ArtifactVirtualFileListener(myProject, this), myProject);
+    ((ArtifactPointerManagerImpl)ArtifactPointerManager.getInstance(project)).setArtifactManager(this);
   }
 
   @NotNull
@@ -225,6 +225,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
   }
 
   public void initComponent() {
+    VirtualFileManager.getInstance().addVirtualFileListener(new ArtifactVirtualFileListener(myProject, this), myProject);
     updateWatchedRoots();
   }
 
@@ -326,6 +327,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
     finally {
       myInsideCommit = false;
     }
+    updateWatchedRoots();
   }
 
   public Project getProject() {
index 92401f8a24ef913e399857a8b23e1e40bd6a9a0f..60ebae5d470a250509e6953b3aa524a41b3ba002 100644 (file)
@@ -29,10 +29,9 @@ import java.util.Map;
 public class ArtifactPointerManagerImpl extends ArtifactPointerManager {
   private final Map<String, ArtifactPointerImpl> myUnresolvedPointers = new HashMap<String, ArtifactPointerImpl>();
   private final Map<Artifact, ArtifactPointerImpl> myPointers = new HashMap<Artifact, ArtifactPointerImpl>();
-  private final Project myProject;
+  private ArtifactManager myArtifactManager;
 
   public ArtifactPointerManagerImpl(Project project) {
-    myProject = project;
     project.getMessageBus().connect().subscribe(ArtifactManager.TOPIC, new ArtifactAdapter() {
       @Override
       public void artifactRemoved(@NotNull Artifact artifact) {
@@ -73,6 +72,10 @@ public class ArtifactPointerManagerImpl extends ArtifactPointerManager {
     });
   }
 
+  public void setArtifactManager(ArtifactManager artifactManager) {
+    myArtifactManager = artifactManager;
+  }
+
   private void disposePointer(Artifact artifact) {
     final ArtifactPointerImpl pointer = myPointers.remove(artifact);
     if (pointer != null) {
@@ -82,9 +85,11 @@ public class ArtifactPointerManagerImpl extends ArtifactPointerManager {
   }
 
   public ArtifactPointer createPointer(@NotNull String name) {
-    final Artifact artifact = ArtifactManager.getInstance(myProject).findArtifact(name);
-    if (artifact != null) {
-      return createPointer(artifact);
+    if (myArtifactManager != null) {
+      final Artifact artifact = myArtifactManager.findArtifact(name);
+      if (artifact != null) {
+        return createPointer(artifact);
+      }
     }
 
     ArtifactPointerImpl pointer = myUnresolvedPointers.get(name);
index 353216e390d7918029804b67a215c2c686a746d2..9610bfa3e74115d2da802366c85a566f4c7709bc 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.intellij.packaging.artifacts;
 
-import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.packaging.elements.CompositePackagingElement;
@@ -41,7 +40,7 @@ public abstract class ArtifactManager implements ArtifactModel {
   };
 
   public static ArtifactManager getInstance(@NotNull Project project) {
-    return ServiceManager.getService(project, ArtifactManager.class);
+    return project.getComponent(ArtifactManager.class);
   }
 
   public abstract Artifact[] getSortedArtifacts();
index 012f1ba8e26756a19d6711d520b6c6d96f1761fe..ab449e0eecc2fc302e5fefb98ffad1241b82d3ee 100644 (file)
 package com.intellij.debugger.actions;
 
 import com.intellij.debugger.DebuggerBundle;
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.diff.*;
 import com.intellij.openapi.ide.CopyPasteManager;
 import com.intellij.openapi.project.Project;
-import org.jetbrains.annotations.Nullable;
 
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
@@ -29,6 +29,7 @@ import java.awt.datatransfer.Transferable;
  * @author Jeka
  */
 public class CompareValueWithClipboardAction extends BaseValueAction {
+  private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.CompareValueWithClipboardAction");
   protected void processText(final Project project, final String text) {
     DiffManager.getInstance().getDiffTool().show(new ClipboardSelectionContents(text, project));
   }
@@ -65,16 +66,16 @@ public class CompareValueWithClipboardAction extends BaseValueAction {
       return DebuggerBundle.message("diff.clipboard.vs.value.dialog.title");
     }
 
-    @Nullable
     private static DiffContent createClipboardContent() {
       Transferable content = CopyPasteManager.getInstance().getContents();
-      String text;
+      String text = "";
       try {
         text = (String) (content.getTransferData(DataFlavor.stringFlavor));
-      } catch (Exception e) {
-        return null;
       }
-      return text != null ? new SimpleContent(text) : null;
+      catch (Exception e) {
+        LOG.info(e);
+      }
+      return new SimpleContent(text);
     }
   }
 }
\ No newline at end of file
index f1b56f007155e07541976b7ffa80400f9a024487..7ba14ec4a017f7aa79df1185264ae1c57c3fe864 100644 (file)
@@ -16,8 +16,8 @@
 package com.intellij.ide.util.newProjectWizard;
 
 import com.intellij.ide.IdeBundle;
-import com.intellij.ide.highlighter.ProjectFileType;
 import com.intellij.ide.highlighter.ModuleFileType;
+import com.intellij.ide.highlighter.ProjectFileType;
 import com.intellij.ide.util.newProjectWizard.modes.WizardMode;
 import com.intellij.ide.util.projectWizard.*;
 import com.intellij.openapi.application.ApplicationInfo;
@@ -26,7 +26,7 @@ import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.components.StorageScheme;
+import com.intellij.projectImport.ProjectFormatPanel;
 
 import javax.swing.*;
 import java.awt.*;
@@ -45,10 +45,7 @@ public class ProjectNameStep extends ModuleWizardStep {
   protected final WizardContext myWizardContext;
   protected final StepSequence mySequence;
   protected final WizardMode myMode;
-  private static final String DIR_BASED = ".idea (directory based)";
-  private static final String FILE_BASED = ".ipr (file based)";
-  private final JComboBox myStorageFormatCombo = new JComboBox();
-
+  private ProjectFormatPanel myFormatPanel = new ProjectFormatPanel();
 
   public ProjectNameStep(WizardContext wizardContext, StepSequence sequence, final WizardMode mode) {
     myWizardContext = wizardContext;
@@ -71,21 +68,11 @@ public class ProjectNameStep extends ModuleWizardStep {
     myPanel = new JPanel(new GridBagLayout());
     myPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
     myPanel.add(myNamePathComponent, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 0), 0, 0));
-    JPanel projectFileFormatPanel = new JPanel(new BorderLayout());
-    myPanel.add(projectFileFormatPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 6, 0, 0), 0, 0));
-
-    myNamePathComponent.setVisible(myWizardContext.getProject() == null);
-    projectFileFormatPanel.setVisible(myWizardContext.getProject() == null);
 
-    final JLabel label = new JLabel("Project storage format:");
-    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4));
-    projectFileFormatPanel.add(label, BorderLayout.WEST);
-    projectFileFormatPanel.add(myStorageFormatCombo, BorderLayout.CENTER);
-    myStorageFormatCombo.insertItemAt(DIR_BASED, 0);
-    myStorageFormatCombo.insertItemAt(FILE_BASED, 1);
-
-    myStorageFormatCombo.setSelectedItem(DIR_BASED);
+    myPanel.add(myFormatPanel.getPanel(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 0, 0, 0), 0, 0));
 
+    myNamePathComponent.setVisible(myWizardContext.getProject() == null);
+    myFormatPanel.setVisible(myWizardContext.getProject() == null);
     myAdditionalContentPanel = new JPanel(new GridBagLayout());
     myPanel.add(myAdditionalContentPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
   }
@@ -100,16 +87,12 @@ public class ProjectNameStep extends ModuleWizardStep {
     myWizardContext.setProjectFileDirectory(projectFileDirectory);
     final ProjectBuilder moduleBuilder = myMode.getModuleBuilder();
     myWizardContext.setProjectBuilder(moduleBuilder);
-    myWizardContext.setProjectStorageFormat(getSelectedProjectStorageFormat());
+    myFormatPanel.updateData(myWizardContext);
     if (moduleBuilder instanceof SourcePathsBuilder) {
       ((SourcePathsBuilder)moduleBuilder).setContentEntryPath(projectFileDirectory);
     }
   }
 
-  private StorageScheme getSelectedProjectStorageFormat() {
-    return FILE_BASED.equals(myStorageFormatCombo.getSelectedItem()) ? StorageScheme.DEFAULT : StorageScheme.DIRECTORY_BASED;
-  }
-
   public Icon getIcon() {
     return myWizardContext.getProject() == null ? NEW_PROJECT_ICON : ICON;
   }
@@ -124,7 +107,7 @@ public class ProjectNameStep extends ModuleWizardStep {
 
   public String getProjectFilePath() {
     if (myWizardContext.getProject() == null) {
-      if (getSelectedProjectStorageFormat() == StorageScheme.DEFAULT) {
+      if (myFormatPanel.isDefault()) {
         return getProjectFileDirectory() + "/" + myNamePathComponent.getNameValue() + ProjectFileType.DOT_DEFAULT_EXTENSION;
       }
       else {
index 5f17e12c671f93ee20c22f99d296b7830bd65491..abc93e948ccaa647bba19723e003bee5f2ce7741 100644 (file)
@@ -92,7 +92,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
   private ArtifactValidationManagerImpl myValidationManager;
 
   public ArtifactEditorImpl(final @NotNull ArtifactsStructureConfigurableContext context, @NotNull Artifact artifact, @NotNull ArtifactEditorSettings settings) {
-    myContext = new ArtifactEditorContextImpl(context, this);
+    myContext = createArtifactEditorContext(context);
     myOriginalArtifact = artifact;
     myProject = context.getProject();
     mySubstitutionParameters.setTypesToShowContent(settings.getTypesToShowContent());
@@ -118,6 +118,10 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
     updateShowContentCheckbox();
   }
 
+  protected ArtifactEditorContextImpl createArtifactEditorContext(ArtifactsStructureConfigurableContext parentContext) {
+    return new ArtifactEditorContextImpl(parentContext, this);
+  }
+
   private ActionGroup createShowSpecificContentOptionsGroup() {
     final DefaultActionGroup group = new DefaultActionGroup();
     for (ComplexPackagingElementType<?> type : PackagingElementFactory.getInstance().getComplexElementTypes()) {
@@ -237,7 +241,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
   }
 
   private void onShowContentSettingsChanged() {
-    ((ArtifactsStructureConfigurableContextImpl)myContext.getParent()).getDefaultSettings().setTypesToShowContent(mySubstitutionParameters.getTypesToSubstitute());
+    myContext.getParent().getDefaultSettings().setTypesToShowContent(mySubstitutionParameters.getTypesToSubstitute());
   }
 
   public void updateShowContentCheckbox() {
index 3bb092504ef22bab4dc310dcaf5800288590f2b6..43748425f84660c7e55e579475e3012c52fe8042 100644 (file)
@@ -56,4 +56,6 @@ public interface ArtifactsStructureConfigurableContext extends PackagingElementR
   ArtifactProjectStructureElement getOrCreateArtifactElement(@NotNull Artifact artifact);
 
   ModifiableRootModel getOrCreateModifiableRootModel(Module module);
+
+  ArtifactEditorSettings getDefaultSettings();
 }
index d40909d8a881c8ee4f2583f967d9c9e418df84f6..9e20c905a444b0f900c93d4755e5c389a0ce3af6 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.ide.dnd.DnDDragStartBean;
 import com.intellij.ide.dnd.DnDManager;
 import com.intellij.ide.dnd.aware.DnDAwareTree;
 import com.intellij.ide.util.treeView.AbstractTreeBuilder;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode;
@@ -58,7 +59,9 @@ public class LayoutTree extends SimpleDnDAwareTree implements AdvancedDnDSource
     setRootVisible(true);
     setShowsRootHandles(false);
     setCellEditor(new LayoutTreeCellEditor());
-    DnDManager.getInstance().registerSource(this);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().registerSource(this);
+    }
   }
 
   public void addSubtreeToUpdate(DefaultMutableTreeNode newNode) {
@@ -107,7 +110,9 @@ public class LayoutTree extends SimpleDnDAwareTree implements AdvancedDnDSource
   }
 
   public void dispose() {
-    DnDManager.getInstance().unregisterSource(this);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().unregisterSource(this);
+    }
   }
 
   public LayoutTreeSelection getSelection() {
@@ -119,7 +124,7 @@ public class LayoutTree extends SimpleDnDAwareTree implements AdvancedDnDSource
     final SimpleNode node = getNodeFor(path);
     if (node instanceof PackagingElementNode) {
       final List<? extends PackagingElement<?>> elements = ((PackagingElementNode<?>)node).getPackagingElements();
-      if (elements.size() == 1) {
+      if (!elements.isEmpty()) {
         return elements.get(0);
       }
     }
index c61706b7776845e68f683f2052178da5e3e65225..3b7c3a3ad4d931f1603fa2bfb67b5ef8c5f665ba 100644 (file)
@@ -19,16 +19,22 @@ import com.intellij.ide.dnd.DnDEvent;
 import com.intellij.ide.dnd.DnDManager;
 import com.intellij.ide.dnd.DnDTarget;
 import com.intellij.openapi.Disposable;
-import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.*;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactRootNode;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingNodeSource;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingTreeNodeFactory;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactType;
 import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.elements.PackagingElement;
 import com.intellij.packaging.elements.PackagingElementFactory;
 import com.intellij.packaging.elements.PackagingElementType;
+import com.intellij.packaging.impl.elements.DirectoryPackagingElement;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
 import com.intellij.packaging.ui.PackagingSourceItem;
@@ -38,10 +44,12 @@ import com.intellij.ui.treeStructure.SimpleNode;
 import com.intellij.ui.treeStructure.SimpleTreeBuilder;
 import com.intellij.ui.treeStructure.SimpleTreeStructure;
 import com.intellij.ui.treeStructure.WeightBasedComparator;
+import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.ui.tree.TreeUtil;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
 
 import javax.swing.*;
 import javax.swing.event.TreeSelectionEvent;
@@ -90,7 +98,9 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
     myTreePanel = new JPanel(new BorderLayout());
     myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
     myTreePanel.add(myPropertiesPanelWrapper, BorderLayout.SOUTH);
-    DnDManager.getInstance().registerTarget(this, myTree);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().registerTarget(this, myTree);
+    }
   }
 
   @Nullable
@@ -101,7 +111,7 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
   public void setSortElements(boolean sortElements) {
     mySortElements = sortElements;
     myBuilder.setNodeDescriptorComparator(getComparator());
-    ((ArtifactsStructureConfigurableContextImpl)myArtifactsEditor.getContext().getParent()).getDefaultSettings().setSortElements(sortElements);
+    myArtifactsEditor.getContext().getParent().getDefaultSettings().setSortElements(sortElements);
   }
 
   @Nullable
@@ -155,50 +165,118 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
   }
 
   public void addNewPackagingElement(@NotNull PackagingElementType<?> type) {
-    final PackagingElementNode<?> parentNode = getParentNode(myTree.getSelection());
-    final PackagingElement<?> element = parentNode.getElementIfSingle();
-    if (!checkCanAdd(type, element, parentNode)) return;
-
-    final CompositePackagingElement<?> parent = element instanceof CompositePackagingElement<?> ? (CompositePackagingElement<?>)element
-                                                                                             : getArtifact().getRootElement();
+    PackagingElementNode<?> parentNode = getParentNode(myTree.getSelection());
+    final PackagingElement<?> element = parentNode.getFirstElement();
+    final CompositePackagingElement<?> parent;
+    if (element instanceof CompositePackagingElement<?>) {
+      parent = (CompositePackagingElement<?>)element;
+    }
+    else {
+      parent = getArtifact().getRootElement();
+      parentNode = myTree.getRootPackagingNode();
+    }
+    if (!checkCanAdd(parent, parentNode)) return;
 
     final List<? extends PackagingElement<?>> children = type.chooseAndCreate(myContext, getArtifact(), parent);
+    final PackagingElementNode<?> finalParentNode = parentNode;
     editLayout(new Runnable() {
       public void run() {
+        CompositePackagingElement<?> actualParent = getOrCreateModifiableParent(parent, finalParentNode);
         for (PackagingElement<?> child : children) {
-          parent.addOrFindChild(child);
+          actualParent.addOrFindChild(child);
         }
       }
     });
     updateAndSelect(parentNode, children);
   }
 
-  public boolean checkCanAdd(@Nullable PackagingElementType<?> type, PackagingElement<?> parentElement, PackagingElementNode<?> parentNode) {
-    final Collection<PackagingNodeSource> nodeSources = parentNode.getNodeSources();
-    final String elementType = type != null ? type.getPresentableName() : "new element";
-    if (parentElement == null || nodeSources.size() > 1) {
-      Messages.showErrorDialog(myArtifactsEditor.getMainComponent(), "Cannot add " +
-                                                                     elementType + ": the selected node is consisting of several different elements.");
-      return false;
+  private static CompositePackagingElement<?> getOrCreateModifiableParent(CompositePackagingElement<?> parentElement, PackagingElementNode<?> node) {
+    PackagingElementNode<?> current = node;
+    List<String> dirNames = new ArrayList<String>();
+    while (current != null && !(current instanceof ArtifactRootNode)) {
+      final PackagingElement<?> packagingElement = current.getFirstElement();
+      if (!(packagingElement instanceof DirectoryPackagingElement)) {
+        return parentElement;
+      }
+      dirNames.add(((DirectoryPackagingElement)packagingElement).getDirectoryName());
+      current = current.getParentNode();
     }
 
-    if (nodeSources.size() == 1) {
-      final PackagingNodeSource source = nodeSources.iterator().next();
-      final Artifact artifact = source.getSourceArtifact();
-      if (artifact != null) {
-        final int answer = Messages.showYesNoDialog(myArtifactsEditor.getMainComponent(),
-                                                    "The selected node comes from '" + artifact.getName() +
-                                                    "' artifact. Do you want to add " + elementType + " into it?",
-                                                    "Add Elements", null);
-        if (answer != 0) {
-          return false;
-        }
+    if (current == null) return parentElement;
+    final PackagingElement<?> rootElement = current.getElementIfSingle();
+    if (!(rootElement instanceof CompositePackagingElement<?>)) return parentElement;
+
+    Collections.reverse(dirNames);
+    String path = StringUtil.join(dirNames, "/");
+    return PackagingElementFactory.getInstance().getOrCreateDirectory((CompositePackagingElement<?>)rootElement, path);
+  }
+
+  public boolean checkCanModify(@NotNull PackagingElement<?> element, @NotNull PackagingElementNode<?> node) {
+    return checkCanModify(node.getNodeSource(element));
+  }
+
+  public boolean checkCanModifyChildren(@NotNull PackagingElement<?> parentElement,
+                                        @NotNull PackagingElementNode<?> parentNode,
+                                        @NotNull Collection<? extends PackagingElementNode<?>> children) {
+    final List<PackagingNodeSource> sources = new ArrayList<PackagingNodeSource>(parentNode.getNodeSource(parentElement));
+    for (PackagingElementNode<?> child : children) {
+      sources.addAll(child.getNodeSources());
+    }
+    return checkCanModify(sources);
+  }
+
+  public boolean checkCanModify(final Collection<PackagingNodeSource> nodeSources) {
+    if (nodeSources.isEmpty()) {
+      return true;
+    }
+
+    if (nodeSources.size() > 1) {
+      Messages.showErrorDialog(myArtifactsEditor.getMainComponent(),
+                               "The selected node consist of several elements so it cannot be edited.\nSwitch off 'Show content of elements' checkbox to edit the output layout.");
+    }
+    else {
+    final PackagingNodeSource source = ContainerUtil.getFirstItem(nodeSources, null);
+      if (source != null) {
+        Messages.showErrorDialog(myArtifactsEditor.getMainComponent(),
+                                 "The selected node belongs to '" + source.getPresentableName() + "' element so it cannot be edited.\nSwitch off 'Show content of elements' checkbox to edit the output layout.");
+      }
+    }
+    return false;
+
+  }
+
+  public boolean checkCanAdd(CompositePackagingElement<?> parentElement, PackagingElementNode<?> parentNode) {
+    boolean allParentsAreDirectories = true;
+    PackagingElementNode<?> current = parentNode;
+    while (current != null && !(current instanceof ArtifactRootNode)) {
+      final PackagingElement<?> element = current.getFirstElement();
+      if (!(element instanceof DirectoryPackagingElement)) {
+        allParentsAreDirectories = false;
+        break;
+      }
+      current = current.getParentNode();
+    }
+
+    return allParentsAreDirectories || checkCanModify(parentElement, parentNode);
+  }
+
+  public boolean checkCanRemove(final List<? extends PackagingElementNode<?>> nodes) {
+    Set<PackagingNodeSource> rootSources = new HashSet<PackagingNodeSource>();
+    for (PackagingElementNode<?> node : nodes) {
+      rootSources.addAll(getRootNodeSources(node.getNodeSources()));
+    }
+
+    if (!rootSources.isEmpty()) {
+      final String message;
+      if (rootSources.size() == 1) {
+        final String name = rootSources.iterator().next().getPresentableName();
+        message = "The selected node belongs to '" + name + "' element. Do you want to remove the whole '" + name + "' element from the artifact?";
       }
       else {
-        Messages.showErrorDialog(myArtifactsEditor.getMainComponent(), "Cannot add " +
-                                                                       elementType + ": the selected node comes from '" + source.getPresentableName() + "'");
-        return false;
+        message = "The selected node belongs to " + nodes.size() + " elements. Do you want to remove all these elements from the artifact?";
       }
+      final int answer = Messages.showYesNoDialog(myArtifactsEditor.getMainComponent(), message, "Remove Elements", null);
+      if (answer != 0) return false;
     }
     return true;
   }
@@ -232,6 +310,21 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
     }
   }
 
+  @TestOnly
+  public void selectNode(@NotNull String parentPath, @NotNull String nodeName) {
+    final PackagingElementNode<?> parent = myTree.findCompositeNodeByPath(parentPath);
+    if (parent == null) return;
+
+    for (SimpleNode node : parent.getChildren()) {
+      if (node instanceof PackagingElementNode) {
+        if (nodeName.equals(((PackagingElementNode)node).getElementPresentation().getSearchName())) {
+          myBuilder.select(node);
+          return;
+        }
+      }
+    }
+  }
+
   public void editLayout(Runnable action) {
     myContext.editLayout(myOriginalArtifact, action);
   }
@@ -254,10 +347,20 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
     for (PackagingElementNode<?> node : nodes) {
       final List<? extends PackagingElement<?>> toDelete = node.getPackagingElements();
       for (PackagingElement<?> element : toDelete) {
-        final CompositePackagingElement<?> parent = node.getParentElement(element);
-        if (parent != null) {
-          parents.add(parent);
-          parent.removeChild(element);
+        final Collection<PackagingNodeSource> nodeSources = node.getNodeSource(element);
+        if (nodeSources.isEmpty()) {
+          final CompositePackagingElement<?> parent = node.getParentElement(element);
+          if (parent != null) {
+            parents.add(parent);
+            parent.removeChild(element);
+          }
+        }
+        else {
+          Collection<PackagingNodeSource> rootSources = getRootNodeSources(nodeSources);
+          for (PackagingNodeSource source : rootSources) {
+            parents.add(source.getSourceParentElement());
+            source.getSourceParentElement().removeChild(source.getSourceElement());
+          }
         }
       }
     }
@@ -267,34 +370,28 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
     }
   }
 
-  public boolean checkCanRemove(final List<? extends PackagingElementNode<?>> nodes) {
-    Set<Artifact> parentArtifacts = new HashSet<Artifact>();
-    for (PackagingElementNode<?> node : nodes) {
-      final Collection<PackagingNodeSource> sources = node.getNodeSources();
-      for (PackagingNodeSource source : sources) {
-        final Artifact artifact = source.getSourceArtifact();
-        if (artifact != null) {
-          parentArtifacts.add(artifact);
-        }
-        else {
-          Messages.showErrorDialog(myArtifactsEditor.getMainComponent(), "'" + node.getElementPresentation().getPresentableName() + "' comes from '" + source.getPresentableName() + "' so it cannot be removed itself");
-          return false;
-        }
+  private static Collection<PackagingNodeSource> getRootNodeSources(Collection<PackagingNodeSource> nodeSources) {
+    Set<PackagingNodeSource> result = new HashSet<PackagingNodeSource>();
+    collectRootNodeSources(nodeSources, result);
+    return result;
+  }
+
+  private static void collectRootNodeSources(Collection<PackagingNodeSource> nodeSources, Set<PackagingNodeSource> result) {
+    for (PackagingNodeSource nodeSource : nodeSources) {
+      final Collection<PackagingNodeSource> parentSources = nodeSource.getParentSources();
+      if (parentSources.isEmpty()) {
+        result.add(nodeSource);
+      }
+      else {
+        collectRootNodeSources(parentSources, result);
       }
     }
-    if (!parentArtifacts.isEmpty()) {
-      final int answer = Messages.showYesNoDialog(myArtifactsEditor.getMainComponent(),
-                                                  "Some elements come from included artifacts. Do you want to remove it?",
-                                                  "Remove Elements", null);
-      if (answer != 0) return false;
-    }
-    return true;
   }
 
   private PackagingElementNode<?> getParentNode(final LayoutTreeSelection selection) {
     final PackagingElementNode<?> node = selection.getNodeIfSingle();
     if (node != null) {
-      if (node.getElementIfSingle() instanceof CompositePackagingElement) {
+      if (node.getFirstElement() instanceof CompositePackagingElement) {
         return node;
       }
       final PackagingElementNode<?> parent = node.getParentNode();
@@ -310,7 +407,9 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
   }
 
   public void dispose() {
-    DnDManager.getInstance().unregisterTarget(this, myTree);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().unregisterTarget(this, myTree);
+    }
   }
 
   public boolean update(DnDEvent aEvent) {
@@ -323,7 +422,7 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
         final PackagingElementDraggingObject draggingObject = (PackagingElementDraggingObject)object;
         final PackagingElementNode node = getNode(parent);
         if (node != null && draggingObject.canDropInto(node)) {
-          final PackagingElement element = node.getElementIfSingle();
+          final PackagingElement element = node.getFirstElement();
           if (element instanceof CompositePackagingElement) {
             draggingObject.setTargetNode(node);
             draggingObject.setTargetElement((CompositePackagingElement<?>)element);
@@ -344,16 +443,17 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
       final PackagingElementNode<?> targetNode = draggingObject.getTargetNode();
       final CompositePackagingElement<?> targetElement = draggingObject.getTargetElement();
       if (targetElement == null || targetNode == null || !draggingObject.checkCanDrop()) return;
-      if (!checkCanAdd(null, targetElement, targetNode)) {
+      if (!checkCanAdd(targetElement, targetNode)) {
         return;
       }
       final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
       editLayout(new Runnable() {
         public void run() {
           draggingObject.beforeDrop();
+          final CompositePackagingElement<?> parent = getOrCreateModifiableParent(targetElement, targetNode);
           for (PackagingElement<?> element : draggingObject.createPackagingElements(myContext)) {
             toSelect.add(element);
-            targetElement.addOrFindChild(element);
+            parent.addOrFindChild(element);
           }
         }
       });
index 2cc19955dff323627345b5371ecab1e8f0f105fb..1bbe35c178493900f5b5cb50551f98a1677dbc26 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
 import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent;
 import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.packaging.artifacts.ArtifactPointerManager;
 import com.intellij.packaging.artifacts.ModifiableArtifact;
@@ -50,8 +51,10 @@ public class ExtractArtifactAction extends LayoutTreeActionBase {
     final LayoutTreeSelection selection = treeComponent.getSelection();
     final CompositePackagingElement<?> parent = selection.getCommonParentElement();
     if (parent == null) return;
+    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
+    if (parentNode == null) return;
 
-    if (!treeComponent.checkCanRemove(selection.getNodes())) {
+    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
       return;
     }
 
index 7a69521191d579f75d88e5d72c4f2ba4d9550703..7bc93fd10e9684ac683e33b80dd420fab42cd007 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
 import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent;
 import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection;
+import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode;
 import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.elements.ArtifactRootElement;
@@ -30,6 +31,8 @@ import com.intellij.packaging.impl.artifacts.ArtifactUtil;
 import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 
+import java.util.Collections;
+
 /**
  * @author nik
  */
@@ -57,11 +60,11 @@ public class InlineArtifactAction extends DumbAwareAction {
     if (node == null || !(element instanceof ArtifactPackagingElement)) return;
 
     final CompositePackagingElement<?> parent = node.getParentElement(element);
-    if (parent == null) {
+    final CompositePackagingElementNode parentNode = node.getParentNode();
+    if (parent == null || parentNode == null) {
       return;
     }
-    if (!treeComponent.checkCanRemove(selection.getNodes())) return;
-    if (!treeComponent.checkCanAdd(null, parent, node)) return;
+    if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node))) return;
 
     treeComponent.editLayout(new Runnable() {
       public void run() {
index 4340a1e201f52aeb36c951e429c0ff1b0d1c5048..8d9b1129c336e361264cfcd43737f8bc64fe6498 100644 (file)
@@ -25,7 +25,7 @@ import com.intellij.packaging.elements.PackagingElement;
 
 import javax.swing.*;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -79,21 +79,20 @@ public class MovePackagingElementAction extends DumbAwareAction {
     if (parentElement == null || element == null) return;
 
 
-    if (myLayoutTreeComponent.checkCanRemove(Collections.singletonList(node))
-        && myLayoutTreeComponent.checkCanAdd(null, parentElement, parent)) {
-      final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
-      myLayoutTreeComponent.editLayout(new Runnable() {
-        public void run() {
-          final int index = parentElement.getChildren().indexOf(element);
-          final PackagingElement<?> moved = parentElement.moveChild(index, myDirection);
-          if (moved != null) {
-            toSelect.add(moved);
-          }
+    if (!myLayoutTreeComponent.checkCanModifyChildren(parentElement, parent, Arrays.asList(node))) return;
+
+    final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
+    myLayoutTreeComponent.editLayout(new Runnable() {
+      public void run() {
+        final int index = parentElement.getChildren().indexOf(element);
+        final PackagingElement<?> moved = parentElement.moveChild(index, myDirection);
+        if (moved != null) {
+          toSelect.add(moved);
         }
-      });
-      if (!toSelect.isEmpty()) {
-        myLayoutTreeComponent.updateAndSelect(parent, toSelect);
       }
+    });
+    if (!toSelect.isEmpty()) {
+      myLayoutTreeComponent.updateAndSelect(parent, toSelect);
     }
   }
 }
index ec2f86f9dc2394b1c188c4f3984b898613c4e9bd..d7969d6fc11f27aede42489273064f3b2bd53054 100644 (file)
@@ -51,7 +51,10 @@ public class RenamePackagingElementAction extends DumbAwareAction {
   public void actionPerformed(AnActionEvent e) {
     final LayoutTreeSelection selection = myArtifactEditor.getLayoutTreeComponent().getSelection();
     final PackagingElementNode<?> node = selection.getNodeIfSingle();
-    if (node == null) return;
+    final PackagingElement<?> element = selection.getElementIfSingle();
+    if (node == null || element == null) return;
+    if (!myArtifactEditor.getLayoutTreeComponent().checkCanModify(element, node)) return;
+    
     final TreePath path = selection.getPath(node);
     myArtifactEditor.getLayoutTreeComponent().startRenaming(path);
   }
index 19967d45d4bb0ddeb53844ec194e0c15b8c0307a..7bf8c2da73030c7904640cc0f5113074fbe563a0 100644 (file)
@@ -15,9 +15,9 @@
  */
 package com.intellij.openapi.roots.ui.configuration.artifacts.nodes;
 
-import com.intellij.packaging.elements.ComplexPackagingElement;
-import com.intellij.packaging.elements.PackagingElement;
 import com.intellij.packaging.artifacts.Artifact;
+import com.intellij.packaging.elements.ComplexPackagingElement;
+import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -30,12 +30,12 @@ import java.util.Collection;
 public class PackagingNodeSource {
   private final ComplexPackagingElement<?> mySourceElement;
   private final PackagingElementNode<?> mySourceParentNode;
-  private final PackagingElement<?> mySourceParentElement;
+  private final CompositePackagingElement<?> mySourceParentElement;
   private final Collection<PackagingNodeSource> myParentSources;
 
   public PackagingNodeSource(@NotNull ComplexPackagingElement<?> sourceElement,
                              @NotNull PackagingElementNode<?> sourceParentNode,
-                             @NotNull PackagingElement<?> sourceParentElement,
+                             @NotNull CompositePackagingElement<?> sourceParentElement,
                              @Nullable Collection<PackagingNodeSource> parentSources) {
     mySourceElement = sourceElement;
     mySourceParentNode = sourceParentNode;
@@ -61,7 +61,8 @@ public class PackagingNodeSource {
     return mySourceParentNode;
   }
 
-  public PackagingElement<?> getSourceParentElement() {
+  @NotNull
+  public CompositePackagingElement<?> getSourceParentElement() {
     return mySourceParentElement;
   }
 
index 0d97437aa6a7ddbff3b0aeb0204bf4971d4ada59..615542cd1d4697228d333f002830b23e86ba5f35 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.ide.dnd.DnDSource;
 import com.intellij.ide.dnd.aware.DnDAwareTree;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl;
 import com.intellij.openapi.roots.ui.configuration.artifacts.SimpleDnDAwareTree;
@@ -60,7 +61,9 @@ public class SourceItemsTree implements DnDSource, Disposable{
     myTree.setRootVisible(false);
     myTree.setShowsRootHandles(true);
     Disposer.register(this, myBuilder);
-    DnDManager.getInstance().registerSource(this, myTree);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().registerSource(this, myTree);
+    }
     PopupHandler.installPopupHandler(myTree, createPopupGroup(), ActionPlaces.UNKNOWN, ActionManager.getInstance());
   }
 
@@ -95,7 +98,9 @@ public class SourceItemsTree implements DnDSource, Disposable{
   }
 
   public void dispose() {
-    DnDManager.getInstance().unregisterSource(this, myTree);
+    if (!ApplicationManager.getApplication().isUnitTestMode()) {
+      DnDManager.getInstance().unregisterSource(this, myTree);
+    }
   }
 
   private DefaultMutableTreeNode[] getSelectedTreeNodes() {
index 90126587152f802123194856dd17f7db4ce0dfe5..a14a4e827b993d508640ecb6e021110eb1db0c87 100644 (file)
@@ -42,6 +42,10 @@ public class LibraryEditor implements Disposable {
   }
 
   public void dispose() {
+    if (myModel != null) {
+      // dispose if wasn't committed
+      Disposer.dispose(myModel);
+    }
   }
 
   public String[] getUrls(OrderRootType rootType) {
@@ -96,7 +100,6 @@ public class LibraryEditor implements Disposable {
   public Library.ModifiableModel getModel() {
     if (myModel == null) {
       myModel = myLibrary.getModifiableModel();
-      Disposer.register(this, myModel);
     }
     return myModel;
   }
index f55dce26610ea78f0b8243be7c6aecdaf16eff61..5acabf86cc120b80a2a1c6d4da4bf5dbbfaebc64 100644 (file)
@@ -2,7 +2,7 @@
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.projectImport.ProjectFormatPanel">
   <grid id="27dc6" binding="myWholePanel" layout-manager="GridBagLayout">
     <constraints>
-      <xy x="20" y="20" width="131" height="39"/>
+      <xy x="20" y="20" width="140" height="41"/>
     </constraints>
     <properties/>
     <border type="none"/>
@@ -10,7 +10,7 @@
       <component id="29c74" class="javax.swing.JLabel">
         <constraints>
           <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-          <gridbag top="5" left="10" bottom="0" right="5" weightx="0.0" weighty="0.0"/>
+          <gridbag top="5" left="5" bottom="0" right="5" weightx="0.0" weighty="0.0"/>
         </constraints>
         <properties>
           <text value="Project file format:"/>
index 9be5e895ef4a08a79361e867391f52823d65d67b..329ebb61a1b55e2d662e33221c4c2720da89a93c 100644 (file)
@@ -20,6 +20,7 @@
  */
 package com.intellij.projectImport;
 
+import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.ide.util.projectWizard.WizardContext;
 import com.intellij.openapi.components.StorageScheme;
 
@@ -31,10 +32,12 @@ public class ProjectFormatPanel {
   private JComboBox myStorageFormatCombo;
   private JPanel myWholePanel;
 
+  public static final String STORAGE_FORMAT_PROPERTY = "default.storage.format";
+
   public ProjectFormatPanel() {
     myStorageFormatCombo.insertItemAt(DIR_BASED, 0);
     myStorageFormatCombo.insertItemAt(FILE_BASED, 1);
-    myStorageFormatCombo.setSelectedItem(DIR_BASED);
+    myStorageFormatCombo.setSelectedItem(PropertiesComponent.getInstance().getOrInit(STORAGE_FORMAT_PROPERTY, DIR_BASED));
   }
 
 
@@ -49,5 +52,14 @@ public class ProjectFormatPanel {
   public void updateData(WizardContext context) {
     context.setProjectStorageFormat(
       FILE_BASED.equals(myStorageFormatCombo.getSelectedItem()) ? StorageScheme.DEFAULT : StorageScheme.DIRECTORY_BASED);
+    PropertiesComponent.getInstance().setValue(STORAGE_FORMAT_PROPERTY, isDefault() ? FILE_BASED : DIR_BASED);
+  }
+
+  public void setVisible(boolean visible) {
+    myWholePanel.setVisible(visible);
+  }
+
+  public boolean isDefault() {
+    return FILE_BASED.equals(myStorageFormatCombo.getSelectedItem());
   }
 }
\ No newline at end of file
index a7fad12d5c99b826ca401e40fa26a8f42b09beaa..82dc5ca09ee9225687b3ede423684cd44031f7b9 100644 (file)
@@ -49,7 +49,8 @@ public class TodoJavaTreeHelper extends TodoTreeHelper {
   public PsiElement getSelectedElement(final Object userObject) {
     if (userObject instanceof TodoPackageNode) {
       TodoPackageNode descriptor = (TodoPackageNode)userObject;
-      return descriptor.getValue().getPackage();
+      final PackageElement packageElement = descriptor.getValue();
+      return packageElement != null ? packageElement.getPackage() : null;
     }
     return super.getSelectedElement(userObject);
   }
index 8ca1da32f9dfcb37a3dffcd06c4743b3767f6357..41095075aadf06969415d0f7c90183f711d7fc12 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.ide.util.projectWizard.ProjectWizardStepFactory;
 import com.intellij.ide.util.projectWizard.WizardContext;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.psi.CommonClassNames;
@@ -116,6 +117,7 @@ public class JavaModuleType extends ModuleType<JavaModuleBuilder> {
   }
 
   public static boolean isValidJavaSdk(final Module module) {
+    if (ModuleRootManager.getInstance(module).getSourceRoots().length == 0) return true;
     return JavaPsiFacade.getInstance(module.getProject()).findClass(CommonClassNames.JAVA_LANG_OBJECT, 
                                                                     module.getModuleWithLibrariesScope()) != null;
   }
index ffa0f7720947ca74d40384137a7b19e5999ee082..0e23dc5a18e83d466ed0485e472bf7234f061061 100644 (file)
@@ -35,6 +35,7 @@ import com.intellij.util.VisibilityUtil;
 import com.intellij.util.containers.MultiMap;
 import gnu.trove.TIntArrayList;
 import gnu.trove.TIntProcedure;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -94,7 +95,9 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
     }
 
 
-    removeParametersFromCall(callExpression.getArgumentList(), data.getParametersToRemove());
+    final PsiExpressionList argumentList = callExpression.getArgumentList();
+    LOG.assertTrue(argumentList != null, callExpression.getText());
+    removeParametersFromCall(argumentList, data.getParametersToRemove());
     return false;
   }
 
@@ -108,12 +111,14 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
     return false;
   }
 
-  private static void removeParametersFromCall(final PsiExpressionList argList, TIntArrayList parametersToRemove) {
+  private static void removeParametersFromCall(@NotNull final PsiExpressionList argList, TIntArrayList parametersToRemove) {
     final PsiExpression[] exprs = argList.getExpressions();
     parametersToRemove.forEachDescending(new TIntProcedure() {
       public boolean execute(final int paramNum) {
         try {
-          exprs[paramNum].delete();
+          if (paramNum < exprs.length) {
+            exprs[paramNum].delete();
+          }
         }
         catch (IncorrectOperationException e) {
           LOG.error(e);
index 0e3d45b00729c2bdbf2b152e6115137ba918aa39..e15651b92f66836f6237d39683647fff0f1c8dd8 100644 (file)
@@ -126,7 +126,7 @@ public class OldReferenceResolver {
           if (subj.getParent() != parameterList) return;
           int index = parameterList.getParameterIndex((PsiParameter)subj);
           if (index < 0) return;
-          if (index < parameters.length) {
+          if (index < myActualArgs.length) {
             PsiExpression actualArg = myActualArgs[index];
             int copyingSafetyLevel = RefactoringUtil.verifySafeCopyExpression(actualArg);
             if (copyingSafetyLevel == RefactoringUtil.EXPR_COPY_PROHIBITED) {
index 979b6c427d5e5e1e9c0550b746fc4e2e2d5cdef1..ac3aa984c0b3816b9fac6ed66e05ecec7e4fdcc6 100644 (file)
@@ -26,12 +26,13 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.*;
 import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.lang.TitledHandler;
 import org.jetbrains.annotations.NotNull;
 
 /**
  * @author yole
  */
-public class DirectoryAsPackageRenameHandler implements RenameHandler {
+public class DirectoryAsPackageRenameHandler implements RenameHandler, TitledHandler {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler");
 
   public boolean isAvailableOnDataContext(final DataContext dataContext) {
@@ -106,4 +107,8 @@ public class DirectoryAsPackageRenameHandler implements RenameHandler {
       message.append(directory.getVirtualFile().getPresentableUrl());
     }
   }
+
+  public String getActionTitle() {
+    return RefactoringBundle.message("rename.directory.title");
+  }
 }
index d041fdad3ddb3cd6ff8a90e003ba9f9e4897066c..538ba915d2d73c78114a35ed54bcbadf0075e21f 100644 (file)
@@ -126,7 +126,9 @@ public class ReplaceConstructorWithBuilderDialog extends RefactoringDialog {
       }
     };
     myNewClassName.getDocument().addDocumentListener(validateButtonsListener);
-
+    final PsiClass psiClass = myConstructors[0].getContainingClass();
+    LOG.assertTrue(psiClass != null);
+    myNewClassName.setText(psiClass.getName() + "Builder");
 
     return myWholePanel;
   }
index c8e0fbaee4f8e35b8abac34f509d35d593437144..d085a934d6b1143af0fd976ee6382b7904725795 100644 (file)
@@ -27,6 +27,7 @@ package com.intellij.refactoring.ui;
 import com.intellij.openapi.util.Iconable;
 import com.intellij.psi.PsiClass;
 import com.intellij.refactoring.RefactoringBundle;
+import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 import java.awt.*;
@@ -52,12 +53,14 @@ public class ClassCellRenderer extends DefaultListCellRenderer {
           int index,
           boolean isSelected,
           boolean cellHasFocus) {
-    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
-
-    return customizeRenderer(this, value, myShowReadOnly);
+    final Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+    if (value != null) {
+      return customizeRenderer(this, value, myShowReadOnly);
+    }
+    return rendererComponent;
   }
 
-  public static JLabel customizeRenderer(final JLabel cellRendererComponent, final Object value, final boolean showReadOnly) {
+  public static JLabel customizeRenderer(final JLabel cellRendererComponent, @NotNull final Object value, final boolean showReadOnly) {
     PsiClass aClass = (PsiClass) value;
     cellRendererComponent.setText(getClassText(aClass));
 
@@ -72,7 +75,7 @@ public class ClassCellRenderer extends DefaultListCellRenderer {
     return cellRendererComponent;
   }
 
-  private static String getClassText(PsiClass aClass) {
+  private static String getClassText(@NotNull PsiClass aClass) {
     String qualifiedName = aClass.getQualifiedName();
     if (qualifiedName != null) {
       return qualifiedName;
diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterIncompleteEnumDefinition.java b/java/java-tests/testData/refactoring/introduceParameter/afterIncompleteEnumDefinition.java
new file mode 100644 (file)
index 0000000..7796b34
--- /dev/null
@@ -0,0 +1,10 @@
+enum Test {
+  Root(position + "");
+
+  public Test(String description, String anObject) {
+    System.out.println(description);
+    System.out.println(anObject);
+  }
+
+}
+
diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforeIncompleteEnumDefinition.java b/java/java-tests/testData/refactoring/introduceParameter/beforeIncompleteEnumDefinition.java
new file mode 100644 (file)
index 0000000..21a3f7c
--- /dev/null
@@ -0,0 +1,10 @@
+enum Test {
+  Root();
+
+  public Test(String description, int position) {
+    System.out.println(description);
+    System.out.println(<selection>position + ""</selection>);
+  }
+
+}
+
index 9e4bec4898db1edb774dc26babc797671c96f240..63950d0af0dc45dab32ab9170335616b4e7dc4bc 100644 (file)
@@ -229,6 +229,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
     doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false);
   }
 
+  public void testIncompleteEnumDefinition() throws Exception {
+    doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, false, false);
+  }
+
   private void doTestThroughHandler() throws Exception {
     configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
     new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() {
index 3bfdb90d9d4df536f559947765d1556ef7cedba1..9b26c0aa8cf80c2e70cfba523a7dec14676100a3 100644 (file)
@@ -109,9 +109,14 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent.
   }
 
   private void resetImpl() {
-    myModel.reset();
-    for (CodeStyleConfigurableWrapper panel : myPanels) {
-      panel.resetPanel();
+    if (myModel != null) {
+      myModel.reset();
+    }
+
+    if (myPanels != null) {
+      for (CodeStyleConfigurableWrapper panel : myPanels) {
+        panel.resetPanel();
+      }
     }
   }
 
@@ -263,12 +268,16 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent.
   }
 
   public boolean isModified() {
-    boolean schemeListModified = myModel.isSchemeListModified();
-    if (schemeListModified) {
-      myApplyCompleted = false;
-      myRevertCompleted = false;
+    if (myModel != null) {
+      boolean schemeListModified = myModel.isSchemeListModified();
+      if (schemeListModified) {
+        myApplyCompleted = false;
+        myRevertCompleted = false;
+      }
+      return schemeListModified;
     }
-    return schemeListModified;
+
+    return false;
   }
 
   public String getId() {
index 896945df10a0fdc6d05c28eefabeb253ed8331d8..fa3932580e170345ff0bbde90cde8551c790d7e1 100644 (file)
@@ -536,8 +536,10 @@ public class TemplateState implements Disposable {
       new Runnable() {
         public void run() {
           BitSet calcedSegments = new BitSet();
+          int maxAttempts = (myTemplate.getVariableCount()+1)*3;
 
           do {
+            maxAttempts--;
             calcedSegments.clear();
             for (int i = myCurrentVariableNumber + 1; i < myTemplate.getVariableCount(); i++) {
               String variableName = myTemplate.getVariableNameAt(i);
@@ -565,7 +567,7 @@ public class TemplateState implements Disposable {
               }
             }
           }
-          while (!calcedSegments.isEmpty());
+          while (!calcedSegments.isEmpty() && maxAttempts >= 0);
         }
       }
     );
index 9277865af832ff84f4b5c7902c230c1e863a4968..3459a102d6fcd0141755b44e91954883a5e36aa2 100644 (file)
@@ -97,26 +97,19 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl
   private void checkUpdate() {
     if (myProject.isDisposed()) return;
 
-    Window mywindow = SwingUtilities.windowForComponent(myPanel);
-    if (mywindow != null && !mywindow.isActive()) return;
+    final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+    if (SwingUtilities.isDescendingFrom(myPanel, owner)) return;
 
-    final KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
-    final Window focusWindow = focusManager.getFocusedWindow();
+    final DataContext dataContext = DataManager.getInstance().getDataContext(owner);
+    if (dataContext.getData(myKey) == this) return;
+    if (PlatformDataKeys.PROJECT.getData(dataContext) != myProject) return;
 
-    if (focusWindow == mywindow) {
-      final Component owner = focusManager.getFocusOwner();
-      if (SwingUtilities.isDescendingFrom(myPanel, owner)) return;
-
-      final DataContext dataContext = DataManager.getInstance().getDataContext(owner);
-      if (dataContext.getData(myKey) == this) return;
-
-      final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
-      if (files != null && files.length == 1) {
-        setFile(files[0]);
-      }
-      else {
-        setFile(null);
-      }
+    final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
+    if (files != null && files.length == 1) {
+      setFile(files[0]);
+    }
+    else {
+      setFile(null);
     }
   }
 
index 7ccc06254c540363365204e9d23d65b0b2d85882..ca98e641c29ee644990d3b84202b6e4cae5eb30e 100644 (file)
@@ -33,13 +33,15 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Ref;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
+import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.lang.TitledHandler;
 import com.intellij.refactoring.rename.RenameHandler;
 import org.jetbrains.annotations.NotNull;
 
 /**
  * @author dsl
  */
-public class RenameModuleHandler implements RenameHandler {
+public class RenameModuleHandler implements RenameHandler, TitledHandler {
   private static final Logger LOG = Logger.getInstance("#com.intellij.ide.projectView.actions.RenameModuleHandler");
 
   public boolean isAvailableOnDataContext(DataContext dataContext) {
@@ -66,6 +68,10 @@ public class RenameModuleHandler implements RenameHandler {
                              new MyInputValidator(project, module));
   }
 
+  public String getActionTitle() {
+    return RefactoringBundle.message("rename.module.title");
+  }
+
   private static class MyInputValidator implements InputValidator {
     private final Project myProject;
     private final Module myModule;
index ccdd66ef0aebd0b97c2f149d6f7206998dc618f9..02d8bf753cca2f785a571e0ada029050e5bd732f 100644 (file)
@@ -17,6 +17,7 @@
 package com.intellij.refactoring.actions;
 
 import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
+import com.intellij.ide.IdeEventQueue;
 import com.intellij.lang.Language;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.editor.Editor;
@@ -51,8 +52,10 @@ public abstract class BaseRefactoringAction extends AnAction {
     PsiDocumentManager.getInstance(project).commitAllDocuments();
     final Editor editor = e.getData(PlatformDataKeys.EDITOR);
     final PsiElement[] elements = getPsiElementArray(dataContext);
+    int eventCount = IdeEventQueue.getInstance().getEventCount();
     RefactoringActionHandler handler = getHandler(dataContext);
     if (handler == null) return;
+    IdeEventQueue.getInstance().setEventCount(eventCount);
     if (editor != null) {
       final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
       if (file == null) return;
index 93350aecb88be99003c1de3eb2e5b7a8a0b4c728..1b3a45b30633dd24faeac8b3cccd2ac7a54c52bc 100644 (file)
 package com.intellij.refactoring.rename;
 
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.lang.TitledHandler;
 import com.intellij.util.containers.HashSet;
+import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 /**
  * @author dsl
@@ -49,17 +61,85 @@ public class RenameHandlerRegistry {
     return myDefaultElementRenameHandler.isAvailableOnDataContext(dataContext);
   }
 
+  @Nullable
   public RenameHandler getRenameHandler(DataContext dataContext) {
+    final Map<String, RenameHandler> availableHandlers = new TreeMap<String, RenameHandler>();
     for (RenameHandler renameHandler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
-      if (renameHandler.isRenaming(dataContext)) return renameHandler;
+      if (renameHandler.isRenaming(dataContext)) {
+        availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
+      }
     }
     for (RenameHandler renameHandler : myHandlers) {
-      if (renameHandler.isRenaming(dataContext)) return renameHandler;
+      if (renameHandler.isRenaming(dataContext)) {
+        availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
+      }
+    }
+    if (availableHandlers.size() == 1) return availableHandlers.values().iterator().next();
+    if (availableHandlers.size() > 1) {
+      final String[] strings = availableHandlers.keySet().toArray(new String[availableHandlers.keySet().size()]);
+      final HandlersChooser chooser = new HandlersChooser(PlatformDataKeys.PROJECT.getData(dataContext), strings);
+      chooser.show();
+      if (chooser.isOK()) {
+        return availableHandlers.get(chooser.getSelection());
+      }
+      return null;
     }
     return myDefaultElementRenameHandler.isRenaming(dataContext) ? myDefaultElementRenameHandler : null;
   }
 
+  private static String getHandlerTitle(RenameHandler renameHandler) {
+    return renameHandler instanceof TitledHandler ? StringUtil.capitalize(((TitledHandler)renameHandler).getActionTitle().toLowerCase()) : renameHandler.toString();
+  }
+
   public void registerHandler(RenameHandler handler) {
     myHandlers.add(handler);
   }
+
+  private static class HandlersChooser extends DialogWrapper {
+    private final String[] myRenamers;
+    private String mySelection;
+
+    protected HandlersChooser(Project project, String [] renamers) {
+      super(project);
+      myRenamers = renamers;
+      mySelection = renamers[0];
+      setTitle(RefactoringBundle.message("select.refactoring.title"));
+      init();
+    }
+
+    @Override
+    protected JComponent createNorthPanel() {
+      final JPanel radioPanel = new JPanel();
+      radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
+      final JLabel descriptionLabel = new JLabel(RefactoringBundle.message("what.would.you.like.to.do"));
+      descriptionLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
+      radioPanel.add(descriptionLabel);
+      final ButtonGroup bg = new ButtonGroup();
+      boolean selected = true;
+      for (final String renamer : myRenamers) {
+        final JRadioButton rb = new JRadioButton(renamer, selected);
+        final ActionListener listener = new ActionListener() {
+          public void actionPerformed(ActionEvent e) {
+            if (rb.isSelected()) {
+              mySelection = renamer;
+            }
+          }
+        };
+        rb.addActionListener(listener);
+        selected = false;
+        bg.add(rb);
+        radioPanel.add(rb);
+      }
+      return radioPanel;
+    }
+
+    public String getSelection() {
+      return mySelection;
+    }
+
+    @Override
+    protected JComponent createCenterPanel() {
+      return null;
+    }
+  }
 }
index cff2bac08d4655e2a60148499113f539423edb2f..716ddb837b02f3b9cd4459a8489851cc80730aa8 100644 (file)
@@ -43,7 +43,7 @@ import java.awt.event.ItemListener;
 
 public class Messages {
   private static TestDialog ourTestImplementation = TestDialog.DEFAULT;
-  private static final TestInputDialog ourTestInputImplementation = TestInputDialog.DEFAULT;
+  private static TestInputDialog ourTestInputImplementation = TestInputDialog.DEFAULT;
 
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.ui.Messages");
   protected static final String OK_BUTTON = CommonBundle.getOkButtonText();
@@ -55,13 +55,24 @@ public class Messages {
   public static TestDialog setTestDialog(TestDialog newValue) {
     Application application = ApplicationManager.getApplication();
     if (application != null) {
-      LOG.assertTrue(application.isUnitTestMode(), "This methos is available for tests only");
+      LOG.assertTrue(application.isUnitTestMode(), "This method is available for tests only");
     }
     TestDialog oldValue = ourTestImplementation;
     ourTestImplementation = newValue;
     return oldValue;
   }
 
+  @TestOnly
+  public static TestInputDialog setTestInputDialog(TestInputDialog newValue) {
+    Application application = ApplicationManager.getApplication();
+    if (application != null) {
+      LOG.assertTrue(application.isUnitTestMode(), "This method is available for tests only");
+    }
+    TestInputDialog oldValue = ourTestInputImplementation;
+    ourTestInputImplementation = newValue;
+    return oldValue;
+  }
+
   public static Icon getErrorIcon() {
     return UIUtil.getErrorIcon();
   }
index b8cdb70a5ec04d77a807cf0b47f0b873e041968c..98bf517b35b41dc6f0170edae07c1be43d15d923 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.newvfs.FileSystemInterface;
 import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
 import com.intellij.util.ArrayUtil;
+import com.intellij.util.TimedReference;
 import gnu.trove.THashMap;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -51,7 +52,7 @@ public class JarHandler implements FileSystemInterface {
   @NonNls private static final String JARS_FOLDER = "jars";
 
   private final Object lock = new Object();
-  private SoftReference<ZipFile> myZipFile = new SoftReference<ZipFile>(null);
+  private final TimedReference<ZipFile> myZipFile = new TimedReference<ZipFile>(null);
   private final JarFileSystemImpl myFileSystem;
   private final String myBasePath;
   private SoftReference<Map<String, EntryInfo>> myRelPathsToEntries = new SoftReference<Map<String, EntryInfo>>(null);
@@ -87,7 +88,7 @@ public class JarHandler implements FileSystemInterface {
   public VirtualFile markDirty() {
     synchronized (lock) {
       myRelPathsToEntries.clear();
-      myZipFile = new SoftReference<ZipFile>(null);
+      myZipFile.set(null);
 
       final NewVirtualFile root = (NewVirtualFile)
         JarFileSystem.getInstance().findFileByPath(myBasePath + JarFileSystem.JAR_SEPARATOR);
@@ -223,7 +224,7 @@ public class JarHandler implements FileSystemInterface {
     if (zip == null) {
       try {
         zip = new ZipFile(getMirrorFile(getOriginalFile()));
-        myZipFile = new SoftReference<ZipFile>(zip);
+        myZipFile.set(zip);
       }
       catch (IOException e) {
         return null;
@@ -360,4 +361,4 @@ public class JarHandler implements FileSystemInterface {
   public void deleteFile(final Object requestor, final VirtualFile file) throws IOException {
     throwReadOnly();
   }
-}
\ No newline at end of file
+}
index 74250a50aeb61e29466cfd6c5babf5a3671323ed..25abb7ea4dca0198faccbfde0bbb5f64fe3aa705 100644 (file)
@@ -715,4 +715,6 @@ introduce.constant.enum.cb=Introduce as &enum constant
 move.enum.constant.cb=Move as &enum constants if possible
 move.to.different.language=Target class {2} has different language than {0} {1}
 dont.support.inner.classes={0} do not support inner classes
-move.specified.elements=Move specified elements
\ No newline at end of file
+move.specified.elements=Move specified elements
+rename.directory.title=Rename &Directory
+rename.module.title=Rename &Module
\ No newline at end of file
index 9a11ddca8963bf17c4838ab8b420ce54d560f2bf..d8ded4d3838f8aaf17458c6a9140c9cbdc7e644b 100644 (file)
@@ -20,6 +20,7 @@
 package com.intellij.util.containers;
 
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 public abstract class SLRUCache<K, V> extends SLRUMap<K,V> {
   protected SLRUCache(final int protectedQueueSize, final int probationalQueueSize) {
@@ -42,4 +43,9 @@ public abstract class SLRUCache<K, V> extends SLRUMap<K,V> {
     return value;
   }
 
+  @Nullable
+  public V getIfCached(K key) {
+    return super.get(key);
+  }
+
 }
\ No newline at end of file
index 13b7d1cd69bab726ce07835819ecfd57d9f984d7..8f3acc1042227abe446884121291613068cd742b 100644 (file)
  */
 package com.intellij.util.io;
 
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.util.containers.SLRUCache;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
 import java.io.*;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
 
 public class PersistentHashMapValueStorage {
-  private final DataOutputStream myAppender;
-  private RAReader myReader;
+  @Nullable
+  private RAReader myCompactionModeReader = null;
   private long mySize;
   private final File myFile;
+  private final String myPath;
   private boolean myCompactionMode = false;
 
+  private static final int CACHE_PROTECTED_QUEUE_SIZE = 10;
+  private static final int CACHE_PROBATIONAL_QUEUE_SIZE = 20;
+
+  private static final FileAccessorCache<DataOutputStream> ourAppendersCache = new FileAccessorCache<DataOutputStream>(CACHE_PROTECTED_QUEUE_SIZE, CACHE_PROBATIONAL_QUEUE_SIZE) {
+    @NotNull
+    public CacheValue<DataOutputStream> createValue(String path) {
+      try {
+        return new CachedAppender(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path, true))));
+      }
+      catch (FileNotFoundException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  };
+
+  private static final FileAccessorCache<RAReader> ourReadersCache = new FileAccessorCache<RAReader>(CACHE_PROTECTED_QUEUE_SIZE, CACHE_PROBATIONAL_QUEUE_SIZE) {
+    @NotNull
+    public CacheValue<RAReader> createValue(String path) {
+      return new CachedReader(new FileReader(new File(path)));
+    }
+  };
+
   public PersistentHashMapValueStorage(String path) throws IOException {
-    myAppender = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path, true)));
+    myPath = SystemInfo.isFileSystemCaseSensitive? FileUtil.toSystemDependentName(path) : FileUtil.toSystemDependentName(path).toLowerCase(Locale.US);
+
     myFile = new File(path);
-    myReader = new FileReader(myFile);
     mySize = myFile.length();
 
     if (mySize == 0) {
@@ -42,9 +73,15 @@ public class PersistentHashMapValueStorage {
   public long appendBytes(byte[] data, long prevChunkAddress) throws IOException {
     assert !myCompactionMode;
     long result = mySize;
-    myAppender.writeLong(prevChunkAddress);
-    myAppender.writeInt(data.length);
-    myAppender.write(data);
+    final CacheValue<DataOutputStream> appender = ourAppendersCache.get(myPath);
+    try {
+      appender.get().writeLong(prevChunkAddress);
+      appender.get().writeInt(data.length);
+      appender.get().write(data);
+    }
+    finally {
+      appender.release();
+    }
     mySize += data.length + 8 + 4;
 
     return result;
@@ -64,20 +101,34 @@ public class PersistentHashMapValueStorage {
     int chunkCount = 0;
 
     byte[] headerBits = new byte[8 + 4];
-    while (chunk != 0) {
-      myReader.get(chunk, headerBits, 0, 12);
-      final long prevChunkAddress = Bits.getLong(headerBits, 0);
-      final int chunkSize = Bits.getInt(headerBits, 8);
-      final int off = size - bytesRead - chunkSize;
-      
-      checkPreconditions(result, chunkSize, off);
-      
-      myReader.get(chunk + 12, result, off, chunkSize);
-      chunk = prevChunkAddress;
-      bytesRead += chunkSize;
-      chunkCount++;
+    RAReader reader = myCompactionModeReader;
+    CacheValue<RAReader> readerHandle = null;
+    if (reader == null) {
+      readerHandle = ourReadersCache.get(myPath);
+      reader = readerHandle.get();
     }
-    
+
+    try {
+      while (chunk != 0) {
+        reader.get(chunk, headerBits, 0, 12);
+        final long prevChunkAddress = Bits.getLong(headerBits, 0);
+        final int chunkSize = Bits.getInt(headerBits, 8);
+        final int off = size - bytesRead - chunkSize;
+
+        checkPreconditions(result, chunkSize, off);
+
+        reader.get(chunk + 12, result, off, chunkSize);
+        chunk = prevChunkAddress;
+        bytesRead += chunkSize;
+        chunkCount++;
+      }
+    }
+    finally {
+      if (readerHandle != null) {
+        readerHandle.release();
+      }
+    }
+
     //assert bytesRead == size;
     if (bytesRead != size) {
       throw new IOException("Read from storage " + bytesRead + " bytes, but requested " + size + " bytes");
@@ -103,28 +154,34 @@ public class PersistentHashMapValueStorage {
   }
 
   public void force() {
-    try {
-      myAppender.flush();
-    }
-    catch (IOException e) {
-      throw new RuntimeException(e);
+    final CacheValue<DataOutputStream> cached = ourAppendersCache.getIfCached(myPath);
+    if (cached != null) {
+      try {
+        cached.get().flush();
+      }
+      catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+      finally {
+        cached.release();
+      }
     }
   }
 
   public void dispose() {
-    try {
-      myAppender.close();
-      myReader.dispose();
-    }
-    catch (IOException e) {
-      throw new RuntimeException(e);
+    ourReadersCache.remove(myPath);
+    ourAppendersCache.remove(myPath);
+
+    if (myCompactionModeReader != null) {
+      myCompactionModeReader.dispose();
+      myCompactionModeReader = null;
     }
   }
 
   public void switchToCompactionMode(PagedFileStorage.StorageLock lock) {
-    myReader.dispose();
+    ourReadersCache.remove(myPath);
     try {
-      myReader = new MappedReader(myFile, lock);
+      myCompactionModeReader = new MappedReader(myFile, lock);
     }
     catch (IOException e) {
       throw new RuntimeException(e);
@@ -184,4 +241,91 @@ public class PersistentHashMapValueStorage {
       }
     }
   }
+
+  private static abstract class FileAccessorCache<T> extends SLRUCache<String, CacheValue<T>> {
+    private final Object myLock = new Object();
+    private FileAccessorCache(int protectedQueueSize, int probationalQueueSize) {
+      super(protectedQueueSize, probationalQueueSize);
+    }
+
+    @NotNull
+    public final CacheValue<T> get(String key) {
+      synchronized (myLock) {
+        final CacheValue<T> value = super.get(key);
+        value.allocate();
+        return value;
+      }
+    }
+
+    @Override
+    public CacheValue<T> getIfCached(String key) {
+      synchronized (myLock) {
+        final CacheValue<T> value = super.getIfCached(key);
+        if (value != null) {
+          value.allocate();
+        }
+        return value;
+      }
+    }
+
+    public boolean remove(String key) {
+      synchronized (myLock) {
+        return super.remove(key);
+      }
+    }
+
+    protected final void onDropFromCache(String key, CacheValue<T> value) {
+      value.release();
+    }
+  }
+
+  private static class CachedAppender extends CacheValue<DataOutputStream> {
+    private CachedAppender(DataOutputStream os) {
+      super(os);
+    }
+
+    protected void disposeAccessor(DataOutputStream os) {
+      try {
+        os.close();
+      }
+      catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  private static class CachedReader extends CacheValue<RAReader> {
+    private CachedReader(RAReader reader) {
+      super(reader);
+    }
+
+    protected void disposeAccessor(RAReader reader) {
+      reader.dispose();
+    }
+  }
+
+  private abstract static class CacheValue<T> {
+    private final T myFileAccessor;
+    private final AtomicInteger myRefCount = new AtomicInteger(1);
+
+    private CacheValue(T fileAccessor) {
+      myFileAccessor = fileAccessor;
+    }
+
+    public final void allocate() {
+      myRefCount.incrementAndGet();
+    }
+
+    public final void release() {
+      if (myRefCount.decrementAndGet() == 0) {
+        disposeAccessor(myFileAccessor);
+      }
+    }
+
+    public T get() {
+      return myFileAccessor;
+    }
+
+    protected abstract void disposeAccessor(T accesor);
+  }
 }
index 829270932ddf59c3613ecfcce1e66981b1d4f917..5113474c3cf510570a652ed637b815f4c737d72c 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.plugins.intelliLang.AdvancedSettingsUI">
-  <grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
       <xy x="20" y="20" width="562" height="446"/>
       </grid>
       <vspacer id="5c670">
         <constraints>
-          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
       </vspacer>
+      <grid id="a5863" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="0" left="0" bottom="0" right="0"/>
+        <constraints>
+          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none" title="General Hints"/>
+        <children>
+          <component id="34215" class="javax.swing.JCheckBox" binding="myAnalyzeReferencesCheckBox">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="&amp;Analyze references"/>
+            </properties>
+          </component>
+          <component id="eae73" class="javax.swing.JCheckBox" binding="myIncludeUncomputableOperandsAsCheckBox">
+            <constraints>
+              <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="Include uncomputable operands as literals"/>
+            </properties>
+          </component>
+          <component id="b63a5" class="javax.swing.JCheckBox" binding="myUseDataflowAnalysisIfCheckBox">
+            <constraints>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <selected value="false"/>
+              <text value="&amp;Use dataflow analysis (slow) "/>
+            </properties>
+          </component>
+        </children>
+      </grid>
     </children>
   </grid>
   <buttonGroups>
index 4f817124c435660cf155c86b6db492d1ab0d8106..56cf6cbfd5f0ef03002442ba33c2c797641275ca 100644 (file)
@@ -53,6 +53,9 @@ public class AdvancedSettingsUI implements Configurable {
   private JPanel myLanguageAnnotationPanel;
   private JPanel myPatternAnnotationPanel;
   private JPanel mySubstAnnotationPanel;
+  private JCheckBox myAnalyzeReferencesCheckBox;
+  private JCheckBox myUseDataflowAnalysisIfCheckBox;
+  private JCheckBox myIncludeUncomputableOperandsAsCheckBox;
 
   private final ReferenceEditorWithBrowseButton myAnnotationField;
   private final ReferenceEditorWithBrowseButton myPatternField;
@@ -126,6 +129,15 @@ public class AdvancedSettingsUI implements Configurable {
     if (!mySubstField.getText().equals(myConfiguration.getSubstAnnotationClass())) {
       return true;
     }
+    if (myConfiguration.isResolveReferences() != myAnalyzeReferencesCheckBox.isSelected()) {
+      return true;
+    }
+    if (myConfiguration.isUseDfaIfAvailable() != myUseDataflowAnalysisIfCheckBox.isSelected()) {
+      return true;
+    }
+    if (myConfiguration.isIncludeUncomputablesAsLiterals() != myIncludeUncomputableOperandsAsCheckBox.isSelected()) {
+      return true;
+    }
     return false;
   }
 
@@ -144,6 +156,10 @@ public class AdvancedSettingsUI implements Configurable {
     myConfiguration.setLanguageAnnotation(myAnnotationField.getText());
     myConfiguration.setPatternAnnotation(myPatternField.getText());
     myConfiguration.setSubstAnnotation(mySubstField.getText());
+
+    myConfiguration.setResolveReferences(myAnalyzeReferencesCheckBox.isSelected());
+    myConfiguration.setUseDfaIfAvailable(myUseDataflowAnalysisIfCheckBox.isSelected());
+    myConfiguration.setIncludeUncomputablesAsLiterals(myIncludeUncomputableOperandsAsCheckBox.isSelected());
   }
 
   public void reset() {
@@ -154,6 +170,10 @@ public class AdvancedSettingsUI implements Configurable {
     myNoInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.NONE);
     myAssertInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.ASSERT);
     myExceptionInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.EXCEPTION);
+
+    myAnalyzeReferencesCheckBox.setSelected(myConfiguration.isResolveReferences());
+    myUseDataflowAnalysisIfCheckBox.setSelected(myConfiguration.isUseDfaIfAvailable());
+    myIncludeUncomputableOperandsAsCheckBox.setSelected(myConfiguration.isIncludeUncomputablesAsLiterals());
   }
 
   public void disposeUIResources() {
index 64241b9039bf8011e123cde2bc99d879c0bb82f8..31b2fa186f888fd15e0cd891db36ab41dfc03bc5 100644 (file)
@@ -77,6 +77,8 @@ public final class Configuration implements PersistentStateComponent<Element> {
   @NonNls private static final String SUBST_ANNOTATION_NAME = "SUBST_ANNOTATION";
   @NonNls private static final String ENTRY_NAME = "entry";
   @NonNls private static final String RESOLVE_REFERENCES = "RESOLVE_REFERENCES";
+  @NonNls private static final String USE_DFA_IF_AVAILABLE = "USE_DFA_IF_AVAILABLE";
+  @NonNls private static final String INCLUDE_UNCOMPUTABLES_AS_LITERALS = "INCLUDE_UNCOMPUTABLES_AS_LITERALS";
 
   private final Map<String, List<BaseInjection>> myInjections = new ConcurrentFactoryMap<String, List<BaseInjection>>() {
     @Override
@@ -94,6 +96,8 @@ public final class Configuration implements PersistentStateComponent<Element> {
   @NotNull private String mySubstAnnotation;
 
   private boolean myResolveReferences;
+  private boolean myIncludeUncomputablesAsLiterals;
+  private boolean myUseDfaIfAvailable;
 
   // cached annotation name pairs
   private Pair<String, ? extends Set<String>> myLanguageAnnotationPair;
@@ -144,9 +148,10 @@ public final class Configuration implements PersistentStateComponent<Element> {
     setLanguageAnnotation(JDOMExternalizerUtil.readField(element, LANGUAGE_ANNOTATION_NAME));
     setPatternAnnotation(JDOMExternalizerUtil.readField(element, PATTERN_ANNOTATION_NAME));
     setSubstAnnotation(JDOMExternalizerUtil.readField(element, SUBST_ANNOTATION_NAME));
-    final String resolveReferences = JDOMExternalizerUtil.readField(element, RESOLVE_REFERENCES);
-    setResolveReferences(resolveReferences == null || Boolean.parseBoolean(resolveReferences));
-    
+    setResolveReferences(readBoolean(element, RESOLVE_REFERENCES, true));
+    setUseDfaIfAvailable(readBoolean(element, USE_DFA_IF_AVAILABLE, true));
+    setIncludeUncomputablesAsLiterals(readBoolean(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, true));
+
     if (mergeWithOriginalAndCompile) {
       mergeWithDefaultConfiguration();
 
@@ -158,6 +163,12 @@ public final class Configuration implements PersistentStateComponent<Element> {
     }
   }
 
+  private static boolean readBoolean(Element element, String key, boolean defValue) {
+    final String value = JDOMExternalizerUtil.readField(element, key);
+    if (value == null) return defValue;
+    return Boolean.parseBoolean(value);
+  }
+
   private void mergeWithDefaultConfiguration() {
     Configuration cfg = null;
     try {
@@ -363,6 +374,22 @@ public final class Configuration implements PersistentStateComponent<Element> {
     myResolveReferences = resolveReferences;
   }
 
+  public boolean isIncludeUncomputablesAsLiterals() {
+    return myIncludeUncomputablesAsLiterals;
+  }
+
+  public void setIncludeUncomputablesAsLiterals(boolean flag) {
+    myIncludeUncomputablesAsLiterals = flag;
+  }
+
+  public boolean isUseDfaIfAvailable() {
+    return myUseDfaIfAvailable;
+  }
+
+  public void setUseDfaIfAvailable(boolean flag) {
+    myUseDfaIfAvailable = flag;
+  }
+
   @Nullable
   public BaseInjection findExistingInjection(@NotNull final BaseInjection injection) {
     final List<BaseInjection> list = getInjections(injection.getSupportId());
index 5427e23de28437c8594865f140a7f4ad2ccb6d3e..6dbf7b1a5207afaa973ce13fdfa550fce58718d9 100644 (file)
@@ -220,7 +220,9 @@ public class PatternValidator extends LocalInspectionTool {
     if (pattern == null) return;
 
     List<PsiExpression> nonConstantElements = new SmartList<PsiExpression>();
-    String o = SubstitutedExpressionEvaluationHelper.computeExpression(expression, nonConstantElements);
+    final Object result = new SubstitutedExpressionEvaluationHelper(expression.getProject()).computeExpression(
+      expression, myConfiguration.isUseDfaIfAvailable(), false, nonConstantElements);
+    final String o = result == null ? null : String.valueOf(result);
     if (o != null) {
       if (!pattern.matcher(o).matches()) {
         if (annotations.length > 1) {
index ea5975ac5159633f6061f924860d330dd8b65539..feed23cd41fefe8a8e345342a596d88ceaa86df4 100644 (file)
@@ -95,7 +95,7 @@ public class ContextComputationProcessor {
     }
     else {
       final SmartList<PsiExpression> uncomputables = new SmartList<PsiExpression>();
-      final Object o = expression instanceof PsiExpression? myEvaluationHelper.computeExpression((PsiExpression)expression, true, uncomputables) : null;
+      final Object o = expression instanceof PsiExpression? myEvaluationHelper.computeExpression((PsiExpression)expression, uncomputables) : null;
       if (uncomputables.size() > 0) {
         unparsable.set(Boolean.TRUE);
       }
index 78dab4b9835f525edfafd74b28ae140f558c1ef6..51b252465365f00f98013e355431b7d0efe200a6 100644 (file)
@@ -23,10 +23,10 @@ import com.intellij.psi.*;
 import com.intellij.psi.util.CachedValue;
 import com.intellij.util.containers.ConcurrentHashMap;
 import org.intellij.plugins.intelliLang.Configuration;
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ConcurrentMap;
 
@@ -47,11 +47,11 @@ public class SubstitutedExpressionEvaluationHelper {
     myConfiguration = Configuration.getInstance();
   }
 
-  public Object computeExpression(final PsiExpression e, final boolean includeUncomputablesAsLiterals) {
-    return computeExpression(e, includeUncomputablesAsLiterals, null);
+  public Object computeExpression(final PsiExpression e, final List<PsiExpression> uncomputables) {
+    return computeExpression(e, myConfiguration.isUseDfaIfAvailable(), myConfiguration.isIncludeUncomputablesAsLiterals(), uncomputables);
   }
 
-  public Object computeExpression(final PsiExpression e, final boolean includeUncomputablesAsLiterals, final List<PsiExpression> uncomputables) {
+  public Object computeExpression(final PsiExpression e, final boolean useDfa, final boolean includeUncomputablesAsLiterals, final List<PsiExpression> uncomputables) {
     final ConcurrentMap<PsiElement, Object> map = new ConcurrentHashMap<PsiElement, Object>();
     //if (true) return myHelper.computeConstantExpression(e, false);
     return myHelper.computeExpression(e, false, new PsiConstantEvaluationHelper.AuxEvaluator() {
@@ -77,7 +77,8 @@ public class SubstitutedExpressionEvaluationHelper {
             if (substituted != null) return substituted;
             if (resolved instanceof PsiVariable) {
               resolvedType = ((PsiVariable)resolved).getType();
-              final Collection<PsiExpression> values = DfaUtil.getCachedVariableValues(((PsiVariable)resolved), o);
+              final Collection<PsiExpression> values =
+                !useDfa? Collections.<PsiExpression>emptyList() : DfaUtil.getCachedVariableValues(((PsiVariable)resolved), o);
               // return the first computed value as far as we do not support multiple injection
               for (PsiExpression value : values) {
                 final Object computedValue = auxEvaluator.computeExpression(value, this);
@@ -126,16 +127,4 @@ public class SubstitutedExpressionEvaluationHelper {
     return null;
   }
 
-  /**
-   * Computes the value for the passed expression.
-   *
-   * @param e           The expression whose value to compute
-   * @param nonConstant list that returns non-constant and non-substituted expressions
-   * @return the computed value, or null if the expression isn't compile time constant and not susbtituted
-   */
-  @Nullable
-  public static String computeExpression(@NotNull final PsiExpression e, @Nullable List<PsiExpression> nonConstant) {
-    final Object result = new SubstitutedExpressionEvaluationHelper(e.getProject()).computeExpression(e, false, nonConstant);
-    return result == null? null : String.valueOf(result);
-  }
 }
index 22a0e2f476bb06956f52c26e216ccd4354b67ef0..e54101556470620de383b7d1d00354a66e16b27d 100644 (file)
@@ -93,6 +93,12 @@ public class ConstantSubexpressionIntention extends MutablyNamedIntention {
             newExpression += '"' + StringUtil.escapeStringCharacters(
                     constantValue.toString()) + '"';
         } else if (constantValue != null) {
+            if (constantValue instanceof Number) {
+                final Number number = (Number) constantValue;
+                if (0 > number.doubleValue()) {
+                    newExpression += " ";
+                }
+            }
             newExpression += constantValue.toString();
         }
         replaceExpression(newExpression, expression);
index 5dd93586102df469622f0fad7ca7bb4c0bd77f1b..a9b47f0964bfdab28462c1fe88b79f377be8c1c3 100644 (file)
@@ -29,6 +29,8 @@ public class CommentTokenizer extends Tokenizer<PsiComment> {
   @Nullable
   @Override
   public Token[] tokenize(@NotNull PsiComment element) {
+    // doccomment chameleon expands as PsiComment inside PsiComment, avoid duplication
+    if (element.getParent() instanceof PsiComment) return null;
     return new Token[]{new Token<PsiComment>(element, element.getText(),false)};
   }
 
index 5c0f3b3d8c919247b2b6ecf87b70d359636118ae..5fc21c9c9e70f0bd89c4f9c08416ecbf6a891012 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 /*some <TYPO descr="Typo: In word 'commments'">commments</TYPO> */
+/**some <TYPO descr="Typo: In word 'commments'">commments</TYPO> */
 function  test<TYPO descr="Typo: In word 'Fuunction'">Fuunction</TYPO>(){
   var <TYPO descr="Typo: In word 'upddate'">upddate</TYPO> = "test variable";
 }
index 0fa1b38604a2e62cb6013153340af26a18c74b73..3114b28d7b7111871ad32c064be651061b284eb8 100644 (file)
     <applicationService serviceInterface="com.intellij.packaging.elements.PackagingElementFactory"
                         serviceImplementation="com.intellij.packaging.impl.elements.PackagingElementFactoryImpl"/>
 
-    <projectService serviceInterface="com.intellij.packaging.artifacts.ArtifactManager"
-                    serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactManagerImpl"/>
     <projectService serviceInterface="com.intellij.packaging.artifacts.ArtifactPointerManager"
                     serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactPointerManagerImpl"/>
     <projectService serviceInterface="com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinder"
index 7c8ce3396c89906774430a6b975c14038c26247d..e8df7259a6c3cf99a7c0b533298eb425d57f3f93 100644 (file)
       first-show="5"
       successive-show="7"
       />
-    <feature
-      id="editing.completion.completeStatement"
-      tip-file="CompleteMethod.html"
-      min-usage-count="5"
-      first-show="10"
-      successive-show="7"
-      />
   </group>
   
   <group id="editing">
index 15f1adb9059e62c64d8993b9497c355f8d926a9e..01cb22a0e9b3f0c7d38327d7803dbbd15ac3964e 100644 (file)
@@ -6,6 +6,10 @@
   </application-components>
   
   <project-components>
+    <component>
+      <interface-class>com.intellij.packaging.artifacts.ArtifactManager</interface-class>
+      <implementation-class>com.intellij.packaging.impl.artifacts.ArtifactManagerImpl</implementation-class>
+    </component>
     <component>
       <interface-class>com.intellij.compiler.CompilerConfiguration</interface-class>
       <implementation-class>com.intellij.compiler.CompilerConfigurationImpl</implementation-class>
index 2e6442f03b1845c4664b9d9ee6d27db3406f78d2..6dbcab0dbda9afb5ba15e8b8a98119cdc289f4c2 100644 (file)
@@ -139,10 +139,12 @@ public class URIReferenceProvider extends PsiReferenceProvider {
          )
       ) {
       if (!s.startsWith(XmlUtil.TAG_DIR_NS_PREFIX)) {
-        final boolean namespaceSoftRef = parent instanceof XmlAttribute &&
+        boolean namespaceSoftRef = parent instanceof XmlAttribute &&
           NAMESPACE_ATTR_NAME.equals(((XmlAttribute)parent).getName()) &&
           ((XmlAttribute)parent).getParent().getAttributeValue("schemaLocation") != null;
-
+        if (!namespaceSoftRef && parent instanceof XmlAttribute && ((XmlAttribute)parent).isNamespaceDeclaration()) {
+          namespaceSoftRef = parent.getContainingFile().getContext() != null;
+        }
         return getUrlReference(element, namespaceSoftRef);
       }
     }