From ef14ea4d80bd21a8546efdc41e345a9a8dafad27 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 12 Nov 2010 19:58:15 +0300 Subject: [PATCH 01/33] cosmetics changes --- .../ide/util/TreeJavaClassChooserDialog.java | 4 ++-- .../ide/util/AbstractTreeClassChooserDialog.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/util/TreeJavaClassChooserDialog.java b/java/java-impl/src/com/intellij/ide/util/TreeJavaClassChooserDialog.java index 0b89a178b24d..e7468e299420 100644 --- a/java/java-impl/src/com/intellij/ide/util/TreeJavaClassChooserDialog.java +++ b/java/java-impl/src/com/intellij/ide/util/TreeJavaClassChooserDialog.java @@ -107,8 +107,8 @@ public class TreeJavaClassChooserDialog extends AbstractTreeClassChooserDialog

getInheritorsProvider() { - return new JavaInheritorsProvider(getProject(), getBaseClass(), getScope()); + protected BaseClassInheritorsProvider getInheritorsProvider(@NotNull PsiClass baseClass) { + return new JavaInheritorsProvider(getProject(), baseClass, getScope()); } private static class JavaInheritorsProvider extends BaseClassInheritorsProvider { diff --git a/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java b/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java index 5d9ee72c7f6a..35c223ff3e20 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java @@ -260,12 +260,12 @@ abstract public class AbstractTreeClassChooserDialog protected ChooseByNameModel createChooseByNameModel() { if (myBaseClass == null) { - return new MyGotoClassModel(myProject, this); + return new MyGotoClassModel(myProject, this); } else { - BaseClassInheritorsProvider inheritorsProvider = getInheritorsProvider(); + BaseClassInheritorsProvider inheritorsProvider = getInheritorsProvider(myBaseClass); if (inheritorsProvider != null) { - return new SubclassGotoClassModel(myProject, this, inheritorsProvider); + return new SubclassGotoClassModel(myProject, this, inheritorsProvider); } else { throw new IllegalStateException("inheritors provider is null"); @@ -273,8 +273,14 @@ abstract public class AbstractTreeClassChooserDialog } } + /** + * Makes sense only in case of not null base class. + * + * @param baseClass + * @return + */ @Nullable - protected abstract BaseClassInheritorsProvider getInheritorsProvider(); + protected abstract BaseClassInheritorsProvider getInheritorsProvider(@NotNull T baseClass); private void handleSelectionChanged() { T selection = calcSelectedClass(); From 74adee9ee803f524c27bcfc96feffe9aa9130f3f Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 12 Nov 2010 20:00:46 +0300 Subject: [PATCH 02/33] cosmetics changes --- .../com/intellij/ide/util/AbstractTreeClassChooserDialog.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java b/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java index 35c223ff3e20..c15c45356bb5 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/AbstractTreeClassChooserDialog.java @@ -280,7 +280,9 @@ abstract public class AbstractTreeClassChooserDialog * @return */ @Nullable - protected abstract BaseClassInheritorsProvider getInheritorsProvider(@NotNull T baseClass); + protected BaseClassInheritorsProvider getInheritorsProvider(@NotNull T baseClass) { + return null; + } private void handleSelectionChanged() { T selection = calcSelectedClass(); From 472cab1e79ba5f5e373b9805a56af32956f129c8 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 14:42:43 +0300 Subject: [PATCH 03/33] clean up --- .../org/jetbrains/android/compiler/AndroidPackagingCompiler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java index e3d2a7790615..64011b818627 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java @@ -79,6 +79,7 @@ public class AndroidPackagingCompiler implements PackagingCompiler { } } + @NotNull private static VirtualFile[] getSourceRootsForModuleAndDependencies(@NotNull Module module) { Set result = new HashSet(); fillSourceRoots(module, new HashSet(), result); From ccd6c9544ccd7e7317538e07bfd1856fc2a92a74 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 15:16:00 +0300 Subject: [PATCH 04/33] IDEA-61072 correct importing of manifest and resourceDir paths when they are filtered --- .../android/maven/AndroidFacetImporter.java | 74 +++++++++++++++++-- .../maven/AndroidMavenProviderImpl.java | 59 +++++++++++++++ .../maven/compiler/MavenResourceCompiler.java | 2 +- 3 files changed, 126 insertions(+), 9 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/maven/AndroidFacetImporter.java b/plugins/android/src/org/jetbrains/android/maven/AndroidFacetImporter.java index 72e61c597654..5b41168a1c68 100644 --- a/plugins/android/src/org/jetbrains/android/maven/AndroidFacetImporter.java +++ b/plugins/android/src/org/jetbrains/android/maven/AndroidFacetImporter.java @@ -24,6 +24,7 @@ import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import org.jdom.Element; import org.jetbrains.android.facet.AndroidFacet; @@ -34,6 +35,7 @@ import org.jetbrains.android.sdk.AndroidPlatform; import org.jetbrains.android.sdk.AndroidSdk; import org.jetbrains.android.sdk.EmptySdkLog; import org.jetbrains.android.util.AndroidUtils; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.importing.FacetImporter; import org.jetbrains.idea.maven.importing.MavenModifiableModelsProvider; @@ -139,11 +141,12 @@ public class AndroidFacetImporter extends FacetImporter includes = MavenResourceCompiler.collectPatterns(resource.getIncludes(), "**/*"); + List excludes = MavenResourceCompiler.collectPatterns(resource.getExcludes(), null); + String targetPath = FileUtil.toSystemIndependentName(resource.getTargetPath()); + + if (processResources(module.getProject(), resDir, resDir, includes, excludes, targetPath, processor)) { + return true; + } + } + } + return false; + } + + static boolean processResources(Project project, + VirtualFile sourceRoot, + VirtualFile file, + List includes, + List excludes, + String resOutputDir, + ResourceProcessor processor) { + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + if (!fileIndex.isIgnored(file)) { + String relPath = VfsUtil.getRelativePath(file, sourceRoot, '/'); + if (relPath != null && MavenUtil.isIncluded(relPath, includes, excludes)) { + if (processor.process(file, resOutputDir + "/" + relPath)) { + return true; + } + } + } + if (file.isDirectory()) { + for (VirtualFile child : file.getChildren()) { + if (processResources(project, sourceRoot, child, includes, excludes, resOutputDir, processor)) { + return true; + } + } + } + return false; + } + @Override public boolean isMavenizedModule(@NotNull Module module) { MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(module.getProject()); @@ -125,4 +180,8 @@ public class AndroidMavenProviderImpl implements AndroidMavenProvider { } return false; } + + interface ResourceProcessor { + boolean process(@NotNull VirtualFile resource, @NotNull String outputPath); + } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java index 3fd96aee6893..6448129cfbad 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java @@ -262,7 +262,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { } } - private List collectPatterns(List values, String defaultValue) { + public static List collectPatterns(List values, String defaultValue) { List result = new ArrayList(); if (values == null || values.isEmpty()) { if (defaultValue == null) return Collections.emptyList(); From 12f14c91ee6269dcc7f9f6eb8ef3e90eb73fbbe4 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 16:06:51 +0300 Subject: [PATCH 05/33] error messages about debugger status --- .../android/run/AndroidApplicationLauncher.java | 3 ++- .../jetbrains/android/run/AndroidRunConfiguration.java | 10 ++++++++-- .../org/jetbrains/android/run/AndroidRunningState.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidApplicationLauncher.java b/plugins/android/src/org/jetbrains/android/run/AndroidApplicationLauncher.java index 1d833d50ad8a..00c58793e59d 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidApplicationLauncher.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidApplicationLauncher.java @@ -18,6 +18,7 @@ package org.jetbrains.android.run; import com.android.ddmlib.ClientData; import com.android.ddmlib.IDevice; +import com.intellij.execution.process.ProcessHandler; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -32,7 +33,7 @@ import java.io.IOException; public abstract class AndroidApplicationLauncher { public abstract boolean launch(@NotNull AndroidRunningState state, @NotNull IDevice device) throws IOException; - public boolean isReadyForDebugging(ClientData data) { + public boolean isReadyForDebugging(ClientData data, ProcessHandler processHandler) { return data.getDebuggerConnectionStatus() == ClientData.DebuggerStatus.WAITING; } } diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfiguration.java b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfiguration.java index 6f550d4860f2..64dd0fc2cb42 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunConfiguration.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunConfiguration.java @@ -176,21 +176,27 @@ public class AndroidRunConfiguration extends AndroidRunConfigurationBase impleme @SuppressWarnings({"EnumSwitchStatementWhichMissesCases"}) @Override - public boolean isReadyForDebugging(ClientData data) { + public boolean isReadyForDebugging(ClientData data, ProcessHandler processHandler) { if (myActivityName == null) { ClientData.DebuggerStatus status = data.getDebuggerConnectionStatus(); switch (status) { case ERROR: + if (processHandler != null) { + processHandler.notifyTextAvailable("Debug port is busy", STDOUT); + } LOG.info("Debug port is busy"); return false; case ATTACHED: + if (processHandler != null) { + processHandler.notifyTextAvailable("Debugger already attached", STDOUT); + } LOG.info("Debugger already attached"); return false; default: return true; } } - return super.isReadyForDebugging(data); + return super.isReadyForDebugging(data, processHandler); } public boolean launch(@NotNull AndroidRunningState state, @NotNull IDevice device) throws IOException { diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java index 01e0121a8f6b..84720f46f9d5 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidRunningState.java @@ -405,7 +405,7 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb } private void launchDebug(Client client) { - if (myDebugLauncher != null && myApplicationLauncher.isReadyForDebugging(client.getClientData())) { + if (myDebugLauncher != null && myApplicationLauncher.isReadyForDebugging(client.getClientData(), getProcessHandler())) { String port = Integer.toString(client.getDebuggerListenPort()); myDebugLauncher.launchDebug(client.getDevice(), port); myDebugLauncher = null; From b82a0938ba3e2b11ee27f4e7416355e175a887c0 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 16:29:38 +0300 Subject: [PATCH 06/33] EA-23467 fix "already disposed" --- .../org/jetbrains/android/newProject/AndroidModuleBuilder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java index 1440af8ca59d..0de3ee1561ef 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java @@ -220,6 +220,9 @@ public class AndroidModuleBuilder extends JavaModuleBuilder { @Override public void run() { try { + if (project.isDisposed()) { + return; + } if (myProjectType == ProjectType.APPLICATION) { Manifest manifest = facet.getManifest(); if (manifest != null && myApplicationName.length() > 0) { From 406a42195b1a310a24072d853d54dddd599df7b6 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 16:34:54 +0300 Subject: [PATCH 07/33] EA-23357 fix "already disposed" --- .../android/dom/AndroidResourceDomFileDescription.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/android/src/org/jetbrains/android/dom/AndroidResourceDomFileDescription.java b/plugins/android/src/org/jetbrains/android/dom/AndroidResourceDomFileDescription.java index 8352d0d2a83b..8ff8a6facf0f 100644 --- a/plugins/android/src/org/jetbrains/android/dom/AndroidResourceDomFileDescription.java +++ b/plugins/android/src/org/jetbrains/android/dom/AndroidResourceDomFileDescription.java @@ -51,6 +51,9 @@ public abstract class AndroidResourceDomFileDescription ex public boolean isMyFile(@NotNull final XmlFile file, @Nullable Module module) { return ApplicationManager.getApplication().runReadAction(new Computable() { public Boolean compute() { + if (file.getProject().isDisposed()) { + return false; + } for (String resourceType : myResourceTypes) { if (ResourceManager.isInResourceSubdirectory(file, resourceType)) { return AndroidFacet.getInstance(file) != null; From f2a06998ba003e957bbf1c65fd2638266c2689aa Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 15:11:43 +0300 Subject: [PATCH 08/33] assertion expanded --- .../com/intellij/util/xml/impl/PhysicalDomParentStrategy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java index afaa453d1bbd..65d13fdb34d5 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java @@ -84,7 +84,7 @@ public class PhysicalDomParentStrategy implements DomParentStrategy { if (myElement != thatElement) { final PsiElement nav1 = myElement.getNavigationElement(); final PsiElement nav2 = thatElement.getNavigationElement(); - assert nav1 == nav2 : nav1 + "!=" + nav2; + assert nav1 == nav2 : nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset(); } return true; } From d5c838a3e8109b736218ca76d2d9da325ab37a5b Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 18:00:52 +0300 Subject: [PATCH 09/33] when doing runtime type casting in the debugger evaluation, use allScope for resolving --- .../codeInsight/completion/JavaCompletionUtil.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java index f0588fb2a53c..5a7f23960f39 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java @@ -618,17 +618,20 @@ public class JavaCompletionUtil { if (qualifier != null) { final Project project = qualifier.getProject(); final PairFunction evaluator = refExpr.getContainingFile().getCopyableUserData(DYNAMIC_TYPE_EVALUATOR); + PsiReferenceExpression context = refExpr; PsiType type = null; if (evaluator != null) { type = evaluator.fun(qualifier, parameters); + context = null; } if (type == null) { type = GuessManager.getInstance(project).getControlFlowExpressionType(qualifier); + context = refExpr; } if (type != null) { processor.clear(); - return addQualifierCastingVariants(processor, refExpr, type, set); + return addQualifierCastingVariants(processor, refExpr, type, set, context); } } } @@ -637,13 +640,13 @@ public class JavaCompletionUtil { private static PsiType addQualifierCastingVariants(JavaCompletionProcessor processor, PsiReferenceExpression refExpr, PsiType castTo, - THashSet set) { + THashSet set, final PsiReferenceExpression context) { Project project = refExpr.getProject(); PsiExpression qualifier = refExpr.getQualifierExpression(); assert qualifier != null; final String newText = "((" + castTo.getCanonicalText() + ") " + qualifier.getText() + ")." + refExpr.getReferenceName(); - final PsiExpression newRef = JavaPsiFacade.getElementFactory(project).createExpressionFromText(newText, refExpr); + final PsiExpression newRef = JavaPsiFacade.getElementFactory(project).createExpressionFromText(newText, context); ((PsiReferenceExpression)newRef).processVariants(processor); final LookupElement castItem = PsiTypeLookupItem.createLookupItem(castTo, refExpr); @@ -785,6 +788,9 @@ public class JavaCompletionUtil { public static boolean containsMethodCalls(@Nullable final PsiElement qualifier) { if (qualifier == null) return false; if (qualifier instanceof PsiMethodCallExpression) return true; + if (qualifier instanceof PsiArrayAccessExpression) { + return containsMethodCalls(((PsiArrayAccessExpression)qualifier).getArrayExpression()); + } return containsMethodCalls(getQualifier(qualifier)); } From 536a54736e4a729b7c2646ecbbb25cf03656d2ea Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 12:50:49 +0300 Subject: [PATCH 10/33] read access (EA-22404) --- .../intellij/find/findUsages/JavaFindUsagesHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java index ea368ffc712b..61935766ea7e 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java @@ -349,7 +349,13 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ if (element instanceof PomTarget) { addAliasingUsages((PomTarget)element, processor, options); } - if (!ThrowSearchUtil.isSearchable(element) && options.isSearchForTextOccurrences && options.searchScope instanceof GlobalSearchScope) { + final Boolean isSearchable = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public Boolean compute() { + return ThrowSearchUtil.isSearchable(element); + } + }); + if (!isSearchable && options.isSearchForTextOccurrences && options.searchScope instanceof GlobalSearchScope) { // todo add to fastTrack processUsagesInText(element, processor, (GlobalSearchScope)options.searchScope); } From 4c57d286a720474301f3eb5abfbada7c6cf23d49 Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 13:15:55 +0300 Subject: [PATCH 11/33] introduce: remember choice if success --- .../refactoring/introduceVariable/IntroduceVariableBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index fdb2e6363fca..a6f499f28ecc 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -459,7 +459,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme final Pass callback = new Pass() { @Override - public void pass(OccurrencesChooser.ReplaceChoice choice) { + public void pass(final OccurrencesChooser.ReplaceChoice choice) { final Ref> variable = new Ref>(); final IntroduceVariableSettings settings = getSettings(project, editor, expr, occurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, choice); @@ -509,13 +509,13 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme startOffset = editor.getDocument().getLineEndOffset(editor.getDocument().getLineNumber(startOffset)); } editor.getCaretModel().moveToOffset(startOffset); + typeSelectorManager.typeSelected(ReassignVariableUtil.getVariableType(declarationStatement)); } editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, null); for (RangeMarker occurrenceMarker : occurrenceMarkers) { occurrenceMarker.dispose(); } editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY, null); - typeSelectorManager.typeSelected(ReassignVariableUtil.getVariableType(declarationStatement)); exprMarker.dispose(); } }); From 83ed87001f01580d22b6b588e7b78b692be693ee Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 16:28:36 +0300 Subject: [PATCH 12/33] inplace introduce: adjust final: local setting --- .../IntroduceVariableBase.java | 66 +++++++++++++++++-- .../ReassignVariableUtil.java | 20 +++++- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index a6f499f28ecc..e4158eb5f8fc 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -28,8 +28,11 @@ import com.intellij.codeInsight.completion.JavaCompletionUtil; import com.intellij.codeInsight.highlighting.HighlightManager; import com.intellij.codeInsight.intention.impl.TypeExpression; import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.template.*; +import com.intellij.codeInsight.template.impl.TemplateManagerImpl; +import com.intellij.codeInsight.template.impl.TextExpression; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.util.PropertiesComponent; import com.intellij.lang.LanguageRefactoringSupport; @@ -49,6 +52,8 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.*; +import com.intellij.psi.impl.PsiVariableEx; +import com.intellij.psi.impl.java.stubs.PsiModifierListStub; import com.intellij.psi.impl.source.tree.java.ReplaceExpressionUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -487,26 +492,37 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, declarationStatement); editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY, occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()])); + final boolean cantChangeFinalModifier = hasWriteAccess || (inFinalContext && choice == OccurrencesChooser.ReplaceChoice.ALL); final VariableInplaceRenamer renamer = new VariableInplaceRenamer(elementToRename, editor){ @Override protected void addAdditionalVariables(TemplateBuilderImpl builder) { final PsiTypeElement typeElement = elementToRename.getTypeElement(); builder.replaceElement(typeElement, "Variable_Type", - ReassignVariableUtil.createExpression(expression, typeElement.getText()), false, true); + ReassignVariableUtil.createExpression(expression, typeElement.getText(), !cantChangeFinalModifier), false, true); + if (!cantChangeFinalModifier) { + builder.replaceElement(elementToRename.getModifierList(), "_FINAL_", new FinalExpression(project), false, true); + } } }; renamer.setAdvertisementText( - ReassignVariableUtil.getAdvertisementText(editor, declarationStatement, elementToRename.getType(), typeSelectorManager.getTypesForAll())); + ReassignVariableUtil.getAdvertisementText(editor, declarationStatement, elementToRename.getType(), typeSelectorManager.getTypesForAll(), !cantChangeFinalModifier)); renamer.performInplaceRename(false, new LinkedHashSet(Arrays.asList(suggestedName.names)), new Consumer() { @Override public void consume(Boolean apply) { if (apply) { + final Document document = editor.getDocument(); + final PsiVariable psiVariable = + PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiVariable.class); + if (psiVariable != null) { + JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL); + FinalExpression.adjustLine(psiVariable, document); + } int startOffset = exprMarker.getStartOffset(); final PsiReference referenceAt = file.findReferenceAt(startOffset); if (referenceAt != null && referenceAt.resolve() instanceof PsiLocalVariable) { startOffset = referenceAt.getElement().getTextRange().getEndOffset(); } else { - startOffset = editor.getDocument().getLineEndOffset(editor.getDocument().getLineNumber(startOffset)); + startOffset = document.getLineEndOffset(document.getLineNumber(startOffset)); } editor.getCaretModel().moveToOffset(startOffset); typeSelectorManager.typeSelected(ReassignVariableUtil.getVariableType(declarationStatement)); @@ -803,8 +819,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme replaceChoice == OccurrencesChooser.ReplaceChoice.ALL || replaceChoice == OccurrencesChooser.ReplaceChoice.NO_WRITE; final boolean declareFinal = !anyAssignmentLHS && (replaceAll && - declareFinalIfAll || - CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS); + declareFinalIfAll || createFinals(project)); final boolean replaceWrite = anyAssignmentLHS && replaceChoice == OccurrencesChooser.ReplaceChoice.ALL; return new IntroduceVariableSettings() { @Override @@ -840,6 +855,11 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme }; } + private static boolean createFinals(Project project) { + final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS; + return createFinals == null ? CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS : createFinals.booleanValue(); + } + public interface Validator { boolean isOK(IntroduceVariableSettings dialog); } @@ -863,4 +883,40 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme conflicts.putValue(occurence, RefactoringBundle.message("introducing.variable.may.break.code.logic")); } } + + private static class FinalExpression extends Expression { + private final Project myProject; + + public FinalExpression(Project project) { + myProject = project; + } + + @Override + public Result calculateResult(ExpressionContext context) { + return new TextResult(createFinals(myProject) ? PsiKeyword.FINAL : ""); + } + + @Override + public Result calculateQuickResult(ExpressionContext context) { + return calculateResult(context); + } + + @Override + public LookupElement[] calculateLookupItems(ExpressionContext context) { + LookupElement[] lookupElements = new LookupElement[2]; + lookupElements[0] = LookupElementBuilder.create(""); + lookupElements[1] = LookupElementBuilder.create(PsiModifier.FINAL + " "); + return lookupElements; + } + + public static void adjustLine(final PsiVariable psiVariable, final Document document) { + final int modifierListOffset = psiVariable.getTextRange().getStartOffset(); + final int varLineNumber = document.getLineNumber(modifierListOffset); + ApplicationManager.getApplication().runWriteAction(new Runnable() { //adjust line indent if final was inserted and then deleted + public void run() { + CodeStyleManager.getInstance(psiVariable.getProject()).adjustLineIndent(document, document.getLineStartOffset(varLineNumber)); + } + }); + } + } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/ReassignVariableUtil.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/ReassignVariableUtil.java index a812ec211c41..f3c1f4b9006d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/ReassignVariableUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/ReassignVariableUtil.java @@ -174,7 +174,7 @@ public class ReassignVariableUtil { } @Nullable - static String getAdvertisementText(Editor editor, PsiDeclarationStatement declaration, PsiType type, PsiType[] typesForAll) { + static String getAdvertisementText(Editor editor, PsiDeclarationStatement declaration, PsiType type, PsiType[] typesForAll, boolean canAdjustFinal) { final VariablesProcessor processor = findVariablesOfType(editor, declaration, type); final Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); if (processor.size() > 0) { @@ -189,10 +189,21 @@ public class ReassignVariableUtil { return "Press " + shortcuts[0] + " to change type"; } } + return adjustFinalText(canAdjustFinal); + } + + @Nullable + private static String adjustFinalText(boolean canBeFinalAdjusted) { + if (canBeFinalAdjusted) { + final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("PreviousTemplateVariable"); + if (shortcuts.length > 0) { + return "Press " + shortcuts[0] + " to adjust final modifier"; + } + } return null; } - public static Expression createExpression(final TypeExpression expression, final String defaultType) { + public static Expression createExpression(final TypeExpression expression, final String defaultType, final boolean canBeFinalAdjusted) { return new Expression() { @Override public com.intellij.codeInsight.template.Result calculateResult(ExpressionContext context) { @@ -208,6 +219,11 @@ public class ReassignVariableUtil { public LookupElement[] calculateLookupItems(ExpressionContext context) { return expression.calculateLookupItems(context); } + + @Override + public String getAdvertisingText() { + return adjustFinalText(canBeFinalAdjusted); + } }; } } From d9f9a44bb675938bbbb59ede45a24c5861227d82 Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 17:25:15 +0300 Subject: [PATCH 13/33] inline redundant array creation: preserve comments (IDEA-61141 ) --- .../intellij/refactoring/util/InlineUtil.java | 8 ++- .../quickFix/PreserveComments.java | 8 +++ .../quickFix/PreserveComments_after.java | 7 ++ ...undantArray4VarargsCallInspectionTest.java | 69 +++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments.java create mode 100644 java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments_after.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInspection/RedundantArray4VarargsCallInspectionTest.java diff --git a/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java b/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java index a79be5cf89d4..044493afcecb 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java @@ -186,7 +186,13 @@ public class InlineUtil { PsiExpression[] initializers = arrayInitializer.getInitializers(); if (initializers.length > 0) { - argumentList.addRange(initializers[0], initializers[initializers.length - 1]); + PsiElement lastInitializerSibling = initializers[initializers.length - 1]; + while (lastInitializerSibling != null) { + final PsiElement nextSibling = lastInitializerSibling.getNextSibling(); + if (nextSibling.getNode().getElementType() == JavaTokenType.RBRACE) break; + lastInitializerSibling = nextSibling; + } + argumentList.addRange(initializers[0], lastInitializerSibling); } args[args.length - 1].delete(); } diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments.java b/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments.java new file mode 100644 index 000000000000..854b0a445812 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments.java @@ -0,0 +1,8 @@ +class Test { + void foo(String... strs){} + void bar() { + foo(new String[] { + "edwqefwe", //my comment + }); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments_after.java b/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments_after.java new file mode 100644 index 000000000000..d118e7501ce0 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/quickFix/PreserveComments_after.java @@ -0,0 +1,7 @@ +class Test { + void foo(String... strs){} + void bar() { + foo("edwqefwe", //my comment + ); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArray4VarargsCallInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArray4VarargsCallInspectionTest.java new file mode 100644 index 000000000000..f35305a8d60a --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArray4VarargsCallInspectionTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2010 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 com.intellij.codeInspection; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInspection.miscGenerics.RedundantArrayForVarargsCallInspection; +import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.fixtures.*; +import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; + +/** + * User: anna + * Date: 11/13/10 + */ +public class RedundantArray4VarargsCallInspectionTest extends UsefulTestCase { + protected CodeInsightTestFixture myFixture; + private RedundantArrayForVarargsCallInspection myInspection; + + @Override + protected void setUp() throws Exception { + super.setUp(); + IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory(); + TestFixtureBuilder fixtureBuilder = factory.createLightFixtureBuilder(new DefaultLightProjectDescriptor()); + final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture(); + myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, + new LightTempDirTestFixtureImpl(true)); + myInspection = new RedundantArrayForVarargsCallInspection(); + myFixture.enableInspections(myInspection); + myFixture.setUp(); + myFixture.setTestDataPath(getTestDataPath()); + } + + @Override + protected void tearDown() throws Exception { + myFixture.tearDown(); + myFixture = null; + myInspection = null; + super.tearDown(); + } + + public void testPreserveComments() { + doTest(); + } + + private void doTest() { + myFixture.configureByFile(getTestName(false) + ".java"); + myFixture.launchAction(assertOneElement(myFixture.filterAvailableIntentions(InspectionsBundle.message("inspection.redundant.array.creation.quickfix")))); + myFixture.checkResultByFile(getTestName(false) + "_after.java"); + } + + + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/inspection/redundantArrayForVarargs/quickFix"; + } + +} \ No newline at end of file From 64915b026ce16ffbbfe38a3dfe40a95faf20b7ca Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Sat, 13 Nov 2010 18:22:55 +0300 Subject: [PATCH 14/33] text in statusbar fix --- .../daemon/impl/StatusBarUpdater.java | 7 +++++++ .../problems/WolfTheProblemSolverImpl.java | 20 +++++++++---------- .../intellij/openapi/wm/ex/StatusBarEx.java | 3 +++ .../openapi/wm/impl/TestWindowManager.java | 5 +++++ .../wm/impl/status/IdeStatusBarImpl.java | 11 +++++++++- .../wm/impl/status/InfoAndProgressPanel.java | 16 ++++++++++----- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/StatusBarUpdater.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/StatusBarUpdater.java index 7f1dc2435509..da03072428fc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/StatusBarUpdater.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/StatusBarUpdater.java @@ -57,6 +57,13 @@ public class StatusBarUpdater implements Disposable { updateLater(); } }); + + project.getMessageBus().connect().subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListener() { + @Override + public void daemonFinished() { + updateLater(); + } + }); } private void updateLater() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java index 13b505597f61..c6c651faeded 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java @@ -34,10 +34,7 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatusListener; import com.intellij.openapi.vcs.FileStatusManager; @@ -53,6 +50,7 @@ import gnu.trove.THashMap; import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -239,7 +237,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } pass.setProgressLimit(progressLimit); final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); - String oldInfo = saveStatusBarInfo(statusBar); + Pair oldInfo = saveStatusBarInfo(statusBar); try { for (final VirtualFile virtualFile : files) { progress.checkCanceled(); @@ -313,19 +311,21 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return true; } - private static String saveStatusBarInfo(final StatusBar statusBar) { - String oldInfo = null; + @Nullable + private static Pair saveStatusBarInfo(final StatusBar statusBar) { + Pair oldInfo = null; if (statusBar instanceof StatusBarEx) { - oldInfo = statusBar.getInfo(); + oldInfo = Pair.create(statusBar.getInfo(), ((StatusBarEx)statusBar).getInfoRequestor()); } + return oldInfo; } - private static void restoreStatusBarInfo(final StatusBar statusBar, final String oldInfo) { + private static void restoreStatusBarInfo(final StatusBar statusBar, final Pair oldInfo) { if (statusBar instanceof StatusBarEx) { LaterInvocator.invokeLater(new Runnable() { public void run() { - statusBar.setInfo(oldInfo); + statusBar.setInfo(oldInfo.first, oldInfo.second); } }); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java b/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java index c5bfcccec57a..f6920f33b941 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java @@ -50,4 +50,7 @@ public interface StatusBarEx extends StatusBar, Disposable { Dimension getSize(); boolean isVisible(); + + @Nullable + String getInfoRequestor(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java index 5b8093414a0e..babc5365212f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java @@ -103,6 +103,11 @@ public final class TestWindowManager extends WindowManagerEx implements Applicat public void setInfo(@Nullable String s, @Nullable String requestor) { } + @Override + public String getInfoRequestor() { + return null; + } + public boolean isVisible() { return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java index 8703a993e592..6ae6be7a762b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.ui.popup.BalloonHandler; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.CustomStatusBarWidget; @@ -69,6 +70,7 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx { private JPanel myCenterPanel; private String myInfo; + private String myRequestor; private List myCustomComponentIds = new ArrayList(); @@ -377,7 +379,9 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx { UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { if (myInfoAndProgressPanel != null) { - myInfo = myInfoAndProgressPanel.setText(s, requestor); + Pair pair = myInfoAndProgressPanel.setText(s, requestor); + myInfo = pair.first; + myRequestor = pair.second; } } }); @@ -387,6 +391,11 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx { return myInfo; } + @Override + public String getInfoRequestor() { + return myRequestor; + } + public void addProgress(ProgressIndicatorEx indicator, TaskInfo info) { myInfoAndProgressPanel.addProgress(indicator, info); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java index d58ef3bbe5cd..fea8ed9a7443 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java @@ -16,7 +16,9 @@ package com.intellij.openapi.wm.impl.status; import com.intellij.idea.ActionsBundle; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.TaskInfo; import com.intellij.openapi.ui.MessageType; @@ -24,6 +26,7 @@ import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.BalloonHandler; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.MultiValuesMap; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.CustomStatusBarWidget; @@ -49,7 +52,10 @@ import javax.swing.event.HyperlinkListener; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidget { private final ProcessPopup myPopup; @@ -330,17 +336,17 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge myRefreshAndInfoPanel.repaint(); } - public String setText(final String text, final String requestor) { + public Pair setText(final String text, final String requestor) { if (text == null || text.length() == 0) { if ((requestor != null && !requestor.equals(myCurrentRequestor)) || (myCurrentRequestor != null && !myCurrentRequestor.equals(requestor))) { - return myInfoPanel.getText(); + return Pair.create(myInfoPanel.getText(), myCurrentRequestor); } } myInfoPanel.setText(text); myCurrentRequestor = requestor; - return text; + return Pair.create(text, requestor); } public void setRefreshVisible(final boolean visible) { From 4eed30b7f3d098087ce3856620016f68a337a81e Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 18:34:13 +0300 Subject: [PATCH 15/33] don't focus autopopup (whatever there is) in java&groovy comments --- .../completion/UnfocusedComments.java | 33 +++++++++++++++++++ plugins/groovy/src/META-INF/plugin.xml | 1 + resources/src/META-INF/IdeaPlugin.xml | 1 + 3 files changed, 35 insertions(+) create mode 100644 platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java new file mode 100644 index 000000000000..0372a0e00941 --- /dev/null +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2010 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 com.intellij.codeInsight.completion; + +import com.intellij.psi.PsiComment; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; + +/** + * @author peter + */ +public class UnfocusedComments extends CompletionConfidence { + @Override + public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { + if (PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiComment.class) != null) { + return false; + } + return null; + } +} diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 727436fd6114..e04ecf31d5d5 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -182,6 +182,7 @@ + diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index b472d5100535..46131f2b8817 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -231,6 +231,7 @@ id="excludeFromCompletion" order="last"/> + Date: Sat, 13 Nov 2010 18:37:00 +0300 Subject: [PATCH 16/33] License agreement dialog UI fixed --- .../src/messages/LicenseCommonBundle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/messages/LicenseCommonBundle.properties b/platform/platform-resources-en/src/messages/LicenseCommonBundle.properties index 8d1a6ea7d742..299312b036d2 100644 --- a/platform/platform-resources-en/src/messages/LicenseCommonBundle.properties +++ b/platform/platform-resources-en/src/messages/LicenseCommonBundle.properties @@ -2,5 +2,5 @@ license.agreement.title=License Agreement license.agreement.title.for=License Agreement for {0} button.ok=OK button.cancel=Cancel -license.agreement.prompt=Please read the following license agreement carefully.\nTo proceed you must agree to all terms of this license\nby checking the checkbox +license.agreement.prompt=Please read the following license agreement carefully.
To proceed you must agree to all terms of this license by checking the checkbox. license.agreement.accept.checkbox=Accept all terms of the license \ No newline at end of file From 40cb6ce7666f041bf344a6d4dcfc45aefc9e4b16 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Sat, 13 Nov 2010 19:01:06 +0300 Subject: [PATCH 17/33] L&F manager API cleanup --- .../src/com/intellij/find/EditorSearchComponent.java | 5 ++--- .../platform-api/src/com/intellij/ide/ui/LafManager.java | 6 ++++++ .../platform-api/src/com/intellij/ui/SearchTextField.java | 3 +-- .../openapi/wm/impl/status/InlineProgressIndicator.java | 3 +-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java index 2998bae49291..0269ac05030f 100644 --- a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java +++ b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java @@ -23,7 +23,6 @@ import com.intellij.codeInsight.highlighting.HighlightManager; import com.intellij.codeInsight.highlighting.HighlightManagerImpl; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.find.impl.FindManagerImpl; -import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.Editor; @@ -55,6 +54,7 @@ import com.intellij.ui.components.JBList; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -114,8 +114,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider { protected void paintBorder(final Graphics g) { super.paintBorder(g); - final LafManager lafManager = LafManager.getInstance(); - if (!(lafManager.isUnderAquaLookAndFeel() || lafManager.isUnderQuaquaLookAndFeel()) && isFocusOwner()) { + if (!(UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderQuaquaLookAndFeel()) && isFocusOwner()) { final Rectangle bounds = getBounds(); g.setColor(FOCUS_CATCHER_COLOR); g.drawRect(0, 0, bounds.width - 1, bounds.height - 1); diff --git a/platform/platform-api/src/com/intellij/ide/ui/LafManager.java b/platform/platform-api/src/com/intellij/ide/ui/LafManager.java index 5cee6055592b..638e783a4f8c 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/LafManager.java +++ b/platform/platform-api/src/com/intellij/ide/ui/LafManager.java @@ -33,8 +33,14 @@ public abstract class LafManager { public abstract UIManager.LookAndFeelInfo getCurrentLookAndFeel(); + /** + * @deprecated use {@link com.intellij.util.ui.UIUtil#isUnderAquaLookAndFeel()} + */ public abstract boolean isUnderAquaLookAndFeel(); + /** + * @deprecated use {@link com.intellij.util.ui.UIUtil#isUnderQuaquaLookAndFeel()} + */ public abstract boolean isUnderQuaquaLookAndFeel(); public abstract void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo); diff --git a/platform/platform-api/src/com/intellij/ui/SearchTextField.java b/platform/platform-api/src/com/intellij/ui/SearchTextField.java index 6e628059ae50..0a6690df8eb6 100644 --- a/platform/platform-api/src/com/intellij/ui/SearchTextField.java +++ b/platform/platform-api/src/com/intellij/ui/SearchTextField.java @@ -19,7 +19,6 @@ */ package com.intellij.ui; -import com.intellij.ide.ui.LafManager; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.CommonShortcuts; @@ -157,7 +156,7 @@ public class SearchTextField extends JPanel { } private static boolean hasNativeLeopardSearchControl() { - return SystemInfo.isMacOSLeopard && LafManager.getInstance().isUnderAquaLookAndFeel(); + return SystemInfo.isMacOSLeopard && UIUtil.isUnderAquaLookAndFeel(); } public void addDocumentListener(DocumentListener listener) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java index e160f4945b3f..2133a811b43b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java @@ -16,7 +16,6 @@ package com.intellij.openapi.wm.impl.status; import com.intellij.ide.IdeBundle; -import com.intellij.ide.ui.LafManager; import com.intellij.openapi.Disposable; import com.intellij.openapi.progress.TaskInfo; import com.intellij.openapi.progress.util.ProgressIndicatorBase; @@ -105,7 +104,7 @@ public class InlineProgressIndicator extends ProgressIndicatorBase implements Di myComponent.add(myProcessName, BorderLayout.NORTH); final Font font = myProcessName.getFont(); - final boolean aqua = LafManager.getInstance().isUnderAquaLookAndFeel(); + final boolean aqua = UIUtil.isUnderAquaLookAndFeel(); int size = font.getSize() - (aqua ? 4 : 2); if (size < (aqua ? 8 : 10)) { From 1408c4300b4fbe7a7d54db0abea4d97f944a2aed Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 19:08:29 +0300 Subject: [PATCH 18/33] cs: disposed: reinit on rootsChanged() --- .../ChangeSignatureGestureDetector.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java index 38e092beb685..784dfc9fa111 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java @@ -15,8 +15,11 @@ */ package com.intellij.refactoring.changeSignature; +import com.intellij.ProjectTopics; import com.intellij.codeInsight.template.TemplateManager; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.diagnostic.Logger; @@ -29,17 +32,25 @@ import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.event.EditorFactoryEvent; import com.intellij.openapi.editor.event.EditorFactoryListener; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootEvent; +import com.intellij.openapi.roots.ModuleRootListener; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * User: anna @@ -65,6 +76,21 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme myFileEditorManager = fileEditorManager; myProject = project; myTemplateManager = templateManager; + project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { + public void beforeRootsChange(ModuleRootEvent event) { + final Set files = new HashSet(myListenerMap.keySet()); + for (PsiFile psiFile : files) { + removeDocListener(myPsiDocumentManager.getDocument(psiFile), psiFile); + } + } + + public void rootsChanged(ModuleRootEvent event) { + final FileDocumentManager documentManager = FileDocumentManager.getInstance(); + for (VirtualFile file : myFileEditorManager.getOpenFiles()) { + addDocListener(documentManager.getDocument(file)); + } + } + }); } public static ChangeSignatureGestureDetector getInstance(Project project){ @@ -126,10 +152,9 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme @Override public void projectOpened() { myPsiManager.addPsiTreeChangeListener(this); - EditorFactory.getInstance().addEditorFactoryListener(this); + EditorFactory.getInstance().addEditorFactoryListener(this, myProject); Disposer.register(myProject, new Disposable() { public void dispose() { - EditorFactory.getInstance().removeEditorFactoryListener(ChangeSignatureGestureDetector.this); myPsiManager.removePsiTreeChangeListener(ChangeSignatureGestureDetector.this); LOG.assertTrue(myListenerMap.isEmpty(), myListenerMap); } From 64889bd6a99fc02f5f820e5a14112fbe4e0a2ba6 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Sat, 13 Nov 2010 18:55:35 +0300 Subject: [PATCH 19/33] fix NotNull assertion --- .../ant/config/impl/configuration/AnActionListEditor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/AnActionListEditor.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/AnActionListEditor.java index 7505748709f4..aba37795858b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/AnActionListEditor.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/AnActionListEditor.java @@ -159,7 +159,12 @@ public class AnActionListEditor extends JPanel { } public void select(T item) { - ListScrollingUtil.selectItem(myList, item); + if (item != null) { + ListScrollingUtil.selectItem(myList, item); + } + else { + ListScrollingUtil.ensureSelectionExists(myList); + } } public void updateItem(T item) { From 34610f9a2a88d0489973e75a9dd5189ed9591acd Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Sat, 13 Nov 2010 19:02:09 +0300 Subject: [PATCH 20/33] select item after dialog initialization --- .../ant/config/impl/configuration/BuildFilePropertiesPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java index 955ffc1c6cf7..878251b01b83 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java @@ -401,8 +401,8 @@ public class BuildFilePropertiesPanel { mySetDefaultAnt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AntSetPanel antSetPanel = new AntSetPanel(myAntGlobalConfiguration); - antSetPanel.setSelection(myProjectDefaultAnt.find(myAntGlobalConfiguration)); antSetPanel.reset(); + antSetPanel.setSelection(myProjectDefaultAnt.find(myAntGlobalConfiguration)); AntInstallation antInstallation = antSetPanel.showDialog(mySetDefaultAnt); if (antInstallation == null) { return; From a8f668baaeb7b9c713bbfb7d81c13f0f7598ac8d Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Sat, 13 Nov 2010 19:43:34 +0300 Subject: [PATCH 21/33] fixed python debug console highlighting --- .../console/LanguageConsoleImpl.java | 19 ++++++++---- .../execution/impl/ConsoleViewImpl.java | 31 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 524777f3eb24..4b9a4b34f958 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -64,6 +64,7 @@ import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import javax.swing.FocusManager; import javax.swing.*; @@ -318,7 +319,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { final Document history = myHistoryViewer.getDocument(); final MarkupModel markupModel = history.getMarkupModel(myProject); final int offset = history.getTextLength(); - history.insertString(offset, text); + appendToHistoryDocument(history, text); markupModel.addRangeHighlighter(offset, history.getTextLength(), HighlighterLayer.SYNTAX, @@ -359,15 +360,15 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { private String addTextRangeToHistory(TextRange textRange, final EditorEx consoleEditor) { final DocumentImpl history = (DocumentImpl)myHistoryViewer.getDocument(); final MarkupModel markupModel = history.getMarkupModel(myProject); - history.insertString(history.getTextLength(), myPrompt); + appendToHistoryDocument(history, myPrompt); markupModel.addRangeHighlighter(history.getTextLength() - myPrompt.length(), history.getTextLength(), HighlighterLayer.SYNTAX, ConsoleViewContentType.USER_INPUT.getAttributes(), HighlighterTargetArea.EXACT_RANGE); - int offset = history.getTextLength(); final String text = consoleEditor.getDocument().getText(textRange); - history.insertString(offset, text); - offset = history.getTextLength() - text.length(); //offset can be changed after text trimming after insert due to buffer constraints + //offset can be changed after text trimming after insert due to buffer constraints + appendToHistoryDocument(history, text); + int offset = history.getTextLength() - text.length(); final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(0); while (!iterator.atEnd()) { final int localOffset = textRange.getStartOffset(); @@ -382,10 +383,16 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { duplicateHighlighters(markupModel, consoleEditor.getDocument().getMarkupModel(myProject), offset, textRange); duplicateHighlighters(markupModel, consoleEditor.getMarkupModel(), offset, textRange); } - if (!text.endsWith("\n")) history.insertString(history.getTextLength(), "\n"); + if (!text.endsWith("\n")) { + appendToHistoryDocument(history, "\n"); + } return text; } + protected void appendToHistoryDocument(@NotNull Document history, @NotNull String text) { + history.insertString(history.getTextLength(), text); + } + private static void duplicateHighlighters(MarkupModel to, MarkupModel from, int offset, TextRange textRange) { for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) { final int localOffset = textRange.getStartOffset(); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 61ba08d2a6fd..10e854ef43e6 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -454,17 +454,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo myDeferredUserInput.append(s); } - boolean needNew = true; - if (!myTokens.isEmpty()) { - final TokenInfo lastToken = myTokens.get(myTokens.size() - 1); - if (lastToken.contentType == contentType) { - lastToken.endOffset = myContentSize; // optimization - needNew = false; - } - } - if (needNew) { - myTokens.add(new TokenInfo(contentType, myContentSize - s.length(), myContentSize)); - } + addToken(s.length(), contentType); if (s.indexOf('\n') >= 0 || s.indexOf('\r') >= 0) { if (contentType == ConsoleViewContentType.USER_INPUT) { @@ -478,6 +468,25 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } } + protected void beforeExternalAddContentToDocument(int length, ConsoleViewContentType contentType) { + myContentSize+=length; + addToken(length, contentType); + } + + private void addToken(int length, ConsoleViewContentType contentType) { + boolean needNew = true; + if (!myTokens.isEmpty()) { + final TokenInfo lastToken = myTokens.get(myTokens.size() - 1); + if (lastToken.contentType == contentType) { + lastToken.endOffset = myContentSize; // optimization + needNew = false; + } + } + if (needNew) { + myTokens.add(new TokenInfo(contentType, myContentSize - length, myContentSize)); + } + } + private ModalityState getStateForUpdate() { return myStateForUpdate != null ? myStateForUpdate.compute() : ModalityState.stateForComponent(this); } From af19b6f56db971437fc9974055ae744643eb70ea Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 19:45:51 +0300 Subject: [PATCH 22/33] IDEA-61149 live template context: XSL_TEXT --- .../src/messages/CodeInsightBundle.properties | 1 + .../src/META-INF/XmlPlugin.xml | 1 + .../xpath-lang/src/liveTemplates/xsl.xml | 504 +++++++++--------- xml/impl/resources/liveTemplates/zen_xsl.xml | 36 +- .../template/XslTextContextType.java | 44 ++ 5 files changed, 328 insertions(+), 258 deletions(-) create mode 100644 xml/impl/src/com/intellij/codeInsight/template/XslTextContextType.java diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index e1f4f4d39dcd..482e99c8a68e 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -461,3 +461,4 @@ rename.public.class.family=Rename Public Class rename.public.class.text=Rename class ''{0}'' to ''{1}'' rename.named.element.text=Rename ''{0}'' to ''{1}'' dialog.edit.template.checkbox.html.text=HTML Text +dialog.edit.template.checkbox.xsl.text=XSL Text diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index acaef5fde886..05ca6432eb5f 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -243,6 +243,7 @@ + diff --git a/plugins/xpath/xpath-lang/src/liveTemplates/xsl.xml b/plugins/xpath/xpath-lang/src/liveTemplates/xsl.xml index 78521b7dff0d..833e636054e4 100644 --- a/plugins/xpath/xpath-lang/src/liveTemplates/xsl.xml +++ b/plugins/xpath/xpath-lang/src/liveTemplates/xsl.xml @@ -2,91 +2,97 @@ diff --git a/xml/impl/resources/liveTemplates/zen_xsl.xml b/xml/impl/resources/liveTemplates/zen_xsl.xml index de97235db242..dbd599b3e1e7 100644 --- a/xml/impl/resources/liveTemplates/zen_xsl.xml +++ b/xml/impl/resources/liveTemplates/zen_xsl.xml @@ -4,115 +4,115 @@ - diff --git a/xml/impl/src/com/intellij/codeInsight/template/XslTextContextType.java b/xml/impl/src/com/intellij/codeInsight/template/XslTextContextType.java new file mode 100644 index 000000000000..4514fe0e6c36 --- /dev/null +++ b/xml/impl/src/com/intellij/codeInsight/template/XslTextContextType.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2010 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 com.intellij.codeInsight.template; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author Eugene.Kudelevsky + */ +public class XslTextContextType extends TemplateContextType { + protected XslTextContextType() { + super("XSL_TEXT", CodeInsightBundle.message("dialog.edit.template.checkbox.xsl.text"), XmlContextType.class); + } + + @Override + public boolean isInContext(@NotNull PsiFile file, int offset) { + if (file.getFileType() == StdFileTypes.XML && FileUtil.getExtension(file.getName()).equals("xsl")) { + PsiElement element = file.findElementAt(offset); + return element == null || HtmlTextContextType.isInContext(element); + } + return false; + } + + @Override + public boolean isInContext(@NotNull FileType fileType) { + return false; + } +} From db83bf08448c79b3a922a2b3c1f24bf4837a3b06 Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 13 Nov 2010 19:53:00 +0300 Subject: [PATCH 23/33] cs && lookups together --- .../com/intellij/codeInsight/lookup/impl/TypedHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java index 1bcc18340f56..0554f161d61b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/TypedHandler.java @@ -26,8 +26,10 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorBundle; import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.actionSystem.TypedActionHandler; import com.intellij.openapi.extensions.Extensions; @@ -55,7 +57,7 @@ public class TypedHandler implements TypedActionHandler { final LookupElement currentItem = lookup.getCurrentItem(); final CharFilter.Result result = getLookupAction(charTyped, currentItem, lookup); - + CommandProcessor.getInstance().setCurrentCommandName(EditorBundle.message("typing.in.editor.command.name")); lookup.performGuardedChange(new Runnable() { public void run() { EditorModificationUtil.deleteSelectedText(editor); From b38aa18e79efa82ef53466d316774a42314cfe00 Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Sat, 13 Nov 2010 16:58:56 +0300 Subject: [PATCH 24/33] inner class AttachSourcesDescriptor can be static --- .../libraryEditor/DefaultLibraryRootsComponentDescriptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java index db5f76353b1c..b775e13e1e34 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/DefaultLibraryRootsComponentDescriptor.java @@ -105,7 +105,7 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen } } - private class AttachSourcesDescriptor extends ChooserBasedAttachRootButtonDescriptor { + private static class AttachSourcesDescriptor extends ChooserBasedAttachRootButtonDescriptor { private AttachSourcesDescriptor() { super(OrderRootType.SOURCES, ProjectBundle.message("module.libraries.attach.sources.button")); } From 12cba6310e30a4aea466b13c258b92347ac4d26d Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Sat, 13 Nov 2010 20:07:09 +0300 Subject: [PATCH 25/33] fix Android test running under linux --- .../jetbrains/android/facet/AndroidRootUtil.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/facet/AndroidRootUtil.java b/plugins/android/src/org/jetbrains/android/facet/AndroidRootUtil.java index e63fa861d677..cb107ed732c7 100644 --- a/plugins/android/src/org/jetbrains/android/facet/AndroidRootUtil.java +++ b/plugins/android/src/org/jetbrains/android/facet/AndroidRootUtil.java @@ -74,17 +74,18 @@ public class AndroidRootUtil { @Nullable public static VirtualFile getFileByRelativeModulePath(Module module, String relativePath, boolean lookInContentRoot) { String moduleDirPath = new File(module.getModuleFilePath()).getParent(); - if (moduleDirPath == null) return null; - String absPath = FileUtil.toSystemIndependentName(moduleDirPath + relativePath); - VirtualFile file = LocalFileSystem.getInstance().findFileByPath(absPath); - if (file != null) { - return file; + if (moduleDirPath != null) { + String absPath = FileUtil.toSystemIndependentName(moduleDirPath + relativePath); + VirtualFile file = LocalFileSystem.getInstance().findFileByPath(absPath); + if (file != null) { + return file; + } } if (lookInContentRoot) { for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) { - absPath = FileUtil.toSystemIndependentName(contentRoot.getPath() + relativePath); - file = LocalFileSystem.getInstance().findFileByPath(absPath); + String absPath = FileUtil.toSystemIndependentName(contentRoot.getPath() + relativePath); + VirtualFile file = LocalFileSystem.getInstance().findFileByPath(absPath); if (file != null) { return file; } From 5688daa3686708291729b00bb3e6e33b60be7200 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 18:56:15 +0300 Subject: [PATCH 26/33] less error-prone CompletionConfidence API --- .../codeInsight/completion/AlwaysFocusLookup.java | 6 ++++-- .../codeInsight/completion/CompletionConfidence.java | 11 ++++++----- .../codeInsight/completion/UnfocusedComments.java | 8 +++++--- .../completion/UnfocusedNameIdentifier.java | 10 ++++++---- .../completion/CodeCompletionHandlerBase.java | 12 +++++++----- .../lang/completion/GroovyCompletionConfidence.java | 12 +++++++----- .../completion/XmlNameCompletionConfidence.java | 10 ++++++---- 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/AlwaysFocusLookup.java b/platform/lang-api/src/com/intellij/codeInsight/completion/AlwaysFocusLookup.java index 028cb9a5f8b0..c3633d607d64 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/AlwaysFocusLookup.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/AlwaysFocusLookup.java @@ -15,14 +15,16 @@ */ package com.intellij.codeInsight.completion; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; /** * @author peter */ public class AlwaysFocusLookup extends CompletionConfidence { + @NotNull @Override - public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { - return true; + public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { + return ThreeState.YES; } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java index 84b44292f99f..9a833e215d1f 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidence.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,11 +26,11 @@ import org.jetbrains.annotations.Nullable; */ public abstract class CompletionConfidence { - @Nullable - public abstract Boolean shouldFocusLookup(@NotNull CompletionParameters parameters); + @NotNull + public abstract ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters); - @Nullable - public Boolean shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { - return null; + @NotNull + public ThreeState shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { + return ThreeState.UNSURE; } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java index 0372a0e00941..0a79233d03ad 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedComments.java @@ -17,17 +17,19 @@ package com.intellij.codeInsight.completion; import com.intellij.psi.PsiComment; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; /** * @author peter */ public class UnfocusedComments extends CompletionConfidence { + @NotNull @Override - public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { + public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { if (PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiComment.class) != null) { - return false; + return ThreeState.NO; } - return null; + return ThreeState.UNSURE; } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedNameIdentifier.java b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedNameIdentifier.java index f0127bba878c..bd59deb551f3 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedNameIdentifier.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/UnfocusedNameIdentifier.java @@ -17,27 +17,29 @@ package com.intellij.codeInsight.completion; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; /** * @author peter */ public class UnfocusedNameIdentifier extends CompletionConfidence { + @NotNull @Override - public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { + public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { final PsiElement position = parameters.getPosition(); final PsiElement parent = position.getParent(); if (parent instanceof PsiNameIdentifierOwner) { final PsiElement nameIdentifier = ((PsiNameIdentifierOwner)parent).getNameIdentifier(); if (nameIdentifier == position) { - return false; + return ThreeState.NO; } if (nameIdentifier != null && position.getTextRange().equals(nameIdentifier.getTextRange())) { //sometimes name identifiers are non-physical (e.g. Groovy) - return false; + return ThreeState.NO; } } - return null; + return ThreeState.UNSURE; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 7d3dd6825fc0..776f5946c8c4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -68,6 +68,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.reference.SoftReference; import com.intellij.ui.LightweightHint; import com.intellij.util.Consumer; +import com.intellij.util.ThreeState; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; @@ -207,8 +208,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { Language language = elementAt != null ? PsiUtilBase.findLanguageFromElement(elementAt):psiFile.getLanguage(); for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) { - final Boolean result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API - if (result == Boolean.TRUE) return; + final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API + if (result == ThreeState.YES) return; + if (result == ThreeState.NO) break; } } else { CommandProcessor.getInstance().executeCommand(project, initCmd, null, null); @@ -224,9 +226,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { final Language language = PsiUtilBase.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset()); for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) { - final Boolean result = confidence.shouldFocusLookup(parameters); - if (result != null) { - return result; + final ThreeState result = confidence.shouldFocusLookup(parameters); + if (result != ThreeState.UNSURE) { + return result == ThreeState.YES; } } return false; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionConfidence.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionConfidence.java index b00f3dcb37c2..2e55d0ca097d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionConfidence.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionConfidence.java @@ -15,6 +15,7 @@ package org.jetbrains.plugins.groovy.lang.completion; import com.intellij.codeInsight.completion.CompletionConfidence; import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.psi.PsiElement; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; @@ -23,19 +24,20 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere * @author peter */ public class GroovyCompletionConfidence extends CompletionConfidence { + @NotNull @Override - public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { + public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { final PsiElement position = parameters.getPosition(); if (position.getParent() instanceof GrReferenceExpression) { final GrExpression expression = ((GrReferenceExpression)position.getParent()).getQualifierExpression(); if (expression == null) { - return true; + return ThreeState.YES; } if (expression.getType() == null) { - return false; + return ThreeState.NO; } - return true; + return ThreeState.YES; } - return null; + return ThreeState.UNSURE; } } diff --git a/xml/impl/resources/com/intellij/codeInsight/completion/XmlNameCompletionConfidence.java b/xml/impl/resources/com/intellij/codeInsight/completion/XmlNameCompletionConfidence.java index 8693c214d1b5..77a54ecf577c 100644 --- a/xml/impl/resources/com/intellij/codeInsight/completion/XmlNameCompletionConfidence.java +++ b/xml/impl/resources/com/intellij/codeInsight/completion/XmlNameCompletionConfidence.java @@ -3,21 +3,23 @@ package com.intellij.codeInsight.completion; import com.intellij.lang.ASTNode; import com.intellij.psi.tree.IElementType; import com.intellij.psi.xml.XmlTokenType; +import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; /** * @author peter */ public class XmlNameCompletionConfidence extends CompletionConfidence{ + @NotNull @Override - public Boolean shouldFocusLookup(@NotNull CompletionParameters parameters) { + public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { final ASTNode node = parameters.getPosition().getNode(); - if (node == null) return null; + if (node == null) return ThreeState.UNSURE; final IElementType elementType = node.getElementType(); if (elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) { - return true; + return ThreeState.YES; } - return null; + return ThreeState.UNSURE; } } From a5b6b477936a40dd2c62b5fef5b9535527af9dc7 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 19:00:39 +0300 Subject: [PATCH 27/33] check for disposed console view (EA-23492) --- .../src/com/intellij/execution/impl/ConsoleViewImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 10e854ef43e6..26197899d6ec 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -947,6 +947,10 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo myFoldingAlarm.cancelAllRequests(); final Runnable runnable = new Runnable() { public void run() { + if (myEditor == null || myEditor.isDisposed()) { + return; + } + assertIsDispatchThread(); final FoldingModel model = myEditor.getFoldingModel(); final Runnable operation = new Runnable() { From 65ad79ba84a6f76c3713ed40b40cd5d9017c79eb Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 19:03:54 +0300 Subject: [PATCH 28/33] some type parameters don't have superclasses (EA-23486) --- .../plugins/groovy/lang/resolve/ResolveUtil.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index 1fdd5d3ee2df..930e9ecbc25c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -197,7 +197,7 @@ public class ResolveUtil { return type; } - public static Map getAllSuperTypes(PsiType base, final Project project) { + public static Map getAllSuperTypes(@NotNull PsiType base, final Project project) { final Map> cache = CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider>>() { @Override @@ -209,9 +209,14 @@ public class ResolveUtil { final PsiClass cls = PsiUtil.resolveClassInType(base); //noinspection ConstantConditions - String key = cls instanceof PsiTypeParameter - ? cls.getName() + cls.getSuperClass().getName() - : TypeConversionUtil.erasure(base).getCanonicalText(); + String key; + if (cls instanceof PsiTypeParameter) { + final PsiClass superClass = cls.getSuperClass(); + key = cls.getName() + (superClass == null ? CommonClassNames.JAVA_LANG_OBJECT : superClass.getName()); + } + else { + key = TypeConversionUtil.erasure(base).getCanonicalText(); + } if (key == null) key = ""; Map result = cache.get(key); if (result == null) { From 7add06e36a08e7d8d58a65ffdd6235982da50af7 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 19:06:05 +0300 Subject: [PATCH 29/33] don't bind to elements with no qualified name (EA-23479) --- .../groovy/lang/psi/impl/GrReferenceElementImpl.java | 6 ++++-- .../statements/expressions/GrReferenceExpressionImpl.java | 2 +- .../lang/psi/impl/types/GrCodeReferenceElementImpl.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrReferenceElementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrReferenceElementImpl.java index 00f565355128..0f5f46988cab 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrReferenceElementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrReferenceElementImpl.java @@ -89,7 +89,9 @@ public abstract class GrReferenceElementImpl extends GroovyPsiElementImpl implem final String newName = ((PsiClass) element).getName(); final GrReferenceElementImpl newElement = ((GrReferenceElementImpl)handleElementRename(newName)); if (newElement.isReferenceTo(element)) return newElement; - return newElement.bindWithQualifiedRef(((PsiClass)element).getQualifiedName()); + final String qualifiedName = ((PsiClass)element).getQualifiedName(); + if (qualifiedName == null) return newElement; + return newElement.bindWithQualifiedRef(qualifiedName); } else if (element instanceof PsiMember) { PsiMember member = (PsiMember)element; if (!isPhysical()) { @@ -111,7 +113,7 @@ public abstract class GrReferenceElementImpl extends GroovyPsiElementImpl implem } - protected abstract PsiElement bindWithQualifiedRef(String qName); + protected abstract PsiElement bindWithQualifiedRef(@NotNull String qName); protected boolean bindsCorrectly(PsiElement element) { return isReferenceTo(element); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index e08726e617e8..10f9bbcafd99 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -329,7 +329,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements } @Override - protected PsiElement bindWithQualifiedRef(String qName) { + protected PsiElement bindWithQualifiedRef(@NotNull String qName) { final GrTypeArgumentList list = getTypeArgumentList(); final String typeArgs = (list != null) ? list.getText() : ""; final String text = qName + typeArgs; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java index 9ec5c74959d3..da2aa2b8fa5e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java @@ -66,7 +66,7 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl implement } @Override - protected PsiElement bindWithQualifiedRef(String qName) { + protected PsiElement bindWithQualifiedRef(@NotNull String qName) { final GrTypeArgumentList list = getTypeArgumentList(); final String typeArgs = (list != null) ? list.getText() : ""; final String text = qName + typeArgs; From dd6eee117d33cba463fb19cc4ff4f239321a0769 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 20:25:20 +0300 Subject: [PATCH 30/33] clearing child dom seems to be unneeded anymore --- .../util/xml/impl/DynamicGenericInfo.java | 91 ++++++++----------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java index af6a1709f7c0..f9eed39d6e84 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DynamicGenericInfo.java @@ -17,10 +17,7 @@ package com.intellij.util.xml.impl; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlElement; -import com.intellij.psi.xml.XmlTag; -import com.intellij.semantic.SemService; import com.intellij.util.ArrayUtil; import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; @@ -77,59 +74,12 @@ public class DynamicGenericInfo extends DomGenericInfoEx { try { DomExtensionsRegistrarImpl registrar = runDomExtenders(); + //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (element) { if (myInitialized) return true; - if (registrar != null) { - final SemService semService = SemService.getSemService(myInvocationHandler.getManager().getProject()); - - final List fixeds = registrar.getFixeds(); - final List collections = registrar.getCollections(); - final List attributes = registrar.getAttributes(); - if (!attributes.isEmpty()) { - ChildrenDescriptionsHolder newAttributes = new ChildrenDescriptionsHolder(myStaticGenericInfo.getAttributes()); - for (final DomExtensionImpl extension : attributes) { - newAttributes.addDescription(extension.addAnnotations(new AttributeChildDescriptionImpl(extension.getXmlName(), extension.getType()))); - } - for (XmlAttribute attribute : ((XmlTag)element).getAttributes()) { - semService.clearCachedSemElements(attribute); - } - myAttributes = newAttributes; - } - - boolean clearSubTags = false; - if (!fixeds.isEmpty()) { - ChildrenDescriptionsHolder newFixeds = new ChildrenDescriptionsHolder(myStaticGenericInfo.getFixed()); - for (final DomExtensionImpl extension : fixeds) { - newFixeds.addDescription(extension.addAnnotations(new FixedChildDescriptionImpl(extension.getXmlName(), extension.getType(), extension.getCount(), ArrayUtil.EMPTY_COLLECTION_ARRAY))); - } - clearSubTags = true; - myFixeds = newFixeds; - } - if (!collections.isEmpty()) { - ChildrenDescriptionsHolder newCollections = new ChildrenDescriptionsHolder(myStaticGenericInfo.getCollections()); - for (final DomExtensionImpl extension : collections) { - newCollections.addDescription(extension.addAnnotations(new CollectionChildDescriptionImpl(extension.getXmlName(), extension.getType(), - Collections.emptyList() - ))); - } - clearSubTags = true; - myCollections = newCollections; - } - - final DomExtensionImpl extension = registrar.getCustomChildrenType(); - if (extension != null) { - myCustomChildren = new CustomDomChildrenDescriptionImpl(null, extension.getType(), extension.getTagNameDescriptor()); - clearSubTags = true; - } - - if (clearSubTags) { - for (XmlTag tag : ((XmlTag)element).getSubTags()) { - semService.clearCachedSemElements(tag); - } - } - + applyExtensions(registrar); } myInitialized = true; } @@ -140,6 +90,42 @@ public class DynamicGenericInfo extends DomGenericInfoEx { return true; } + private void applyExtensions(DomExtensionsRegistrarImpl registrar) { + final List fixeds = registrar.getFixeds(); + final List collections = registrar.getCollections(); + final List attributes = registrar.getAttributes(); + if (!attributes.isEmpty()) { + ChildrenDescriptionsHolder newAttributes = new ChildrenDescriptionsHolder(myStaticGenericInfo.getAttributes()); + for (final DomExtensionImpl extension : attributes) { + newAttributes.addDescription(extension.addAnnotations(new AttributeChildDescriptionImpl(extension.getXmlName(), extension.getType()))); + } + myAttributes = newAttributes; + } + + if (!fixeds.isEmpty()) { + ChildrenDescriptionsHolder newFixeds = new ChildrenDescriptionsHolder(myStaticGenericInfo.getFixed()); + for (final DomExtensionImpl extension : fixeds) { + //noinspection unchecked + newFixeds.addDescription(extension.addAnnotations(new FixedChildDescriptionImpl(extension.getXmlName(), extension.getType(), extension.getCount(), ArrayUtil.EMPTY_COLLECTION_ARRAY))); + } + myFixeds = newFixeds; + } + if (!collections.isEmpty()) { + ChildrenDescriptionsHolder newCollections = new ChildrenDescriptionsHolder(myStaticGenericInfo.getCollections()); + for (final DomExtensionImpl extension : collections) { + newCollections.addDescription(extension.addAnnotations(new CollectionChildDescriptionImpl(extension.getXmlName(), extension.getType(), + Collections.emptyList() + ))); + } + myCollections = newCollections; + } + + final DomExtensionImpl extension = registrar.getCustomChildrenType(); + if (extension != null) { + myCustomChildren = new CustomDomChildrenDescriptionImpl(null, extension.getType(), extension.getTagNameDescriptor()); + } + } + @Nullable private DomExtensionsRegistrarImpl runDomExtenders() { DomExtensionsRegistrarImpl registrar = null; @@ -155,6 +141,7 @@ public class DynamicGenericInfo extends DomGenericInfoEx { if (extenders != null) { if (registrar == null) registrar = new DomExtensionsRegistrarImpl(); for (final DomExtender extender : extenders) { + //noinspection unchecked extender.registerExtensions(domElement, registrar); } } From 73376080e73a19d65a35a79dac4d73e7f3c33570 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 20:56:17 +0300 Subject: [PATCH 31/33] check that we're completing inside the reference (EA-16521) --- .../completion/LegacyCompletionContributor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java index 5c6ea46dd1cf..777cd4687edd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java @@ -102,11 +102,8 @@ public class LegacyCompletionContributor extends CompletionContributor { } } else if (ref instanceof PsiDynaReference) { - int offset = startOffset - ref.getElement().getTextRange().getStartOffset(); for (final PsiReference reference : ((PsiDynaReference)ref).getReferences()) { - if (ReferenceRange.containsOffsetInElement(reference, offset)) { - processReference(result, startOffset, consumer, reference); - } + processReference(result, startOffset, consumer, reference); } } else if (ref != null) { @@ -118,6 +115,10 @@ public class LegacyCompletionContributor extends CompletionContributor { final int startOffset, final PairConsumer consumer, final PsiReference reference) { + if (!ReferenceRange.containsOffsetInElement(reference, startOffset)) { + return; + } + final int offsetInElement = startOffset - reference.getElement().getTextRange().getStartOffset(); final String prefix = reference.getElement().getText().substring(reference.getRangeInElement().getStartOffset(), offsetInElement); consumer.consume(reference, result.withPrefixMatcher(prefix)); From ba04c6761770a30d623fdbdec6e3ec7f21727249 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 21:26:05 +0300 Subject: [PATCH 32/33] that was too rude --- .../codeInsight/completion/LegacyCompletionContributor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java index 777cd4687edd..12d78fe19501 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/LegacyCompletionContributor.java @@ -115,11 +115,11 @@ public class LegacyCompletionContributor extends CompletionContributor { final int startOffset, final PairConsumer consumer, final PsiReference reference) { - if (!ReferenceRange.containsOffsetInElement(reference, startOffset)) { + final int offsetInElement = startOffset - reference.getElement().getTextRange().getStartOffset(); + if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) { return; } - final int offsetInElement = startOffset - reference.getElement().getTextRange().getStartOffset(); final String prefix = reference.getElement().getText().substring(reference.getRangeInElement().getStartOffset(), offsetInElement); consumer.consume(reference, result.withPrefixMatcher(prefix)); } From 686804d3c7637c825f69c1fab08c6edb6929f107 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Sat, 13 Nov 2010 21:26:26 +0300 Subject: [PATCH 33/33] some assertions for prefix which is not an actual string before caret --- .../codeInsight/completion/CodeCompletionHandlerBase.java | 5 ++++- .../com/intellij/codeInsight/completion/CompletionData.java | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 776f5946c8c4..6bad9233a7e2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -384,7 +384,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { final CompletionContext newContext = ref.get().getFirst(); insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, newContext); - return new CompletionParameters(insertedElement, newContext.file, myCompletionType, newContext.getStartOffset(), invocationCount); + final int offset = newContext.getStartOffset(); + LOG.assertTrue(insertedElement.getContainingFile().findElementAt(offset) == insertedElement, "wrong offset"); + LOG.assertTrue(insertedElement.getContainingFile().getText().substring(insertedElement.getTextRange().getStartOffset(), insertedElement.getTextRange().getEndOffset()).equals(insertedElement.getText()), "wrong text"); + return new CompletionParameters(insertedElement, newContext.file, myCompletionType, offset, invocationCount); } private AutoCompletionDecision shouldAutoComplete( diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionData.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionData.java index 4384f57240b9..1ed42076a386 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionData.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionData.java @@ -20,6 +20,7 @@ import com.intellij.codeInsight.TailType; import com.intellij.codeInsight.lookup.*; import com.intellij.codeInsight.template.Template; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.paths.PsiDynaReference; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.TextRange; @@ -193,6 +194,10 @@ public class CompletionData { public static String findPrefixStatic(final PsiElement insertedElement, final int offsetInFile, ElementPattern prefixStartTrim) { if(insertedElement == null) return ""; + final Document document = insertedElement.getContainingFile().getViewProvider().getDocument(); + assert document != null; + LOG.assertTrue(!PsiDocumentManager.getInstance(insertedElement.getProject()).isUncommited(document), "Uncommitted"); + final String prefix = getReferencePrefix(insertedElement, offsetInFile); if (prefix != null) return prefix;