From 79d895e243a2b177eb482d9c89c3bfc85a2507dd Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 16 Dec 2011 12:22:10 +0100 Subject: [PATCH 01/10] rename: ability to force select all --- .../rename/RenameHandlerRegistry.java | 2 ++ .../inplace/VariableInplaceRenamer.java | 8 ++--- .../spellchecker/quickfixes/RenameTo.java | 29 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) 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 41456d26e959..f29a9f00186c 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java @@ -24,6 +24,7 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler; @@ -44,6 +45,7 @@ import java.util.TreeMap; * @author dsl */ public class RenameHandlerRegistry { + public static final Key SELECT_ALL = Key.create("rename.selectAll"); private final Set myHandlers = new HashSet(); private static final RenameHandlerRegistry INSTANCE = new RenameHandlerRegistry(); private final PsiElementRenameHandler myDefaultElementRenameHandler; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index 43f7a295a184..5d19eb3a39eb 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -72,10 +72,7 @@ import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilBase; import com.intellij.refactoring.RefactoringBundle; -import com.intellij.refactoring.rename.AutomaticRenamingDialog; -import com.intellij.refactoring.rename.NameSuggestionProvider; -import com.intellij.refactoring.rename.RenameProcessor; -import com.intellij.refactoring.rename.RenameUtil; +import com.intellij.refactoring.rename.*; import com.intellij.refactoring.rename.naming.AutomaticRenamer; import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory; import com.intellij.refactoring.util.CommonRefactoringUtil; @@ -465,7 +462,8 @@ public class VariableInplaceRenamer { } protected boolean shouldSelectAll() { - return false; + final Boolean selectAll = myEditor.getUserData(RenameHandlerRegistry.SELECT_ALL); + return selectAll != null && selectAll.booleanValue(); } protected void navigateToAlreadyStarted(Document oldDocument, int exitCode) { diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java index 7df80f0edfa8..2bf1a9205d96 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java @@ -25,12 +25,12 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.refactoring.actions.RenameElementAction; import com.intellij.refactoring.rename.NameSuggestionProvider; +import com.intellij.refactoring.rename.RenameHandlerRegistry; import com.intellij.spellchecker.util.SpellCheckerBundle; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; @@ -104,21 +104,20 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { ) ); } - - DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent())); - AnAction action = new RenameElementAction(); - final boolean hadSelection = editor.getSelectionModel().hasSelection(); - final TextRange range = psiElement.getTextRange(); - if (range != null) { - editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); + + final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL); + try { + editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true); + DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent())); + AnAction action = new RenameElementAction(); + AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0); + action.actionPerformed(event); + if (provider != null) { + provider.setActive(false); + } } - AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0); - action.actionPerformed(event); - if (provider != null) { - provider.setActive(false); - } - if (!hadSelection) { - editor.getSelectionModel().removeSelection(); + finally { + editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll); } } }; From b2d651f9ae8494f4ba03f26a18f2b7c191244d87 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 15 Dec 2011 17:53:38 +0400 Subject: [PATCH 02/10] EA-32620 - IAE: VisualPosition. Debug info is added --- .../openapi/editor/LogicalPosition.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/LogicalPosition.java b/platform/platform-api/src/com/intellij/openapi/editor/LogicalPosition.java index 3afce0f163f7..84e000db407b 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/LogicalPosition.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/LogicalPosition.java @@ -87,12 +87,12 @@ public class LogicalPosition implements Comparable { */ public final int foldingColumnDiff; - public LogicalPosition(int line, int column) { + public LogicalPosition(int line, int column) throws IllegalArgumentException { this(line, column, 0, 0, 0, 0, 0, false); } public LogicalPosition(int line, int column, int softWrapLinesBeforeCurrentLogicalLine, int softWrapLinesOnCurrentLogicalLine, - int softWrapColumnDiff, int foldedLines, int foldingColumnDiff) + int softWrapColumnDiff, int foldedLines, int foldingColumnDiff) throws IllegalArgumentException { this( line, column, softWrapLinesBeforeCurrentLogicalLine, softWrapLinesOnCurrentLogicalLine, softWrapColumnDiff, foldedLines, @@ -102,7 +102,16 @@ public class LogicalPosition implements Comparable { private LogicalPosition(int line, int column, int softWrapLinesBeforeCurrentLogicalLine, int softWrapLinesOnCurrentLogicalLine, int softWrapColumnDiff, int foldedLines, int foldingColumnDiff, boolean visualPositionAware) - { + throws IllegalArgumentException { + if (column + softWrapColumnDiff + foldingColumnDiff < 0) { + throw new IllegalArgumentException(String.format( + "Attempt to create %s with invalid arguments - resulting column is negative (%d). Given arguments: line=%d, column=%d, " + + "soft wrap lines before: %d, soft wrap lines current: %d, soft wrap column diff: %d, folded lines: %d, folding column " + + "diff: %d, visual position aware: %b", + getClass().getName(), column + softWrapColumnDiff + foldingColumnDiff, line, column, softWrapLinesBeforeCurrentLogicalLine, + softWrapLinesOnCurrentLogicalLine, softWrapColumnDiff, foldedLines, foldingColumnDiff, visualPositionAware + )); + } this.line = line; this.column = column; this.softWrapLinesBeforeCurrentLogicalLine = softWrapLinesBeforeCurrentLogicalLine; @@ -147,9 +156,9 @@ public class LogicalPosition implements Comparable { ? "" : "; soft wrap: lines=" + (softWrapLinesBeforeCurrentLogicalLine + softWrapLinesOnCurrentLogicalLine) + " (before=" + softWrapLinesBeforeCurrentLogicalLine + "; current=" + softWrapLinesOnCurrentLogicalLine + ")") - + (softWrapColumnDiff == 0 ? "" : "columns diff=" + softWrapColumnDiff + ";" ) - + (foldedLines == 0? "" : " folding: lines = " + foldedLines + ";") - + (foldingColumnDiff == 0 ? "" : " columns diff=" + foldingColumnDiff); + + (softWrapColumnDiff == 0 ? "" : "; columns diff=" + softWrapColumnDiff + ";" ) + + (foldedLines == 0? "" : "; folding: lines = " + foldedLines + ";") + + (foldingColumnDiff == 0 ? "" : "; columns diff=" + foldingColumnDiff); } public int compareTo(LogicalPosition position) { From 02ef56a2259bc9949ed6491e8f50a8f47ec867e9 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 16 Dec 2011 16:20:56 +0400 Subject: [PATCH 03/10] EA-29579 - assert: CaretModelImpl.moveToOffset Don't report nested caret move if it changes position at soft wrap-introduced virtual space --- .../openapi/editor/impl/CaretModelImpl.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index b11b88efc34b..ec7206e3fad2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -542,8 +542,26 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, "Adjusting caret position by moving it before soft wrap. Moving to visual position %s%n", visualPosition )); } - moveToVisualPosition(visualPosition); - return; + final LogicalPosition logicalPosition = myEditor.visualToLogicalPosition(visualPosition); + final int tmpOffset = myEditor.logicalPositionToOffset(logicalPosition); + if (tmpOffset == myOffset) { + boolean restore = myReportCaretMoves; + myReportCaretMoves = false; + try { + moveToVisualPosition(visualPosition); + return; + } + finally { + myReportCaretMoves = restore; + } + } + else { + LogMessageEx.error(LOG, "Invalid editor dimension mapping", String.format( + "Expected to map visual position '%s' to offset %d but got the following: -> logical position '%s'; -> offset %d. " + + "State: %s", visualPosition, myOffset, logicalPosition, tmpOffset, myEditor.dumpState() + )); + } + } } From cf6806b673ddeb2cadd3b56e9bb10d82497bf525 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 16 Dec 2011 13:42:50 +0100 Subject: [PATCH 04/10] fix tests --- .../intellij/execution/junit/TestPackage.java | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 884fe6db8bd9..3c75043754eb 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -94,39 +94,7 @@ public class TestPackage extends TestObject { @Override public void startNotified(ProcessEvent event) { super.startNotified(event); - final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); - final TestClassFilter filter; - try { - filter = getClassFilter(data); - } - catch (CantRunException e) { - //should not happen - return; - } - tasks[0] = findTestsWithProgress(new FindCallback() { - public void found(@NotNull final Collection classes, final boolean isJunit4) { - try { - addClassesListToJavaParameters(classes, new Function() { - @Nullable - public String fun(PsiElement element) { - if (element instanceof PsiClass) { - return JavaExecutionUtil.getRuntimeQualifiedName((PsiClass)element); - } - else if (element instanceof PsiMethod) { - PsiMethod method = (PsiMethod)element; - return JavaExecutionUtil.getRuntimeQualifiedName(method.getContainingClass()) + "," + method.getName(); - } - else { - return null; - } - } - }, getPackage(data).getQualifiedName(), false, isJunit4); - } - catch (CantRunException e) { - //can't be here - } - } - }, filter); + tasks[0] = (MySearchForTestsTask)findTests(); } @Override @@ -142,6 +110,43 @@ public class TestPackage extends TestObject { return handler; } + public Task findTests() { + final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); + final TestClassFilter filter; + try { + filter = getClassFilter(data); + } + catch (CantRunException e) { + //should not happen + return null; + } + + return findTestsWithProgress(new FindCallback() { + public void found(@NotNull final Collection classes, final boolean isJunit4) { + try { + addClassesListToJavaParameters(classes, new Function() { + @Nullable + public String fun(PsiElement element) { + if (element instanceof PsiClass) { + return JavaExecutionUtil.getRuntimeQualifiedName((PsiClass)element); + } + else if (element instanceof PsiMethod) { + PsiMethod method = (PsiMethod)element; + return JavaExecutionUtil.getRuntimeQualifiedName(method.getContainingClass()) + "," + method.getName(); + } + else { + return null; + } + } + }, getPackage(data).getQualifiedName(), false, isJunit4); + } + catch (CantRunException e) { + //can't be here + } + } + }, filter); + } + protected void initialize() throws ExecutionException { super.initialize(); final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); From 922a4963001d8389e5c0c41dfb970e35aa96ebdc Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 16 Dec 2011 13:55:22 +0100 Subject: [PATCH 05/10] Correct wording for safe write option --- .../src/com/intellij/ide/GeneralSettingsPanel.form | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsPanel.form b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsPanel.form index 88a1158b41c5..3bef6a650100 100644 --- a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsPanel.form +++ b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsPanel.form @@ -149,8 +149,8 @@ - - + + From 5ddc6b6ee6815fe2abe1b858f570af4a7df758c2 Mon Sep 17 00:00:00 2001 From: "kirill.safonov" Date: Fri, 16 Dec 2011 18:16:46 +0400 Subject: [PATCH 06/10] Change signature dialog table: correctly add and remove cell editor listeners (IDEA-78550) --- .../ChangeSignatureDialogBase.java | 28 +++++++++++++------ .../ui/CodeFragmentTableCellEditorBase.java | 4 +++ .../refactoring/ui/StringTableCellEditor.java | 4 +++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java index f8174fc869b2..fa324b0344e2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java @@ -65,10 +65,8 @@ import javax.swing.table.TableCellEditor; import java.awt.*; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.Collections; +import java.util.*; import java.util.List; -import java.util.Set; /** * @author Konstantin Bulenkov @@ -370,16 +368,30 @@ public abstract class ChangeSignatureDialogBase

>(myParametersTableModel) { + + public void removeEditor() { + clearEditorListeners(); + super.removeEditor(); + } + @Override public void editingStopped(ChangeEvent e) { super.editingStopped(e); repaint(); // to update disabled cells background } - @Nullable - @Override - public TableCellEditor getCellEditor(final int row, final int column) { - final TableCellEditor editor = super.getCellEditor(row, column); + private void clearEditorListeners() { + final TableCellEditor editor = getCellEditor(); + if (editor instanceof StringTableCellEditor) { + final StringTableCellEditor ed = (StringTableCellEditor)editor; + ed.clearListeners(); + } + else if (editor instanceof CodeFragmentTableCellEditorBase) { + ((CodeFragmentTableCellEditorBase)editor).clearListeners(); + } + } + + public Component prepareEditor(final TableCellEditor editor, final int row, final int column) { final DocumentAdapter listener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { @@ -400,7 +412,7 @@ public abstract class ChangeSignatureDialogBase

Date: Fri, 16 Dec 2011 15:26:32 +0100 Subject: [PATCH 07/10] rename: replace the whole expression if lookup is chosen --- .../rename/inplace/VariableInplaceRenamer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index 5d19eb3a39eb..3d55f6b6d605 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -15,6 +15,8 @@ */ package com.intellij.refactoring.rename.inplace; +import com.intellij.codeInsight.completion.InsertHandler; +import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; import com.intellij.codeInsight.highlighting.HighlightManager; @@ -824,7 +826,21 @@ public class VariableInplaceRenamer { myLookupItems = new LookupElement[names.size()]; final Iterator iterator = names.iterator(); for (int i = 0; i < myLookupItems.length; i++) { - myLookupItems[i] = LookupElementBuilder.create(iterator.next()); + final String suggestion = iterator.next(); + myLookupItems[i] = LookupElementBuilder.create(suggestion).setInsertHandler(new InsertHandler() { + @Override + public void handleInsert(InsertionContext context, LookupElement item) { + if (shouldSelectAll()) return; + final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor); + final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor); + if (templateState != null) { + final TextRange range = templateState.getCurrentVariableRange(); + if (range != null) { + myEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), suggestion); + } + } + } + }); } } From 8fba9c66bcc81d17d852b404223c6345db3f05bb Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 16 Dec 2011 15:31:33 +0100 Subject: [PATCH 08/10] don't close the quick doc when selecting another lookup element by mouse (IDEA-64008) --- .../codeInsight/documentation/DocumentationManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java index abe3fc8b8f5d..4b5cae8b6ec4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java @@ -297,7 +297,8 @@ public class DocumentationManager { } }, keyboardShortcut != null ? keyboardShortcut.getFirstKeyStroke() : null)); // Null keyStroke is ok here - final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component) + boolean hasLookup = LookupManager.getActiveLookup(myEditor) != null; + final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component) .setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE) .setProject(project) .addListener(updateProcessor) @@ -308,6 +309,7 @@ public class DocumentationManager { .setResizable(true) .setMovable(true) .setRequestFocus(requestFocus) + .setCancelOnClickOutside(!hasLookup) // otherwise selecting lookup items by mouse would close the doc .setTitle(getTitle(element, false)) .setCouldPin(pinCallback) .setCancelCallback(new Computable() { From 2b5d768064c211e865b031a9d0dc86b2a4c47766 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 16 Dec 2011 15:56:16 +0100 Subject: [PATCH 09/10] IDEA-78075 Notifications: notifications with 'log=false' should expire when closed or hidden --- .../impl/NotificationsManagerImpl.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java index c349a82ff8dd..9e7841e21960 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java @@ -136,11 +136,20 @@ public class NotificationsManagerImpl extends NotificationsManager implements No } final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(notification.getGroupId()); - if (settings.isShouldLog() && settings.getDisplayType() != NotificationDisplayType.NONE) { + boolean shouldLog = settings.isShouldLog(); + boolean displayable = settings.getDisplayType() != NotificationDisplayType.NONE; + if (shouldLog && displayable) { myModel.add(notification, project); } - showWhenVisible(notification, project); + boolean willBeShown = displayable && NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS; + if (!shouldLog && !willBeShown) { + notification.expire(); + } + + if (NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS) { + showWhenVisible(notification, project); + } } private static void showWhenVisible(final Notification notification, final Project project) { @@ -187,8 +196,18 @@ public class NotificationsManagerImpl extends NotificationsManager implements No case STICKY_BALLOON: case BALLOON: default: - if (NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS) { - notifyByBalloon(notification, type, project); + Balloon balloon = notifyByBalloon(notification, type, project); + if (!settings.isShouldLog()) { + if (balloon == null) { + notification.expire(); + } else { + balloon.addListener(new JBPopupAdapter() { + @Override + public void onClosed(LightweightWindowEvent event) { + notification.expire(); + } + }); + } } break; case TOOL_WINDOW: @@ -216,10 +235,11 @@ public class NotificationsManagerImpl extends NotificationsManager implements No } } - private static void notifyByBalloon(final Notification notification, + @Nullable + private static Balloon notifyByBalloon(final Notification notification, final NotificationDisplayType displayType, @Nullable final Project project) { - if (ApplicationManager.getApplication().isUnitTestMode()) return; + if (ApplicationManager.getApplication().isUnitTestMode()) return null; Window window = findWindowForBalloon(project); if (window instanceof IdeFrameImpl) { @@ -240,7 +260,9 @@ public class NotificationsManagerImpl extends NotificationsManager implements No } }); } + return balloon; } + return null; } @Nullable From f10baa830bb733443c6387ae93c53a7e9199dc0e Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 16 Dec 2011 17:13:03 +0100 Subject: [PATCH 10/10] IDEA-69920 Support additional imports added by the Griffon compiler --- plugins/gradle/src/META-INF/plugin.xml | 1 + .../GradleDefaultImportContributor.java | 62 ++++++++++ .../gradle/config/GradleScriptType.java | 31 ----- plugins/groovy/src/META-INF/plugin.xml | 2 + .../GriffonDefaultImportContributor.java | 114 ++++++++++++++++++ .../groovy/lang/psi/impl/GroovyFileImpl.java | 13 +- .../resolve/DefaultImportContributor.java | 35 ++++++ 7 files changed, 222 insertions(+), 36 deletions(-) create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonDefaultImportContributor.java create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/DefaultImportContributor.java diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 9dea0a91e319..d317fcd0aece 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -46,6 +46,7 @@ + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java new file mode 100644 index 000000000000..21da0843bebe --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.config; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.extensions.GroovyScriptTypeDetector; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author peter + */ +public class GradleDefaultImportContributor extends DefaultImportContributor { + + @Override + public List appendImplicitlyImportedPackages(@NotNull GroovyFile file) { + if (file.isScript() && GroovyScriptTypeDetector.getScriptType(file) instanceof GradleScriptType) { + return Arrays.asList( + "org.gradle", + "org.gradle.util", + "org.gradle.api", + "org.gradle.api.artifacts", + "org.gradle.api.artifacts.dsl", + "org.gradle.api.artifacts.specs", + "org.gradle.api.dependencies", + "org.gradle.api.execution", + "org.gradle.api.file", + "org.gradle.api.logging", + "org.gradle.api.initialization", + "org.gradle.api.invocation", + "org.gradle.api.plugins", + "org.gradle.api.plugins.quality", + "org.gradle.api.specs", + "org.gradle.api.tasks", + "org.gradle.api.tasks.bundling", + "org.gradle.api.tasks.compile", + "org.gradle.api.tasks.javadoc", + "org.gradle.api.tasks.testing", + "org.gradle.api.tasks.util", + "org.gradle.api.tasks.wrapper" + ); + } + return Collections.emptyList(); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleScriptType.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleScriptType.java index ad65a832013a..1bbe0aeabd1b 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleScriptType.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleScriptType.java @@ -57,9 +57,7 @@ import org.jetbrains.plugins.groovy.util.GroovyUtils; import javax.swing.*; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -279,33 +277,4 @@ public class GradleScriptType extends GroovyScriptType { return result; } - - @Override - public List appendImplicitImports(@NotNull GroovyFile file) { - return Arrays.asList( - "org.gradle", - "org.gradle.util", - "org.gradle.api", - "org.gradle.api.artifacts", - "org.gradle.api.artifacts.dsl", - "org.gradle.api.artifacts.specs", - "org.gradle.api.dependencies", - "org.gradle.api.execution", - "org.gradle.api.file", - "org.gradle.api.logging", - "org.gradle.api.initialization", - "org.gradle.api.invocation", - "org.gradle.api.plugins", - "org.gradle.api.plugins.quality", - "org.gradle.api.specs", - "org.gradle.api.tasks", - "org.gradle.api.tasks.bundling", - "org.gradle.api.tasks.compile", - "org.gradle.api.tasks.javadoc", - "org.gradle.api.tasks.testing", - "org.gradle.api.tasks.util", - "org.gradle.api.tasks.wrapper" - - ); - } } diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 0bf08464e550..85c4a56a3cc8 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -29,6 +29,7 @@ + @@ -117,6 +118,7 @@ + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonDefaultImportContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonDefaultImportContributor.java new file mode 100644 index 000000000000..8a2f59d81848 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonDefaultImportContributor.java @@ -0,0 +1,114 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.griffon; + +import com.intellij.lang.properties.IProperty; +import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiPackage; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.CachedValueProvider; +import com.intellij.psi.util.CachedValuesManager; +import com.intellij.psi.util.PsiModificationTracker; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor; +import org.jetbrains.plugins.groovy.mvc.MvcFramework; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author peter + */ +public class GriffonDefaultImportContributor extends DefaultImportContributor { + + private Pair, List> getDefaultImports(@NotNull final Module module) { + return CachedValuesManager.getManager(module.getProject()).getCachedValue(module, new CachedValueProvider, List>>() { + @Override + public Result, List>> compute() { + PsiPackage aPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage("META-INF"); + if (aPackage != null) { + for (PsiDirectory directory : aPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module))) { + PsiFile file = directory.findFile("griffon-default-imports.properties"); + if (file instanceof PropertiesFile) { + List modelImports = tokenize(((PropertiesFile)file).findPropertyByKey("models")); + List viewImports = tokenize(((PropertiesFile)file).findPropertyByKey("views")); + return Result.create(Pair.create(modelImports, viewImports), PsiModificationTracker.MODIFICATION_COUNT); + } + } + } + + return Result.create(new Pair, List>(new ArrayList(), new ArrayList()), + PsiModificationTracker.MODIFICATION_COUNT); + } + + private List tokenize(IProperty models) { + List modelImports = new ArrayList(); + if (models != null) { + String value = models.getValue(); + if (value != null) { + String[] split = value.split(", "); + for (String s : split) { + modelImports.add(StringUtil.trimEnd(s, ".")); + } + } + } + return modelImports; + } + }); + } + + @Override + public List appendImplicitlyImportedPackages(@NotNull GroovyFile file) { + Module module = ModuleUtil.findModuleForPsiElement(file); + MvcFramework framework = MvcFramework.getInstance(module); + if (framework instanceof GriffonFramework) { + ArrayList result = new ArrayList(); + result.add("griffon.core"); + result.add("griffon.util"); + + VirtualFile griffonApp = framework.findAppDirectory(file); + if (griffonApp != null) { + VirtualFile models = griffonApp.findChild("models"); + VirtualFile views = griffonApp.findChild("views"); + VirtualFile vFile = file.getOriginalFile().getVirtualFile(); + + assert vFile != null; + assert module != null; + if (models != null && VfsUtilCore.isAncestor(models, vFile, true)) { + result.addAll(getDefaultImports(module).first); + } + else if (views != null && VfsUtilCore.isAncestor(views, vFile, true)) { + result.addAll(getDefaultImports(module).second); + } + } + + return result; + } + + return Collections.emptyList(); + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java index 3dd8327bd876..9c7ac07496bb 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java @@ -24,7 +24,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.ElementBase; -import com.intellij.psi.impl.file.PsiPackageImpl; import com.intellij.psi.scope.DelegatingScopeProcessor; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.stubs.StubElement; @@ -55,12 +54,14 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter; import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFileStub; +import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor; import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint; import javax.swing.*; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; /** @@ -222,12 +223,14 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile { } - private List getImplicitlyImportedPackages() { - final ArrayList result = new ArrayList(); + private LinkedHashSet getImplicitlyImportedPackages() { + final LinkedHashSet result = new LinkedHashSet(); ContainerUtil.addAll(result, IMPLICITLY_IMPORTED_PACKAGES); - if (isScript()) { - result.addAll(GroovyScriptTypeDetector.getScriptType(this).appendImplicitImports(this)); + + for (DefaultImportContributor contributor : DefaultImportContributor.EP_NAME.getExtensions()) { + result.addAll(contributor.appendImplicitlyImportedPackages(this)); } + return result; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/DefaultImportContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/DefaultImportContributor.java new file mode 100644 index 000000000000..98710b0888de --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/DefaultImportContributor.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.lang.resolve; + +import com.intellij.openapi.extensions.ExtensionPointName; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; + +import java.util.Collections; +import java.util.List; + +/** + * @author peter + */ +public abstract class DefaultImportContributor { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("org.intellij.groovy.defaultImportContributor"); + + public List appendImplicitlyImportedPackages(@NotNull GroovyFile file) { + return Collections.emptyList(); + } + +}