Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Irina Chernushina
2009-10-08 19:06:12 +04:00
40 changed files with 525 additions and 238 deletions
@@ -81,7 +81,7 @@ public abstract class FacetBasedPackagingElementType<E extends PackagingElement<
private class ChooseFacetsDialog extends ChooseElementsDialog<F> {
private ChooseFacetsDialog(Project project, List<? extends F> items, String title, String description) {
super(project, items, title, description);
super(project, items, title, description, true);
}
@Override
@@ -43,7 +43,7 @@ public class LibraryElementType extends ComplexPackagingElementType<LibraryPacka
final List<Library> selected = context.chooseLibraries(getAllLibraries(context), ProjectBundle.message("dialog.title.packaging.choose.library"));
final List<LibraryPackagingElement> elements = new ArrayList<LibraryPackagingElement>();
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;
}
@@ -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<LibraryPackagingElement> {
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<? extends PackagingElement<?>> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) {
@@ -63,7 +71,7 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
}
public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
return new LibraryElementPresentation(myLevel, myName, findLibrary(context), context);
return new LibraryElementPresentation(myLibraryName, myLevel, myModuleName, findLibrary(context), context);
}
@Override
@@ -73,8 +81,9 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
}
LibraryPackagingElement packagingElement = (LibraryPackagingElement)element;
return myLevel != null && myName != null && myLevel.equals(packagingElement.getLevel())
&& myName.equals(packagingElement.getName());
return myLevel != null && myLibraryName != null && myLevel.equals(packagingElement.getLevel())
&& myLibraryName.equals(packagingElement.getLibraryName())
&& Comparing.equal(myModuleName, packagingElement.getModuleName());
}
public LibraryPackagingElement getState() {
@@ -83,7 +92,8 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
public void loadState(LibraryPackagingElement state) {
myLevel = state.getLevel();
myName = state.getName();
myLibraryName = state.getLibraryName();
myModuleName = state.getModuleName();
}
@Attribute(LIBRARY_LEVEL_ATTRIBUTE)
@@ -96,22 +106,49 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
}
@Attribute(LIBRARY_NAME_ATTRIBUTE)
public String getName() {
return myName;
public String getLibraryName() {
return myLibraryName;
}
public void setLibraryName(String libraryName) {
myLibraryName = libraryName;
}
@Attribute(MODULE_NAME_ATTRIBUTE)
public String getModuleName() {
return myModuleName;
}
public void setModuleName(String moduleName) {
myModuleName = moduleName;
}
@Override
public String toString() {
return "lib:" + myName + "(" + myLevel + ")";
}
public void setName(String name) {
myName = name;
return "lib:" + myLibraryName + "(" + (myModuleName != null ? "module " + myModuleName: myLevel ) + ")";
}
@Nullable
public Library findLibrary(@NotNull PackagingElementResolvingContext context) {
return LibraryLink.findLibrary(myName, myLevel, context.getProject());
if (myModuleName == null) {
return LibraryLink.findLibrary(myLibraryName, myLevel, context.getProject());
}
final ModulesProvider modulesProvider = context.getModulesProvider();
final Module module = modulesProvider.getModule(myModuleName);
if (module != null) {
for (OrderEntry entry : modulesProvider.getRootModel(module).getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entry;
if (libraryEntry.isModuleLevel()) {
final String libraryName = libraryEntry.getLibraryName();
if (libraryName != null && libraryName.equals(myLibraryName)) {
return libraryEntry.getLibrary();
}
}
}
}
}
return null;
}
public static PackagingElementOutputKind getKindForLibrary(final Library library) {
@@ -5,8 +5,11 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDialog;
import com.intellij.openapi.fileChooser.FileChooserFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.ui.Messages;
@@ -14,15 +17,14 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactPointerManager;
import com.intellij.packaging.elements.*;
import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
import com.intellij.packaging.ui.ArtifactEditorContext;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.ui.properties.ArchiveElementPropertiesPanel;
import com.intellij.packaging.impl.ui.properties.DirectoryElementPropertiesPanel;
import com.intellij.packaging.ui.ArtifactEditorContext;
import com.intellij.packaging.ui.PackagingElementPropertiesPanel;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Icons;
import com.intellij.util.PathUtil;
@@ -172,8 +174,15 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory {
@Override
public List<? extends PackagingElement<?>> 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<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>();
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
@@ -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);
}
}
@@ -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
@@ -81,11 +81,6 @@ public class ClasspathPanel extends JPanel {
private final EventDispatcher<OrderPanelListener> myListeners = EventDispatcher.create(OrderPanelListener.class);
private PopupAction[] myPopupActions = null;
private Icon[] myIcons = null;
private static final Comparator<Module> MODULES_COMPARATOR = new Comparator<Module>() {
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;
}
@@ -77,7 +77,7 @@ public class ArtifactConfigurable extends NamedConfigurable<Artifact> {
}
public String getHelpTopic() {
return null;
return "reference.settingsdialog.project.structure.artifacts";
}
@Override
@@ -79,7 +79,7 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
}
public List<Artifact> chooseArtifacts(final List<? extends Artifact> 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.<Artifact>emptyList();
}
@@ -118,14 +118,14 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
}
public List<Module> chooseModules(final List<Module> modules, final String title) {
ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, "");
ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, null);
dialog.show();
List<Module> selected = dialog.getChosenElements();
return dialog.isOK() ? selected : Collections.<Module>emptyList();
}
public List<Library> chooseLibraries(final List<Library> 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.<Library>emptyList();
}
@@ -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);
@@ -13,11 +13,7 @@ import java.util.List;
public class ChooseArtifactsDialog extends ChooseElementsDialog<Artifact> {
public ChooseArtifactsDialog(Project project, List<? extends Artifact> items, String title, String description) {
super(project, items, title, description);
}
public ChooseArtifactsDialog(JComponent component, String title, List<Artifact> items) {
super(component, items, title, true);
super(project, items, title, description, true);
}
protected String getItemText(Artifact item) {
@@ -21,11 +21,11 @@ import java.util.List;
public class ChooseModulesDialog extends ChooseElementsDialog<Module> {
public ChooseModulesDialog(Component parent, final List<Module> items, final String title) {
super(parent, items, title);
super(parent, items, title, null, true);
}
public ChooseModulesDialog(final Project project, final List<? extends Module> items, final String title, final String description) {
super(project, items, title, description);
super(project, items, title, description, true);
}
protected Icon getItemIcon(final Module item) {
@@ -470,11 +470,6 @@ public class LibraryTableEditor implements Disposable {
private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
final List<Module> modules = new ArrayList<Module>();
modules.addAll(Arrays.asList(rootConfigurable.getModules()));
Collections.sort(modules, new Comparator<Module>() {
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()));
@@ -16,11 +16,7 @@ import java.util.List;
public class ChooseLibrariesDialog extends ChooseElementsDialog<Library> {
public ChooseLibrariesDialog(Project project, List<? extends Library> items, String title, String description) {
super(project, items, title, description);
}
public ChooseLibrariesDialog(JComponent component, String title, List<Library> items) {
super(component, items, title, true);
super(project, items, title, description, true);
}
protected String getItemText(final Library item) {
@@ -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<RefElement> 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<UnusedCodeExtension> 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) {
@@ -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<String>) 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 <code>true</code> if annotated of at least one annotation from the annotations list
*/
public static boolean checkAnnotatedUsingPatterns(PsiModifierListOwner owner, Collection<String> annotations) {
List<String> 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<String>();
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;
}
}
+21
View File
@@ -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
+21
View File
@@ -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
@@ -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<TemplateGroup, TemplateGroup> 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(),
@@ -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<LookupItem> array = new ArrayList<LookupItem>();
List<TemplateImpl> matchingTemplates = new ArrayList<TemplateImpl>();
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<TemplateImpl> matchingTemplates) {
ArrayList<LookupItem> array = new ArrayList<LookupItem>();
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();
}
@@ -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<String, String> processor) {
public boolean startTemplate(final Editor editor, char shortcutChar, final PairProcessor<String, String> 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<TemplateImpl> 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<String, String> 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<TemplateImpl> filterApplicableCandidates(PsiFile file, int offset, List<TemplateImpl> candidates) {
List<TemplateImpl> result = new ArrayList<TemplateImpl>();
for (TemplateImpl candidate : candidates) {
if (isApplicable(file, offset, candidate)) {
result.add(candidate);
}
}
return result;
}
public TemplateContextType getContextType(@NotNull PsiFile file, int offset) {
@@ -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<Element>, Expo
private @NonNls static final String TEMPLATE = "template";
private @NonNls static final String DELETED_TEMPLATES = "deleted_templates";
private final List<String> myDeletedTemplates = new ArrayList<String>();
private final List<TemplateKey> myDeletedTemplates = new ArrayList<TemplateKey>();
public static final char SPACE_CHAR = ' ';
public static final char TAB_CHAR = '\t';
@@ -79,7 +80,8 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
private static final @NonNls String TEMPLATES_CONFIG_FOLDER = "templates";
private final Map<String,Template> myTemplates = new LinkedHashMap<String,Template>();
private final List<TemplateImpl> myAllTemplates = new ArrayList<TemplateImpl>();
private final MultiMap<String,TemplateImpl> myTemplates = new MultiMap<String,TemplateImpl>();
private final Map<String,Template> myTemplatesById = new LinkedHashMap<String,Template>();
private final Map<String,TemplateImpl> myDefaultTemplates = new LinkedHashMap<String, TemplateImpl>();
@@ -92,6 +94,20 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
private final SchemeProcessor<TemplateGroup> 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<Element>, 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<TemplateImpl> 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<Element>, 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<Element>, 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<Element>, Expo
myDefaultShortcutChar = defaultShortcutChar;
}
public TemplateImpl getTemplate(@NonNls String key) {
return (TemplateImpl) myTemplates.get(key);
public Collection<TemplateImpl> getTemplates(@NonNls String key) {
return myTemplates.get(key);
}
public TemplateImpl getTemplate(@NonNls String key, String group) {
final Collection<TemplateImpl> 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<Element>, 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<Element>, 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<Element>, 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<Element>, 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<Element>, 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<Element>, Expo
public List<TemplateGroup> getTemplateGroups() {
return mySchemesManager.getAllSchemes();
}
public List<TemplateImpl> collectMatchingCandidates(String key, char shortcutChar) {
final Collection<TemplateImpl> templates = getTemplates(key);
List<TemplateImpl> candidates = new ArrayList<TemplateImpl>();
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;
}
}
}
@@ -73,7 +73,7 @@ public class TemplateState implements Disposable {
private boolean myTemplateIndented = false;
private Document myDocument;
private boolean myFinished;
private PairProcessor<String, String> myProcessor;
@Nullable private PairProcessor<String, String> 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<String, String> processor) {
public void start(TemplateImpl template, @Nullable final PairProcessor<String, String> processor) {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
myProcessor = processor;
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
@@ -41,5 +41,11 @@ public interface ModuleSettings extends ComponentManagerSettings {
void addExcludedFolder(@NotNull File directory);
List<File> getModuleLibraryRootUrls(String libraryName);
@NotNull
List<File> getModuleLibraryRoots(String libraryName);
@NotNull
Collection<ModuleSettings> getAllModuleDependencies();
boolean hasModuleLibrary(String libraryName);
}
@@ -42,7 +42,8 @@ public class ConversionContextImpl implements ConversionContext {
private ProjectSettingsImpl myProjectSettings;
private WorkspaceSettingsImpl myWorkspaceSettings;
private List<File> myNonExistingModuleFiles = new ArrayList<File>();
private Map<File, ModuleSettingsImpl> myModuleSettingsMap = new HashMap<File, ModuleSettingsImpl>();
private Map<File, ModuleSettingsImpl> myFile2ModuleSettings = new HashMap<File, ModuleSettingsImpl>();
private Map<String, ModuleSettingsImpl> myName2ModuleSettings = new HashMap<String, ModuleSettingsImpl>();
private RunManagerSettingsImpl myRunManagerSettings;
private File mySettingsBaseDir;
private ComponentManagerSettings myCompilerManagerSettings;
@@ -175,6 +176,7 @@ public class ConversionContextImpl implements ConversionContext {
}
}
@NotNull
public List<File> getClassRoots(Element libraryElement, ModuleSettingsImpl moduleSettings) {
List<File> files = new ArrayList<File>();
//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<File> getNonExistingModuleFiles() {
return myNonExistingModuleFiles;
}
@@ -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<File> 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<File> getModuleLibraryRoots(String libraryName) {
final Element library = findModuleLibraryElement(libraryName);
return library != null ? myContext.getClassRoots(library, this) : Collections.<File>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<Element> getOrderEntries() {
final Element component = getComponentElement(MODULE_ROOT_MANAGER_COMPONENT);
return JDomConvertingUtil.getChildren(component, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME);
}
@NotNull
public Collection<ModuleSettings> getAllModuleDependencies() {
Set<ModuleSettings> dependencies = new HashSet<ModuleSettings>();
collectDependencies(dependencies);
return dependencies;
}
private void collectDependencies(Set<ModuleSettings> 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 {
@@ -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<VirtualFile> files = new LinkedHashSet<VirtualFile>();
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;
}
@@ -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<VirtualFile> files = new LinkedHashSet<VirtualFile>();
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;
}
@@ -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<PsiFile> PSI_FILE = new Key<PsiFile>("PSI for stubs");
@@ -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<T> extends DialogWrapper {
private String myDescription;
public ChooseElementsDialog(Project project, List<? extends T> items, String title, final String description) {
this(project, items, title, description, false);
}
public ChooseElementsDialog(Project project, List<? extends T> 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<T> items, String title) {
this(parent, items, title, false);
this(parent, items, title, null, false);
}
public ChooseElementsDialog(Component parent, List<T> items, String title, final boolean sort) {
public ChooseElementsDialog(Component parent, List<T> items, String title, @Nullable String description, final boolean sort) {
super(parent, true);
if (sort) {
Collections.sort(items, new Comparator<T>() {
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<? extends T> items, final String title) {
private void initializeDialog(final List<? extends T> items, final String title, boolean sort) {
setTitle(title);
myChooser = new ElementsChooser<T>(false) {
protected String getItemText(@NotNull final T item) {
@@ -52,7 +48,15 @@ public abstract class ChooseElementsDialog<T> extends DialogWrapper {
};
myChooser.setColorUnmarkedElements(false);
setElements(items, items.size() > 0 ? items.subList(0, 1) : Collections.<T>emptyList());
List<? extends T> elements = new ArrayList<T>(items);
if (sort) {
Collections.sort(elements, new Comparator<T>() {
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.<T>emptyList());
myChooser.getComponent().registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doOKAction();
@@ -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<String, Map<IFile, Element>> myStates = new HashMap<String, Map<IFile, Element>>();
private long myLastTimestamp = 0;
private MyStorageData myOriginalData;
public Set<String> 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<String, Map<IFile, Element>>(myStates);
result.myLastTimestamp = myLastTimestamp;
result.myOriginalData = this;
return result;
}
public void clear() {
myStates.clear();
myOriginalData = null;
}
public boolean containsComponent(final String componentName) {
@@ -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);
}
}
@@ -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<IOException> 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);
@@ -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
@@ -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) {
@@ -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;
}
}