From 7a613d9b9dab6e3291445ff2b39518cd8fa6b725 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 2 Dec 2009 12:57:34 +0300 Subject: [PATCH 1/5] verbose diagnostics for not found template --- .../impl/FileTemplateManagerImpl.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateManagerImpl.java index 941c89108a1e..b1dda7a1eaa5 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateManagerImpl.java @@ -597,9 +597,9 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo return getTemplateFromManager(templateName, myJ2eeTemplatesManager); } - private FileTemplate getTemplateFromManager(@NotNull @NonNls String templateName, @NotNull FileTemplateManagerImpl templatesManager) { + private static FileTemplate getTemplateFromManager(@NotNull @NonNls String templateName, @NotNull FileTemplateManagerImpl templatesManager) { String name = templateName; - String extension = myTypeManager.getExtension(name); + String extension = templatesManager.myTypeManager.getExtension(name); if (extension.length() > 0) { name = name.substring(0, name.length() - extension.length() - 1); } @@ -612,24 +612,39 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo else { if (ApplicationManager.getApplication().isUnitTestMode() && templateName.endsWith("ForTest")) return null; - String message = templateNotFound(templateName, templatesManager); + String message = templatesManager.templateNotFoundMessage(templateName); LOG.error(message); } return null; } - private static String templateNotFound(String templateName, FileTemplateManagerImpl templatesManager) { - Collection defaultTemplates = templatesManager.getDefaultTemplates(); + private String templateNotFoundMessage(String templateName) { + Collection defaultTemplates = getDefaultTemplates(); @NonNls String message = - "Unable to find template '" + templateName + "' in " + templatesManager + " in '"+templatesManager.myDefaultTemplatesDir+"'" + - "\n" + - "Default templates are: "; - message += StringUtil.join(defaultTemplates, new Function() { + "Unable to find template '" + templateName + "' in " + this + + "\n Default templates are: " + toString(defaultTemplates); + message+= "\n Default template dir: '"+ myDefaultTemplatesDir+"'"; + for (VirtualFile topDir : getTopTemplatesDir()) { + VirtualFile parentDir = myDefaultTemplatesDir.equals(".") ? topDir : topDir.findChild(myDefaultTemplatesDir); + if (parentDir == null) { + message += "\n No templates in '" + topDir.getPath() + "'"; + } + else { + message += "\n " + parentDir.getPath() + ": " + toString(listDir(parentDir)); + } + } + + message += "\n Deleted templates: " + myDeletedTemplatesManager.DELETED_DEFAULT_TEMPLATES; + + return message; + } + + private static String toString(Collection defaultTemplates) { + return StringUtil.join(defaultTemplates, new Function() { public String fun(VirtualFile virtualFile) { return virtualFile.getPresentableUrl(); } - }, ","); - return message; + }, ", "); } @@ -722,7 +737,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo if (file == null) { String message = ""; for (FileTemplateManagerImpl child : ArrayUtil.append(myChildren,this)) { - message += templateNotFound(name, child) + "\n"; + message += child.templateNotFoundMessage(name) + "\n"; } LOG.error(message); return null; From aadf0c3aebb1b1e4ec5818e581f98f6c687702ec Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 2 Dec 2009 14:14:18 +0300 Subject: [PATCH 2/5] ensure indexes up to date in tests --- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 8263966c0ac3..44f99146b3f5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -83,6 +83,7 @@ import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerImpl; +import com.intellij.psi.impl.cache.impl.todo.TodoIndex; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.resolve.FileContextUtil; @@ -1082,8 +1083,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull public static List instantiateAndRun(PsiFile file, Editor editor, int[] toIgnore, boolean allowDirt) { Project project = file.getProject(); - FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); - assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); + ensureIndexesUpToDate(project); FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap(); for (int ignoreId : toIgnore) { fileStatusMap.markFileUpToDate(editor.getDocument(), file, ignoreId); @@ -1111,6 +1111,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } } + private static void ensureIndexesUpToDate(Project project) { + FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); + FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); + assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); + } + public String getTestDataPath() { return myTestDataPath; } From 3e4bc80f5b1d3c54292c0e89049bfc54913cc6d7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 2 Dec 2009 17:34:44 +0300 Subject: [PATCH 3/5] do not show bulb for disabled intentions [nik] --- .../intention/IntentionManager.java | 38 ++++++++++++++----- .../daemon/impl/ShowIntentionsPass.java | 2 +- .../impl/config/IntentionManagerImpl.java | 38 +++++++++++++------ .../impl/config/PlainTextDescriptor.java | 7 +++- .../src/com/intellij/ui/LightweightHint.java | 5 +++ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/intention/IntentionManager.java b/platform/lang-api/src/com/intellij/codeInsight/intention/IntentionManager.java index 0d0ac47bfa7b..b5c9897b09eb 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/intention/IntentionManager.java +++ b/platform/lang-api/src/com/intellij/codeInsight/intention/IntentionManager.java @@ -42,7 +42,7 @@ public abstract class IntentionManager { */ @Deprecated public static IntentionManager getInstance(Project project) { - return ServiceManager.getService(IntentionManager.class); + return getInstance(); } public static IntentionManager getInstance() { @@ -54,15 +54,25 @@ public abstract class IntentionManager { * * @param action the intention action to register. */ - public abstract void addAction(IntentionAction action); + public abstract void addAction(@NotNull IntentionAction action); /** * Returns all registered intention actions. * * @return array of registered actions. */ + @NotNull public abstract IntentionAction[] getIntentionActions(); + /** + * Returns all registered intention actions which are available now + * (not disabled via Settings|Intentions or Alt-Enter|Disable intention quick fix) + * + * @return array of actions. + */ + @NotNull + public abstract IntentionAction[] getAvailableIntentionActions(); + /** * Registers an intention action which can be enabled or disabled through the "Intention * Settings" dialog. To provide the description and the example code for the intention, @@ -79,25 +89,32 @@ public abstract class IntentionManager { * @param category the name of the category or categories under which the intention will be shown * in the "Intention Settings" dialog. */ - public abstract void registerIntentionAndMetaData(IntentionAction action, String... category); + public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action, @NotNull String... category); /** - * @deprecated custom directory name causes problem with internationalization of inspection descriptions. + * @deprecated custom directory name causes problem with internationalization of intention descriptions. + * Register intention class via extension point {@link IntentionManager.EP_INTENTION_ACTIONS} instead. */ @Deprecated - public abstract void registerIntentionAndMetaData(IntentionAction action, String[] category, String descriptionDirectoryName); + public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action, + @NotNull String[] category, + @NotNull String descriptionDirectoryName); - public abstract void registerIntentionAndMetaData(IntentionAction action, String[] category, - String description, String exampleFileExtension, - String[] exampleTextBefore, String[] exampleTextAfter); + public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action, + @NotNull String[] category, + @NotNull String description, + @NotNull String exampleFileExtension, + @NotNull String[] exampleTextBefore, + @NotNull String[] exampleTextAfter); - public abstract void unregisterIntention(IntentionAction intentionAction); + public abstract void unregisterIntention(@NotNull IntentionAction intentionAction); /** * @return actions used as additional options for the given problem. * E.g. actions for suppress the problem via comment, javadoc or annotation, * and edit corresponding inspection settings. */ + @NotNull public abstract List getStandardIntentionOptions(@NotNull HighlightDisplayKey displayKey, @NotNull PsiElement context); /** @@ -105,5 +122,6 @@ public abstract class IntentionManager { * @param action action to convert. * @return quick fix instance. */ - public abstract LocalQuickFix convertToFix(IntentionAction action); + @NotNull + public abstract LocalQuickFix convertToFix(@NotNull IntentionAction action); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java index 82aeb3423aaa..d24c827650c6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java @@ -190,7 +190,7 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass { int offset = editor.getCaretModel().getOffset(); Project project = psiFile.getProject(); - for (IntentionAction action : IntentionManager.getInstance().getIntentionActions()) { + for (IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) { Pair place = ShowIntentionActionsHandler.availableFor(psiFile, editor, action, psiElement); if (place != null) { List enableDisableIntentionAction = new ArrayList(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java index e2fe36e585cd..35050e89d68f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java @@ -108,7 +108,7 @@ public class IntentionManagerImpl extends IntentionManager { return new IntentionActionWrapper(intentionActionBean,categories); } - public void registerIntentionAndMetaData(IntentionAction action, String... category) { + public void registerIntentionAndMetaData(@NotNull IntentionAction action, @NotNull String... category) { registerIntentionAndMetaData(action, category, getDescriptionDirectoryName(action)); } @@ -132,12 +132,12 @@ public class IntentionManagerImpl extends IntentionManager { mySettings.registerIntentionMetaData(action, category, descriptionDirectoryName); } - public void registerIntentionAndMetaData(final IntentionAction action, - final String[] category, - final String description, - final String exampleFileExtension, - final String[] exampleTextBefore, - final String[] exampleTextAfter) { + public void registerIntentionAndMetaData(@NotNull final IntentionAction action, + @NotNull final String[] category, + @NotNull final String description, + @NotNull final String exampleFileExtension, + @NotNull final String[] exampleTextBefore, + @NotNull final String[] exampleTextAfter) { addAction(action); IntentionActionMetaData metaData = new IntentionActionMetaData(action, category, @@ -148,19 +148,20 @@ public class IntentionManagerImpl extends IntentionManager { } @Override - public void unregisterIntention(IntentionAction intentionAction) { + public void unregisterIntention(@NotNull IntentionAction intentionAction) { myActions.remove(intentionAction); mySettings.unregisterMetaData(intentionAction); } - private static TextDescriptor[] mapToDescriptors(String[] texts, String fileName) { + private static TextDescriptor[] mapToDescriptors(String[] texts, @NonNls String fileName) { TextDescriptor[] result = new TextDescriptor[texts.length]; for (int i = 0; i < texts.length; i++) { - result [i] = new PlainTextDescriptor(texts [i], fileName); + result [i] = new PlainTextDescriptor(texts[i], fileName); } return result; } + @NotNull public List getStandardIntentionOptions(@NotNull final HighlightDisplayKey displayKey, @NotNull final PsiElement context) { List options = new ArrayList(9); options.add(new EditInspectionToolsSettingsAction(displayKey)); @@ -169,7 +170,8 @@ public class IntentionManagerImpl extends IntentionManager { return options; } - public LocalQuickFix convertToFix(final IntentionAction action) { + @NotNull + public LocalQuickFix convertToFix(@NotNull final IntentionAction action) { if (action instanceof LocalQuickFix) { return (LocalQuickFix)action; } @@ -196,12 +198,24 @@ public class IntentionManagerImpl extends IntentionManager { }; } - public void addAction(IntentionAction action) { + public void addAction(@NotNull IntentionAction action) { myActions.add(action); } + @NotNull public IntentionAction[] getIntentionActions() { return myActions.toArray(new IntentionAction[myActions.size()]); } + @NotNull + @Override + public IntentionAction[] getAvailableIntentionActions() { + List list = new ArrayList(myActions.size()); + for (IntentionAction action : myActions) { + if (mySettings.isEnabled(action)) { + list.add(action); + } + } + return list.toArray(new IntentionAction[list.size()]); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/PlainTextDescriptor.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/PlainTextDescriptor.java index 8939ad2c7732..c2c4421c131f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/PlainTextDescriptor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/PlainTextDescriptor.java @@ -16,6 +16,9 @@ package com.intellij.codeInsight.intention.impl.config; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + import java.io.IOException; /** @@ -25,15 +28,17 @@ public class PlainTextDescriptor implements TextDescriptor { private final String myText; private final String myFileName; - public PlainTextDescriptor(final String text, final String fileName) { + public PlainTextDescriptor(@NotNull String text, @NonNls @NotNull String fileName) { myText = text; myFileName = fileName; } + @NotNull public String getText() throws IOException { return myText; } + @NotNull public String getFileName() { return myFileName; } diff --git a/platform/platform-impl/src/com/intellij/ui/LightweightHint.java b/platform/platform-impl/src/com/intellij/ui/LightweightHint.java index 8533c9f2b1bf..fee011278f7f 100644 --- a/platform/platform-impl/src/com/intellij/ui/LightweightHint.java +++ b/platform/platform-impl/src/com/intellij/ui/LightweightHint.java @@ -226,4 +226,9 @@ public class LightweightHint extends UserDataHolderBase implements Hint { hide(); } } + + @Override + public String toString() { + return getComponent().toString(); + } } From 06edb7695ad1c6dea15a2fcac0e3c41a3c34526f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 2 Dec 2009 17:36:39 +0300 Subject: [PATCH 4/5] do not hide intention bulb when hovering over other tooltips [nik] --- .../codeInsight/hint/LineTooltipRenderer.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java index 8cd93fd594b0..cb1e903f019e 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java @@ -61,30 +61,13 @@ public class LineTooltipRenderer implements TooltipRenderer { //setup text myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), ""); - final boolean [] expanded = new boolean[] { myCurrentWidth > 0 && dressDescription(editor)}; + final boolean expanded = myCurrentWidth > 0 && dressDescription(editor); //pane final JEditorPane pane = initPane(myText); pane.setCaretPosition(0); final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); final JComponent contentComponent = editor.getContentComponent(); - // This listener makes hint transparent for mouse events. It means that hint is closed - // by MousePressed and this MousePressed goes into the underlying editor component. - pane.addMouseListener(new MouseAdapter() { - public void mouseReleased(final MouseEvent e) { - if (!myActiveLink) { - MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent); - hintManager.hideAllHints(); - contentComponent.dispatchEvent(newMouseEvent); - } - } - - public void mouseExited(final MouseEvent e) { - if (!expanded[0]) { - hintManager.hideAllHints(); - } - } - }); final JComponent editorComponent = editor.getComponent(); final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane(); @@ -94,8 +77,8 @@ public class LineTooltipRenderer implements TooltipRenderer { final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane); scrollPane.setBorder(null); - int width = expanded[0] ? 3 * myCurrentWidth / 2 : pane.getPreferredSize().width; - int height = expanded[0] ? Math.max(pane.getPreferredSize().height, 150) : pane.getPreferredSize().height; + int width = expanded ? 3 * myCurrentWidth / 2 : pane.getPreferredSize().width; + int height = expanded ? Math.max(pane.getPreferredSize().height, 150) : pane.getPreferredSize().height; if (alignToRight) { p.x -= width; @@ -166,7 +149,7 @@ public class LineTooltipRenderer implements TooltipRenderer { return; } if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - if (!expanded[0]) { // more -> less + if (!expanded) { // more -> less for (final TooltipLinkHandlerEP handlerEP : Extensions.getExtensions(TooltipLinkHandlerEP.EP_NAME)) { if (handlerEP.handleLink(e.getDescription(), editor, pane)) { myText = convertTextOnLinkHandled(myText); @@ -189,6 +172,25 @@ public class LineTooltipRenderer implements TooltipRenderer { } } }); + + // This listener makes hint transparent for mouse events. It means that hint is closed + // by MousePressed and this MousePressed goes into the underlying editor component. + pane.addMouseListener(new MouseAdapter() { + public void mouseReleased(final MouseEvent e) { + if (!myActiveLink) { + MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent); + hint.hide(); + contentComponent.dispatchEvent(newMouseEvent); + } + } + + public void mouseExited(final MouseEvent e) { + if (!expanded) { + hint.hide(); + } + } + }); + hintManager.showEditorHint(hint, editor, p, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, 0, false); @@ -260,9 +262,7 @@ public class LineTooltipRenderer implements TooltipRenderer { final LineTooltipRenderer lineTooltipRenderer = (LineTooltipRenderer)o; - if (myText != null ? !myText.equals(lineTooltipRenderer.myText) : lineTooltipRenderer.myText != null) return false; - - return true; + return myText == null ? lineTooltipRenderer.myText == null : myText.equals(lineTooltipRenderer.myText); } public int hashCode() { From cc66b3b79f01289f808d47abdb5aeab44987043c Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 3 Dec 2009 10:43:57 +0300 Subject: [PATCH 5/5] tests hang --- .../intellij/refactoring/rename/RenameHandlerRegistry.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java index 1b3a45b30633..3bbec4f6c2d2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java @@ -18,6 +18,7 @@ package com.intellij.refactoring.rename; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -77,6 +78,9 @@ public class RenameHandlerRegistry { if (availableHandlers.size() == 1) return availableHandlers.values().iterator().next(); if (availableHandlers.size() > 1) { final String[] strings = availableHandlers.keySet().toArray(new String[availableHandlers.keySet().size()]); + if (ApplicationManager.getApplication().isUnitTestMode()) { + return availableHandlers.get(strings[strings.length - 1]); + } final HandlersChooser chooser = new HandlersChooser(PlatformDataKeys.PROJECT.getData(dataContext), strings); chooser.show(); if (chooser.isOK()) {