From f271d2a54806feeef8a01fbd87db6897840bc39e Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Thu, 8 Oct 2009 15:23:58 +0400 Subject: [PATCH 01/11] fix reloading project on settings save: fix event requestor to be SaveSession instead of Virtual file + fix resaving of splitted components (push lastTimeStamp to original StorageData [one from which current one was cloned]) --- .../impl/stores/DirectoryBasedStorage.java | 6 ++++- .../impl/stores/FileBasedStorage.java | 19 +------------- .../components/impl/stores/StorageUtil.java | 25 ++++++++++++------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java index ac6922a10e58..49540c2b927b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java @@ -247,7 +247,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { myDir.mkDir(); } - StorageUtil.save(file, element); + StorageUtil.save(file, element, MySaveSession.this); myStorageData.updateLastTimestamp(file); } } @@ -359,6 +359,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { private static class MyStorageData { private Map> myStates = new HashMap>(); private long myLastTimestamp = 0; + private MyStorageData myOriginalData; public Set getComponentNames() { return myStates.keySet(); @@ -379,6 +380,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { public void updateLastTimestamp(final IFile file) { myLastTimestamp = Math.max(myLastTimestamp, file.getTimeStamp()); + if (myOriginalData != null) myOriginalData.myLastTimestamp = myLastTimestamp; } public long getLastTimeStamp() { @@ -419,11 +421,13 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { final MyStorageData result = new MyStorageData(); result.myStates = new HashMap>(myStates); result.myLastTimestamp = myLastTimestamp; + result.myOriginalData = this; return result; } public void clear() { myStates.clear(); + myOriginalData = null; } public boolean containsComponent(final String componentName) { diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java index 159223721891..80cd1bfe56eb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java @@ -29,7 +29,6 @@ import javax.swing.*; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -150,23 +149,7 @@ public class FileBasedStorage extends XmlElementStorage { protected void doSave() throws StateStorageException { if (!myBlockSavingTheContent) { final byte[] text = StorageUtil.printDocument(getDocumentToSave()); - - //StorageUtil.save(myFile, text); - VirtualFile virtualFile = ensureVirtualFile(); - if (virtualFile != null) { - try { - OutputStream out = virtualFile.getOutputStream(this); - try { - out.write(text); - } - finally { - out.close(); - } - } - catch (IOException e) { - LOG.error(e); - } - } + StorageUtil.save(myFile, text, this); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java index 47df3cd45724..6c9d7c32db9a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java @@ -27,10 +27,7 @@ import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; @@ -45,7 +42,7 @@ public class StorageUtil { private StorageUtil() { } - static void save(final IFile file, final byte[] text) throws StateStorage.StateStorageException { + static void save(final IFile file, final byte[] text, final Object requestor) throws StateStorage.StateStorageException { final String filePath = file.getCanonicalPath(); try { final Ref refIOException = Ref.create(null); @@ -63,7 +60,17 @@ public class StorageUtil { } try { - getOrCreateVirtualFile(file, file).setBinaryContent(text); + final VirtualFile virtualFile = getOrCreateVirtualFile(requestor, file); + + OutputStream outputStream = null; + try { + outputStream = virtualFile.getOutputStream(requestor); + outputStream.write(text); + outputStream.flush(); + } + finally { + if (outputStream != null) outputStream.close(); + } } catch (IOException e) { refIOException.set(e); @@ -92,7 +99,7 @@ public class StorageUtil { return backupFile; } - static VirtualFile getOrCreateVirtualFile(Object requestor, IFile ioFile) throws IOException { + static VirtualFile getOrCreateVirtualFile(final Object requestor, final IFile ioFile) throws IOException { VirtualFile vFile = getVirtualFile(ioFile); if (vFile == null) { @@ -154,9 +161,9 @@ public class StorageUtil { return JDOMUtil.writeElement(element, SystemProperties.getLineSeparator()); } - static void save(IFile file, Element element) throws StateStorage.StateStorageException { + static void save(IFile file, Element element, final Object requestor) throws StateStorage.StateStorageException { try { - save(file, JDOMUtil.writeElement(element, SystemProperties.getLineSeparator()).getBytes(CharsetToolkit.UTF8)); + save(file, JDOMUtil.writeElement(element, SystemProperties.getLineSeparator()).getBytes(CharsetToolkit.UTF8), requestor); } catch (IOException e) { throw new StateStorage.StateStorageException(e); From 56036f4421057eabe4dc3c6f11eb1bd55f50cc5a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Oct 2009 15:28:06 +0400 Subject: [PATCH 02/11] IDEA-23967 XML structure view should have a 'sort by name' option like the Java structure viewer --- .../structureView/impl/xml/XmlStructureViewTreeModel.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlStructureViewTreeModel.java b/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlStructureViewTreeModel.java index b925d3538eec..bba53264ed24 100644 --- a/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlStructureViewTreeModel.java +++ b/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlStructureViewTreeModel.java @@ -35,6 +35,7 @@ import com.intellij.ide.structureView.StructureViewExtension; import com.intellij.ide.structureView.StructureViewFactoryEx; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.structureView.TextEditorBasedStructureViewModel; +import com.intellij.ide.util.treeView.smartTree.Sorter; import com.intellij.lang.dtd.DTDLanguage; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -46,6 +47,7 @@ import java.util.Collection; public class XmlStructureViewTreeModel extends TextEditorBasedStructureViewModel{ private final XmlFile myFile; private static final Class[] myClasses = new Class[]{XmlTag.class, XmlFile.class, XmlEntityDecl.class, XmlElementDecl.class, XmlAttlistDecl.class, XmlConditionalSection.class}; + private static Sorter[] mySorters = {Sorter.ALPHA_SORTER}; public XmlStructureViewTreeModel(XmlFile file) { super(file); @@ -83,4 +85,9 @@ public class XmlStructureViewTreeModel extends TextEditorBasedStructureViewModel } return editorElement; } + + @NotNull + public Sorter[] getSorters() { + return mySorters; + } } From 8866bda1f63c4fb6621ef052804bde31739c4420 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 8 Oct 2009 15:29:10 +0400 Subject: [PATCH 03/11] named module libraries supported in artifacts --- .../impl/elements/LibraryElementType.java | 2 +- .../elements/LibraryPackagingElement.java | 79 ++++++++++++++----- .../elements/PackagingElementFactoryImpl.java | 25 ++++-- .../impl/ui/LibraryElementPresentation.java | 18 +++-- .../elements/PackagingElementFactory.java | 2 +- .../conversion/ConversionContext.java | 5 +- .../intellij/conversion/ModuleSettings.java | 8 +- .../impl/ConversionContextImpl.java | 22 +++++- .../conversion/impl/ModuleSettingsImpl.java | 58 +++++++++++--- 9 files changed, 166 insertions(+), 53 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java index 2b26eb5aac53..62085385dce9 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java @@ -43,7 +43,7 @@ public class LibraryElementType extends ComplexPackagingElementType selected = context.chooseLibraries(getAllLibraries(context), ProjectBundle.message("dialog.title.packaging.choose.library")); final List elements = new ArrayList(); for (Library library : selected) { - elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName())); + elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName(), null)); } return elements; } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java index 3b3d3ff84482..1525aed82fb9 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java @@ -1,23 +1,28 @@ package com.intellij.packaging.impl.elements; +import com.intellij.openapi.deployment.LibraryLink; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.LibraryOrderEntry; +import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.deployment.LibraryLink; +import com.intellij.packaging.artifacts.ArtifactType; import com.intellij.packaging.elements.ComplexPackagingElement; import com.intellij.packaging.elements.PackagingElement; -import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.elements.PackagingElementOutputKind; +import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.ui.LibraryElementPresentation; -import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.ArtifactEditorContext; -import com.intellij.packaging.artifacts.ArtifactType; +import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.util.PathUtil; import com.intellij.util.xmlb.annotations.Attribute; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NonNls; import java.util.ArrayList; import java.util.List; @@ -26,19 +31,22 @@ import java.util.List; * @author nik */ public class LibraryPackagingElement extends ComplexPackagingElement { - private String myLevel; - private String myName; @NonNls public static final String LIBRARY_NAME_ATTRIBUTE = "name"; + @NonNls public static final String MODULE_NAME_ATTRIBUTE = "module-name"; @NonNls public static final String LIBRARY_LEVEL_ATTRIBUTE = "level"; + private String myLevel; + private String myLibraryName; + private String myModuleName; public LibraryPackagingElement() { super(LibraryElementType.LIBRARY_ELEMENT_TYPE); } - public LibraryPackagingElement(String level, String name) { + public LibraryPackagingElement(String level, String libraryName, String moduleName) { super(LibraryElementType.LIBRARY_ELEMENT_TYPE); myLevel = level; - myName = name; + myLibraryName = libraryName; + myModuleName = moduleName; } public List> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) { @@ -63,7 +71,7 @@ public class LibraryPackagingElement extends ComplexPackagingElement> createLibraryElements(@NotNull Library library) { final LibraryTable table = library.getTable(); + final String libraryName = library.getName(); if (table != null) { - return Collections.singletonList(createLibraryFiles(table.getTableLevel(), library.getName())); + return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null)); + } + if (libraryName != null) { + final Module module = ((LibraryImpl)library).getModule(); + if (module != null) { + return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName())); + } } final List> elements = new ArrayList>(); for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) { @@ -185,8 +194,8 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { @NotNull @Override - public PackagingElement createLibraryFiles(@NotNull String level, @NotNull String name) { - return new LibraryPackagingElement(level, name); + public PackagingElement createLibraryFiles(@NotNull String libraryName, @NotNull String level, String moduleName) { + return new LibraryPackagingElement(level, libraryName, moduleName); } @NotNull diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java index 0582cc93af1d..a5ee7ad7b683 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java @@ -13,23 +13,28 @@ import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.Icons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author nik */ public class LibraryElementPresentation extends PackagingElementPresentation { + private final String myLevel; + private final String myModuleName; private final Library myLibrary; - private final String myName; + private final String myLibraryName; private final ArtifactEditorContext myContext; - public LibraryElementPresentation(String level, String name, Library library, ArtifactEditorContext context) { + public LibraryElementPresentation(String libraryName, String level, @Nullable String moduleName, Library library, ArtifactEditorContext context) { + myLevel = level; + myModuleName = moduleName; myLibrary = library; - myName = name; + myLibraryName = libraryName; myContext = context; } public String getPresentableName() { - return myName; + return myLibraryName; } @Override @@ -50,11 +55,12 @@ public class LibraryElementPresentation extends PackagingElementPresentation { public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { if (myLibrary != null) { presentationData.setIcons(Icons.LIBRARY_ICON); - presentationData.addText(myName, mainAttributes); + presentationData.addText(myLibraryName, mainAttributes); presentationData.addText(getLibraryTableComment(myLibrary), commentAttributes); } else { - presentationData.addText(myName, SimpleTextAttributes.ERROR_ATTRIBUTES); + presentationData.addText(myLibraryName + " (" + (myModuleName != null ? "module '" + myModuleName + "'" : myLevel) + ")", + SimpleTextAttributes.ERROR_ATTRIBUTES); } } diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java index f16ce44e63ef..aa3e9d6dd574 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java @@ -42,7 +42,7 @@ public abstract class PackagingElementFactory { public abstract PackagingElement createArtifactElement(@NotNull Artifact artifact, @NotNull Project project); @NotNull - public abstract PackagingElement createLibraryFiles(@NotNull String level, @NotNull String name); + public abstract PackagingElement createLibraryFiles(@NotNull String libraryName, @NotNull String level, String moduleName); @NotNull diff --git a/platform/lang-impl/src/com/intellij/conversion/ConversionContext.java b/platform/lang-impl/src/com/intellij/conversion/ConversionContext.java index 9e368bf5593e..0ef9f67d34a8 100644 --- a/platform/lang-impl/src/com/intellij/conversion/ConversionContext.java +++ b/platform/lang-impl/src/com/intellij/conversion/ConversionContext.java @@ -28,6 +28,9 @@ public interface ConversionContext { ModuleSettings getModuleSettings(File moduleFile) throws CannotConvertException; + @Nullable + ModuleSettings getModuleSettings(@NotNull String moduleName); + @NotNull String collapsePath(@NotNull String path); @@ -36,6 +39,6 @@ public interface ConversionContext { @Nullable ComponentManagerSettings getCompilerSettings(); - @Nullable + @Nullable ComponentManagerSettings getProjectRootManagerSettings(); } diff --git a/platform/lang-impl/src/com/intellij/conversion/ModuleSettings.java b/platform/lang-impl/src/com/intellij/conversion/ModuleSettings.java index be8ed687bf70..b7a1836dd788 100644 --- a/platform/lang-impl/src/com/intellij/conversion/ModuleSettings.java +++ b/platform/lang-impl/src/com/intellij/conversion/ModuleSettings.java @@ -41,5 +41,11 @@ public interface ModuleSettings extends ComponentManagerSettings { void addExcludedFolder(@NotNull File directory); - List getModuleLibraryRootUrls(String libraryName); + @NotNull + List getModuleLibraryRoots(String libraryName); + + @NotNull + Collection getAllModuleDependencies(); + + boolean hasModuleLibrary(String libraryName); } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java index 0b5a1028ba9f..0a649bea3779 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java @@ -42,7 +42,8 @@ public class ConversionContextImpl implements ConversionContext { private ProjectSettingsImpl myProjectSettings; private WorkspaceSettingsImpl myWorkspaceSettings; private List myNonExistingModuleFiles = new ArrayList(); - private Map myModuleSettingsMap = new HashMap(); + private Map myFile2ModuleSettings = new HashMap(); + private Map myName2ModuleSettings = new HashMap(); private RunManagerSettingsImpl myRunManagerSettings; private File mySettingsBaseDir; private ComponentManagerSettings myCompilerManagerSettings; @@ -175,6 +176,7 @@ public class ConversionContextImpl implements ConversionContext { } } + @NotNull public List getClassRoots(Element libraryElement, ModuleSettingsImpl moduleSettings) { List files = new ArrayList(); //todo[nik] support jar directories @@ -309,14 +311,28 @@ public class ConversionContextImpl implements ConversionContext { public ModuleSettings getModuleSettings(File moduleFile) throws CannotConvertException { - ModuleSettingsImpl settings = myModuleSettingsMap.get(moduleFile); + ModuleSettingsImpl settings = myFile2ModuleSettings.get(moduleFile); if (settings == null) { settings = new ModuleSettingsImpl(moduleFile, this); - myModuleSettingsMap.put(moduleFile, settings); + myFile2ModuleSettings.put(moduleFile, settings); + myName2ModuleSettings.put(settings.getModuleName(), settings); } return settings; } + public ModuleSettings getModuleSettings(@NotNull String moduleName) { + if (!myName2ModuleSettings.containsKey(moduleName)) { + for (File moduleFile : myModuleFiles) { + try { + getModuleSettings(moduleFile); + } + catch (CannotConvertException ignored) { + } + } + } + return myName2ModuleSettings.get(moduleName); + } + public List getNonExistingModuleFiles() { return myNonExistingModuleFiles; } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java index 5f238066527b..27fdb185b557 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java @@ -8,10 +8,9 @@ import com.intellij.ide.highlighter.ModuleFileType; import com.intellij.ide.impl.convert.JDomConvertingUtil; import com.intellij.openapi.module.impl.ModuleImpl; import com.intellij.openapi.roots.impl.*; -import com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; @@ -21,10 +20,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author nik @@ -139,17 +135,57 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements } } - public List getModuleLibraryRootUrls(String libraryName) { - final Element component = getComponentElement(MODULE_ROOT_MANAGER_COMPONENT); - for (Element element : JDomConvertingUtil.getChildren(component, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME)) { + @NotNull + public List getModuleLibraryRoots(String libraryName) { + final Element library = findModuleLibraryElement(libraryName); + return library != null ? myContext.getClassRoots(library, this) : Collections.emptyList(); + } + + public boolean hasModuleLibrary(String libraryName) { + return findModuleLibraryElement(libraryName) != null; + } + + @Nullable + private Element findModuleLibraryElement(String libraryName) { + for (Element element : getOrderEntries()) { if (ModuleLibraryOrderEntryImpl.ENTRY_TYPE.equals(element.getAttributeValue(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR))) { final Element library = element.getChild(LibraryImpl.ELEMENT); if (library != null && libraryName.equals(library.getAttributeValue(LibraryImpl.LIBRARY_NAME_ATTR))) { - return myContext.getClassRoots(library, this); + return library; + } + } + } + return null; + } + + private List getOrderEntries() { + final Element component = getComponentElement(MODULE_ROOT_MANAGER_COMPONENT); + return JDomConvertingUtil.getChildren(component, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME); + } + + @NotNull + public Collection getAllModuleDependencies() { + Set dependencies = new HashSet(); + collectDependencies(dependencies); + return dependencies; + } + + private void collectDependencies(Set dependencies) { + if (!dependencies.add(this)) { + return; + } + + for (Element element : getOrderEntries()) { + if (ModuleOrderEntryImpl.ENTRY_TYPE.equals(element.getAttributeValue(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR))) { + final String moduleName = element.getAttributeValue(ModuleOrderEntryImpl.MODULE_NAME_ATTR); + if (moduleName != null) { + final ModuleSettings moduleSettings = myContext.getModuleSettings(moduleName); + if (moduleSettings != null) { + ((ModuleSettingsImpl)moduleSettings).collectDependencies(dependencies); + } } } } - return Collections.emptyList(); } private void addExcludedFolder(File directory, Element contentRoot) throws IOException { From eebf87db276c1e13a7d05434bcd6447d3cd168a5 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 8 Oct 2009 15:25:32 +0400 Subject: [PATCH 04/11] consider GlobalSearchScope when indexing unsaved docs --- .../util/indexing/FileBasedIndex.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index c38046e52735..57fcf7318649 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -549,7 +549,7 @@ public class FileBasedIndex implements ApplicationComponent { try { checkRebuild(indexId, false); myChangedFilesUpdater.forceUpdate(filter); - indexUnsavedDocuments(indexId, project); + indexUnsavedDocuments(indexId, project, filter); } catch (StorageException e) { scheduleRebuild(indexId, e); @@ -917,7 +917,7 @@ public class FileBasedIndex implements ApplicationComponent { return docs; } - private void indexUnsavedDocuments(ID indexId, Project project) throws StorageException { + private void indexUnsavedDocuments(ID indexId, Project project, GlobalSearchScope filter) throws StorageException { if (myUpToDateIndices.contains(indexId)) { return; // no need to index unsaved docs @@ -928,11 +928,12 @@ public class FileBasedIndex implements ApplicationComponent { // now index unsaved data final StorageGuard.Holder guard = setDataBufferingEnabled(true); try { + boolean allDocsProcessed = true; final Semaphore semaphore = myUnsavedDataIndexingSemaphores.get(indexId); semaphore.down(); try { for (Document document : documents) { - indexUnsavedDocument(document, indexId, project); + allDocsProcessed &= indexUnsavedDocument(document, indexId, project, filter); } } finally { @@ -943,7 +944,9 @@ public class FileBasedIndex implements ApplicationComponent { break; // hack. Most probably that other indexing threads is waiting for PsiLock, which we're are holding. } } - myUpToDateIndices.add(indexId); // safe to set the flag here, becase it will be cleared under the WriteAction + if (allDocsProcessed) { + myUpToDateIndices.add(indexId); // safe to set the flag here, becase it will be cleared under the WriteAction + } } } finally { @@ -996,12 +999,15 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void indexUnsavedDocument(final Document document, final ID requestedIndexId, Project project) throws StorageException { + // returns false if doc was not indexed because the file does not fit in scope + private boolean indexUnsavedDocument(final Document document, final ID requestedIndexId, Project project, GlobalSearchScope filter) throws StorageException { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { - return; + return true; + } + if (filter != null && !filter.accept(vFile)) { + return false; } - final PsiFile dominantContentFile = findDominantPsiForDocument(document, project); DocumentContent content; @@ -1036,6 +1042,7 @@ public class FileBasedIndex implements ApplicationComponent { dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, null); } } + return true; } public static final Key PSI_FILE = new Key("PSI for stubs"); From 91cd74913f1507feab78a00b3f0aae00f0a4fe9e Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 8 Oct 2009 16:20:49 +0400 Subject: [PATCH 05/11] annotations patterns support in DeadCodeInspection (IDEA-24043 Jersey request methods should not be inspected as "method is never used") --- .../deadCode/DeadCodeInspection.java | 6 +++- .../intellij/codeInsight/AnnotationUtil.java | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadCodeInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadCodeInspection.java index fd9fca255d87..50d38b890652 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadCodeInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadCodeInspection.java @@ -67,6 +67,9 @@ public class DeadCodeInspection extends FilteringInspectionTool { public boolean ADD_NONJAVA_TO_ENTRIES = true; public JDOMExternalizableStringList ADDITIONAL_ANNOTATIONS = new JDOMExternalizableStringList(); + private static final String[] ADDITIONAL_ANNOS = { + "javax.ws.rs.*" + }; private HashSet myProcessedSuspicious = null; private int myPhase; @@ -86,6 +89,7 @@ public class DeadCodeInspection extends FilteringInspectionTool { public final UnusedCodeExtension[] myExtensions; public DeadCodeInspection() { + ADDITIONAL_ANNOTATIONS.addAll(Arrays.asList(ADDITIONAL_ANNOS)); myQuickFixActions = new QuickFixAction[]{new PermanentDeleteAction(), new CommentOutBin(), new MoveToEntries()}; ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL); final UnusedCodeExtension[] deadCodeAddins = point.getExtensions(); @@ -430,7 +434,7 @@ public class DeadCodeInspection extends FilteringInspectionTool { if (isAddMainsEnabled() && PsiMethodUtil.hasMainMethod(aClass)) return true; } if (element instanceof PsiModifierListOwner - && AnnotationUtil.isAnnotated((PsiModifierListOwner)element, ADDITIONAL_ANNOTATIONS)) { + && AnnotationUtil.checkAnnotatedUsingPatterns((PsiModifierListOwner)element, ADDITIONAL_ANNOTATIONS)) { return true; } for (UnusedCodeExtension extension : myExtensions) { diff --git a/java/openapi/src/com/intellij/codeInsight/AnnotationUtil.java b/java/openapi/src/com/intellij/codeInsight/AnnotationUtil.java index 0a750e806c2b..2e6592ee5b56 100644 --- a/java/openapi/src/com/intellij/codeInsight/AnnotationUtil.java +++ b/java/openapi/src/com/intellij/codeInsight/AnnotationUtil.java @@ -222,4 +222,40 @@ public class AnnotationUtil { public static boolean isJetbrainsAnnotation(@NonNls final String simpleName) { return ArrayUtil.find(SIMPLE_NAMES, simpleName) != -1; } + + /** + * Works similar to #isAnnotated(PsiModifierListOwner, Collection) but supports FQN patters + * like "javax.ws.rs.*". Supports ending "*" only. + * + * @param owner modifier list + * @param annotations annotations qualified names or patterns. Patterns can have '*' at the end + * @return true if annotated of at least one annotation from the annotations list + */ + public static boolean checkAnnotatedUsingPatterns(PsiModifierListOwner owner, Collection annotations) { + List fqns = null; + final PsiModifierList modList; + if (owner == null || (modList = owner.getModifierList()) == null) return false; + + for (String fqn : annotations) { + if (! fqn.endsWith("*") && isAnnotated(owner, fqn, false)) { + return true; + } else { + if (fqns == null) { + fqns = new ArrayList(); + final PsiAnnotation[] annos = modList.getAnnotations(); + for (PsiAnnotation anno : annos) { + fqns.add(anno.getQualifiedName()); + } + if (fqns.isEmpty()) return false; + } + fqn = fqn.substring(0, fqn.length() - 2); + for (String annoFQN : fqns) { + if (annoFQN.startsWith(fqn)) { + return true; + } + } + } + } + return false; + } } From 23f915cf31f5bf070fa1d72fe07d54077753f337 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 8 Oct 2009 16:26:21 +0400 Subject: [PATCH 06/11] IDEADEV-40744: Map a Help Id to the Project Structure | Artifacts page --- .../ui/configuration/artifacts/ArtifactConfigurable.java | 2 +- .../artifacts/ArtifactsStructureConfigurable.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java index c01793edcad6..15023bdbf985 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactConfigurable.java @@ -77,7 +77,7 @@ public class ArtifactConfigurable extends NamedConfigurable { } public String getHelpTopic() { - return null; + return "reference.settingsdialog.project.structure.artifacts"; } @Override diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java index 28f3f3e03eb9..70e069e5116c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java @@ -136,6 +136,12 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { myPackagingEditorContext.disposeUIResources(); } + @Override + public String getHelpTopic() { + final String topic = super.getHelpTopic(); + return topic != null ? topic : "reference.settingsdialog.project.structure.artifacts"; + } + @Override protected void removeArtifact(Artifact artifact) { myPackagingEditorContext.getModifiableArtifactModel().removeArtifact(artifact); From b533ad63a9e0918bd24e17c0e9f710cc8bcc8d60 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 8 Oct 2009 16:57:29 +0400 Subject: [PATCH 07/11] IDEADEV-40728: Artifacts editor: Choose library dialog: libraries could be sorted --- .../FacetBasedPackagingElementType.java | 2 +- .../ui/configuration/ClasspathPanel.java | 6 ---- .../artifacts/ArtifactEditorContextImpl.java | 6 ++-- .../artifacts/ChooseArtifactsDialog.java | 6 +--- .../libraryEditor/ChooseModulesDialog.java | 4 +-- .../libraryEditor/LibraryTableEditor.java | 5 --- .../packaging/ChooseLibrariesDialog.java | 6 +--- .../ide/util/ChooseElementsDialog.java | 36 ++++++++++--------- 8 files changed, 28 insertions(+), 43 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java index e655141d15d6..c8095dab4413 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java @@ -81,7 +81,7 @@ public abstract class FacetBasedPackagingElementType { private ChooseFacetsDialog(Project project, List items, String title, String description) { - super(project, items, title, description); + super(project, items, title, description, true); } @Override diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java index b0acf7b44886..1119075c48e2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ClasspathPanel.java @@ -81,11 +81,6 @@ public class ClasspathPanel extends JPanel { private final EventDispatcher myListeners = EventDispatcher.create(OrderPanelListener.class); private PopupAction[] myPopupActions = null; private Icon[] myIcons = null; - private static final Comparator MODULES_COMPARATOR = new Comparator() { - public int compare(Module elem1, Module elem2) { - return elem1.getName().compareToIgnoreCase(elem2.getName()); - } - }; private JButton myEditButton; protected ClasspathPanel(Project project, ModifiableRootModel rootModel, final ModulesProvider modulesProvider) { @@ -691,7 +686,6 @@ public class ClasspathPanel extends JPanel { elements.add(module); } } - Collections.sort(elements, MODULES_COMPARATOR); return elements; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java index edf3b635de22..caf65e3bd9e3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java @@ -79,7 +79,7 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext { } public List chooseArtifacts(final List artifacts, final String title) { - ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(getProject(), artifacts, title, ""); + ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(getProject(), artifacts, title, null); dialog.show(); return dialog.isOK() ? dialog.getChosenElements() : Collections.emptyList(); } @@ -118,14 +118,14 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext { } public List chooseModules(final List modules, final String title) { - ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, ""); + ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, null); dialog.show(); List selected = dialog.getChosenElements(); return dialog.isOK() ? selected : Collections.emptyList(); } public List chooseLibraries(final List libraries, final String title) { - ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(getProject(), libraries, title, ""); + ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(getProject(), libraries, title, null); dialog.show(); return dialog.isOK() ? dialog.getChosenElements() : Collections.emptyList(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java index 23da2268b333..7c36d7bf0694 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java @@ -13,11 +13,7 @@ import java.util.List; public class ChooseArtifactsDialog extends ChooseElementsDialog { public ChooseArtifactsDialog(Project project, List items, String title, String description) { - super(project, items, title, description); - } - - public ChooseArtifactsDialog(JComponent component, String title, List items) { - super(component, items, title, true); + super(project, items, title, description, true); } protected String getItemText(Artifact item) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseModulesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseModulesDialog.java index 82141c6dea4d..08fd7f06a61d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseModulesDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseModulesDialog.java @@ -21,11 +21,11 @@ import java.util.List; public class ChooseModulesDialog extends ChooseElementsDialog { public ChooseModulesDialog(Component parent, final List items, final String title) { - super(parent, items, title); + super(parent, items, title, null, true); } public ChooseModulesDialog(final Project project, final List items, final String title, final String description) { - super(project, items, title, description); + super(project, items, title, description, true); } protected Icon getItemIcon(final Module item) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java index 02db7efd4fdb..c5731e49fdcf 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java @@ -470,11 +470,6 @@ public class LibraryTableEditor implements Disposable { private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) { final List modules = new ArrayList(); modules.addAll(Arrays.asList(rootConfigurable.getModules())); - Collections.sort(modules, new Comparator() { - public int compare(final Module m1, final Module m2) { - return m1.getName().compareToIgnoreCase(m2.getName()); - } - }); final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject, modules, ProjectBundle.message("choose.modules.dialog.title"), ProjectBundle.message("choose.modules.dialog.description", libraryToSelect.getName())); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java index b95c2d57e156..e9f9f1aca5e8 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java @@ -16,11 +16,7 @@ import java.util.List; public class ChooseLibrariesDialog extends ChooseElementsDialog { public ChooseLibrariesDialog(Project project, List items, String title, String description) { - super(project, items, title, description); - } - - public ChooseLibrariesDialog(JComponent component, String title, List items) { - super(component, items, title, true); + super(project, items, title, description, true); } protected String getItemText(final Library item) { diff --git a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java index c862c8e85c48..80a6d09937e0 100644 --- a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java @@ -9,9 +9,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; +import java.util.*; import java.util.List; /** @@ -22,28 +20,26 @@ public abstract class ChooseElementsDialog extends DialogWrapper { private String myDescription; public ChooseElementsDialog(Project project, List items, String title, final String description) { + this(project, items, title, description, false); + } + + public ChooseElementsDialog(Project project, List items, String title, final String description, boolean sort) { super(project, true); myDescription = description; - initializeDialog(items, title); + initializeDialog(items, title, sort); } public ChooseElementsDialog(Component parent, List items, String title) { - this(parent, items, title, false); + this(parent, items, title, null, false); } - public ChooseElementsDialog(Component parent, List items, String title, final boolean sort) { + public ChooseElementsDialog(Component parent, List items, String title, @Nullable String description, final boolean sort) { super(parent, true); - if (sort) { - Collections.sort(items, new Comparator() { - public int compare(final T o1, final T o2) { - return getItemText(o1).compareToIgnoreCase(getItemText(o2)); - } - }); - } - initializeDialog(items, title); + myDescription = description; + initializeDialog(items, title, sort); } - private void initializeDialog(final List items, final String title) { + private void initializeDialog(final List items, final String title, boolean sort) { setTitle(title); myChooser = new ElementsChooser(false) { protected String getItemText(@NotNull final T item) { @@ -52,7 +48,15 @@ public abstract class ChooseElementsDialog extends DialogWrapper { }; myChooser.setColorUnmarkedElements(false); - setElements(items, items.size() > 0 ? items.subList(0, 1) : Collections.emptyList()); + List elements = new ArrayList(items); + if (sort) { + Collections.sort(elements, new Comparator() { + public int compare(final T o1, final T o2) { + return getItemText(o1).compareToIgnoreCase(getItemText(o2)); + } + }); + } + setElements(elements, elements.size() > 0 ? elements.subList(0, 1) : Collections.emptyList()); myChooser.getComponent().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { doOKAction(); From d0d1809f937480e962f6012b5a2e2a59e51cbbaf Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 8 Oct 2009 16:21:38 +0400 Subject: [PATCH 08/11] Changing preconditions order may have significant performance implications. --- .../plugins/groovy/lang/psi/util/GroovyPropertyUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java index 627fff57fad9..ee137adb1d16 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyPropertyUtils.java @@ -94,10 +94,8 @@ public class GroovyPropertyUtils { public static boolean isSimplePropertyGetter(PsiMethod method, String propertyName) { if (method == null || method.isConstructor()) return false; if (method.getParameterList().getParametersCount() != 0) return false; - final PsiType type = method.getReturnType(); - if (type != null && type == PsiType.VOID) return false; if (!isGetterName(method.getName())) return false; - return propertyName == null || propertyName.equals(getPropertyNameByGetter(method)); + return (propertyName == null || propertyName.equals(getPropertyNameByGetter(method))) && method.getReturnType() != PsiType.VOID; } public static boolean isSimplePropertySetter(PsiMethod method) { From b2ee8d31fe0ebf1beba66e8d13e77cf7f9aff577 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 8 Oct 2009 17:24:17 +0400 Subject: [PATCH 09/11] svnkit/sqljet license --- license/sqljet-license.txt | 21 +++++++++++++++++++++ license/svnkit-license.txt | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 license/sqljet-license.txt create mode 100644 license/svnkit-license.txt diff --git a/license/sqljet-license.txt b/license/sqljet-license.txt new file mode 100644 index 000000000000..bfa2adabe8c7 --- /dev/null +++ b/license/sqljet-license.txt @@ -0,0 +1,21 @@ +Copyright (C) 2009 TMate Software Ltd + +SQLJet Library Software License + +* Definitions + +SQLJet Library - means SQLJet software library, developed by TMate Software (http://sqljet.com/). + +IntelliJ Platform - means software platform developed by JetBrains. + +* License + +As part of IntelliJ Platform software application, SQLJet library could be used and distributed in binary or source form without any limitations when the following conditions are met: + +(1) SQLJet library is distributed along with IntelliJ Platform software application and SQLJet library API is used programmatically by IntelliJ Platform software application. + +(2) SQLJet library is distributed along with third-party software application based on IntelliJ Platform software application and SQLJet library API is used programmatically by IntelliJ Platform software application. + +Above licensing conditions are only applicable when SQLJet library is distributed as part of IntelliJ Platform software application or third-party software application based on IntelliJ Platform software application. + +For licensing terms applicable to SQLJet library outside of of IntelliJ Platform software application, please refer to http://sqljet.com/ web page or contact TMate Software at support@sqljet.com diff --git a/license/svnkit-license.txt b/license/svnkit-license.txt new file mode 100644 index 000000000000..17900a26092e --- /dev/null +++ b/license/svnkit-license.txt @@ -0,0 +1,21 @@ +Copyright (C) 2009 TMate Software Ltd + +SVNKit Library Software License + +* Definitions + +SVNKit Library - means SVNKit software library, developed by TMate Software (http://svnkit.com/). + +IntelliJ Platform - means software platform developed by JetBrains. + +* License + +As part of IntelliJ Platform software application, SVNKit library could be used and distributed in binary or source form without any limitations when the following conditions are met: + +(1) SVNKit library is distributed along with IntelliJ Platform software application and SVNKit library API is used programmatically by IntelliJ Platform software application. + +(2) SVNKit library is distributed along with third-party software application based on IntelliJ Platform software application and SVNKit library API is used programmatically by IntelliJ Platform software application. + +Above licensing conditions are only applicable when SVNKit library is distributed as part of IntelliJ Platform software application or third-party software application based on IntelliJ Platform software application. + +For licensing terms applicable to SVNKit library outside of of IntelliJ Platform software application, please refer to http://svnkit.com/licensing.html web page or contact TMate Software at support@svnkit.com From a35afb71e611d3f5b361f495f84777e8771533e7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 8 Oct 2009 18:11:45 +0400 Subject: [PATCH 10/11] allow using multiple live templates with the same abbreviation (as long as they're in different groups) --- .../template/impl/EditTemplateDialog.java | 22 ++-- .../template/impl/ListTemplatesHandler.java | 28 +++-- .../template/impl/TemplateManagerImpl.java | 91 +++++++------- .../template/impl/TemplateSettings.java | 117 ++++++++++++++---- .../template/impl/TemplateState.java | 4 +- .../impl/editorActions/EnterHandler.java | 2 +- .../impl/editorActions/SpaceHandler.java | 2 +- .../impl/editorActions/TabHandler.java | 2 +- .../src/messages/CodeInsightBundle.properties | 2 +- 9 files changed, 170 insertions(+), 100 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java index 6a9bb3129fb7..5aac39c26bb7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java @@ -533,19 +533,19 @@ public class EditTemplateDialog extends DialogWrapper { protected void doOKAction() { String key = myKeyField.getText().trim(); + final String newGroup = (String)myGroupCombo.getSelectedItem(); + for (TemplateGroup templateGroup : myTemplateGroups) { - for (TemplateImpl template : templateGroup.getElements()) { - if (template.getKey().equals(key) && myTemplate != template) { - Messages.showMessageDialog( - getContentPane(), - CodeInsightBundle.message("dialog.edit.template.error.already.exists", key, template.getGroupName()), - CodeInsightBundle.message("dialog.edit.template.error.title"), - Messages.getErrorIcon() - ); - return; + if (templateGroup.getName().equals(newGroup)) { + for (TemplateImpl template : templateGroup.getElements()) { + if (template.getKey().equals(key) && myTemplate != template) { + Messages.showMessageDialog(getContentPane(), + CodeInsightBundle.message("dialog.edit.template.error.already.exists", key, template.getGroupName()), + CodeInsightBundle.message("dialog.edit.template.error.title"), Messages.getErrorIcon()); + return; + } } } - } if (!TemplateImplUtil.validateTemplateText(myTemplateEditor.getDocument().getText())) { @@ -559,7 +559,7 @@ public class EditTemplateDialog extends DialogWrapper { } SchemesManager schemesManager = TemplateSettings.getInstance().getSchemesManager(); - TemplateGroup group = schemesManager.findSchemeByName((String)myGroupCombo.getSelectedItem()); + TemplateGroup group = schemesManager.findSchemeByName(newGroup); if (group != null && schemesManager.isShared(group)) { Messages.showMessageDialog ( getContentPane(), diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java index c93342db2344..8ffcf6563c22 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java @@ -18,6 +18,7 @@ import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.List; public class ListTemplatesHandler implements CodeInsightActionHandler{ public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { @@ -27,17 +28,15 @@ public class ListTemplatesHandler implements CodeInsightActionHandler{ PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); int offset = editor.getCaretModel().getOffset(); String prefix = getPrefix(editor.getDocument(), offset); - - ArrayList array = new ArrayList(); + + List matchingTemplates = new ArrayList(); for (TemplateImpl template : SurroundWithTemplateHandler.getApplicableTemplates(editor, file, false)) { - String key = template.getKey(); - if (key.startsWith(prefix)) { - array.add(new LookupItem(template, key)); + if (template.getKey().startsWith(prefix)) { + matchingTemplates.add(template); } } - LookupElement[] items = array.toArray(new LookupElement[array.size()]); - - if (items.length == 0){ + + if (matchingTemplates.size() == 0) { String text = prefix.length() == 0 ? CodeInsightBundle.message("templates.no.defined") : CodeInsightBundle.message("templates.no.defined.with.prefix", prefix); @@ -45,13 +44,24 @@ public class ListTemplatesHandler implements CodeInsightActionHandler{ return; } + showTemplatesLookup(project, editor, prefix, matchingTemplates); + } + + public static void showTemplatesLookup(final Project project, final Editor editor, String prefix, List matchingTemplates) { + ArrayList array = new ArrayList(); + for (TemplateImpl template: matchingTemplates) { + array.add(new LookupItem(template, template.getKey())); + } + LookupElement[] items = array.toArray(new LookupElement[array.size()]); + final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, items, prefix, LookupArranger.DEFAULT); lookup.addLookupListener( new LookupAdapter() { public void itemSelected(LookupEvent event) { + final TemplateImpl template = (TemplateImpl)event.getItem().getObject(); new WriteCommandAction(project) { protected void run(Result result) throws Throwable { - TemplateManager.getInstance(project).startTemplate(editor, '\0'); + ((TemplateManagerImpl) TemplateManager.getInstance(project)).startTemplateWithPrefix(editor, template, null); } }.execute(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index 00b69f8e9e87..0c0719a47824 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -23,9 +23,7 @@ import com.intellij.util.PairProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class TemplateManagerImpl extends TemplateManager implements ProjectComponent { protected Project myProject; @@ -108,7 +106,7 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo } public boolean startTemplate(@NotNull Editor editor, char shortcutChar) { - return startTemplate(this, editor, shortcutChar, null); + return startTemplate(editor, shortcutChar, null); } public void startTemplate(@NotNull final Editor editor, @NotNull Template template) { @@ -164,11 +162,7 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo startTemplate(editor, null, template, listener, null); } - public boolean startTemplate(TemplateManagerImpl templateManager, final Editor editor, char shortcutChar) { - return startTemplate(templateManager, editor, shortcutChar, null); - } - - public boolean startTemplate(TemplateManagerImpl templateManager, final Editor editor, char shortcutChar, final PairProcessor processor) { + public boolean startTemplate(final Editor editor, char shortcutChar, final PairProcessor processor) { final Document document = editor.getDocument(); PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject); if (file == null) return false; @@ -176,36 +170,25 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo TemplateSettings templateSettings = TemplateSettings.getInstance(); CharSequence text = document.getCharsSequence(); final int caretOffset = editor.getCaretModel().getOffset(); - TemplateImpl template = null; - int wordStart = 0; + String key = null; + List candidates = Collections.emptyList(); for (int i = templateSettings.getMaxKeyLength(); i >= 1 ; i--) { - wordStart = caretOffset - i; + int wordStart = caretOffset - i; if (wordStart < 0) { continue; } - String key = text.subSequence(wordStart, caretOffset).toString(); - template = templateSettings.getTemplate(key); - if (template != null && template.isDeactivated()) { - template = null; - } - if (template != null) { - if (Character.isJavaIdentifierStart(key.charAt(0))) { - if (wordStart > 0 && Character.isJavaIdentifierPart(text.charAt(wordStart - 1))) { - template = null; - continue; - } + key = text.subSequence(wordStart, caretOffset).toString(); + if (Character.isJavaIdentifierStart(key.charAt(0))) { + if (wordStart > 0 && Character.isJavaIdentifierPart(text.charAt(wordStart - 1))) { + continue; } - break; } + + candidates = templateSettings.collectMatchingCandidates(key, shortcutChar); + if (!candidates.isEmpty()) break; } - if (template == null) return false; - - if (shortcutChar != 0 && getShortcutChar(template) != shortcutChar) { - return false; - } - - if (template.isSelectionTemplate()) return false; + if (candidates.isEmpty()) return false; CommandProcessor.getInstance().executeCommand( myProject, new Runnable() { @@ -215,39 +198,53 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo }, "", null ); - if (!isApplicable(file, caretOffset - template.getKey().length(), template)) { + + candidates = filterApplicableCandidates(file, caretOffset - key.length(), candidates); + if (candidates.isEmpty()) { return false; } if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), myProject)) { - return false; + return false; } - final int wordStart0 = wordStart; - final TemplateImpl template0 = template; - final TemplateState templateState0 = templateManager.initTemplateState(editor); + + if (candidates.size() == 1) { + TemplateImpl template = candidates.get(0); + startTemplateWithPrefix(editor, template, processor); + } + else { + ListTemplatesHandler.showTemplatesLookup(myProject, editor, key, candidates); + } + + return true; + } + + public void startTemplateWithPrefix(final Editor editor, final TemplateImpl template, @Nullable final PairProcessor processor) { + final int caretOffset = editor.getCaretModel().getOffset(); + final int wordStart = caretOffset - template.getKey().length(); + final TemplateState templateState = initTemplateState(editor); CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( myProject, new Runnable() { public void run() { - editor.getDocument().deleteString(wordStart0, caretOffset); - editor.getCaretModel().moveToOffset(wordStart0); + editor.getDocument().deleteString(wordStart, caretOffset); + editor.getCaretModel().moveToOffset(wordStart); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); - templateState0.start(template0, processor); + templateState.start(template, processor); } }, CodeInsightBundle.message("insert.code.template.command"), null ); - return true; } - private static char getShortcutChar(TemplateImpl template) { - char c = template.getShortcutChar(); - if (c == TemplateSettings.DEFAULT_CHAR) { - return TemplateSettings.getInstance().getDefaultShortcutChar(); - } - else { - return c; + private static List filterApplicableCandidates(PsiFile file, int offset, List candidates) { + List result = new ArrayList(); + for (TemplateImpl candidate : candidates) { + if (isApplicable(file, offset, candidate)) { + result.add(candidate); + } } + return result; } public TemplateContextType getContextType(@NotNull PsiFile file, int offset) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index 97adcacebcf7..df1d0f7f1230 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -14,6 +14,7 @@ import com.intellij.openapi.options.SchemesManagerFactory; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.WriteExternalException; +import com.intellij.util.containers.MultiMap; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; @@ -45,7 +46,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo private @NonNls static final String TEMPLATE = "template"; private @NonNls static final String DELETED_TEMPLATES = "deleted_templates"; - private final List myDeletedTemplates = new ArrayList(); + private final List myDeletedTemplates = new ArrayList(); public static final char SPACE_CHAR = ' '; public static final char TAB_CHAR = '\t'; @@ -79,7 +80,8 @@ public class TemplateSettings implements PersistentStateComponent, Expo private static final @NonNls String TEMPLATES_CONFIG_FOLDER = "templates"; - private final Map myTemplates = new LinkedHashMap(); + private final List myAllTemplates = new ArrayList(); + private final MultiMap myTemplates = new MultiMap(); private final Map myTemplatesById = new LinkedHashMap(); private final Map myDefaultTemplates = new LinkedHashMap(); @@ -92,6 +94,20 @@ public class TemplateSettings implements PersistentStateComponent, Expo private final SchemeProcessor myProcessor; private static final String FILE_SPEC = "$ROOT_CONFIG$/templates"; + private static class TemplateKey { + final String groupName; + final String key; + + private TemplateKey(String groupName, String key) { + this.groupName = groupName; + this.key = key; + } + + public static TemplateKey keyOf(TemplateImpl template) { + return new TemplateKey(template.getGroupName(), template.getKey()); + } + } + public TemplateSettings(SchemesManagerFactory schemesManagerFactory) { @@ -192,14 +208,22 @@ public class TemplateSettings implements PersistentStateComponent, Expo List children = deleted.getChildren(); for (final Object aChildren : children) { Element child = (Element)aChildren; - myDeletedTemplates.add(child.getAttributeValue(NAME)); + myDeletedTemplates.add(new TemplateKey(child.getAttributeValue(NAME), child.getAttributeValue(GROUP))); } } - for (String name : myDeletedTemplates) { - Template toDelete = myTemplates.get(name); - if (toDelete != null) { - removeTemplate(toDelete); + for (TemplateKey templateKey : myDeletedTemplates) { + if (templateKey.groupName == null) { + final Collection templates = myTemplates.get(templateKey.key); + for (TemplateImpl template : templates) { + removeTemplate(template); + } + } + else { + final TemplateImpl toDelete = getTemplate(templateKey.key, templateKey.groupName); + if (toDelete != null) { + removeTemplate(toDelete); + } } } @@ -220,9 +244,10 @@ public class TemplateSettings implements PersistentStateComponent, Expo if (myDeletedTemplates.size() > 0) { Element deleted = new Element(DELETED_TEMPLATES); - for (final String myDeletedTemplate : myDeletedTemplates) { + for (final TemplateKey deletedTemplate : myDeletedTemplates) { Element template = new Element(TEMPLATE); - template.setAttribute(NAME, myDeletedTemplate); + template.setAttribute(NAME, deletedTemplate.key); + template.setAttribute(GROUP, deletedTemplate.groupName); deleted.addContent(template); } @@ -240,7 +265,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo } public TemplateImpl[] getTemplates() { - return myTemplates.values().toArray(new TemplateImpl[myTemplates.size()]); + return myAllTemplates.toArray(new TemplateImpl[myAllTemplates.size()]); } public char getDefaultShortcutChar() { @@ -251,8 +276,18 @@ public class TemplateSettings implements PersistentStateComponent, Expo myDefaultShortcutChar = defaultShortcutChar; } - public TemplateImpl getTemplate(@NonNls String key) { - return (TemplateImpl) myTemplates.get(key); + public Collection getTemplates(@NonNls String key) { + return myTemplates.get(key); + } + + public TemplateImpl getTemplate(@NonNls String key, String group) { + final Collection templates = myTemplates.get(key); + for (TemplateImpl template : templates) { + if (template.getGroupName().equals(group)) { + return template; + } + } + return null; } public Template getTemplateById(@NonNls String id) { @@ -278,7 +313,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo } private void clearPreviouslyRegistered(final Template template) { - TemplateImpl existing = getTemplate(template.getKey()); + TemplateImpl existing = getTemplate(template.getKey(), ((TemplateImpl) template).getGroupName()); if (existing != null) { LOG.info("Template with key " + template.getKey() + " and id " + template.getId() + " already registered"); TemplateGroup group = mySchemesManager.findSchemeByName(existing.getGroupName()); @@ -288,17 +323,19 @@ public class TemplateSettings implements PersistentStateComponent, Expo mySchemesManager.removeScheme(group); } } - myTemplates.remove(template.getKey()); + myTemplates.removeValue(template.getKey(), existing); } } private void addTemplateImpl(Template template) { - if (!myTemplates.containsKey(template.getKey())) { - myTemplates.put(template.getKey(), template); - - myMaxKeyLength = Math.max(myMaxKeyLength, template.getKey().length()); + final TemplateImpl templateImpl = (TemplateImpl)template; + if (getTemplate(templateImpl.getKey(), templateImpl.getGroupName()) == null) { + myTemplates.putValue(template.getKey(), templateImpl); + myAllTemplates.add(templateImpl); } - myDeletedTemplates.remove(template.getKey()); + + myMaxKeyLength = Math.max(myMaxKeyLength, template.getKey().length()); + myDeletedTemplates.remove(TemplateKey.keyOf((TemplateImpl)template)); } @@ -312,10 +349,11 @@ public class TemplateSettings implements PersistentStateComponent, Expo } public void removeTemplate(Template template) { - myTemplates.remove(template.getKey()); + myTemplates.removeValue(template.getKey(), (TemplateImpl )template); - TemplateImpl templImpl = (TemplateImpl)template; - String groupName = templImpl.getGroupName(); + TemplateImpl templateImpl = (TemplateImpl)template; + myAllTemplates.remove(templateImpl); + String groupName = templateImpl.getGroupName(); TemplateGroup group = mySchemesManager.findSchemeByName(groupName); if (group != null) { @@ -422,14 +460,11 @@ public class TemplateSettings implements PersistentStateComponent, Expo Element element = (Element)o1; TemplateImpl template = readTemplateFromElement(isDefault, groupName, element); - boolean doNotRegister = isDefault && (myDeletedTemplates.contains(template.getKey()) || myTemplates.containsKey(template.getKey())); + boolean doNotRegister = isDefault && (myDeletedTemplates.contains(TemplateKey.keyOf(template)) || myTemplates.containsKey(template.getKey())); if(!doNotRegister) { created.put(template.getKey(), template); } - - - } if (registerTemplate) { @@ -562,7 +597,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo myTemplates.clear(); myDeletedTemplates.clear(); for (TemplateImpl template : myDefaultTemplates.values()) { - myDeletedTemplates.add(template.getKey()); + myDeletedTemplates.add(TemplateKey.keyOf(template)); } mySchemesManager.clearAllSchemes(); myMaxKeyLength = 0; @@ -584,4 +619,32 @@ public class TemplateSettings implements PersistentStateComponent, Expo public List getTemplateGroups() { return mySchemesManager.getAllSchemes(); } + + public List collectMatchingCandidates(String key, char shortcutChar) { + final Collection templates = getTemplates(key); + List candidates = new ArrayList(); + for (TemplateImpl template : templates) { + if (template.isDeactivated()) { + continue; + } + if (getShortcutChar(template) != shortcutChar) { + continue; + } + if (template.isSelectionTemplate()) { + continue; + } + candidates.add(template); + } + return candidates; + } + + private char getShortcutChar(TemplateImpl template) { + char c = template.getShortcutChar(); + if (c == DEFAULT_CHAR) { + return getDefaultShortcutChar(); + } + else { + return c; + } + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java index 4854dcddfaec..c32b84e6ccb2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java @@ -73,7 +73,7 @@ public class TemplateState implements Disposable { private boolean myTemplateIndented = false; private Document myDocument; private boolean myFinished; - private PairProcessor myProcessor; + @Nullable private PairProcessor myProcessor; public TemplateState(@NotNull Project project, final Editor editor) { myProject = project; @@ -214,7 +214,7 @@ public class TemplateState implements Disposable { } } - public void start(TemplateImpl template, final PairProcessor processor) { + public void start(TemplateImpl template, @Nullable final PairProcessor processor) { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); myProcessor = processor; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java index bfdb443acd28..a3d9a7b0fd92 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java @@ -31,7 +31,7 @@ public class EnterHandler extends BaseEnterHandler { TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project); - if (!templateManager.startTemplate(templateManager, editor, TemplateSettings.ENTER_CHAR)) { + if (!templateManager.startTemplate(editor, TemplateSettings.ENTER_CHAR)) { myOriginalHandler.execute(editor, dataContext); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/SpaceHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/SpaceHandler.java index f251787ed08d..984fcec0d31b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/SpaceHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/SpaceHandler.java @@ -29,7 +29,7 @@ public class SpaceHandler implements TypedActionHandler { } TemplateManagerImpl templateManager = (TemplateManagerImpl) TemplateManagerImpl.getInstance(project); - if (!templateManager.startTemplate(templateManager, editor, TemplateSettings.SPACE_CHAR)) { + if (!templateManager.startTemplate(editor, TemplateSettings.SPACE_CHAR)) { myOriginalHandler.execute(editor, charTyped, dataContext); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/TabHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/TabHandler.java index f15d27bc942f..23f15e80fe4d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/TabHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/TabHandler.java @@ -26,7 +26,7 @@ public class TabHandler extends EditorWriteActionHandler { TemplateManagerImpl templateManager = (TemplateManagerImpl) TemplateManagerImpl.getInstance(project); - if (!templateManager.startTemplate(templateManager, editor, TemplateSettings.TAB_CHAR)) { + if (!templateManager.startTemplate(editor, TemplateSettings.TAB_CHAR)) { myOriginalHandler.execute(editor, dataContext); } } diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index 118f4b5f785b..312f2dcb5bf6 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -295,7 +295,7 @@ dialog.edit.template.checkbox.smart.type.completion=Smart type c&ompletion dialog.edit.template.checkbox.other=O&ther dialog.edit.template.error.title=Cannot Save dialog.edit.template.error.malformed.abbreviation=Cannot save the template.\nTemplate abbreviation should contain only letters, digits, dots and hyphens. -dialog.edit.template.error.already.exists=Cannot save the template.\nTemplate with the abbreviation \"{0}\"\nalready exists in group \"{1}\".\nTry another abbreviation. +dialog.edit.template.error.already.exists=Cannot save the template.\nTemplate with the abbreviation \"{0}\"\nalready exists in group \"{1}\".\nPlease choose a different abbreviation or group. dialog.edit.template.error.malformed.template=Error parsing the template finish.template.command=Finish Template insert.code.template.command=Insert Code Template From e4edbaf6a5c3993d1ba1cbb3a3083fbed64f6a13 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 8 Oct 2009 18:44:34 +0400 Subject: [PATCH 11/11] IDEADEV-40762: correct getData(VIRTUAL_FILE_ARRAY) for content roots of the modules --- .../ide/navigationToolbar/NavBarPanel.java | 18 ++++++++++++++++-- .../ide/projectView/impl/ProjectViewImpl.java | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index fc8898d08bd3..54b3e4a82196 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -74,7 +74,9 @@ import javax.swing.border.Border; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; /** * User: anna @@ -237,7 +239,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner { public void select() { updateModel(); updateList(); - + if (!myList.isEmpty()) { myModel.setSelectedIndex(myList.size() - 1); IdeFocusManager.getInstance(myProject).requestFocus(this, true); @@ -563,7 +565,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner { private void navigateInsideBar(final Object object) { myModel.updateModel(object); updateList(); - + myModel.setSelectedIndex(myList.size() - 1); if (myHint != null) { @@ -646,6 +648,18 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner { return element != null && element.isValid() ? new PsiElement[]{element} : null; } + if (dataId.equals(DataConstants.VIRTUAL_FILE_ARRAY)) { + PsiElement[] psiElements = (PsiElement[])getData(DataConstants.PSI_ELEMENT_ARRAY); + if (psiElements == null) return null; + Set files = new LinkedHashSet(); + for (PsiElement element : psiElements) { + if (element instanceof PsiFileSystemItem) { + files.add(((PsiFileSystemItem)element).getVirtualFile()); + } + } + return files.size() > 0 ? files.toArray(new VirtualFile[files.size()]) : null; + } + if (dataId.equals(DataConstants.CONTEXT_COMPONENT)) { return this; } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 749ad5357c18..d2231fe2f1dc 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -970,6 +970,17 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat PsiElement[] elements = currentProjectViewPane.getSelectedPSIElements(); return elements.length == 0 ? null : elements; } + if (DataConstants.VIRTUAL_FILE_ARRAY.equals(dataId)) { + PsiElement[] psiElements = (PsiElement[])getData(DataConstants.PSI_ELEMENT_ARRAY); + if (psiElements == null) return null; + Set files = new LinkedHashSet(); + for (PsiElement element : psiElements) { + if (element instanceof PsiFileSystemItem) { + files.add(((PsiFileSystemItem)element).getVirtualFile()); + } + } + return files.size() > 0 ? files.toArray(new VirtualFile[files.size()]) : null; + } if (DataConstantsEx.TARGET_PSI_ELEMENT.equals(dataId)) { return null; }