From 11b01a85f9537f9a7bcad7ae081c603fd9eb4105 Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Sat, 3 Dec 2011 14:40:37 +0400 Subject: [PATCH 1/7] IDEA-77884 Smart completion inserts qualified names for inner Groovy classes --- .../groovy/lang/GrReferenceAdjuster.java | 57 ++++++++++--------- .../GroovySmartCompletionTest.groovy | 6 +- ...InnerClassReferenceWithoutQualifier.groovy | 6 ++ ...lassReferenceWithoutQualifier_after.groovy | 6 ++ 4 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier.groovy create mode 100644 plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier_after.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GrReferenceAdjuster.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GrReferenceAdjuster.java index df87b6bbfc29..67efad10bc79 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GrReferenceAdjuster.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GrReferenceAdjuster.java @@ -91,36 +91,38 @@ public class GrReferenceAdjuster { final PsiElement resolved = resolveRef(ref, uncomplete); if (resolved == null) return false; - if (!CodeStyleSettingsManager.getSettings(ref.getProject()).INSERT_INNER_CLASS_IMPORTS && resolved instanceof PsiClass && ((PsiClass)resolved).getContainingClass() != null) { - return false; - } - - final GrQualifiedReference copy = getCopy(ref); - - copy.setQualifier(null); - if (!copy.isReferenceTo(resolved)) { - if (resolved instanceof PsiClass) { - final GroovyFileBase file = (GroovyFileBase)ref.getContainingFile(); - final PsiClass clazz = (PsiClass)resolved; - final String qName = clazz.getQualifiedName(); - if (qName != null) { - if (addImports && mayInsertImport(ref)) { - final GrImportStatement added = file.addImportForClass(clazz); - if (!copy.isReferenceTo(resolved)) { - file.removeImport(added); - return false; - } - } - } - } - else { - return false; - } - } + if (!checkCopyWithoutQualifier(ref, addImports, resolved)) return false; ref.setQualifier(null); return true; } + private static boolean checkCopyWithoutQualifier(GrQualifiedReference ref, + boolean addImports, + PsiElement resolved) { + final GrQualifiedReference copy = getCopy(ref); + copy.setQualifier(null); + + if (copy.isReferenceTo(resolved)) return true; + + if (resolved instanceof PsiClass) { + final PsiClass clazz = (PsiClass)resolved; + final String qName = clazz.getQualifiedName(); + if (qName != null && addImports && checkIsInnerClass(clazz) && mayInsertImport(ref)) { + final GroovyFileBase file = (GroovyFileBase)ref.getContainingFile(); + final GrImportStatement added = file.addImportForClass(clazz); + if (copy.isReferenceTo(resolved)) return true; + file.removeImport(added); + } + } + + return false; + } + + private static boolean checkIsInnerClass(PsiClass resolved) { + final PsiClass containingClass = resolved.getContainingClass(); + return containingClass == null || CodeStyleSettingsManager.getSettings(resolved.getProject()).INSERT_INNER_CLASS_IMPORTS; + } + @Nullable private static PsiElement resolveRef(GrQualifiedReference ref, boolean uncomplete) { if (!uncomplete) return ref.resolve(); @@ -176,7 +178,8 @@ public class GrReferenceAdjuster { private static boolean mayInsertImport(GrQualifiedReference ref) { return PsiTreeUtil.getParentOfType(ref, GrDocComment.class) == null && !(ref.getContainingFile() instanceof GroovyCodeFragment) && - PsiTreeUtil.getParentOfType(ref, GrImportStatement.class) == null; + PsiTreeUtil.getParentOfType(ref, GrImportStatement.class) == null && + ref.getContainingFile() instanceof GroovyFileBase; } public static boolean seemsToBeQualifiedClassName(@Nullable GrExpression expr) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy index 3e72331e0454..682bdcd4e37e 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy @@ -18,10 +18,10 @@ package org.jetbrains.plugins.groovy.completion; import com.intellij.codeInsight.completion.CompletionType +import com.intellij.codeInsight.completion.StaticallyImportable import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile import org.jetbrains.plugins.groovy.util.TestUtils -import com.intellij.codeInsight.completion.StaticallyImportable /** * @author peter @@ -110,6 +110,10 @@ class Expected { Expected exp = fooField''' } + + void testInnerClassReferenceWithoutQualifier() { + doSmartTest() + } def getFileText(PsiFile file) { return PsiDocumentManager.getInstance(project).getDocument(file).text diff --git a/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier.groovy b/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier.groovy new file mode 100644 index 000000000000..c915cfa25dd4 --- /dev/null +++ b/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier.groovy @@ -0,0 +1,6 @@ +class Foo { + static class Bar {} + { + List l = new AL + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier_after.groovy b/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier_after.groovy new file mode 100644 index 000000000000..c6d80a381f7a --- /dev/null +++ b/plugins/groovy/testdata/groovy/completion/smart/InnerClassReferenceWithoutQualifier_after.groovy @@ -0,0 +1,6 @@ +class Foo { + static class Bar {} + { + List l = new ArrayList() + } +} \ No newline at end of file From 181cf1beb5dc530e6a1a464f2c1d9f2b49d9681e Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Sat, 3 Dec 2011 15:16:26 +0400 Subject: [PATCH 2/7] EA-32398 - IOE: PsiFileImplUtil.checkSetName --- .../convertToJava/ConvertToJavaProcessor.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java index c437d8b4aa39..472d6efe43a5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java @@ -20,14 +20,17 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.refactoring.BaseRefactoringProcessor; +import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.ui.UsageViewDescriptorAdapter; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewDescriptor; +import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.hash.HashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; @@ -93,7 +96,20 @@ public class ConvertToJavaProcessor extends BaseRefactoringProcessor { document.setText(builder.toString()); PsiDocumentManager.getInstance(myProject).commitDocument(document); String fileName = getNewFileName(file); - PsiElement newFile = file.setName(fileName); + PsiElement newFile; + try { + newFile = file.setName(fileName); + } + catch (final IncorrectOperationException e) { + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + Messages.showMessageDialog(myProject, e.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon()); + } + }); + return; + } + if (ApplicationManager.getApplication().isUnitTestMode()) return; // don't move classes to new files with corresponding class names and reformat From da8d7d40786994620707e278d9d3676b10054120 Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Sat, 3 Dec 2011 15:17:05 +0400 Subject: [PATCH 3/7] EA-32385 - assert: GroovyPsiElementFactoryImpl.createStatementFromText --- .../RemoveParenthesesFromMethodPredicate.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/RemoveParenthesesFromMethodPredicate.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/RemoveParenthesesFromMethodPredicate.java index e91359015fb3..7777942d78a6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/RemoveParenthesesFromMethodPredicate.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/RemoveParenthesesFromMethodPredicate.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.intentions.conversions; import com.intellij.psi.PsiElement; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; @@ -50,8 +51,13 @@ class RemoveParenthesesFromMethodPredicate implements PsiElementPredicate { if (rightParen != null) rightParen.delete(); newStatementText.append(argumentList.getText()); } - final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(element.getProject()); - final GrStatement newStatement = factory.createStatementFromText(newStatementText.toString()); + final GrStatement newStatement; + try { + newStatement = GroovyPsiElementFactory.getInstance(element.getProject()).createStatementFromText(newStatementText.toString()); + } + catch (IncorrectOperationException e) { + return false; + } if (newStatement instanceof GrApplicationStatement) { final GrCommandArgumentList newArgList = ((GrApplicationStatement)newStatement).getArgumentList(); if (newArgList == null && argumentList == null || From 6628d52974a7389d50f9600bdd2dae4781c071f5 Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Sat, 3 Dec 2011 16:15:55 +0400 Subject: [PATCH 4/7] check before cast to GroovyFile --- .../gradle/config/GradlePositionManager.java | 4 ++-- .../plugins/groovy/annotator/GroovyAnnotator.java | 2 +- .../annotator/intentions/GrMoveToDirFix.java | 2 ++ .../bugs/GroovyAccessibilityInspection.java | 4 +++- .../conversions/ConvertMapToClassIntention.java | 4 ++-- .../intentions/style/ImportOnDemandIntention.java | 11 +++++++---- .../intentions/style/ImportStaticIntention.java | 15 ++++++++------- .../completion/GroovyClassNameInsertHandler.java | 3 ++- .../completion/GroovyCompletionContributor.java | 1 + .../handlers/AfterNewClassInsertHandler.java | 11 ----------- .../smartEnter/GroovySmartEnterProcessor.java | 3 +-- .../statements/typedef/GrTypeDefinitionImpl.java | 3 +-- .../groovy/refactoring/GroovyRefactoringUtil.java | 2 +- .../extractMethod/ExtractMethodUtil.java | 5 ++--- .../introduce/GrIntroduceHandlerBase.java | 9 ++++----- .../parameter/GrIntroduceParameterHandler.java | 5 ++--- .../refactoring/inline/InlineMethodTest.java | 5 ++--- .../refactoring/inline/InlineVariableTest.java | 5 ++--- .../IntroduceVariableValidatorTest.java | 3 +-- 19 files changed, 44 insertions(+), 53 deletions(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradlePositionManager.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradlePositionManager.java index 43c3f8f4cd30..fa234ee2a2bf 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradlePositionManager.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradlePositionManager.java @@ -30,8 +30,8 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; -import com.intellij.util.containers.FactoryMap; import com.intellij.util.containers.ConcurrentFactoryMap; +import com.intellij.util.containers.FactoryMap; import com.intellij.util.lang.UrlClassLoader; import com.sun.jdi.AbsentInformationException; import com.sun.jdi.ReferenceType; @@ -69,7 +69,7 @@ public class GradlePositionManager extends ScriptPositionManagerHelper { } public boolean isAppropriateScriptFile(@NotNull final PsiFile scriptFile) { - return GroovyScriptTypeDetector.isSpecificScriptFile((GroovyFile)scriptFile, GradleScriptType.INSTANCE); + return scriptFile instanceof GroovyFile && GroovyScriptTypeDetector.isSpecificScriptFile((GroovyFile)scriptFile, GradleScriptType.INSTANCE); } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index c67aec8f8dc0..26f7775ca063 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -787,7 +787,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { assert file != null; PsiDirectory psiDirectory = file.getContainingDirectory(); - if (psiDirectory != null) { + if (psiDirectory != null && file instanceof GroovyFile) { PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); if (aPackage != null) { String packageName = aPackage.getQualifiedName(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java index 3ed96eb198b7..73c5f52c3bf6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GrMoveToDirFix.java @@ -79,6 +79,8 @@ public class GrMoveToDirFix implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + if (!(file instanceof GroovyFile)) return; + final String packageName = ((GroovyFile)file).getPackageName(); final Module module = ModuleUtil.findModuleForFile(file.getVirtualFile(), project); PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyAccessibilityInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyAccessibilityInspection.java index a1d885d4a0dc..ee573ff774aa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyAccessibilityInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyAccessibilityInspection.java @@ -108,7 +108,9 @@ public class GroovyAccessibilityInspection extends BaseInspection { String[] modifiers = {PsiModifier.PROTECTED, PsiModifier.PUBLIC, PsiModifier.PACKAGE_LOCAL}; PsiClass accessObjectClass = PsiTreeUtil.getParentOfType(location, PsiClass.class, false); if (accessObjectClass == null) { - accessObjectClass = ((GroovyFile)location.getContainingFile()).getScriptClass(); + final PsiFile file = location.getContainingFile(); + if (!(file instanceof GroovyFile)) return GroovyFix.EMPTY_ARRAY; + accessObjectClass = ((GroovyFile)file).getScriptClass(); } for (int i = ArrayUtil.indexOf(modifiers, minModifier); i < modifiers.length; i++) { String modifier = modifiers[i]; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertMapToClassIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertMapToClassIntention.java index cc3a9e6595cf..f9c42d5f16fa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertMapToClassIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertMapToClassIntention.java @@ -40,7 +40,6 @@ import org.jetbrains.plugins.groovy.intentions.base.Intention; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; -import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; @@ -77,7 +76,8 @@ public class ConvertMapToClassIntention extends Intention { final GrListOrMap map = (GrListOrMap)element; final GrNamedArgument[] namedArguments = map.getNamedArguments(); LOG.assertTrue(map.getInitializers().length == 0); - final String packageName = ((GroovyFileBase)map.getContainingFile()).getPackageName(); + final PsiFile file = map.getContainingFile(); + final String packageName = file instanceof GroovyFileBase ? ((GroovyFileBase)file).getPackageName() : ""; final CreateClassDialog dialog = new CreateClassDialog(project, GroovyBundle.message("create.class.family.name"), "", packageName, CreateClassKind.CLASS, true, diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportOnDemandIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportOnDemandIntention.java index 8683a9ab471b..320b1b6d0918 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportOnDemandIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportOnDemandIntention.java @@ -29,7 +29,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.intentions.base.Intention; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster; -import org.jetbrains.plugins.groovy.lang.psi.*; +import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference; +import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; /** @@ -41,10 +44,10 @@ public class ImportOnDemandIntention extends Intention { @Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { - LOG.assertTrue(element instanceof GrReferenceElement); + if (!(element instanceof GrReferenceElement)) return; final GrReferenceElement ref = (GrReferenceElement)element; final PsiElement resolved = ref.resolve(); - LOG.assertTrue(resolved instanceof PsiClass); + if (!(resolved instanceof PsiClass)) return; final String qname = ((PsiClass)resolved).getQualifiedName(); @@ -52,7 +55,7 @@ public class ImportOnDemandIntention extends Intention { GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null); final PsiFile containingFile = element.getContainingFile(); - LOG.assertTrue(containingFile instanceof GroovyFile); + if (!(containingFile instanceof GroovyFile)) return; ((GroovyFile)containingFile).addImport(importStatement); for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile), true)) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportStaticIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportStaticIntention.java index bc9ef5f0c7bd..36ceb3948420 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportStaticIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/ImportStaticIntention.java @@ -43,19 +43,20 @@ public class ImportStaticIntention extends Intention { @Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { - LOG.assertTrue(element instanceof GrReferenceExpression); + if (!(element instanceof GrReferenceExpression)) return; final GrReferenceExpression ref = (GrReferenceExpression)element; final PsiElement resolved = ref.resolve(); - LOG.assertTrue(resolved instanceof PsiMember); + if (!(resolved instanceof PsiMember)) return; final PsiClass containingClass = ((PsiMember)resolved).getContainingClass(); - LOG.assertTrue(containingClass != null); + if (containingClass == null) return; final String qname = containingClass.getQualifiedName(); final String name = ((PsiMember)resolved).getName(); final PsiFile containingFile = element.getContainingFile(); - LOG.assertTrue(containingFile instanceof GroovyFile); - ((GroovyFile)containingFile).accept(new GroovyRecursiveElementVisitor() { + if (!(containingFile instanceof GroovyFile)) return; + final GroovyFile file = (GroovyFile)containingFile; + file.accept(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(GrReferenceExpression expression) { super.visitReferenceExpression(expression); @@ -72,7 +73,7 @@ public class ImportStaticIntention extends Intention { GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname + "." + name, true, false, null); - ((GroovyFile)containingFile).addImport(importStatement); + file.addImport(importStatement); for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) { final PsiElement refElement = reference.getElement(); @@ -82,7 +83,7 @@ public class ImportStaticIntention extends Intention { } - ((GroovyFile)containingFile).accept(new GroovyRecursiveElementVisitor() { + file.accept(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(GrReferenceExpression expression) { super.visitReferenceExpression(expression); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java index c92b9f1b3794..e73b13cb07a8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java @@ -55,7 +55,8 @@ public class GroovyClassNameInsertHandler implements InsertHandler T findElementInRange(final GroovyFileBase file, + public static T findElementInRange(final PsiFile file, int startOffset, int endOffset, final Class klass) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/extractMethod/ExtractMethodUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/extractMethod/ExtractMethodUtil.java index 7410da1ec93f..aa0cf3eb81d2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/extractMethod/ExtractMethodUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/extractMethod/ExtractMethodUtil.java @@ -74,8 +74,7 @@ public class ExtractMethodUtil { } startElement = startElement.getParent(); PsiElement parent = startElement.getParent(); - if (parent instanceof GroovyFile && - ((GroovyFile) parent).getScriptClass() == owner) { + if (parent instanceof GroovyFile && ((GroovyFile) parent).getScriptClass() == owner) { return startElement.getNextSibling(); } } @@ -418,7 +417,7 @@ public class ExtractMethodUtil { static PsiElement[] getElementsInOffset(PsiFile file, int startOffset, int endOffset) { PsiElement[] elements; - GrExpression expr = GroovyRefactoringUtil.findElementInRange(((GroovyFileBase) file), startOffset, endOffset, GrExpression.class); + GrExpression expr = GroovyRefactoringUtil.findElementInRange(file, startOffset, endOffset, GrExpression.class); if (expr != null) { PsiElement parent = expr.getParent(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java index fe35c7081066..6ed7c8e88f1b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java @@ -42,7 +42,6 @@ import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; @@ -243,8 +242,8 @@ public abstract class GrIntroduceHandlerBase Date: Sat, 3 Dec 2011 16:21:22 +0400 Subject: [PATCH 5/7] capitalize dialog names & some cleanup --- .../plugins/groovy/GroovyBundle.properties | 10 ++++----- .../GroovyCodeInsightBundle.properties | 2 +- .../dynamic/DynamicToolWindowWrapper.java | 21 +++++++++++-------- .../intentions/dynamic/ui/DynamicDialog.java | 11 ++++------ .../groovy/codeInspection/BaseInspection.java | 3 --- .../GroovyInspectionBundle.properties | 4 ++-- .../groovy/compiler/GroovyCompiler.java | 3 ++- .../groovy/grape/GrabDependencies.java | 3 ++- .../GroovyIntentionsBundle.properties | 4 ++-- .../GroovyMapParameterDialog.java | 2 +- .../plugins/groovy/mvc/MvcConsole.java | 4 ++-- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties index 8b7b70e6c566..8b6b797ae88d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties @@ -260,7 +260,7 @@ class.is.not.expected.here=Class is not expected here fix.package.name=Fix package name #dynamic properties -add.dynamic.property=Add dynamic property ''{0}'' +add.dynamic.property=Add Dynamic Property ''{0}'' duplicate.element.in.the.map=Duplicate element in the map dynamic.toolwindow.search.elements=Search dynamic element dynamic.toolwindow.property.filter=Property Filter @@ -271,16 +271,16 @@ create.field.from.usage=Create Field ''{0}'' create.method.from.usage=Create Method ''{0}'' create.variable.from.usage=Create Variable ''{0}'' add.dynamic.element=Add dynamic element -add.dynamic.method=Add dynamic method +add.dynamic.method=Add Dynamic Method dynamic.type=Type dynamic.name=Name dynamic.properties.table.name=Method arguments dynamic.method.return.type=Return type dynamic.method.property.type=Property type are.you.sure.to.delete.dynamic.property=Are you sure to delete ''{0}''? -dynamic.property.deletion=Deletion dynamic property +dynamic.property.deletion=Deletion Dynamic Property are.you.sure.to.delete.elements=Are you sure to delete ''{0}'' elements? -dynamic.element.deletion=Dynamic element deletion +dynamic.element.deletion=Dynamic Element Deletion dynamic.window=Dynamic window dynamic.properties.table.no.arguments=Arguments list is empty. assignment.expected='=' expected @@ -304,7 +304,7 @@ break.outside.loop=The break statement with named labels is only allowed inside Constructor=Constructor Getter=Getter Setter=Setter -groovy.like.library.found=Groovy library found +groovy.like.library.found=Groovy Library Found groovy.like.library.found.text=Do you want to set up Groovy for module ''{0}'' \n\ with found library ''{1}'' (Groovy version {2})? compile.groovy.files=&Compile Groovy files diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.properties index 9b5b7606bac5..f42faeabcaac 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/GroovyCodeInsightBundle.properties @@ -1,5 +1,5 @@ generate.equals.and.hashcode.already.defined.warning.anonymous=equals() and hashCode() already defined generate.equals.and.hashcode.already.defined.warning=equals() and hashCode() already defined -generate.equals.and.hashcode.already.defined.title=equals() and hashCode() already defined +generate.equals.and.hashcode.already.defined.title=equals() and hashCode() Already Defined generate.equals.compare.nested.arrays.comment= // Compare nested arrays - values of {0} here generate.equals.compare.arrays.comment= // Probably incorrect - comparing Object[] arrays with Arrays.equals \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/DynamicToolWindowWrapper.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/DynamicToolWindowWrapper.java index 46d8dd4b7372..512e00e1dc75 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/DynamicToolWindowWrapper.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/DynamicToolWindowWrapper.java @@ -40,14 +40,15 @@ import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns; import com.intellij.ui.treeStructure.treetable.TreeTable; import com.intellij.ui.treeStructure.treetable.TreeTableModel; import com.intellij.ui.treeStructure.treetable.TreeTableTree; -import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.AbstractTableCellEditor; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.GroovyBundle; import org.jetbrains.plugins.groovy.GroovyFileType; @@ -66,6 +67,7 @@ import javax.swing.tree.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Collection; @@ -247,7 +249,7 @@ public class DynamicToolWindowWrapper { myTreeTable.setTreeCellRenderer(treeCellRenderer); myTreeTable.setRootVisible(false); - myTreeTable.setSelectionMode(DefaultTreeSelectionModel.CONTIGUOUS_TREE_SELECTION); + myTreeTable.setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION); final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor(); @@ -318,11 +320,11 @@ public class DynamicToolWindowWrapper { final String qualifiedName = ((PsiClass)element).getQualifiedName(); return new RefactoringElementListener() { - public void elementMoved(PsiElement newElement) { + public void elementMoved(@NotNull PsiElement newElement) { renameElement(qualifiedName, newElement); } - public void elementRenamed(PsiElement newElement) { + public void elementRenamed(@NotNull PsiElement newElement) { renameElement(qualifiedName, newElement); } @@ -358,7 +360,7 @@ public class DynamicToolWindowWrapper { final int selectionRow = myTreeTable.getTree().getLeadSelectionRow(); myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event); } - }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, KeyEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); + }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); // todo use "myTreeTable.setAutoCreateRowSorter(true);" since 1.6 @@ -510,7 +512,7 @@ public class DynamicToolWindowWrapper { } } - class ClassColumnInfo extends ColumnInfo { + static class ClassColumnInfo extends ColumnInfo { public ClassColumnInfo(String name) { super(name); } @@ -565,7 +567,7 @@ public class DynamicToolWindowWrapper { if (!(childObject instanceof DItemElement)) break; filterText = getFilter(); - if (filterText == null || "".equals(filterText)) { + if (filterText == null || filterText.isEmpty()) { ((DItemElement)childObject).setHightlightedText(""); dynamicNodes.add(dynamicNode); @@ -689,7 +691,8 @@ public class DynamicToolWindowWrapper { } private static String[] mapToUnqualified(final String[] argumentsNames) { - return ContainerUtil.map2Array(argumentsNames, String.class, new Function() { + return ContainerUtil.map2Array(argumentsNames, String.class, new NullableFunction() { + @Nullable public String fun(final String s) { if (s == null) return null; int index = s.lastIndexOf("."); @@ -741,7 +744,7 @@ public class DynamicToolWindowWrapper { if (element == null) return null; return element.getContainingFile(); - } else if (LangDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) { + } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) { return new DeleteProvider() { @Override public void deleteElement(DataContext dataContext) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.java index 42b165d1c77d..2d6746084924 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.java @@ -148,7 +148,7 @@ public abstract class DynamicDialog extends DialogWrapper { setStatusTextAndIcon(null, ""); } - private void setStatusTextAndIcon(final Icon icon, final String text) { + private void setStatusTextAndIcon(@Nullable final Icon icon, final String text) { myTypeStatusLabel.setIcon(icon); myTypeStatusLabel.setText(text); pack(); @@ -177,7 +177,7 @@ public abstract class DynamicDialog extends DialogWrapper { public void actionPerformed(ActionEvent e) { myClassComboBox.requestFocus(); } - }, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); + }, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); } @Nullable @@ -191,7 +191,7 @@ public abstract class DynamicDialog extends DialogWrapper { final EditorComboBoxEditor comboEditor = new EditorComboBoxEditor(myProject, GroovyFileType.GROOVY_FILE_TYPE); final Document document = createDocument(""); - assert document != null; + LOG.assertTrue(document != null); comboEditor.setItem(document); @@ -213,7 +213,7 @@ public abstract class DynamicDialog extends DialogWrapper { public void actionPerformed(ActionEvent e) { myTypeComboBox.requestFocus(); } - }, KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); + }, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); final EditorTextField editorTextField = (EditorTextField) myTypeComboBox.getEditor().getEditorComponent(); @@ -228,9 +228,6 @@ public abstract class DynamicDialog extends DialogWrapper { }); PsiType type = typeConstraints.length == 1 ? typeConstraints[0].getDefaultType() : TypesUtil.getJavaLangObject(myContext); - if (type == null) { - type = TypesUtil.getJavaLangObject(myContext); - } myTypeComboBox.getEditor().setItem(createDocument(type.getCanonicalText())); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspection.java index 7a030222512d..a7d6f5302f2c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspection.java @@ -95,9 +95,6 @@ public abstract class BaseInspection extends GroovySuppressableInspectionTool { final BaseInspectionVisitor visitor = buildGroovyVisitor(problemsHolder, isOnTheFly); groovyFile.accept(visitor); final List problems = problemsHolder.getResults(); - if (problems == null) { - return null; - } return problems.toArray(new ProblemDescriptor[problems.size()]); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.properties index cc1890234c9f..e89d06c35cff 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionBundle.properties @@ -46,7 +46,7 @@ dynamic.property=Dynamic property unresolved.type.status=Type ''{0}'' is not resolved resolved.type.status=Type ''{0}'' is resolved no.type.specified=No type specified -dynamic.element=Dynamic element +dynamic.element=Dynamic Element ######################################################################################################################## # InpectorGroovy properties @@ -57,7 +57,7 @@ pointless.boolean.display.name=Pointless boolean expression pointless.boolean.quickfix=Simplify Cannot.perform.undo.operation=Cannot perform undo operation -Undo.disable=Undo disabled +Undo.disable=Undo Disabled field.already.defined=Variables with field names access.to.inaccessible.element=Access to inaccessible element diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompiler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompiler.java index 4dc37f8f06f6..4f20b2256506 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompiler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompiler.java @@ -138,7 +138,8 @@ public class GroovyCompiler extends GroovyCompilerBase { "You seem to have global Groovy AST transformations defined in your project,\n" + "but they won't be applied to your code because they are not marked as compiler resources.\n" + "Do you want to add them to compiler resource list?\n" + - "(you can do it yourself later in Settings | Compiler | Resource patterns)", "AST Transformations found", + "(you can do it yourself later in Settings | Compiler | Resource patterns)", + "AST Transformations Found", GroovyIcons.GROOVY_ICON_32x32); if (result == 0) { CompilerConfiguration.getInstance(myProject).addResourceFilePattern(AST_TRANSFORM_FILE_NAME); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java index d19dce534bf8..609d1db536bc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java @@ -103,7 +103,8 @@ public class GrabDependencies implements IntentionAction { assert vfile != null; if (JavaPsiFacade.getInstance(project).findClass("org.apache.ivy.core.report.ResolveReport", file.getResolveScope()) == null) { - Messages.showErrorDialog("Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.", "Ivy missing"); + Messages.showErrorDialog("Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.", + "Ivy Missing"); return; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties index 17988f9cecce..23bda96924da 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties @@ -90,7 +90,7 @@ do.not.create.first.new=Use &existing first parameter as map for named arguments convert.cannot.itself=Refactoring is not available for map parameter itself perform.refactoring=Performing refactoring map.param.name=Map parameter &name: -convert.param.to.map.entry=Convert parameter to map entry +convert.param.to.map.entry=Convert Parameter to Map Entry convert.java.style.array.intention.name=Convert java-style array creation convert.java.style.array.intention.family.name=Convert Java-Style Array Creation to Groovy Syntax @@ -102,7 +102,7 @@ create.parameter.for.field=Add parameter for field ''{0}'' create.parameter.for.fields=Add parameter for field... closure.used.as.variable=Closure is passed as argument. Refactoring can break semantic. -convert.map.to.class.intention.name=Convert to class +convert.map.to.class.intention.name=Convert to Class convert.map.to.class.intention.family.name=Convert Groovy native map to class instances do.you.want.to.change.method.return.type=Do you want to change return type of ''{0}'' method do.you.want.to.change.variable.type=Do you want to change type of ''{0}'' diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/GroovyMapParameterDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/GroovyMapParameterDialog.java index cbec4da4b9e5..996026fa150a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/GroovyMapParameterDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/GroovyMapParameterDialog.java @@ -161,7 +161,7 @@ public class GroovyMapParameterDialog extends DialogWrapper { public void actionPerformed(ActionEvent e) { myNameComboBox.requestFocus(); } - }, KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); + }, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); for (String possibleName : possibleNames) { myNameComboBox.addItem(possibleName); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java index 883140d6cb76..a0af4d23a3d1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java @@ -294,7 +294,7 @@ public class MvcConsole implements Disposable { catch (final IOException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - Messages.showErrorDialog(e.getMessage(), "Cannot start process"); + Messages.showErrorDialog(e.getMessage(), "Cannot Start Process"); try { if (onDone != null && !module.isDisposed()) onDone.run(); @@ -359,7 +359,7 @@ public class MvcConsole implements Disposable { super("Kill process", "Kill process", KILL_PROCESS_ICON); } - public void setHandler(OSProcessHandler handler) { + public void setHandler(@Nullable OSProcessHandler handler) { myHandler = handler; } From c8ad54490972cab475fa4c65fc108ff7c986a136 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Sat, 3 Dec 2011 21:17:21 +0100 Subject: [PATCH 6/7] Same-width buttons in New Project wizard --- .../intellij/ide/wizard/AbstractWizard.java | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java index c3605e2bc7e4..aad1e97eedc1 100644 --- a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java +++ b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.ide.wizard; +import com.google.common.collect.Lists; import com.intellij.CommonBundle; import com.intellij.ide.IdeBundle; import com.intellij.openapi.application.ApplicationInfo; @@ -37,6 +38,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -113,10 +115,11 @@ public abstract class AbstractWizard extends DialogWrapper { panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0)); JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - panel.add(buttonPanel, BorderLayout.EAST); if (SystemInfo.isMac) { + panel.add(buttonPanel, BorderLayout.EAST); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + myHelpButton.putClientProperty("JButton.buttonType", "help"); if (UIUtil.isUnderAquaLookAndFeel()) { myHelpButton.setText(""); @@ -127,7 +130,6 @@ public abstract class AbstractWizard extends DialogWrapper { leftPanel.add(myHelpButton); } leftPanel.add(myCancelButton); - panel.add(leftPanel, BorderLayout.WEST); buttonPanel.add(myFinishButton); @@ -139,20 +141,27 @@ public abstract class AbstractWizard extends DialogWrapper { } } else { + panel.add(buttonPanel, BorderLayout.EAST); + GroupLayout layout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(layout); + layout.setAutoCreateGaps(true); + + final GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup(); + final GroupLayout.ParallelGroup vGroup = layout.createParallelGroup(); + final Collection buttons = Lists.newArrayListWithExpectedSize(5); + final boolean helpAvailable = ApplicationInfo.contextHelpAvailable(); + if (mySteps.size() > 1) { - buttonPanel.add(myPreviousButton); - buttonPanel.add(Box.createHorizontalStrut(5)); - buttonPanel.add(myNextButton); - buttonPanel.add(Box.createHorizontalStrut(5)); + add(hGroup, vGroup, buttons, myPreviousButton, myNextButton); + } + add(hGroup, vGroup, buttons, myFinishButton, myCancelButton); + if (helpAvailable) { + add(hGroup, vGroup, buttons, myHelpButton); } - buttonPanel.add(myFinishButton); - buttonPanel.add(Box.createHorizontalStrut(5)); - buttonPanel.add(myCancelButton); - buttonPanel.add(Box.createHorizontalStrut(5)); - if (ApplicationInfo.contextHelpAvailable()) { - buttonPanel.add(myHelpButton); - } + layout.setHorizontalGroup(hGroup); + layout.setVerticalGroup(vGroup); + layout.linkSize(buttons.toArray(new Component[buttons.size()])); } myPreviousButton.setEnabled(false); @@ -201,6 +210,17 @@ public abstract class AbstractWizard extends DialogWrapper { return panel; } + private static void add(final GroupLayout.Group hGroup, + final GroupLayout.Group vGroup, + final Collection all, + final Component... components) { + for (Component component : components) { + hGroup.addComponent(component); + vGroup.addComponent(component); + all.add(component); + } + } + private static class TallImageComponent extends OpaquePanel { private Icon myIcon; From 211495498e824836370dbccae185d6dc35363df4 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Sat, 3 Dec 2011 22:09:58 +0100 Subject: [PATCH 7/7] Place help button on the left under GTK+ --- .../src/com/intellij/ide/wizard/AbstractWizard.java | 12 ++++++++---- .../src/com/intellij/openapi/ui/DialogWrapper.java | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java index aad1e97eedc1..1753af12cf65 100644 --- a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java +++ b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizard.java @@ -141,7 +141,7 @@ public abstract class AbstractWizard extends DialogWrapper { } } else { - panel.add(buttonPanel, BorderLayout.EAST); + panel.add(buttonPanel, BorderLayout.CENTER); GroupLayout layout = new GroupLayout(buttonPanel); buttonPanel.setLayout(layout); layout.setAutoCreateGaps(true); @@ -151,11 +151,15 @@ public abstract class AbstractWizard extends DialogWrapper { final Collection buttons = Lists.newArrayListWithExpectedSize(5); final boolean helpAvailable = ApplicationInfo.contextHelpAvailable(); + if (helpAvailable && UIUtil.isUnderGTKLookAndFeel()) { + add(hGroup, vGroup, buttons, myHelpButton); + } + add(hGroup, vGroup, null, Box.createHorizontalGlue()); if (mySteps.size() > 1) { add(hGroup, vGroup, buttons, myPreviousButton, myNextButton); } add(hGroup, vGroup, buttons, myFinishButton, myCancelButton); - if (helpAvailable) { + if (helpAvailable && !UIUtil.isUnderGTKLookAndFeel()) { add(hGroup, vGroup, buttons, myHelpButton); } @@ -212,12 +216,12 @@ public abstract class AbstractWizard extends DialogWrapper { private static void add(final GroupLayout.Group hGroup, final GroupLayout.Group vGroup, - final Collection all, + @Nullable final Collection collection, final Component... components) { for (Component component : components) { hGroup.addComponent(component); vGroup.addComponent(component); - all.add(component); + if (collection != null) collection.add(component); } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index b2cbf6be8258..63c853ea532c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -368,6 +368,10 @@ public abstract class DialogWrapper { } } } + else if (UIUtil.isUnderGTKLookAndFeel() && Arrays.asList(actions).contains(getHelpAction())) { + leftSideActions = ArrayUtil.append(leftSideActions, getHelpAction()); + actions = ArrayUtil.remove(actions, getHelpAction()); + } JPanel panel = new JPanel(new BorderLayout()); final JPanel lrButtonsPanel = new JPanel(new GridBagLayout());