From f13e3334057b92c8e1d2d832181170ba79846942 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 17 Oct 2012 19:32:44 +0200 Subject: [PATCH 01/43] Annotation. --- .../com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java index 3d4624840112..be9715fff9a5 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java @@ -32,6 +32,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashSet; @@ -89,7 +90,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements JDOMExternaliz } @Override - public final void setVersionString(String versionString) { + public final void setVersionString(@Nullable String versionString) { myVersionString = versionString == null || versionString.isEmpty() ? null : versionString; myVersionDefined = true; } From a2be6066cf6fec1fc9668465c0b1924b7c8d68dd Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 18 Oct 2012 17:50:09 +0200 Subject: [PATCH 02/43] IDEA-92967 (Inspections / Imports / Unused Import: superfluous warning with both static and non-static elements importing) --- .../siyeh/ig/imports/ImportsAreUsedVisitor.java | 16 ++++++++++------ .../siyeh/igtest/imports/unused/Constants.java | 3 +++ .../igtest/imports/unused/UnusedImport.java | 7 +++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java index 6753839eb83d..ecdfbbb4be33 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java @@ -44,14 +44,12 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor { } @Override - public void visitReferenceElement( - @NotNull PsiJavaCodeReferenceElement reference) { + public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) { followReferenceToImport(reference); super.visitReferenceElement(reference); } - private void followReferenceToImport( - PsiJavaCodeReferenceElement reference) { + private void followReferenceToImport(PsiJavaCodeReferenceElement reference) { if (reference.getQualifier() != null) { // it's already fully qualified, so the import statement wasn't // responsible @@ -89,8 +87,14 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor { final String referenceName; if (element instanceof PsiMember) { final PsiMember member = (PsiMember)element; - referenceClass = member.getContainingClass(); - referenceName = member.getName(); + if (member instanceof PsiClass && !member.hasModifierProperty(PsiModifier.STATIC)) { + referenceClass = null; + referenceName = null; + } + else { + referenceClass = member.getContainingClass(); + referenceName = member.getName(); + } } else { referenceClass = null; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java index 6d8e9caff9ff..8aeb52ef35be 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java @@ -4,4 +4,7 @@ public class Constants { public static final int SIZE = 213; + private int field = 0; // I'm not an utility class. + public static void instanceMatMethod() {} + @SuppressWarnings("InnerClassMayBeStatic") public class InstanceInnerMaterial {} } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java index adab39f11837..bbe03b5073f7 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java @@ -6,6 +6,8 @@ import static java.lang.Math.*; import static java.lang.Integer.SIZE; import java.util.List; import java.util.ArrayList; +import static com.siyeh.igtest.imports.unused.Constants.*; +import com.siyeh.igtest.imports.unused.Constants.*; public class UnusedImport { @@ -22,4 +24,9 @@ public class UnusedImport { list.add(i); Entry entry; } + + public void context() { + instanceMatMethod(); + InstanceInnerMaterial innerMaterial = new Constants().new InstanceInnerMaterial(); + } } \ No newline at end of file From cbc7614e096b0a129e3c319f11724470347fbfbd Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 18 Oct 2012 20:13:19 +0400 Subject: [PATCH 03/43] IDEA-93113 Don't show incoming changes and warn about outdated version if incoming changes are not supported by the VCS committed changes provider. --- .../vcs/changes/committed/IncomingChangesIndicator.java | 8 +++----- .../vcs/changes/committed/OutdatedVersionNotifier.java | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java index 225d9089ea35..6ff8cee677f1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java @@ -22,10 +22,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.VcsListener; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.openapi.wm.*; @@ -98,7 +95,8 @@ public class IncomingChangesIndicator { private boolean needIndicator() { final AbstractVcs[] vcss = ProjectLevelVcsManager.getInstance(myProject).getAllActiveVcss(); for (AbstractVcs vcs : vcss) { - if (vcs.getCachingCommittedChangesProvider() != null) { + CachingCommittedChangesProvider provider = vcs.getCachingCommittedChangesProvider(); + if (provider != null && provider.supportsIncomingChanges()) { return true; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java index 7554afd4f093..03df6d2e2fd6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java @@ -25,6 +25,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vcs.CachingCommittedChangesProvider; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; @@ -150,6 +151,9 @@ public class OutdatedVersionNotifier implements ProjectComponent { } private void initPanel(final CommittedChangeList list, final Change c, final FileEditor editor) { + if (!isIncomingChangesSupported(list)) { + return; + } final OutdatedRevisionPanel component = new OutdatedRevisionPanel(list, c); editor.putUserData(PANEL_KEY, component); myFileEditorManager.addTopComponent(editor, component); @@ -205,4 +209,9 @@ public class OutdatedVersionNotifier implements ProjectComponent { updateLabelText(c); } } + + private static boolean isIncomingChangesSupported(@NotNull CommittedChangeList list) { + CachingCommittedChangesProvider provider = list.getVcs().getCachingCommittedChangesProvider(); + return provider != null && provider.supportsIncomingChanges(); + } } From 9d8fc403abb2a64cc28efdb78a1a8028b3caa772 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Thu, 18 Oct 2012 20:19:51 +0400 Subject: [PATCH 04/43] IDEA-90515 Editor tab dragged by dragging Configuration Menu pop-out items --- .../src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java index c7c9638a39c7..184e00782636 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java @@ -25,6 +25,7 @@ import com.intellij.openapi.ui.impl.GlassPaneDialogWrapperPeer; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.IdeGlassPane; import com.intellij.openapi.wm.IdeGlassPaneUtil; +import com.intellij.ui.popup.AbstractPopup; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -254,7 +255,8 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent if (window != null) { for (Component component : window.getComponents()) { if (component instanceof JComponent - && UIUtil.findComponentOfType((JComponent)component, JPopupMenu.class) != null) { + && ((UIUtil.findComponentOfType((JComponent)component, JPopupMenu.class) != null) + || (UIUtil.findComponentOfType((JComponent)component, AbstractPopup.MyContentPanel.class) != null))) { return true; } } From e73492cd2bb95d0a25028999f1e5bf70085f2b09 Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Thu, 18 Oct 2012 18:28:34 +0200 Subject: [PATCH 05/43] Code tolerates null ProgressIndicatorProvider --- .../searches/ClassInheritorsSearch.java | 2 +- .../impl/search/AllClassesSearchExecutor.java | 2 +- .../psi/impl/compiled/ClsFileImpl.java | 2 +- .../progress/ProgressIndicatorProvider.java | 16 +++++++ .../core/CoreApplicationEnvironment.java | 42 ++++++++++--------- .../extapi/psi/StubBasedPsiElementBase.java | 2 +- .../intellij/lang/impl/PsiBuilderImpl.java | 3 +- .../components/impl/ComponentManagerImpl.java | 3 +- .../psi/impl/search/PsiSearchHelperImpl.java | 6 +-- .../module/impl/ModuleManagerImpl.java | 2 +- .../roots/impl/DirectoryIndexImpl.java | 3 +- 11 files changed, 50 insertions(+), 33 deletions(-) diff --git a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java index bf7b89870d83..233bb4251508 100644 --- a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java +++ b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java @@ -58,7 +58,7 @@ public class ClassInheritorsSearch extends ExtensibleQueryFactory() { diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java index 84ca70fbd3b9..bae61557780e 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java @@ -66,7 +66,7 @@ public class AllClassesSearchExecutor implements QueryExecutor final ASTNode mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror); //IMPORTANT: do not take lock too early - FileDocumentManager.getInstance().saveToString() can run write action... - final NonCancelableSection section = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + final NonCancelableSection section = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { setMirror((TreeElement)mirrorTreeElement); diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java index 31c7e5b0b1eb..70e1757acea5 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.progress; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -33,8 +34,23 @@ public abstract class ProgressIndicatorProvider { protected abstract void doCheckCanceled() throws ProcessCanceledException; + @Nullable + public static ProgressIndicator getGlobalProgressIndicator() { + return ourInstance != null ? ourInstance.getProgressIndicator() : null; + } + public abstract NonCancelableSection startNonCancelableSection(); + @NotNull + public static NonCancelableSection startNonCancelableSectionIfSupported() { + return ourInstance != null ? ourInstance.startNonCancelableSection() : new NonCancelableSection() { + @Override + public void done() { + // do nothing + } + }; + } + public static boolean ourNeedToCheckCancel = false; public static void checkCanceled() throws ProcessCanceledException { // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index 9602e9463bc2..f98f1ffe1737 100644 --- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -125,25 +125,7 @@ public class CoreApplicationEnvironment { registerApplicationExtensionPoint(ContentBasedFileSubstitutor.EP_NAME, ContentBasedFileSubstitutor.class); registerExtensionPoint(Extensions.getRootArea(), BinaryFileStubBuilders.EP_NAME, FileTypeExtensionPoint.class); - ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { - @Override - public ProgressIndicator getProgressIndicator() { - return new EmptyProgressIndicator(); - } - - @Override - protected void doCheckCanceled() throws ProcessCanceledException { - } - - @Override - public NonCancelableSection startNonCancelableSection() { - return new NonCancelableSection() { - @Override - public void done() { - } - }; - } - }; + ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider(); myApplication.registerService(JobLauncher.class, new JobLauncher() { @Override @@ -194,6 +176,28 @@ public class CoreApplicationEnvironment { } + protected ProgressIndicatorProvider createProgressIndicatorProvider() { + return new ProgressIndicatorProvider() { + @Override + public ProgressIndicator getProgressIndicator() { + return new EmptyProgressIndicator(); + } + + @Override + protected void doCheckCanceled() throws ProcessCanceledException { + } + + @Override + public NonCancelableSection startNonCancelableSection() { + return new NonCancelableSection() { + @Override + public void done() { + } + }; + } + }; + } + protected VirtualFileSystem createJarFileSystem() { return new CoreJarFileSystem(); } diff --git a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java index 06fbbd248ba0..aa3cb9a2c57a 100644 --- a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java +++ b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java @@ -73,7 +73,7 @@ public class StubBasedPsiElementBase extends ASTDelegateP synchronized (file.getStubLock()) { node = myNode; if (node == null) { - NonCancelableSection criticalSection = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + NonCancelableSection criticalSection = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { if (!file.isValid()) throw new PsiInvalidElementAccessException(this); FileElement treeElement = file.getTreeElement(); diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index eb8e7e9aaf3a..36f78f255abe 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -1053,8 +1053,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder, AS final MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null); final MyComparator comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure); - final ProgressIndicatorProvider provider = ProgressIndicatorProvider.getInstance(); - final ProgressIndicator indicator = provider != null ? provider.getProgressIndicator() : null; + final ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator); return diffLog; } diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 8e14a3bb733d..5b7dff1258d3 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -230,8 +230,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Nullable protected static ProgressIndicator getProgressIndicator() { - final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance(); - return progressManager != null ? progressManager.getProgressIndicator() : null; + return ProgressIndicatorProvider.getGlobalProgressIndicator(); } protected double getPercentageOfComponentsLoaded() { diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 096e4958d37b..90f411c3b023 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -119,7 +119,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (text.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (searchScope instanceof GlobalSearchScope) { StringSearcher searcher = new StringSearcher(text, caseSensitively, true); @@ -344,7 +344,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (qName.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); int dotIndex = qName.lastIndexOf('.'); int dollarIndex = qName.lastIndexOf('$'); @@ -487,7 +487,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { appendCollectorsFromQueryRequests(collectors); - ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); do { final MultiMap, RequestWithProcessor> globals = new MultiMap, RequestWithProcessor>(); final List> customs = ContainerUtil.newArrayList(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 2884248ba360..62ea139d6561 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -199,7 +199,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project protected void loadModules(final ModuleModelImpl moduleModel) { if (myModulePaths != null && myModulePaths.size() > 0) { - final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progressIndicator != null) { progressIndicator.setText("Loading modules..."); progressIndicator.setText2(""); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 6844fc83e74d..d6b4c35c6824 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -634,8 +634,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } protected void doInitialize(boolean reverseAllSets/* for testing order independence*/) { - final ProgressIndicatorProvider progressIndicatorProvider = ProgressIndicatorProvider.getInstance(); - ProgressIndicator progress = progressIndicatorProvider == null ? null : progressIndicatorProvider.getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progress == null) progress = new EmptyProgressIndicator(); progress.pushState(); From a630a8ba7443942408540d5b35eb5dd22c5e5988 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 12:33:30 +0200 Subject: [PATCH 06/43] validity assertions (EA-38796) --- .../com/intellij/psi/impl/source/PsiImmediateClassType.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java index f2436d2270ee..d815bab4235f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java @@ -86,6 +86,7 @@ public class PsiImmediateClassType extends PsiClassType { myClass = aClass; myManager = aClass.getManager(); mySubstitutor = substitutor; + assert substitutor.isValid(); } @Override @@ -140,6 +141,7 @@ public class PsiImmediateClassType extends PsiClassType { @Override public String getCanonicalText() { if (myCanonicalText == null) { + assert mySubstitutor.isValid(); final StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, true, false); myCanonicalText = buffer.toString(); @@ -207,12 +209,14 @@ public class PsiImmediateClassType extends PsiClassType { pineBuffer.append('<'); for (int i = 0; i < typeParameters.length; i++) { PsiTypeParameter typeParameter = typeParameters[i]; + assert typeParameter.isValid(); if (i > 0) pineBuffer.append(','); final PsiType substitutionResult = substitutor.substitute(typeParameter); if (substitutionResult == null) { pineBuffer = null; break; } + assert substitutionResult.isValid(); if (canonical) { if (internal) { pineBuffer.append(substitutionResult.getInternalCanonicalText()); From 932362f7e77f9b6a6e002f9f3ec696c04acff8f0 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 12:35:22 +0200 Subject: [PATCH 07/43] validity assertions (EA-39233) --- .../completion/JavaMemberNameCompletionContributor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java index ca2c38a8f61b..f229536f13cc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java @@ -376,11 +376,15 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor { for (final PsiField field : fields) { if (field == element) continue; - assert field.isValid(); + + assert field.isValid() : "invalid field: " + field; + PsiType fieldType = field.getType(); + assert fieldType.isValid() : "invalid field type: " + field + "; " + fieldType; + final PsiModifierList modifierList = field.getModifierList(); if (staticContext && (modifierList != null && !modifierList.hasModifierProperty(PsiModifier.STATIC))) continue; - if (field.getType().equals(varType)) { + if (fieldType.equals(varType)) { final String getterName = PropertyUtil.suggestGetterName(field.getProject(), field); if ((psiClass.findMethodsByName(getterName, true).length == 0 || psiClass.findMethodBySignature(PropertyUtil.generateGetterPrototype(field), true) == null)) { From 6f026776797b54f829eaae367e3467f4609186c4 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 12:37:04 +0200 Subject: [PATCH 08/43] validity assertions (EA-39252) --- .../src/com/intellij/codeInsight/ExpectedTypesProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index 40f9d755ee95..e2e135a661f2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -1037,6 +1037,7 @@ public class ExpectedTypesProvider { @NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor, @NotNull final Set array) { + LOG.assertTrue(substitutor.isValid()); PsiParameter[] parameters = method.getParameterList().getParameters(); if (!forCompletion && parameters.length != args.length) return; if (parameters.length <= index && !method.isVarArgs()) return; @@ -1172,6 +1173,7 @@ public class ExpectedTypesProvider { private static PsiType getParameterType(@NotNull PsiParameter parameter, @NotNull PsiSubstitutor substitutor) { PsiType type = parameter.getType(); + LOG.assertTrue(type.isValid()); if (parameter.isVarArgs()) { if (type instanceof PsiArrayType) { type = ((PsiArrayType)type).getComponentType(); From af67001e722b040de4939664418e9aff10ba700b Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 12:59:48 +0200 Subject: [PATCH 09/43] FileHolder.toString --- .../vcs-api/src/com/intellij/openapi/vcs/FileHolder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java b/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java index ee27e55cd0ea..ebe2cc62577e 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java @@ -76,4 +76,13 @@ public class FileHolder { public void setIsDir(boolean isDir) { myIsDir = isDir; } + + @Override + public String toString() { + return "FileHolder{" + + "myIoFile=" + myIoFile + + ", myFile=" + myFile + + ", myIsDir=" + myIsDir + + '}'; + } } From 871f5378f0b9b6f57ad08f654abfbf915d44e61f Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 15:34:44 +0200 Subject: [PATCH 10/43] catch ProcessCanceledException during changes update --- .../intellij/openapi/vcs/changes/ChangeListManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index 15e71e12cb1e..19f91605f350 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -633,11 +633,12 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec handleUpdateException(e); } } + } catch (ProcessCanceledException ignore) { } catch (Throwable t) { LOG.debug(t); Rethrow.reThrowRuntime(t); } finally { - if (! myUpdater.isStopped()) { + if (!myUpdater.isStopped()) { dataHolder.notifyDoneProcessingChanges(); } } From 1b4658481e655ff5fe66fd0047350057427cd7cb Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 18 Oct 2012 17:13:32 +0200 Subject: [PATCH 11/43] iterate dirty scope using actual vfs --- .../vcs/changes/VcsDirtyScopeImpl.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java index c2542fb3bfda..de0d9b6fa6a0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java @@ -419,7 +419,7 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { THashSet dirsByRoot = myDirtyDirectoriesRecursively.get(root); if (dirsByRoot != null) { for (FilePath dir : dirsByRoot) { - final VirtualFile vFile = dir.getVirtualFile(); + final VirtualFile vFile = obtainVirtualFile(dir); if (vFile != null && vFile.isValid()) { myVcsManager.iterateVfUnderVcsRoot(vFile, processor); } @@ -431,13 +431,13 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { final THashSet files = myDirtyFiles.get(root); if (files != null) { for (FilePath file : files) { - if (file.getVirtualFile() != null) { - processor.process(file.getVirtualFile()); - } - final VirtualFile vFile = file.getVirtualFile(); - if (vFile != null && vFile.isValid() && vFile.isDirectory()) { - for (VirtualFile child : vFile.getChildren()) { - processor.process(child); + VirtualFile vFile = obtainVirtualFile(file); + if (vFile != null && vFile.isValid()) { + processor.process(vFile); + if (vFile.isDirectory()) { + for (VirtualFile child : vFile.getChildren()) { + processor.process(child); + } } } } @@ -445,6 +445,12 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { } } + @Nullable + private static VirtualFile obtainVirtualFile(FilePath file) { + VirtualFile vFile = file.getVirtualFile(); + return vFile == null ? VfsUtil.findFileByIoFile(file.getIOFile(), false) : vFile; + } + @Override public boolean isEmpty() { return myDirtyDirectoriesRecursively.isEmpty() && myDirtyFiles.isEmpty(); From fedf3fff7af4fb8969fbe7e8014d011b581eae79 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 18 Oct 2012 19:14:39 +0200 Subject: [PATCH 12/43] - Artifact roots are not marked as "generated sources". - To properly mark artifact sources as up-to-date, compilation-start timestamp is advanced for every chunk/group of chunks before starting compilation --- .../com/intellij/compiler/BaseCompilerTestCase.java | 11 ++++++++--- .../org/jetbrains/jps/incremental/CompileContext.java | 2 ++ .../jetbrains/jps/incremental/CompileContextImpl.java | 10 ++++++++-- .../jetbrains/jps/incremental/IncProjectBuilder.java | 2 ++ .../instructions/ArtifactRootDescriptor.java | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 366a7099d0da..b9b3e748665e 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -35,6 +35,7 @@ import junit.framework.Assert; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.util.JpsPathUtil; +import javax.swing.*; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -209,10 +210,10 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { private CompilationLog compile(final ParameterizedRunnable action) { final Ref result = Ref.create(null); final Semaphore semaphore = new Semaphore(); + semaphore.down(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - semaphore.down(); CompilerManagerImpl.testSetup(); final CompileStatusNotification callback = new CompileStatusNotification() { @@ -240,14 +241,18 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { } }); - long start = System.currentTimeMillis(); + final long start = System.currentTimeMillis(); while (!semaphore.waitFor(10)) { if (System.currentTimeMillis() - start > 60 * 1000) { throw new RuntimeException("timeout"); } + if (SwingUtilities.isEventDispatchThread()) { + UIUtil.dispatchAllInvocationEvents(); + } + } + if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } - UIUtil.dispatchAllInvocationEvents(); return result.get(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java index 1c559f9da881..c03ce272ba8a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java @@ -49,6 +49,8 @@ public interface CompileContext extends UserDataHolder, MessageHandler { long getCompilationStartStamp(); + void updateCompilationStartStamp(); + void markNonIncremental(ModuleBuildTarget target); void clearNonIncrementalMark(ModuleBuildTarget target); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java index 853fa414bfe4..140fdb432dc9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java @@ -5,7 +5,8 @@ import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jps.*; +import org.jetbrains.jps.ModuleChunk; +import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.jps.builders.logging.BuildLoggingManager; @@ -34,7 +35,7 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon private final Set myNonIncrementalModules = new HashSet(); private final ProjectPaths myProjectPaths; - private final long myCompilationStartStamp; + private volatile long myCompilationStartStamp; private final ProjectDescriptor myProjectDescriptor; private final Map myBuilderParams; private final CanceledStatus myCancelStatus; @@ -64,6 +65,11 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon return myCompilationStartStamp; } + @Override + public void updateCompilationStartStamp() { + myCompilationStartStamp = System.currentTimeMillis(); + } + @Override public ProjectPaths getProjectPaths() { return myProjectPaths; diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index cd5d40998a25..b335e4fbd32a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -466,6 +466,7 @@ public class IncProjectBuilder { } } finally { + context.updateCompilationStartStamp(); pd.dataManager.closeSourceToOutputStorages(groupChunks); pd.dataManager.flush(true); } @@ -478,6 +479,7 @@ public class IncProjectBuilder { buildChunkIfAffected(context, scope, chunk); } finally { + context.updateCompilationStartStamp(); pd.dataManager.closeSourceToOutputStorages(Collections.singleton(chunk)); pd.dataManager.flush(true); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java index 46cd3a56a584..2b3ca83ff73b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java @@ -94,6 +94,6 @@ public abstract class ArtifactRootDescriptor extends BuildRootDescriptor { @Override public boolean isGenerated() { - return true;//todo[nik] we cannot detect if this root is generated by some other compiler (e.g. javac) so threat all roots as generated for now + return false;//todo[nik] we cannot detect if this root is generated by some other compiler (e.g. javac) so treat all roots as non-generated for now } } From 7bf48f5252587e5253643dde1e3ddacf4a243072 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Oct 2012 18:26:34 +0200 Subject: [PATCH 13/43] eclipse: cleanup model (IDEA-91002) --- .../idea/eclipse/config/EclipseModuleManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java index 69b6268935e8..90e4356661e7 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java @@ -208,6 +208,8 @@ public class EclipseModuleManager implements PersistentStateComponent{ } public void loadState(Element state) { + clear(); + for (Object o : state.getChildren(LIBELEMENT)) { myEclipseUrls.add(((Element)o).getAttributeValue(VALUE_ATTR)); } @@ -233,6 +235,13 @@ public class EclipseModuleManager implements PersistentStateComponent{ } } + private void clear() { + myEclipseUrls.clear(); + myEclipseVariablePaths.clear(); + myUnknownCons.clear(); + mySrcPlace.clear(); + } + public void setExpectedModuleSourcePlace(int expectedModuleSourcePlace) { myExpectedModuleSourcePlace = expectedModuleSourcePlace; } From b87a66990cd995cc989f3d7babf592d4e722acb5 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Oct 2012 19:17:29 +0200 Subject: [PATCH 14/43] nullable problems: do not suggest to annotate as @Nullable when parameter is referenced (IDEA-93083) --- .../nullable/NullableStuffInspection.java | 26 ++++++++++++++----- .../nullableFieldNotnullParam/expected.xml | 9 +++++++ .../nullableFieldNotnullParam/src/Test.java | 21 +++++++++++++++ .../NullableStuffInspectionTest.java | 1 + 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml create mode 100644 java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java diff --git a/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java b/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java index 6530c36e7f55..bfd78c78ca48 100644 --- a/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java @@ -174,13 +174,25 @@ public class NullableStuffInspection extends BaseLocalInspectionTool { new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); } else if (annotated.isDeclaredNullable && manager.isNotNull(parameter, false)) { - final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier(); - assert nameIdentifier2 != null : parameter; - holder.registerProblem(nameIdentifier2, InspectionsBundle.message( - "inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno), - notNullSimpleName), - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); + boolean usedAsQualifier = !ReferencesSearch.search(parameter).forEach(new Processor() { + @Override + public boolean process(PsiReference reference) { + final PsiElement element = reference.getElement(); + if (element instanceof PsiReferenceExpression && element.getParent() instanceof PsiReferenceExpression) { + return false; + } + return true; + } + }); + if (!usedAsQualifier) { + final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier(); + assert nameIdentifier2 != null : parameter; + holder.registerProblem(nameIdentifier2, InspectionsBundle.message( + "inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno), + notNullSimpleName), + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); + } } } diff --git a/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml new file mode 100644 index 000000000000..407582e86f53 --- /dev/null +++ b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 8 + Constructor parameter for @Nullable field is annotated @NotNull + + + diff --git a/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java new file mode 100644 index 000000000000..5cebab7f41c0 --- /dev/null +++ b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java @@ -0,0 +1,21 @@ +import org.jetbrains.annotations.*; + +class Test { + @Nullable private final String baseFile; + @Nullable private final String baseFile1; + + + public Test(@NotNull String baseFile) { + this.baseFile = baseFile; + this.baseFile1 = null; + } + + public Test(@NotNull String baseFile1, boolean a) { + this.baseFile1 = baseFile1; + if (baseFile1.contains("foo")) { + this.baseFile = null; + } else { + this.baseFile = null; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java index cc843df1316e..7299acd8c8e2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java @@ -43,6 +43,7 @@ public class NullableStuffInspectionTest extends InspectionTestCase { public void testProblems() throws Exception{ doTest(); } public void testProblems2() throws Exception{ doTest(); } + public void testNullableFieldNotnullParam() throws Exception{ doTest(); } public void testJdk14() throws Exception{ doTest14(); } public void testGetterSetterProblems() throws Exception{ doTest(); } From 9188442150a10b913d6b85711b17a4d2de1e718b Mon Sep 17 00:00:00 2001 From: "andrey.zaytsev" Date: Thu, 18 Oct 2012 21:04:02 +0400 Subject: [PATCH 15/43] IDEA-92435, IDEA-91516, IDEA-91890 --- .../ui/popup/util/DetailViewImpl.java | 2 +- .../popup/util/MasterDetailPopupBuilder.java | 56 ++++++++++++++++--- .../openapi/ui/popup/PopupChooserBuilder.java | 22 ++++++-- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java b/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java index ba498473a21c..1d4b60920cec 100644 --- a/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java @@ -193,7 +193,7 @@ public class DetailViewImpl extends JPanel implements DetailView, UserDataHolder if (panel != null) { if (myDetailPanelWrapper == null) { myDetailPanelWrapper = new JPanel(new GridLayout(1, 1)); - myDetailPanelWrapper.setBorder(IdeBorderFactory.createEmptyBorder(5, 30, 5, 30)); + myDetailPanelWrapper.setBorder(IdeBorderFactory.createEmptyBorder(5, 30, 5, 5)); myDetailPanelWrapper.add(panel); add(myDetailPanelWrapper, BorderLayout.NORTH); diff --git a/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java b/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java index adb3af88de43..f985ab989e1c 100644 --- a/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java +++ b/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java @@ -22,6 +22,7 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupListener; import com.intellij.openapi.ui.popup.LightweightWindowEvent; import com.intellij.openapi.ui.popup.PopupChooserBuilder; +import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.*; @@ -30,6 +31,7 @@ import com.intellij.ui.speedSearch.FilteringListModel; import com.intellij.util.Function; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -58,6 +60,7 @@ public class MasterDetailPopupBuilder implements MasterController { private boolean myCancelOnClickOutside; private final DetailController myDetailController = new DetailController(this); + private JSplitPane mySplitPane; public String getDimensionServiceKey() { @@ -152,11 +155,6 @@ public class MasterDetailPopupBuilder implements MasterController { setCancelOnClickOutside(myCancelOnClickOutside); - if (myAddDetailViewToEast) { - builder. - setEastComponent((JComponent)myDetailView); - } - if (myDoneRunnable != null) { ActionListener actionListener = new ActionListener() { @@ -220,6 +218,11 @@ public class MasterDetailPopupBuilder implements MasterController { @Override public void onClosed(LightweightWindowEvent event) { myDetailView.clearEditor(); + if (mySplitPane != null) { + final DimensionService dimensionService = DimensionService.getInstance(); + dimensionService.setSize(getSplitterDimensionKey(), + new Dimension(mySplitPane.getDividerLocation(), 0)); + } } }); @@ -244,10 +247,10 @@ public class MasterDetailPopupBuilder implements MasterController { private PopupChooserBuilder createInnerBuilder() { if (myChooserComponent instanceof JList) { - return new PopupChooserBuilder((JList)myChooserComponent); + return new MyPopupChooserBuilder((JList)myChooserComponent); } else if (myChooserComponent instanceof JTree) { - return new PopupChooserBuilder((JTree)myChooserComponent); + return new MyPopupChooserBuilder((JTree)myChooserComponent); } return null; } @@ -338,6 +341,9 @@ public class MasterDetailPopupBuilder implements MasterController { } } else { + if (!allowedToRemoveItems(getSelectedItems()) ) { + return; + } final Object[] items = getSelectedItems(); JTree tree = (JTree)myChooserComponent; TreeUtil.removeSelected(tree); @@ -445,4 +451,40 @@ public class MasterDetailPopupBuilder implements MasterController { return this; } } + + private class MyPopupChooserBuilder extends PopupChooserBuilder { + public MyPopupChooserBuilder(@NotNull JList list) { + super(list); + } + + private MyPopupChooserBuilder(@NotNull JTree tree) { + super(tree); + } + + @Override + protected void addCenterComponentToContentPane(JPanel contentPane, JComponent component) { + if (myAddDetailViewToEast) { + mySplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, component, (JComponent)myDetailView); + + final DimensionService dimensionService = DimensionService.getInstance(); + Dimension size = dimensionService.getSize(getSplitterDimensionKey()); + if (size != null) { + mySplitPane.setDividerLocation((int)size.getWidth()); + } + + mySplitPane.setResizeWeight(0.5); + mySplitPane.setOneTouchExpandable(true); + mySplitPane.setContinuousLayout(true); + + contentPane.add(mySplitPane, BorderLayout.CENTER); + } + else { + super.addCenterComponentToContentPane(contentPane, component); + } + } + } + + private String getSplitterDimensionKey() { + return myDimensionServiceKey + ".splitter"; + } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java index 64008547fe74..47af5ebc3716 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java @@ -19,6 +19,7 @@ package com.intellij.openapi.ui.popup; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.Pair; import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; @@ -263,18 +264,18 @@ public class PopupChooserBuilder { ((JComponent)myScrollPane.getViewport().getView()).setBorder(BorderFactory.createEmptyBorder(viewportPadding.top, viewportPadding.left, viewportPadding.bottom, viewportPadding.right)); if (myChooserComponent instanceof ListWithFilter) { - contentPane.add(myChooserComponent, BorderLayout.CENTER); + addCenterComponentToContentPane(contentPane, myChooserComponent); } else { - contentPane.add(myScrollPane, BorderLayout.CENTER); + addCenterComponentToContentPane(contentPane, myScrollPane); } if (mySouthComponent != null) { - contentPane.add(mySouthComponent, BorderLayout.SOUTH); + addSouthComponentToContentPane(contentPane, mySouthComponent); } if (myEastComponent != null) { - contentPane.add(myEastComponent, BorderLayout.EAST); + addEastComponentToContentPane(contentPane, myEastComponent); } ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(contentPane, myChooserComponent); @@ -314,6 +315,19 @@ public class PopupChooserBuilder { return myPopup; } + protected void addEastComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.EAST); + } + + protected void addSouthComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.SOUTH); + } + + protected void addCenterComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.CENTER); + } + + public PopupChooserBuilder setMinSize(final Dimension dimension) { myMinSize = dimension; return this; From 71328e44bda8e543f8698522f48e06b392b246e0 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 18 Oct 2012 23:16:09 +0400 Subject: [PATCH 16/43] IDEA-92339 Database Console Copy as HTML improvement --- .../intellij/openapi/util/objectTree/DisposerDebugger.java | 5 +---- .../src/com/intellij/util/ui}/TextTransferrable.java | 2 +- .../openapi/vcs/actions/CopyRevisionNumberAction.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) rename platform/{vcs-impl/src/com/intellij/openapi/vcs/history => platform-impl/src/com/intellij/util/ui}/TextTransferrable.java (98%) diff --git a/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java b/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java index 7b4785f14c1b..388d8cbc8f58 100644 --- a/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java +++ b/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java @@ -29,10 +29,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.objectTree.ObjectNode; -import com.intellij.openapi.util.objectTree.ObjectTree; -import com.intellij.openapi.util.objectTree.ObjectTreeListener; -import com.intellij.openapi.vcs.history.TextTransferrable; +import com.intellij.util.ui.TextTransferrable; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.debugger.UiDebuggerExtension; import com.intellij.ui.speedSearch.ElementFilter; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/TextTransferrable.java b/platform/platform-impl/src/com/intellij/util/ui/TextTransferrable.java similarity index 98% rename from platform/vcs-impl/src/com/intellij/openapi/vcs/history/TextTransferrable.java rename to platform/platform-impl/src/com/intellij/util/ui/TextTransferrable.java index 38a943538872..ec5510edb784 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/TextTransferrable.java +++ b/platform/platform-impl/src/com/intellij/util/ui/TextTransferrable.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.vcs.history; +package com.intellij.util.ui; import com.intellij.openapi.diagnostic.Logger; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java index 4d42e9eabdb2..65632a112022 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java @@ -21,7 +21,7 @@ import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.localVcs.UpToDateLineNumberProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.annotate.LineNumberListener; -import com.intellij.openapi.vcs.history.TextTransferrable; +import com.intellij.util.ui.TextTransferrable; import com.intellij.openapi.vcs.history.VcsRevisionNumber; /** From fd9d1764e2398eb7cf71344fda95f985448aa45b Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Oct 2012 20:51:57 +0200 Subject: [PATCH 17/43] good code red: allow containing this before super call (IDEA-67756) --- .../daemon/impl/analysis/HighlightUtil.java | 8 ++++---- .../advHighlighting/ThisBeforeSuper.java | 17 +++++++++++++++++ .../daemon/LightAdvHighlightingTest.java | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 81eb619e0d43..9e74e12ad914 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1819,13 +1819,13 @@ public class HighlightUtil { type = ((PsiReferenceExpression)qualifier).getType(); referencedClass = PsiUtil.resolveClassInType(type); } - else if (qualifier instanceof PsiThisExpression || qualifier == null) { - @SuppressWarnings({"unchecked"}) PsiMethod parent = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); - resolved = parent; - expression = qualifier == null ? expression : qualifier; + else if (qualifier == null) { + resolved = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); if (resolved != null) { referencedClass = ((PsiMethod)resolved).getContainingClass(); } + } else if (qualifier instanceof PsiThisExpression) { + referencedClass = PsiUtil.resolveClassInType(((PsiThisExpression)qualifier).getType()); } } if (resolved instanceof PsiField) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java new file mode 100644 index 000000000000..a54084f533fa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java @@ -0,0 +1,17 @@ +class A +{ + class B + { + } +} + + +class C extends A +{ + class D extends B + { + D(){ + C.this.super(); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 9deb8c636bc5..9d3b286eb4cc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -357,4 +357,5 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testClassicRethrow() throws Exception { doTest(false, false); } public void testRegexp() throws Exception { doTest(false, false); } public void testUnsupportedFeatures() throws Exception { doTest(false, false); } + public void testThisBeforeSuper() throws Exception { doTest(false, false); } } From a40a08d1d955d3d5138595da2dbb4f5cdaced2c2 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Oct 2012 21:36:03 +0200 Subject: [PATCH 18/43] good code red: leave empty subst when processing type params supers (IDEA-67680) --- .../intellij/psi/impl/PsiClassImplUtil.java | 3 ++ .../TypeArgumentsGivenOnRawType.java | 31 +++++++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 35 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 6992c102574a..6c356bb0573c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -675,6 +675,9 @@ public class PsiClassImplUtil { if (superClass == null) continue; PsiSubstitutor finalSubstitutor = obtainFinalSubstitutor(superClass, superTypeResolveResult.getSubstitutor(), aClass, state.get(PsiSubstitutor.KEY), factory, languageLevel); + if (aClass instanceof PsiTypeParameter && PsiUtil.isRawSubstitutor(superClass, finalSubstitutor)) { + finalSubstitutor = PsiSubstitutor.EMPTY; + } if (!processDeclarationsInClass(superClass, processor, state.put(PsiSubstitutor.KEY, finalSubstitutor), visited, last, place, isRaw)) { resolved = true; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java new file mode 100644 index 000000000000..9b85d2949260 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java @@ -0,0 +1,31 @@ +class A { + abstract class C { + void foo(T.C x) { + Integer bar = x.bar(); + } + + void foo1(A.C x) { + Integer bar = x.bar(); + } + + void foo2(A.C x) { + Integer bar = x.bar(); + } + + abstract S bar(); + } +} + +class A1 { + abstract class C { + void foo(T.C x) { + Integer bar = x.bar(); + } + + void foo1(A1.C x) { + Integer bar = x.bar(); + } + + abstract S bar(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 3ebc98e69a9c..55404d58c1ce 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -151,6 +151,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIncompatibleReturnType() throws Exception { doTest(false); } public void testContinueInferenceAfterFirstRawResult() throws Exception { doTest(false); } public void testStaticOverride() throws Exception { doTest(false); } + public void testTypeArgumentsGivenOnRawType() throws Exception { doTest(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); From f541601e41d663f0f8bf7fb7e02d6d90c0270231 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 18 Oct 2012 21:42:01 +0200 Subject: [PATCH 19/43] compilation fix --- .../intellij/openapi/vcs/history/FileHistoryPanelImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index b4f3038e1957..08ce3adf78e2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -67,10 +67,7 @@ import com.intellij.ui.dualView.DualViewColumnInfo; import com.intellij.ui.table.TableView; import com.intellij.util.*; import com.intellij.util.text.DateFormatUtil; -import com.intellij.util.ui.ColumnInfo; -import com.intellij.util.ui.StatusText; -import com.intellij.util.ui.TableViewModel; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.*; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; From a0e1ddf87f7b9485a0e3b47ab67da02b87f0efdc Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 18 Oct 2012 22:37:25 +0200 Subject: [PATCH 20/43] tooltips bg is too dark (by Sergey Ignatov) --- .../platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java index 110de5a78f96..6fa170bab32f 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java @@ -31,6 +31,9 @@ import java.awt.*; * @author Konstantin Bulenkov */ public final class IdeaLaf extends MetalLookAndFeel { + + public static final ColorUIResource TOOLTIP_BACKGROUND_COLOR = new ColorUIResource(255, 255, 231); + public void initComponentDefaults(UIDefaults defaults) { super.initComponentDefaults(defaults); LafManagerImpl.initInputMapDefaults(defaults); @@ -69,7 +72,7 @@ public final class IdeaLaf extends MetalLookAndFeel { //defaults.put("ScrollPaneUI", BegScrollPaneUI.class.getName()); defaults.put("TabbedPane.tabInsets", new Insets(0, 4, 0, 4)); - defaults.put("ToolTip.background", new ColorUIResource(255, 255, 231)); + defaults.put("ToolTip.background", TOOLTIP_BACKGROUND_COLOR); defaults.put("ToolTip.border", new ColoredSideBorder(Color.gray, Color.gray, Color.black, Color.black, 1)); defaults.put("Tree.ancestorInputMap", null); defaults.put("FileView.directoryIcon", AllIcons.Nodes.Folder); From 1d3ebd38953c39d9948791f8e56692c601f48f14 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 19 Oct 2012 01:22:03 +0400 Subject: [PATCH 21/43] IDEA-93183 Antialising issue in the new project wizard --- .../com/intellij/ide/util/newProjectWizard/WizardArrowUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java index b3a51094d109..f4e4f6899dd0 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java @@ -106,6 +106,7 @@ class WizardArrowUI extends BasicButtonUI { textRect.x = 2; textRect.y-=7; c.setForeground(UIUtil.getListForeground(myButton.isSelected())); + GraphicsUtil.setupAntialiasing(g); paintText(g, c, textRect, myButton.getText()); } } From 0cd44e5f3be6cd3d3914167a89a5201d3b5a75be Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 19 Oct 2012 02:00:44 +0400 Subject: [PATCH 22/43] performance: the last index case --- platform/util/src/com/intellij/util/containers/LimitedPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/util/containers/LimitedPool.java b/platform/util/src/com/intellij/util/containers/LimitedPool.java index 8bca28605496..61344fa9bdce 100644 --- a/platform/util/src/com/intellij/util/containers/LimitedPool.java +++ b/platform/util/src/com/intellij/util/containers/LimitedPool.java @@ -57,7 +57,7 @@ public class LimitedPool { } private void ensureCapacity() { - if (storage.length <= index + 1) { + if (storage.length <= index) { int newCapacity = Math.min(capacity, storage.length * 3 / 2); Object[] newStorage = new Object[newCapacity]; System.arraycopy(storage, 0, newStorage, 0, storage.length); From f61be0864fb36a22bbcfdae64b4878272618cc34 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 19 Oct 2012 02:58:53 +0200 Subject: [PATCH 23/43] password field and small fixes --- .../ide/ui/laf/darcula/darcula.properties | 4 +- .../ui/laf/darcula/ui/DarculaComboBoxUI.java | 60 +------------- .../darcula/ui/DarculaPasswordFieldUI.java | 81 +++++++++++++++++++ .../ui/laf/darcula/ui/DarculaTextFieldUI.java | 10 --- 4 files changed, 87 insertions(+), 68 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaPasswordFieldUI.java diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties index 64e97cff5522..c4d4f48b33ea 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties @@ -29,8 +29,10 @@ Focus.color=ff0000 TextField.background=737373 TextFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI TextField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder +PasswordField.background=737373 +PasswordFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaPasswordFieldUI +PasswordField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder -PasswordField.background=aaaaaa CheckBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI ComboBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index 075ff151f761..5226914ce5fb 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java @@ -25,11 +25,8 @@ import javax.swing.*; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; -import javax.swing.plaf.basic.BasicComboBoxEditor; import javax.swing.plaf.basic.BasicComboBoxUI; import java.awt.*; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; import java.awt.geom.Path2D; /** @@ -48,58 +45,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { return new DarculaComboBoxUI(((JComboBox)c)); } - @Override - protected ComboBoxEditor createEditor() { - final ComboBoxEditor ed = new BasicComboBoxEditor.UIResource(){ - @Override - protected JTextField createEditorComponent() { - return super.createEditorComponent(); - } - }; - if (ed != null) { - ed.getEditorComponent().addFocusListener(new FocusListener() { - @Override - public void focusGained(FocusEvent e) { - myComboBox.repaint(); - } - - @Override - public void focusLost(FocusEvent e) { - myComboBox.repaint(); - } - }); - } - - - return ed; - } - - @Override - public void paint(Graphics g, JComponent c) { - hasFocus = comboBox.hasFocus(); - final GraphicsConfig config = new GraphicsConfig(g); - if ( !comboBox.isEditable() ) { - Rectangle r = rectangleForCurrentValue(); - paintCurrentValueBackground(g,r,hasFocus); - paintCurrentValue(g,r,hasFocus); - g.setColor(ColorUtil.fromHex("939393").darker()); - final int xxx = c.getWidth() - c.getBorder().getBorderInsets(c).right - arrowButton.getWidth(); - g.drawLine(xxx, hasFocus ? 2 : 1, xxx, c.getHeight() - (hasFocus ? 3 : 0)); - } else { - g.setColor(editor.getBackground()); - ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); - g.fillRoundRect(1, 1, c.getWidth() - 2, c.getHeight() - 2, 5, 5); - g.setColor(ColorUtil.fromHex("939393")); - final int xxx = editor.getWidth() + c.getBorder().getBorderInsets(c).left; - g.drawLine(xxx, hasFocus ? 3 : 1, xxx, c.getHeight() - (hasFocus ? 2 : 0)); - - editor.repaint(); - } - config.restore(); - } - - protected JButton createArrowButton() { +protected JButton createArrowButton() { final Color bg = myComboBox.getBackground(); final Color fg = myComboBox.getForeground(); JButton button = new BasicArrowButton(SwingConstants.SOUTH, bg, fg, fg, fg) { @@ -126,8 +72,8 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { path.lineTo(xU+1, yU + 2); path.closePath(); g.fill(path); - g.setColor(ColorUtil.fromHex("939393").darker()); - g.drawLine(0, -1, 0 , h); + g.setColor(ColorUtil.fromHex("939393")); + g.drawLine(0, 0, 0 , h); //paintTriangle(g, w / 2, h / 2, 5, SOUTH, myComboBox.isEnabled()); //g.setColor(ColorUtil.fromHex("939393")); //g.drawLine(0,0, 0,h); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaPasswordFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaPasswordFieldUI.java new file mode 100644 index 000000000000..551ecfdd50e9 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaPasswordFieldUI.java @@ -0,0 +1,81 @@ +/* + * Copyright 2000-2012 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.ide.ui.laf.darcula.ui; + +import com.intellij.openapi.ui.GraphicsConfig; +import com.intellij.util.ui.JBInsets; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicPasswordFieldUI; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; + +/** + * @author Konstantin Bulenkov + */ +public class DarculaPasswordFieldUI extends BasicPasswordFieldUI { + + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(final JComponent c) { + c.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + c.repaint(); + } + + @Override + public void focusLost(FocusEvent e) { + c.repaint(); + } + }); + + return new DarculaPasswordFieldUI(); + } + + @Override + protected void paintBackground(Graphics g) { + final JTextComponent c = getComponent(); + final Container parent = c.getParent(); + if (parent != null) { + g.setColor(parent.getBackground()); + g.fillRect(0, 0, c.getWidth(), c.getHeight()); + } + final Border border = c.getBorder(); + if (border instanceof DarculaTextBorder) { + g.setColor(c.getBackground()); + final int width = c.getWidth(); + final int height = c.getHeight(); + final JBInsets insets = ((DarculaTextBorder)border).getBorderInsets(c); + if (c.hasFocus()) { + final GraphicsConfig config = new GraphicsConfig(g); + ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); + + g.fillRoundRect(insets.left - 5, insets.top - 2, width - insets.width() + 10, height - insets.height() + 6, 5, 5); + config.restore(); + } + else { + g.fillRect(insets.left - 5, insets.top - 2, width - insets.width() + 12, height - insets.height() + 6); + } + } else { + super.paintBackground(g); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java index 04cbd44f9107..b89542f0c30f 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java @@ -48,16 +48,6 @@ public class DarculaTextFieldUI extends BasicTextFieldUI { return new DarculaTextFieldUI(); } - @Override - protected void installDefaults() { - super.installDefaults(); - } - - @Override - protected void paintSafely(Graphics g) { - super.paintSafely(g); - } - @Override protected void paintBackground(Graphics g) { final JTextComponent c = getComponent(); From d80c4b38bbcef4e23d8236cf1d5455c6976b5bd8 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Fri, 19 Oct 2012 10:46:46 +0400 Subject: [PATCH 24/43] WI-13349 Generating web module project from template does not work behind a proxy --- .../boilerplate/GithubTagListProvider.java | 53 ++++++++----------- .../templates/github/DownloadUtil.java | 33 ++++++------ .../intellij/util/net/HttpConfigurable.java | 31 ++++++++++- 3 files changed, 67 insertions(+), 50 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java index 5deb52c5dae2..b240f62fb541 100644 --- a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java +++ b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java @@ -9,9 +9,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.platform.templates.github.DownloadUtil; import com.intellij.platform.templates.github.GeneratorException; import com.intellij.platform.templates.github.GithubTagInfo; @@ -53,36 +50,30 @@ public class GithubTagListProvider { return null; } - public Task.Backgroundable updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { + public void updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { final String url = formatTagListDownloadUrl(); - Task.Backgroundable task = - new Task.Backgroundable(null, "Updating versions of " + GithubTagListProvider.this.myRepositoryName + " repository...", true, null) { - - @Override - public void run(@NotNull ProgressIndicator indicator) { - File cacheFile = getCacheFile(); - try { - DownloadUtil.downloadAtomically(indicator, url, cacheFile, myUserName, myRepositoryName); - final ImmutableSet infos = readTagsFromFile(cacheFile); - peer.setErrorMessage(null); - UIUtil.invokeLaterIfNeeded(new Runnable() { - public void run() { - peer.updateTagList(infos); - } - }); - } - catch (IOException e) { - peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); - } - catch (GeneratorException e) { - peer.setErrorMessage(getGeneratorName() + " cache update failed"); - } - } - }; - LOG.info(getGeneratorName() + " starting cache update from " + url + " ..."); - ProgressManager.getInstance().run(task); - return task; + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + File cacheFile = getCacheFile(); + try { + DownloadUtil.downloadAtomically(null, url, cacheFile, myUserName, myRepositoryName); + final ImmutableSet infos = readTagsFromFile(cacheFile); + peer.setErrorMessage(null); + UIUtil.invokeLaterIfNeeded(new Runnable() { + public void run() { + peer.updateTagList(infos); + } + }); + } + catch (IOException e) { + peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); + } + catch (GeneratorException e) { + peer.setErrorMessage(getGeneratorName() + " cache update failed"); + } + } + }); } private String getGeneratorName() { diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java index 810a43c1fb6f..ffafbffb62eb 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java @@ -16,8 +16,6 @@ import org.jetbrains.annotations.Nullable; import java.io.*; import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; import java.util.Locale; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -121,7 +119,7 @@ public class DownloadUtil { }, new Producer() { @Override public Boolean produce() { - return IOExceptionDialog.showErrorDialog("Download Error", "Can not download " + url + ""); + return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'"); } } ); @@ -204,13 +202,7 @@ public class DownloadUtil { if (progress != null) { progress.setText2("Downloading " + location); } - URL url = new URL(location); - try { - HttpConfigurable.getInstance().prepareURL(location); - } catch (IOException e) { - LOG.info("Can not prepareURL '" + location + "'", e); - } - URLConnection urlConnection = url.openConnection(); + HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(location); try { int timeout = (int) TimeUnit.MINUTES.toMillis(2); urlConnection.setConnectTimeout(timeout); @@ -221,16 +213,21 @@ public class DownloadUtil { substituteContentLength(progress, originalText, contentLength); NetUtils.copyStreamContent(progress, in, output, contentLength); } catch (IOException e) { - if (urlConnection instanceof HttpURLConnection) { - HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; - LOG.warn("Can not download '" + location - + "', response code: " + httpURLConnection.getResponseCode() - + ", response message: " + httpURLConnection.getResponseMessage() - + ", headers: " + httpURLConnection.getHeaderFields() - ); - } + LOG.warn("Can not download '" + location + + "', response code: " + urlConnection.getResponseCode() + + ", response message: " + urlConnection.getResponseMessage() + + ", headers: " + urlConnection.getHeaderFields(), + e + ); throw e; } + finally { + try { + urlConnection.disconnect(); + } catch (Exception e) { + LOG.warn("Exception at disconnect()", e); + } + } } private static void substituteContentLength(@Nullable ProgressIndicator progress, @Nullable String text, int contentLengthInBytes) { diff --git a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java index 81751a2f6793..0625791eff97 100644 --- a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java +++ b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java @@ -16,6 +16,7 @@ package com.intellij.util.net; import com.btr.proxy.search.ProxySearch; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.*; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.util.InvalidDataException; @@ -28,6 +29,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Transient; import org.apache.commons.codec.binary.Base64; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.io.IOException; @@ -104,7 +106,7 @@ public class HttpConfigurable implements PersistentStateComponent Date: Fri, 19 Oct 2012 11:13:10 +0400 Subject: [PATCH 25/43] templates tree reordered --- .../newProjectWizard/SelectTemplateStep.java | 39 ++++---- .../templates/ArchivedTemplatesFactory.java | 2 +- .../EmptyModuleTemplatesFactory.java | 83 +++++++++++------- .../Java/Java_Command_Line_Application.zip | Bin 0 -> 1896 bytes 4 files changed, 73 insertions(+), 51 deletions(-) create mode 100644 java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java index bd879e4c11c3..c3397e6cb345 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java @@ -89,19 +89,29 @@ public class SelectTemplateStep extends ModuleWizardStep { Messages.installHyperlinkSupport(myDescriptionPane); ProjectTemplatesFactory[] factories = ProjectTemplatesFactory.EP_NAME.getExtensions(); - final MultiMap groups = new MultiMap(); + final MultiMap groups = new MultiMap(); for (ProjectTemplatesFactory factory : factories) { for (String string : factory.getGroups()) { - groups.putValue(string, factory); + groups.putValues(string, Arrays.asList(factory.createTemplates(string, context))); + } + } + final MultiMap sorted = new MultiMap(); + // put single leafs under "Other" + for (Map.Entry> entry : groups.entrySet()) { + if (entry.getValue().size() > 1 || ArchivedTemplatesFactory.CUSTOM_GROUP.equals(entry.getKey())) { + sorted.put(entry.getKey(), entry.getValue()); + } + else { + sorted.putValues("Other", entry.getValue()); } } SimpleTreeStructure.Impl structure = new SimpleTreeStructure.Impl(new SimpleNode() { @Override public SimpleNode[] getChildren() { - return ContainerUtil.map2Array(groups.entrySet(), NO_CHILDREN, new Function>, SimpleNode>() { + return ContainerUtil.map2Array(sorted.entrySet(), NO_CHILDREN, new Function>, SimpleNode>() { @Override - public SimpleNode fun(Map.Entry> entry) { + public SimpleNode fun(Map.Entry> entry) { return new GroupNode(entry.getKey(), entry.getValue()); } }); @@ -182,7 +192,7 @@ public class SelectTemplateStep extends ModuleWizardStep { } mySettingsPanel.setVisible(settingsPanel != null); String description = template.getDescription(); - if (description != null) { + if (StringUtil.isNotEmpty(description)) { StringBuilder sb = new StringBuilder("'); sb.append(description).append(""); @@ -234,12 +244,10 @@ public class SelectTemplateStep extends ModuleWizardStep { case KeyEvent.VK_DOWN: myTemplatesTree.setSelectionRow(row < myTemplatesTree.getRowCount() - 1 ? row + 1 : 0); break; - case KeyEvent.VK_ENTER: - myTemplatesTree.expandRow(row); } } } - }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_ENTER), mySearchField); + }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); } @Override @@ -368,23 +376,20 @@ public class SelectTemplateStep extends ModuleWizardStep { mySearchField = new SearchTextField(false); } - private class GroupNode extends SimpleNode { + private static class GroupNode extends SimpleNode { private final String myGroup; - private final Collection myFactories; + private final Collection myTemplates; - public GroupNode(String group, Collection factories) { + public GroupNode(String group, Collection templates) { myGroup = group; - myFactories = factories; + myTemplates = templates; } @Override public SimpleNode[] getChildren() { List children = new ArrayList(); - for (ProjectTemplatesFactory factory : myFactories) { - ProjectTemplate[] templates = factory.createTemplates(myGroup, myContext); - for (ProjectTemplate template : templates) { - children.add(new TemplateNode(template)); - } + for (ProjectTemplate template : myTemplates) { + children.add(new TemplateNode(template)); } return children.toArray(new SimpleNode[children.size()]); } diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index 861717875b44..26a014774434 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -99,7 +99,7 @@ public class ArchivedTemplatesFactory implements ProjectTemplatesFactory { } static String getCustomTemplatesPath() { - return PathManager.getConfigPath() + "/projectTemplates"; + return PathManager.getConfigPath() + "/resources/projectTemplates"; } @NotNull diff --git a/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java index 934420591f08..eb8a1fa8477d 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java @@ -39,48 +39,65 @@ public class EmptyModuleTemplatesFactory implements ProjectTemplatesFactory { @NotNull @Override public String[] getGroups() { - return new String[] {GROUP_NAME}; + List builders = ModuleBuilder.getAllBuilders(); + return ContainerUtil.map2Array(builders, String.class, new Function() { + @Override + public String fun(ModuleBuilder builder) { + return getGroupName(builder); + } + }); } @NotNull @Override public ProjectTemplate[] createTemplates(String group, WizardContext context) { List builders = ModuleBuilder.getAllBuilders(); - return ContainerUtil.map2Array(builders, ProjectTemplate.class, new Function() { - @Override - public ProjectTemplate fun(final ModuleBuilder builder) { - return new ProjectTemplate() { - @NotNull - @Override - public String getName() { - return builder.getPresentableName(); - } + for (ModuleBuilder builder : builders) { + if (getGroupName(builder).equals(group)) return new ProjectTemplate[] {new EmptyModuleTemplate(builder)}; + } + return new ProjectTemplate[0]; + } - @Nullable - @Override - public String getDescription() { - return builder.getDescription(); - } + private static String getGroupName(ModuleBuilder builder) { + String name = builder.getPresentableName(); + return name.split(" ")[0]; + } - @Nullable - @Override - public JComponent getSettingsPanel() { - return null; - } + private static class EmptyModuleTemplate implements ProjectTemplate { + private final ModuleBuilder myBuilder; - @NotNull - @Override - public ModuleBuilder createModuleBuilder() { - return builder; - } + public EmptyModuleTemplate(ModuleBuilder builder) { + myBuilder = builder; + } - @Nullable - @Override - public ValidationInfo validateSettings() { - return null; - } - }; - } - }); + @NotNull + @Override + public String getName() { + return myBuilder.getPresentableName(); + } + + @Nullable + @Override + public String getDescription() { + return myBuilder.getDescription(); + } + + @Nullable + @Override + public JComponent getSettingsPanel() { + return null; + } + + @NotNull + @Override + public ModuleBuilder createModuleBuilder() { + return myBuilder; + } + + @Nullable + @Override + public ValidationInfo validateSettings() { + return null; + } } } diff --git a/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip b/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip new file mode 100644 index 0000000000000000000000000000000000000000..c9dbc294b4f67c72b35ce4f6b0ba0e2cf00031ce GIT binary patch literal 1896 zcmWIWW@h1H0D+uYL5^Ssl;8o<&iT2yiFqkLnR%)D0dSQY(Nqedsnp9%NlgT+7Xiv} zFa(ALJL(2LaSs9V5`kC=tNN7G;^d;tf|AVqJiUyP+#K06yLk^N@UR{Tjhh*wlVIp@ z%O}B3Xj+cLAtIeqF*=Dsq2AdsL}2ozWg^6=6%&HZJapu`XTju z4wX}+dY8(pxAI1OHREcH{SWd3#7%2}ZdxdNTlN~zE&7ZM3{qI#l$%+ctXGkn6WZ_S zeb_;u^?mEV_QV&a>jZU`BC8F!mUXFKD~_0CxWu>YP@4Iz`uBPpb@!gF*)#Kd+@@b| zqa;r9@Md>@ylTqya?)zI>q7gt>0h*6C-;2w67xNaFU?!J{e_`JP|@|xYPpW9`&9DO z63^w_pBiQ=X(NAEVT;%GbC1oXR!*I<^tF=SG>$BZ6E`ya+vUxsx@5~JzFAc(a$k1) ze}TXS2X$HE;*zRg*q*zx!tU}{k&Epq>DB26CEx$JyXA|*k)+A>Dd+ufE7hJAKg2C? zrDa}bO1_elKzb|)_gNW<*rvHf*JJxDu z2tIsrh^tFQF#7lc{n;}rmFryW?Kf{Kd;88>X2<(q2k&N-9bOeSjm77yhw$6AqWpc{p`u$h7X-Mxref)FX6BXI{TFUz-#Cn=Fx9_eN z$Pj&b>78-J`e!GFd*a)gwYuwQx z6YGw@|FbAg=;xjdN9814GWky|^_SXZa)OgJo_&7f^M7s3yKRCUvW1gh)v=lt-j$jC^Yl07M@1Gt7(ropo!R-+Z(s;* zg@z%d*g!7~1kl2;xF{J~6o3*Mx@t)*s(lkP^YpS3%Mx{aHgYi;3b_1s_?PJATl`-! zB2!%~yQ92u2j^_thXVia^4>Ez`)2k{O_uip1+hi#k<(j_Xh}z%T~iTuu=8F^#LnxJ z9M(>i@hpC7IA>4x>%)2-tyRZo8a;kI*YI-Rt|Fa2KQy{R%)T3aftfVin{bn0eR=L4K|BB(QF;mh literal 0 HcmV?d00001 From 684f20b062ed294f201c8e03ecf31e8689cb8a6b Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 19 Oct 2012 12:43:54 +0400 Subject: [PATCH 26/43] IDEA-93153 --- .../android/uipreview/SimpleLogger.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java b/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java index c0197f417194..368cceedf544 100644 --- a/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java +++ b/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java @@ -38,7 +38,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + if (throwable != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } @@ -56,7 +61,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + if (throwable != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } @@ -74,7 +84,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, t)); + if (t != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, t)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } From 916217f10c30b11be06c2a3c174ed5bcd83b2b32 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 12:44:05 +0400 Subject: [PATCH 27/43] IDEA-93149, IDEA-93238 Improve formatting for closures --- .../intellij/formatting/ChildAttributes.java | 6 +- .../codeStyle/GroovyCodeStyleSettings.java | 1 + ...oovyLanguageCodeStyleSettingsProvider.java | 2 + .../groovy/formatter/ClosureBodyBlock.java | 73 ++++++++++++ .../plugins/groovy/formatter/GroovyBlock.java | 9 +- .../formatter/GroovyBlockGenerator.java | 106 +++++++++++++++--- .../processors/GroovyIndentProcessor.java | 7 +- .../processors/GroovySpacingProcessor.java | 29 +++-- .../GroovySpacingProcessorBasic.java | 45 +++++++- .../ParameterToMapEntryTest.java | 5 +- .../ExtractClosureTest.groovy | 1 + .../actions/smartEnter/gotoParentInIf.test | 2 +- .../testdata/groovy/codeStyle/try1.test | 4 +- .../testdata/groovy/codeStyle/try2.test | 6 +- .../testdata/groovy/formatter/clo1.test | 2 +- .../testdata/groovy/formatter/clo2.test | 2 +- .../testdata/groovy/formatter/clo3.test | 2 +- .../testdata/groovy/formatter/geese6.test | 2 +- .../testdata/groovy/formatter/geese7.test | 2 +- .../testdata/groovy/formatter/param2.test | 6 +- .../refactoring/extractMethod/clos_em.test | 2 +- .../refactoring/extractMethod/output1.test | 2 +- .../refactoring/inlineMethod/clos_arg1.test | 2 +- .../refactoring/inlineMethod/clos_arg2.test | 4 +- .../refactoring/inlineMethod/clos_arg3.test | 2 +- .../refactoring/introduceVariable/clos1.test | 2 +- .../refactoring/introduceVariable/clos2.test | 4 +- .../refactoring/introduceVariable/clos3.test | 4 +- .../refactoring/introduceVariable/clos4.test | 2 +- .../refactoring/introduceVariable/if1.test | 2 +- .../refactoring/introduceVariable/if2.test | 2 +- ...ameOfClosureImplicitParameter_after.groovy | 2 +- .../groovy/refactoring/rename/closureIt.test | 2 +- .../ComplicatedCase_after.groovy | 2 +- ...losureToMethodWithFieldUsages_after.groovy | 2 +- ...osureWithoutModifiersToMethod_after.groovy | 2 +- .../MethodFromReference_after.groovy | 2 +- ...hodToClosureWithMemberPointer_after.groovy | 2 +- .../MethodToClosure_after.groovy | 2 +- .../StaticMethodToClosure_after.groovy | 2 +- .../testdata/paramToMap/callMethod/A.test | 2 +- .../testdata/paramToMap/closureAtEnd/A.test | 4 +- .../paramToMap/gettersAndCallMethod/A.test | 3 +- .../groovy/testdata/paramToMap/newMap/A.test | 2 +- .../testdata/paramToMap/secondClosure/A.test | 4 +- .../DelegaterInSuperMyClass_after.groovy | 2 +- ...CorrectOccurrencesForLocalVar_after.groovy | 2 +- .../DontReplaceWithGetter_after.groovy | 2 +- .../ReplaceGetterCall_after.groovy | 2 +- .../ReplaceWithGetter_after.groovy | 2 +- .../SimpleClosure_after.groovy | 2 +- .../VarAssignedToClosure_after.groovy | 2 +- 52 files changed, 296 insertions(+), 91 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java diff --git a/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java b/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java index ca4265c7fb5d..88317c76b050 100644 --- a/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java +++ b/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java @@ -15,6 +15,8 @@ */ package com.intellij.formatting; +import org.jetbrains.annotations.Nullable; + /** * Defines the indent and alignment settings which are applied to a new child block * added to a formatting model block. Used for auto-indenting when the Enter key is pressed. @@ -35,7 +37,7 @@ public class ChildAttributes { * @param childIndent the indent for the child block. * @param alignment the alignment for the child block. */ - public ChildAttributes(final Indent childIndent, final Alignment alignment) { + public ChildAttributes(@Nullable final Indent childIndent, @Nullable final Alignment alignment) { myChildIndent = childIndent; myAlignment = alignment; } @@ -45,6 +47,7 @@ public class ChildAttributes { * * @return the indent setting. */ + @Nullable public Indent getChildIndent() { return myChildIndent; } @@ -54,6 +57,7 @@ public class ChildAttributes { * * @return the alignment setting. */ + @Nullable public Alignment getAlignment() { return myAlignment; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java index 201b06bba2f7..de942838e2dc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java @@ -48,6 +48,7 @@ public class GroovyCodeStyleSettings extends CustomCodeStyleSettings { public boolean SPACE_WITHIN_LIST_OR_MAP = false; public boolean ALIGN_NAMED_ARGS_IN_MAP = false; public boolean SPACE_BEFORE_CLOSURE_LBRACE = true; + public boolean SPACE_WITHIN_GSTRING_INJECTION_BRACES = false; //imports public boolean USE_FQ_CLASS_NAMES = false; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java index 0fb03ade0981..a92af5b822c8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java @@ -118,6 +118,7 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_IN_NAMED_ARGUMENT", "In named argument after ':'", CodeStyleSettingsCustomizable.SPACES_OTHER); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_LIST_OR_MAP", "List and maps literals", CodeStyleSettingsCustomizable.SPACES_WITHIN); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_BEFORE_CLOSURE_LBRACE", "Closure left brace in method calls", CodeStyleSettingsCustomizable.SPACES_BEFORE_LEFT_BRACE); + consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_GSTRING_INJECTION_BRACES", "Space within GString injection braces", CodeStyleSettingsCustomizable.SPACES_WITHIN); return; } consumer.showAllStandardOptions(); @@ -127,6 +128,7 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(GroovyFileType.GROOVY_LANGUAGE); defaultSettings.initIndentOptions(); + defaultSettings.SPACE_WITHIN_BRACES = true; return defaultSettings; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java new file mode 100644 index 000000000000..c9b3e028619d --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.formatter; + +import com.intellij.formatting.Block; +import com.intellij.formatting.Indent; +import com.intellij.formatting.Wrap; +import com.intellij.lang.ASTNode; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings; + +import java.util.List; + +/** + * @author Max Medvedev + */ +public class ClosureBodyBlock extends GroovyBlock { + private TextRange myTextRange; + + public ClosureBodyBlock(@NotNull ASTNode node, + @NotNull Indent indent, + @Nullable Wrap wrap, + CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings, + @NotNull AlignmentProvider alignmentProvider) { + super(node, indent, wrap, settings, groovySettings, alignmentProvider); + } + + @NotNull + @Override + public TextRange getTextRange() { + init(); + return myTextRange; + } + + private void init() { + if (mySubBlocks == null) { + GroovyBlockGenerator generator = new GroovyBlockGenerator(this); + List children = GroovyBlockGenerator.getClosureBodyVisibleChildren(myNode.getTreeParent()); + + mySubBlocks = generator.generateSubBlockForCodeBlocks(false, children); + + //at least -> exists + assert !mySubBlocks.isEmpty(); + TextRange firstRange = mySubBlocks.get(0).getTextRange(); + TextRange lastRange = mySubBlocks.get(mySubBlocks.size() - 1).getTextRange(); + myTextRange = new TextRange(firstRange.getStartOffset(), lastRange.getEndOffset()); + } + } + + @NotNull + @Override + public List getSubBlocks() { + init(); + return mySubBlocks; + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java index 36b3a5cf8a45..f8cea6ef822c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java @@ -155,13 +155,16 @@ public class GroovyBlock implements Block, GroovyElementTypes, ASTBlock { */ @Nullable public Spacing getSpacing(Block child1, @NotNull Block child2) { - if ((child1 instanceof GroovyBlock) && (child2 instanceof GroovyBlock)) { + if (child1 instanceof GroovyBlock && child2 instanceof GroovyBlock) { if (((GroovyBlock)child1).getNode() == ((GroovyBlock)child2).getNode()) { return Spacing.getReadOnlySpacing(); } Spacing spacing = new GroovySpacingProcessor(((GroovyBlock)child2).getNode(), mySettings, myGroovySettings).getSpacing(); - return spacing != null ? spacing : GroovySpacingProcessorBasic.getSpacing(((GroovyBlock)child1), ((GroovyBlock)child2), mySettings); + if (spacing != null) { + return spacing; + } + return GroovySpacingProcessorBasic.getSpacing(((GroovyBlock)child1), ((GroovyBlock)child2), mySettings, myGroovySettings); } return null; } @@ -214,7 +217,7 @@ public class GroovyBlock implements Block, GroovyElementTypes, ASTBlock { return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null); } if (psiParent instanceof GrParameterList) { - return new ChildAttributes(this.getIndent(), this.getAlignment()); + return new ChildAttributes(getIndent(), getAlignment()); } if (psiParent instanceof GrListOrMap) { return new ChildAttributes(Indent.getContinuationIndent(), null); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java index e8deb158bf80..886b35d10694 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java @@ -55,6 +55,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaratio import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression; @@ -101,6 +102,31 @@ public class GroovyBlockGenerator implements GroovyElementTypes { myGroovySettings = myBlock.getGroovySettings(); } + static List getClosureBodyVisibleChildren(final ASTNode node) { + List children = visibleChildren(node); + + if (!children.isEmpty()) { + ASTNode first = children.get(0); + if (first.getElementType() == GroovyTokenTypes.mLCURLY) children.remove(0); + } + +/* if (!children.isEmpty()) { + ASTNode second = children.get(0); + if (second.getElementType() == GroovyElementTypes.PARAMETERS_LIST) children.remove(0); + } + + if (!children.isEmpty()) { + ASTNode second = children.get(0); + if (second.getElementType() == GroovyTokenTypes.mCLOSABLE_BLOCK_OP) children.remove(0); + }*/ + + if (!children.isEmpty()) { + ASTNode last = children.get(children.size() - 1); + if (last.getElementType() == GroovyTokenTypes.mRCURLY) children.remove(children.size() - 1); + } + return children; + } + public List generateSubBlocks() { @@ -188,22 +214,54 @@ public class GroovyBlockGenerator implements GroovyElementTypes { } boolean classLevel = blockPsi instanceof GrTypeDefinitionBody; - if (blockPsi instanceof GrCodeBlock || blockPsi instanceof GroovyFile || classLevel) { - List children = visibleChildren(myNode); - calculateAlignments(children, classLevel); - final ArrayList subBlocks = new ArrayList(); + if (blockPsi instanceof GrClosableBlock && + ((GrClosableBlock)blockPsi).getArrow() != null && + ((GrClosableBlock)blockPsi).getParameters().length > 0 && + !getClosureBodyVisibleChildren(myNode).isEmpty()) { + GrClosableBlock closableBlock = (GrClosableBlock)blockPsi; - if (classLevel && myAlignment != null) { - final AlignmentProvider.Aligner aligner = myAlignmentProvider.createAligner(true); - for (ASTNode child : children) { - aligner.append(child.getPsi()); - } + ArrayList blocks = new ArrayList(); + + PsiElement lbrace = closableBlock.getLBrace(); + if (lbrace != null) { + ASTNode node = lbrace.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + blocks.add(new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); } - for (ASTNode childNode : children) { - final Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, childNode); - subBlocks.add(new GroovyBlock(childNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + + /* { + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, parameterListNode); + GroovyBlock block = new GroovyBlock(parameterListNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(block); } - return subBlocks; + + { + PsiElement arrow = closableBlock.getArrow(); + ASTNode node = arrow.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + GroovyBlock block = new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(block); + }*/ + + { + Indent indent = Indent.getNormalIndent(); + ASTNode parameterListNode = closableBlock.getParameterList().getNode(); + ClosureBodyBlock bodyBlock = new ClosureBodyBlock(parameterListNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(bodyBlock); + } + + PsiElement rbrace = closableBlock.getRBrace(); + if (rbrace != null) { + ASTNode node = rbrace.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + blocks.add(new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + } + + return blocks; + } + + if (blockPsi instanceof GrCodeBlock || blockPsi instanceof GroovyFile || classLevel) { + return generateSubBlockForCodeBlocks(classLevel, visibleChildren(myNode)); } // For other cases @@ -214,7 +272,25 @@ public class GroovyBlockGenerator implements GroovyElementTypes { } return subBlocks; } - + + public List generateSubBlockForCodeBlocks(boolean classLevel, final List children) { + + calculateAlignments(children, classLevel); + final ArrayList subBlocks = new ArrayList(); + + if (classLevel && myAlignment != null) { + final AlignmentProvider.Aligner aligner = myAlignmentProvider.createAligner(true); + for (ASTNode child : children) { + aligner.append(child.getPsi()); + } + } + for (ASTNode childNode : children) { + final Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, childNode); + subBlocks.add(new GroovyBlock(childNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + } + return subBlocks; + } + private void calculateAlignments(List children, boolean classLevel) { List currentGroup = null; @@ -330,7 +406,7 @@ public class GroovyBlockGenerator implements GroovyElementTypes { return psi instanceof GrBinaryExpression && (mBOR == ((GrBinaryExpression)psi).getOperationTokenType() || mLOR == ((GrBinaryExpression)psi).getOperationTokenType()); } - private static List visibleChildren(ASTNode node) { + public static List visibleChildren(ASTNode node) { ArrayList list = new ArrayList(); for (ASTNode astNode : getGroovyChildren(node)) { if (canBeCorrectBlock(astNode)) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index aea939055570..3349602a01b2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -25,6 +25,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; +import org.jetbrains.plugins.groovy.formatter.ClosureBodyBlock; import org.jetbrains.plugins.groovy.formatter.GroovyBlock; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag; @@ -85,9 +86,13 @@ public abstract class GroovyIndentProcessor implements GroovyElementTypes { } } + if (child.getElementType() == GroovyElementTypes.PARAMETERS_LIST && parent instanceof ClosureBodyBlock) { + return Indent.getNoneIndent(); + } + // For common code block if (BLOCK_SET.contains(astNode.getElementType()) && - !BLOCK_STATEMENT.equals(astNode.getElementType())) { + !BLOCK_STATEMENT.equals(astNode.getElementType()) || parent instanceof ClosureBodyBlock) { return indentForBlock(psiParent, child); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java index 96b7e8272daf..451d78084289 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java @@ -247,19 +247,20 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { myResult = Spacing.createSpacing(0, 0, 0, true, 100, 0); } } - else if (myType1 == mLCURLY && myType2 != PARAMETERS_LIST && myType2 != mCLOSABLE_BLOCK_OP || myType2 == mRCURLY) { - myResult = Spacing - .createDependentLFSpacing(mySettings.SPACE_WITHIN_BRACES ? 1 : 0, 1, closure.getTextRange(), mySettings.KEEP_LINE_BREAKS, - mySettings.KEEP_BLANK_LINES_IN_CODE); + else if (myType1 == mLCURLY && myType2 == mRCURLY) { //empty closure + myResult = Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + else if (closure.getParameters().length == 0 && (myType1 == mLCURLY && myType2 != PARAMETERS_LIST && myType2 != mCLOSABLE_BLOCK_OP || myType2 == mRCURLY)) { //spaces between statements + + boolean spacesWithinBraces = closure.getParent() instanceof GrStringInjection + ? myGroovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES + : mySettings.SPACE_WITHIN_BRACES; + int minSpaces = spacesWithinBraces ? 1 : 0; + myResult = Spacing.createDependentLFSpacing(minSpaces, 1, closure.getTextRange(), mySettings.KEEP_LINE_BREAKS, + mySettings.KEEP_BLANK_LINES_IN_CODE); } else if (myType1 == mCLOSABLE_BLOCK_OP) { - GrStatement[] statements = closure.getStatements(); - if (statements.length > 0) { - TextRange range = - new TextRange(statements[0].getTextRange().getStartOffset(), statements[statements.length - 1].getTextRange().getEndOffset()); - myResult = - Spacing.createDependentLFSpacing(1, Integer.MAX_VALUE, range, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); - } + myResult = GroovySpacingProcessorBasic.createDependentSpacingForClosure(mySettings, myGroovySettings, closure, true); } } @@ -269,6 +270,9 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { myResult = Spacing.createSpacing(1, 1, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } } + else if (myType1 == mLCURLY && myType2 == mRCURLY) { + myResult = Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } else if (myType1 == mLCURLY && !GrStringUtil.isMultilineStringElement(myChild2) || myType2 == mRCURLY && !GrStringUtil.isMultilineStringElement(myChild1)) { final int spaceWithinBraces = mySettings.SPACE_WITHIN_BRACES ? 1 : 0; @@ -280,7 +284,8 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { public void visitNewExpression(GrNewExpression newExpression) { if (myType1 == kNEW) { createSpaceInCode(true); - } else if (myType2 == ARGUMENTS) { + } + else if (myType2 == ARGUMENTS) { createSpaceInCode(mySettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java index d758275b6368..43df2267b5e8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java @@ -18,17 +18,22 @@ package org.jetbrains.plugins.groovy.formatter.processors; import com.intellij.formatting.Spacing; import com.intellij.lang.ASTNode; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiErrorElement; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.tree.IElementType; +import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings; +import org.jetbrains.plugins.groovy.formatter.ClosureBodyBlock; import org.jetbrains.plugins.groovy.formatter.GroovyBlock; import org.jetbrains.plugins.groovy.formatter.MethodCallWithoutQualifierBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList; @@ -57,7 +62,10 @@ public abstract class GroovySpacingProcessorBasic { private static final Spacing IMPORT_OTHER_SPACING = Spacing.createSpacing(0, 0, 2, true, 100); private static final Spacing LAZY_SPACING = Spacing.createSpacing(0, 239, 0, true, 100); - public static Spacing getSpacing(GroovyBlock child1, GroovyBlock child2, CommonCodeStyleSettings settings) { + public static Spacing getSpacing(GroovyBlock child1, + GroovyBlock child2, + CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings) { ASTNode leftNode = child1.getNode(); ASTNode rightNode = child2.getNode(); @@ -69,12 +77,20 @@ public abstract class GroovySpacingProcessorBasic { //Braces Placement // For multi-line strings - if (!mirrorsAst(child1) || !mirrorsAst(child2)) { + if (!(mirrorsAst(child1) && mirrorsAst(child2))) { return NO_SPACING; } - if (leftType == mGDOC_COMMENT_START && rightType == mGDOC_COMMENT_DATA - || leftType == mGDOC_COMMENT_DATA && rightType == mGDOC_COMMENT_END) { + if (child2 instanceof ClosureBodyBlock) { + return settings.SPACE_WITHIN_BRACES ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE; + } + + if (child1 instanceof ClosureBodyBlock) { + return createDependentSpacingForClosure(settings, groovySettings, (GrClosableBlock)left.getParent(), false); + } + + if (leftType == mGDOC_COMMENT_START && rightType == mGDOC_COMMENT_DATA || + leftType == mGDOC_COMMENT_DATA && rightType == mGDOC_COMMENT_END) { return LAZY_SPACING; } @@ -240,7 +256,26 @@ public abstract class GroovySpacingProcessorBasic { return COMMON_SPACING; } + static Spacing createDependentSpacingForClosure(CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings, GrClosableBlock closure, + final boolean forArrow) { + boolean spaceWithinBraces = closure.getParent() instanceof GrStringInjection + ? groovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES + : settings.SPACE_WITHIN_BRACES; + GrStatement[] statements = closure.getStatements(); + if (statements.length > 0) { + int start = statements[0].getTextRange().getStartOffset(); + int end = statements[statements.length - 1].getTextRange().getEndOffset(); + TextRange range = new TextRange(start, end); + + int minSpaces = spaceWithinBraces || forArrow ? 1 : 0; + int maxSpaces = spaceWithinBraces || forArrow ? 1 : 0; + return Spacing.createDependentLFSpacing(minSpaces, maxSpaces, range, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE); + } + return spaceWithinBraces || forArrow ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE; + } + private static boolean mirrorsAst(GroovyBlock block) { - return block.getNode().getTextRange().equals(block.getTextRange()) || block instanceof MethodCallWithoutQualifierBlock; + return block.getNode().getTextRange().equals(block.getTextRange()) || block instanceof MethodCallWithoutQualifierBlock || block instanceof ClosureBodyBlock; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java index e170b12a3618..7ae3ac3608a9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java @@ -118,8 +118,9 @@ public class ParameterToMapEntryTest extends GroovyFormatterTestCase { PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); final String result = file.getText(); //System.out.println(result); - String expected = getExpectedResult(filePath); - Assert.assertEquals(expected, result); + myFixture.checkResultByFile(filePath.replace(".groovy", ".test"), true); +// String expected = getExpectedResult(filePath); +// Assert.assertEquals(expected, result); } private String getExpectedResult(final String filePath) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy index c43e87ff601c..8e054bc3dd36 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy @@ -61,6 +61,7 @@ public abstract class ExtractClosureTest extends LightGroovyTestCase { } handler.invoke myFixture.project, myFixture.editor, myFixture.file, null + doPostponedFormatting(myFixture.project) myFixture.checkResult after } diff --git a/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test b/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test index 2806efba3af0..70732cb6cbef 100644 --- a/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test +++ b/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test @@ -5,7 +5,7 @@ if (suitable) { } ----- if (suitable) { - expectations.each {pattern, action -> + expectations.each { pattern, action -> if (cloud.match(pattern, action)) { } diff --git a/plugins/groovy/testdata/groovy/codeStyle/try1.test b/plugins/groovy/testdata/groovy/codeStyle/try1.test index 3f28692533da..a27631678668 100644 --- a/plugins/groovy/testdata/groovy/codeStyle/try1.test +++ b/plugins/groovy/testdata/groovy/codeStyle/try1.test @@ -4,7 +4,7 @@ try {foo()} catch (E e) {} finally {bar()} ----- try -{foo()} catch (E e) +{ foo() } catch (E e) {} finally -{bar()} \ No newline at end of file +{ bar() } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/codeStyle/try2.test b/plugins/groovy/testdata/groovy/codeStyle/try2.test index d55aa574a845..850d5a441355 100644 --- a/plugins/groovy/testdata/groovy/codeStyle/try2.test +++ b/plugins/groovy/testdata/groovy/codeStyle/try2.test @@ -1,8 +1,8 @@ -try {foo()} +try {foo()} catch (E e) {} finally {bar()} ----- -try {foo()} -catch (E e) {} finally {bar()} \ No newline at end of file +try { foo() } +catch (E e) {} finally { bar() } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo1.test b/plugins/groovy/testdata/groovy/formatter/clo1.test index 9b39c1380b06..ad3ab79625bd 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo1.test +++ b/plugins/groovy/testdata/groovy/formatter/clo1.test @@ -1,3 +1,3 @@ def a={a,b->c} ----- -def a = {a, b -> c} \ No newline at end of file +def a = { a, b -> c } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo2.test b/plugins/groovy/testdata/groovy/formatter/clo2.test index 0af496445175..a8b2403e7009 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo2.test +++ b/plugins/groovy/testdata/groovy/formatter/clo2.test @@ -1,3 +1,3 @@ foo{a-> a+1} ----- -foo {a -> a + 1} \ No newline at end of file +foo { a -> a + 1 } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo3.test b/plugins/groovy/testdata/groovy/formatter/clo3.test index b266d67a5332..0c5096710957 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo3.test +++ b/plugins/groovy/testdata/groovy/formatter/clo3.test @@ -1,3 +1,3 @@ foo (1,2) {a->3} ----- -foo(1, 2) {a -> 3} +foo(1, 2) { a -> 3 } diff --git a/plugins/groovy/testdata/groovy/formatter/geese6.test b/plugins/groovy/testdata/groovy/formatter/geese6.test index 532c4d563ecc..b9936f06a3c3 100644 --- a/plugins/groovy/testdata/groovy/formatter/geese6.test +++ b/plugins/groovy/testdata/groovy/formatter/geese6.test @@ -4,5 +4,5 @@ ----- foo(2) { foo(2) { - foo(2) {print f} + foo(2) { print f } } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/geese7.test b/plugins/groovy/testdata/groovy/formatter/geese7.test index 1ce0e2900eae..3b7bd7e820dd 100644 --- a/plugins/groovy/testdata/groovy/formatter/geese7.test +++ b/plugins/groovy/testdata/groovy/formatter/geese7.test @@ -5,5 +5,5 @@ ----- foo(2) { foo(2) { - foo(2) {print f} + foo(2) { print f } } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/param2.test b/plugins/groovy/testdata/groovy/formatter/param2.test index 89e3b3cad969..95a55eaa8c93 100644 --- a/plugins/groovy/testdata/groovy/formatter/param2.test +++ b/plugins/groovy/testdata/groovy/formatter/param2.test @@ -4,8 +4,8 @@ def boo = {def a, a+b+c } ----- -def boo = {def a, - def int b, - def final c -> +def boo = { def a, + def int b, + def final c -> a + b + c } diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test index 0d7a4beef570..f36c0caa7040 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test @@ -6,7 +6,7 @@ def foo = { ----- def foo = { int x, int y -> - testMethod(x, y) + testMethod(x, y) } private testMethod(int x, int y) { diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test index e1738a81d52c..1dbded0ea099 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test @@ -22,7 +22,7 @@ class S { } private Closure testMethod() { - Closure sin = {x -> Math.sin(x)} + Closure sin = { x -> Math.sin(x) } return sin } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test index 63cdbe6e2c58..9dc7b98a2529 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test @@ -6,7 +6,7 @@ def qwerty(Closure cl){ return call; } ----- -def call = {int x -> return x + 1}.call() +def call = { int x -> return x + 1 }.call() println(call) def cl = call diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test index 33c0f44a62e9..b64a2c353fd4 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test @@ -7,8 +7,8 @@ def cl = qwerty{int x -> return x + 1}{int x -> return x return call + call1; } ----- -def call = {int x -> return x + 1}(42) -def call1 = {int x -> return x + 1}(45) +def call = { int x -> return x + 1 }(42) +def call1 = { int x -> return x + 1 }(45) println(call) def cl = call + call1 diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test index 084ca5f7ac87..3fc29c5c247d 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test @@ -6,7 +6,7 @@ def cl = qwerty(45){int x -> return x + 1} return call + i; } ----- -def call = {int x -> return x + 1}(42) +def call = { int x -> return x + 1 }(42) println(call) def cl = call + 45 diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test index bbe93eb3c17b..e68e03a5fed8 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x->x} ----- -def preved = {x -> x} +def preved = { x -> x } foo(1, 2, 3, preved) \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test index feb204d954bf..4fa1f214ad41 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x -> x} {x -> y} {x->x} {x -> z} ----- -def preved = {x -> x} -foo(1, 2, 3, preved, {x -> y}, preved) {x -> z} \ No newline at end of file +def preved = { x -> x } +foo(1, 2, 3, preved, { x -> y }, preved) {x -> z} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test index 42569a75d9a6..45d7ba3d84e5 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x -> x} {x -> y} {x->x} {x -> z} ----- -def preved = {x -> x} -foo(1, 2, 3, {x -> x}, {x -> y}, preved) {x -> z} \ No newline at end of file +def preved = { x -> x } +foo(1, 2, 3, { x -> x }, { x -> y }, preved) {x -> z} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test index 10636307bd93..ad2e141f1b85 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test @@ -2,6 +2,6 @@ foo {x->x} {x->x} {x->x} (3) {x->x} ----- -def preved = {x -> x} +def preved = { x -> x } foo(preved, preved, preved)(3, preved) diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test index 02df2be7784c..c83b6e0aee53 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test @@ -3,5 +3,5 @@ if (true) ({x -> 1}) ----- foo {x->x} if (true) { - def preved = {x -> 1} + def preved = { x -> 1 } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test index 561c55284efd..7fd0de759ace 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test @@ -1,5 +1,5 @@ {x->x} if (true) ({x->x}) ----- -def preved = {x -> x} +def preved = { x -> x } if (true) preved \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy index 3df1f7df5488..ba0d65ac4651 100644 --- a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy @@ -1,3 +1,3 @@ -[1, 2, 3].each {int foo -> +[1, 2, 3].each { int foo -> print foo } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test b/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test index 92e9d71240f9..9069e1ccc9be 100644 --- a/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test +++ b/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test @@ -2,6 +2,6 @@ def c = { it } ----- -def c = {def newName -> +def c = { def newName -> newName } \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy b/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy index affe87857c31..9bda9867751b 100644 --- a/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy +++ b/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy @@ -1,4 +1,4 @@ def x=5; def y=7; def name="abc" -print String.valueOf(x++ + ++y) + ' is very "strange" \'expression\'. x=' + String.valueOf(x) + String.valueOf(y) + '=y; ' + name + ' ' + String.valueOf(name.collect {true}) + ' \n wow\\' \ No newline at end of file +print String.valueOf(x++ + ++y) + ' is very "strange" \'expression\'. x=' + String.valueOf(x) + String.valueOf(y) + '=y; ' + name + ' ' + String.valueOf(name.collect { true }) + ' \n wow\\' \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy index be1d6ffc2ac8..216ece3cacce 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy @@ -1,5 +1,5 @@ class X { - def foo(def it = null) {print it} + def foo(def it = null) { print it } def bar() { foo(2) diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy index f02d6a0a1cbd..2978ea962c30 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy @@ -1,3 +1,3 @@ class C { - def clos(def it = null) {/* do smth */} + def clos(def it = null) {/* do smth */ } } \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy index 47d97c3ee2e8..6a0b8b57c074 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - def foo = {def x, def y -> + def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy index e98b38456fd4..971d12a2950e 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy @@ -1,5 +1,5 @@ class X { - def foo = {def it = null -> print it} + def foo = { def it = null -> print it } def bar() { print this.foo diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy index 73f3e9030cfd..7124f3fe067c 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - def foo = {def x, def y -> + def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy index a86b57f68a66..17bd83682448 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - static private final def foo = {def x, def y -> + static private final def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/paramToMap/callMethod/A.test b/plugins/groovy/testdata/paramToMap/callMethod/A.test index 0b7f54921e34..cf97c08adf83 100644 --- a/plugins/groovy/testdata/paramToMap/callMethod/A.test +++ b/plugins/groovy/testdata/paramToMap/callMethod/A.test @@ -1,3 +1,3 @@ def clos = { Map attrs -> println(attrs.i) } clos(i: 1) -clos.call(i: 1) +clos.call(i: 1) \ No newline at end of file diff --git a/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test b/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test index e000ffc6e5c4..3b396e414521 100644 --- a/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test +++ b/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test @@ -1,5 +1,5 @@ -def test = {Map attrs, x -> +def test = { Map attrs, x -> attrs.cl.call() } -test(1, cl: {x -> x}) \ No newline at end of file +test(1, cl: { x -> x }) \ No newline at end of file diff --git a/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test b/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test index 1325a319cb5d..dcdd127ed17d 100644 --- a/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test +++ b/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test @@ -1,5 +1,5 @@ class C { - def clos = {Map attrs -> print attrs.p} + def clos = { Map attrs -> print attrs.p } def foo() { clos(p: 1) @@ -15,4 +15,3 @@ c.clos.call(p: 6) c.getClos()(p: 7) c.getClos().call(p: 8) - diff --git a/plugins/groovy/testdata/paramToMap/newMap/A.test b/plugins/groovy/testdata/paramToMap/newMap/A.test index 96fa6395cee0..0d18b86bb844 100644 --- a/plugins/groovy/testdata/paramToMap/newMap/A.test +++ b/plugins/groovy/testdata/paramToMap/newMap/A.test @@ -1,4 +1,4 @@ -def foo = {Map attrs, a -> +def foo = { Map attrs, a -> a + attrs.b } diff --git a/plugins/groovy/testdata/paramToMap/secondClosure/A.test b/plugins/groovy/testdata/paramToMap/secondClosure/A.test index 8d7c37ab7949..eb3ff57c616a 100644 --- a/plugins/groovy/testdata/paramToMap/secondClosure/A.test +++ b/plugins/groovy/testdata/paramToMap/secondClosure/A.test @@ -1,6 +1,6 @@ -def foo = {Map attrs, cl1 -> +def foo = { Map attrs, cl1 -> cl1.call() attrs.cl2.call() } -foo(cl2: {y -> y}) {x->x} \ No newline at end of file +foo(cl2: { y -> y }) {x->x} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy index 7fada3f18b85..ea3413825f70 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy @@ -11,5 +11,5 @@ class Inh extends Base { foo(123) } - def foo(int anObject) {print anObject} + def foo(int anObject) {print anObject } } \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy index 06d25974456e..61d4070988c7 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy @@ -4,7 +4,7 @@ clos = {print "foo"} clos() clos.call() -clos = {String anObject -> print anObject} +clos = {String anObject -> print anObject } clos("foo") clos.call("foo") diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy index 013c4dd7a253..331e16e92a37 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy @@ -3,7 +3,7 @@ class X { def getFoo(){foo} - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy index 74a5a34ea929..6eda3ff61c42 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy @@ -1,7 +1,7 @@ class X { def foo - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy index 5b800e3e8da7..cdbd4a164b7f 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy @@ -1,7 +1,7 @@ class X { def foo - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy index 943a4ad11c28..38a206abe8ae 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy @@ -1,3 +1,3 @@ -print {int anObject -> +print { int anObject -> print anObject } \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy index 8c9fd877dd94..d8e8cbe1ee8f 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy @@ -1,4 +1,4 @@ Closure clos -clos= {String anObject -> print anObject} +clos= {String anObject -> print anObject } clos("foo") clos.call("foo") From c9193e6cd872f2137bb4b7fe30c47ed55f287a41 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 19 Oct 2012 11:59:01 +0400 Subject: [PATCH 28/43] cleanup --- .../openapi/components/impl/stores/ModuleStoreImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index 0075de8abdb5..5359ba955b2f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -71,7 +71,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM super.load(); final ModuleFileData storageData = getMainStorageData(); - final String moduleTypeId = storageData.myOptions.get(ModuleImpl.ELEMENT_TYPE); + final String moduleTypeId = storageData.myOptions.get(Module.ELEMENT_TYPE); myModule.setOption(Module.ELEMENT_TYPE, ModuleTypeManager.getInstance().findByID(moduleTypeId).getId()); if (ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode()) return; From 84f621e7e3d8daec4f25d0417882d5abde108424 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 19 Oct 2012 12:47:18 +0400 Subject: [PATCH 29/43] assertion when project is initialized assert EDT if only breakpoints are really removed --- .../intellij/debugger/ui/breakpoints/BreakpointManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index cc7aaaa8c9aa..9e9889493213 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -799,11 +799,9 @@ public class BreakpointManager implements JDOMExternalizable { } private void removeInvalidBreakpoints() { - ApplicationManager.getApplication().assertIsDispatchThread(); ArrayList toDelete = new ArrayList(); - for (Iterator it = getBreakpoints().listIterator(); it.hasNext();) { - Breakpoint breakpoint = (Breakpoint)it.next(); + for (Breakpoint breakpoint : getBreakpoints()) { if (!breakpoint.isValid()) { toDelete.add(breakpoint); } From bbb8f0329f3478d5ed4ebb4ab1d2cd82e792efd9 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 19 Oct 2012 12:48:14 +0400 Subject: [PATCH 30/43] computing template module type. corresponding steps update --- .../newProjectWizard/SelectTemplateStep.java | 79 +++++++------ .../templates/ArchivedProjectTemplate.java | 75 +++--------- .../templates/TemplateModuleBuilder.java | 108 ++++++++++++++++++ 3 files changed, 173 insertions(+), 89 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java index c3397e6cb345..98b69580fc32 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java @@ -181,33 +181,10 @@ public class SelectTemplateStep extends ModuleWizardStep { myTemplatesTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { - if (mySettingsPanel.getComponentCount() > 0) { - mySettingsPanel.remove(0); - } ProjectTemplate template = getSelectedTemplate(); - if (template != null) { - JComponent settingsPanel = template.getSettingsPanel(); - if (settingsPanel != null) { - mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); - } - mySettingsPanel.setVisible(settingsPanel != null); - String description = template.getDescription(); - if (StringUtil.isNotEmpty(description)) { - StringBuilder sb = new StringBuilder("'); - sb.append(description).append(""); - description = sb.toString(); - } - - myDescriptionPane.setText(description); - myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description)); - } - else { - mySettingsPanel.setVisible(false); - myDescriptionPanel.setVisible(false); - } - mySettingsPanel.revalidate(); - mySettingsPanel.repaint(); + setupPanels(template); + mySequence.setType(template == null ? null : template.createModuleBuilder().getBuilderId()); + myContext.requestWizardButtonsUpdate(); } }); @@ -223,13 +200,6 @@ public class SelectTemplateStep extends ModuleWizardStep { myDescriptionPanel.setVisible(false); mySettingsPanel.setVisible(false); - TreeState state = SelectTemplateSettings.getInstance().getTreeState(); - if (state != null) { - state.applyTo(myTemplatesTree, (DefaultMutableTreeNode)myTemplatesTree.getModel().getRoot()); - } - else { - myBuilder.expandAll(null); - } new AnAction() { @Override @@ -248,6 +218,49 @@ public class SelectTemplateStep extends ModuleWizardStep { } } }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TreeState state = SelectTemplateSettings.getInstance().getTreeState(); + if (state != null) { + state.applyTo(myTemplatesTree, (DefaultMutableTreeNode)myTemplatesTree.getModel().getRoot()); + } + else { + myBuilder.expandAll(null); + } + } + }); + + } + + private void setupPanels(@Nullable ProjectTemplate template) { + if (mySettingsPanel.getComponentCount() > 0) { + mySettingsPanel.remove(0); + } + if (template != null) { + JComponent settingsPanel = template.getSettingsPanel(); + if (settingsPanel != null) { + mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); + } + mySettingsPanel.setVisible(settingsPanel != null); + String description = template.getDescription(); + if (StringUtil.isNotEmpty(description)) { + StringBuilder sb = new StringBuilder("'); + sb.append(description).append(""); + description = sb.toString(); + } + + myDescriptionPane.setText(description); + myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description)); + } + else { + mySettingsPanel.setVisible(false); + myDescriptionPanel.setVisible(false); + } + mySettingsPanel.revalidate(); + mySettingsPanel.repaint(); } @Override diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java index 8e26316e3a52..07608f4d665e 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java @@ -15,32 +15,16 @@ */ package com.intellij.platform.templates; -import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode; import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.ide.util.projectWizard.WizardContext; -import com.intellij.openapi.module.ModifiableModuleModel; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.module.ModuleWithNameAlreadyExists; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.ui.ValidationInfo; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.io.StreamUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.platform.ProjectTemplate; -import com.intellij.platform.templates.github.ZipUtil; -import com.intellij.util.containers.ContainerUtil; -import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.io.File; import java.io.IOException; import java.net.URL; import java.util.zip.ZipEntry; @@ -74,11 +58,22 @@ public class ArchivedProjectTemplate implements ProjectTemplate { @Override public String getDescription() { + return readEntry(new Condition() { + @Override + public boolean value(ZipEntry entry) { + return entry.getName().endsWith(DESCRIPTION_PATH); + } + }); + } + + @Nullable + String readEntry(Condition condition) { + ZipInputStream stream = null; try { - ZipInputStream stream = getStream(); + stream = getStream(); ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { - if (entry.getName().endsWith(DESCRIPTION_PATH)) { + if (condition.value(entry)) { return StreamUtil.readText(stream); } } @@ -86,58 +81,26 @@ public class ArchivedProjectTemplate implements ProjectTemplate { catch (IOException e) { return null; } + finally { + StreamUtil.closeStream(stream); + } return null; } @NotNull @Override public ModuleBuilder createModuleBuilder() { - return new ModuleBuilder() { - @Override - public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { - - } - - @Override - public ModuleType getModuleType() { - return null; - } - - @NotNull - @Override - public Module createModule(@NotNull ModifiableModuleModel moduleModel) - throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { - final String path = getContentEntryPath(); - String iml; - try { - File dir = new File(path); - ZipInputStream zipInputStream = getStream(); - ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream); - VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir); - iml = ContainerUtil.find(dir.list(), new Condition() { - @Override - public boolean value(String s) { - return s.endsWith(".iml"); - } - }); - new File(path, iml).renameTo(new File(getModuleFilePath())); - RefreshQueue.getInstance().refresh(false, true, null, virtualFile); - } - catch (IOException e) { - throw new RuntimeException(e); - } - return ImportImlMode.setUpLoader(getModuleFilePath()).createModule(moduleModel); - } - }; + return new TemplateModuleBuilder(this); } + @Nullable @Override public ValidationInfo validateSettings() { return null; } - private ZipInputStream getStream() throws IOException { + ZipInputStream getStream() throws IOException { return new ZipInputStream(myArchivePath.openStream()); } diff --git a/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java b/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java new file mode 100644 index 000000000000..b852c890992d --- /dev/null +++ b/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java @@ -0,0 +1,108 @@ +/* + * Copyright 2000-2012 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.platform.templates; + +import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode; +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.openapi.module.*; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.platform.templates.github.ZipUtil; +import com.intellij.util.containers.ContainerUtil; +import org.jdom.Document; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** +* @author Dmitry Avdeev +* Date: 10/19/12 +*/ +class TemplateModuleBuilder extends ModuleBuilder { + private final ModuleType myType; + private ArchivedProjectTemplate myTemplate; + + public TemplateModuleBuilder(ArchivedProjectTemplate template) { + myTemplate = template; + myType = computeModuleType(myTemplate); + } + + @NotNull + private static ModuleType computeModuleType(ArchivedProjectTemplate template) { + String iml = template.readEntry(new Condition() { + @Override + public boolean value(ZipEntry entry) { + return entry.getName().endsWith(".iml"); + } + }); + if (iml == null) return ModuleType.EMPTY; + try { + Document document = JDOMUtil.loadDocument(iml); + String type = document.getRootElement().getAttributeValue(Module.ELEMENT_TYPE); + return ModuleTypeManager.getInstance().findByID(type); + } + catch (Exception e) { + return ModuleType.EMPTY; + } + } + + @Override + public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { + + } + + @Override + public ModuleType getModuleType() { + return myType; + } + + @NotNull + @Override + public Module createModule(@NotNull ModifiableModuleModel moduleModel) + throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { + final String path = getContentEntryPath(); + String iml; + try { + File dir = new File(path); + ZipInputStream zipInputStream = myTemplate.getStream(); + ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream); + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir); + iml = ContainerUtil.find(dir.list(), new Condition() { + @Override + public boolean value(String s) { + return s.endsWith(".iml"); + } + }); + new File(path, iml).renameTo(new File(getModuleFilePath())); + RefreshQueue.getInstance().refresh(false, true, null, virtualFile); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return ImportImlMode.setUpLoader(getModuleFilePath()).createModule(moduleModel); + } +} From e8053fad05da582b1406ab0f422688662522b441 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 19 Oct 2012 12:55:17 +0400 Subject: [PATCH 31/43] template code fixed --- .../Java/Java_Command_Line_Application.zip | Bin 1896 -> 1848 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip b/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip index c9dbc294b4f67c72b35ce4f6b0ba0e2cf00031ce..528f43e665e70325da33e09b5c86ceba4de59e06 100644 GIT binary patch delta 188 zcmaFCw}Wp(Hj5ww0|&#^v|z`^ZI4)@85kHcCfBeiMH+H77znUrGygn1E$XL`w)e&k z!xxS|Pl_B}{_GZv727r=^_xxQrVaO&w44h#uykse#?L?@;ot(W{}b=EhGDj1dmEtUjg2v7i0sVtKlS)|1Ryjj^m Qf*e4o&BVa)odv`L0CU4VX8-^I delta 237 zcmdnN_kwRjHj5w!0|&##SwW5rFfh4>MX7!x7n7lY%WsE&iC(_N{}m%L)y1+q${TlZ z&bECh@c%CFJ%h7vX5Z9gc`r~9Thtyoz2%6Obkx~36=4TE@3lniygtcc?Nk}h;-`jl z_GG_4tk=<6b$q7L Date: Fri, 19 Oct 2012 12:47:01 +0400 Subject: [PATCH 32/43] Access is allowed from event dispatch thread only --- .../ide/util/treeView/AbstractTreeUi.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index ff8b4b37f30a..29a65da83d73 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -736,11 +736,11 @@ public class AbstractTreeUi { expand(getRootNode(), true); } ActionCallback callback; - if (!willUpdate) { - callback = updateNodeChildren(getRootNode(), pass, null, false, false, false, true, true); + if (willUpdate) { + callback = new ActionCallback.Done(); } else { - callback = new ActionCallback.Done(); + callback = updateNodeChildren(getRootNode(), pass, null, false, false, false, true, true); } callback.doWhenDone(new Runnable() { @Override @@ -912,7 +912,7 @@ public class AbstractTreeUi { @Override public void run(final Boolean changes) { if (changes) { - invokeLaterIfNeeded(false, new Runnable() { + invokeLaterIfNeeded(true, new Runnable() { @Override public void run() { Object element = nodeDescriptor.getElement(); @@ -2177,11 +2177,6 @@ public class AbstractTreeUi { } } - private void scheduleMaybeReady() { - myMaybeReady.cancelAllRequests(); - myMaybeReady.addRequest(myMaybeReadyRunnable, Registry.intValue("ide.tree.waitForReadySchedule")); - } - private void flushPendingNodeActions() { final DefaultMutableTreeNode[] nodes = myPendingNodeActions.toArray(new DefaultMutableTreeNode[myPendingNodeActions.size()]); myPendingNodeActions.clear(); @@ -4020,10 +4015,6 @@ public class AbstractTreeUi { myRevalidatedObjects.add(element); AsyncResult revalidated = getBuilder().revalidateElement(element); - if (revalidated == null) { - runDone(onDone); - return; - } revalidated.doWhenDone(new AsyncResult.Handler() { @Override From 85fcac7fc06d848acd2599130930084c2aa4def3 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 19 Oct 2012 13:30:36 +0400 Subject: [PATCH 33/43] assertion --- .../codeInsight/intention/impl/IntentionHintComponent.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java index a51deeb2d26c..0057f067e225 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java @@ -152,6 +152,7 @@ public class IntentionHintComponent extends JPanel implements Disposable, Scroll @Override public void dispose() { + ApplicationManager.getApplication().assertIsDispatchThread(); myDisposed = true; myComponentHint.hide(); super.hide(); @@ -420,7 +421,7 @@ public class IntentionHintComponent extends JPanel implements Disposable, Scroll myPopupShown = true; } - private void recreateMyPopup(IntentionListStep step) { + private void recreateMyPopup(@NotNull IntentionListStep step) { if (myPopup != null) { Disposer.dispose(myPopup); } From a444dcfa01b17d72dcff7ea2547a8aeb47ca2c96 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 19 Oct 2012 12:27:08 +0200 Subject: [PATCH 34/43] good code red:do not override calculated subst with raw (IDEA-67680) --- .../daemon/impl/analysis/GenericsHighlightUtil.java | 7 +++++++ .../src/com/intellij/psi/impl/PsiClassImplUtil.java | 5 +---- .../src/com/intellij/psi/impl/PsiElementFactoryImpl.java | 2 +- .../impl/source/tree/java/PsiMethodCallExpressionImpl.java | 2 +- .../advHighlighting/aClassLoader_hl.java | 2 +- .../genericsHighlighting/TypeArgumentsGivenOnRawType.java | 2 +- .../daemon/LightAdvHighlightingPerformanceTest.java | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 370d479a1a89..98a8e90fcc45 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -1280,16 +1280,23 @@ public class GenericsHighlightUtil { if (refParamList.getTypeArguments().length == 0) return null; JavaResolveResult resolveResult = null; PsiElement parent = refParamList.getParent(); + PsiElement qualifier = null; if (parent instanceof PsiJavaCodeReferenceElement) { resolveResult = ((PsiJavaCodeReferenceElement)parent).advancedResolve(false); + qualifier = ((PsiJavaCodeReferenceElement)parent).getQualifier(); } else if (parent instanceof PsiCallExpression) { resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics(); + if (parent instanceof PsiMethodCallExpression) { + final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)parent).getMethodExpression(); + qualifier = methodExpression.getQualifier(); + } } if (resolveResult != null) { PsiElement element = resolveResult.getElement(); if (!(element instanceof PsiTypeParameterListOwner)) return null; if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) return null; + if (qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() instanceof PsiTypeParameter) return null; PsiClass containingClass = ((PsiMember)element).getContainingClass(); if (containingClass != null && PsiUtil.isRawSubstitutor(containingClass, resolveResult.getSubstitutor())) { if ((parent instanceof PsiCallExpression || parent instanceof PsiMethodReferenceExpression) && PsiUtil.isLanguageLevel7OrHigher(parent)) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 6c356bb0573c..af330dace6e5 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -583,7 +583,7 @@ public class PsiClassImplUtil { @NotNull PsiElementFactory elementFactory, @NotNull LanguageLevel languageLevel) { if (PsiUtil.isRawSubstitutor(aClass, substitutor)) { - return elementFactory.createRawSubstitutor(candidateClass); + return elementFactory.createRawSubstitutor(candidateClass).putAll(substitutor); } final PsiType containingType = elementFactory.createType(candidateClass, candidateSubstitutor, languageLevel); PsiType type = substitutor.substitute(containingType); @@ -675,9 +675,6 @@ public class PsiClassImplUtil { if (superClass == null) continue; PsiSubstitutor finalSubstitutor = obtainFinalSubstitutor(superClass, superTypeResolveResult.getSubstitutor(), aClass, state.get(PsiSubstitutor.KEY), factory, languageLevel); - if (aClass instanceof PsiTypeParameter && PsiUtil.isRawSubstitutor(superClass, finalSubstitutor)) { - finalSubstitutor = PsiSubstitutor.EMPTY; - } if (!processDeclarationsInClass(superClass, processor, state.put(PsiSubstitutor.KEY, finalSubstitutor), visited, last, place, isRaw)) { resolved = true; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index 23bbfdcd8600..6d829eb2bf65 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -335,7 +335,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps if (substitutorMap == null) substitutorMap = new HashMap(); substitutorMap.put(parameter, null); } - return baseSubstitutor.putAll(PsiSubstitutorImpl.createSubstitutor(substitutorMap)); + return PsiSubstitutorImpl.createSubstitutor(substitutorMap).putAll(baseSubstitutor); } @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java index ad1a5689aa34..e4e25c9b00c1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java @@ -216,8 +216,8 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements } if (is15OrHigher) { final PsiSubstitutor substitutor = result.getSubstitutor(); - if (PsiUtil.isRawSubstitutor(method, substitutor)) return TypeConversionUtil.erasure(ret); PsiType substitutedReturnType = substitutor.substitute(ret); + if (substitutedReturnType == null) return TypeConversionUtil.erasure(ret); PsiType lowerBound = PsiType.NULL; if (substitutedReturnType instanceof PsiCapturedWildcardType) { lowerBound = ((PsiCapturedWildcardType)substitutedReturnType).getLowerBound(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java index c7f959b6a630..5ad3d729e363 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java @@ -1723,7 +1723,7 @@ class SystemClassLoaderAction implements (cls, true, parent); - ctor = c.getDeclaredConstructor(cp); + ctor = c.getDeclaredConstructor(cp); sys = (ClassLoader) ctor.newInstance(params); Thread.currentThread().setContextClassLoader(sys); return sys; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java index 9b85d2949260..147fd862fe77 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java @@ -5,7 +5,7 @@ class A { } void foo1(A.C x) { - Integer bar = x.bar(); + Integer bar = x.bar(); } void foo2(A.C x) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java index a331e33c9cc6..92ce7d60ceac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java @@ -119,7 +119,7 @@ public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTest public void testAClassLoader() throws Exception { List errors = doTest(Math.max(1000, 10000 - JobSchedulerImpl.CORES_COUNT * 1000)); - if (173 != errors.size()) { + if (174 != errors.size()) { doTest(getFilePath("_hl"), false, false); fail("Actual: " + errors.size()); } From 65a985c3cdbd8aaeacfc0c681f6d451548624b8b Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 12:59:32 +0400 Subject: [PATCH 35/43] EA-40062 logging --- .../GroovyGenerateConstructorHandler.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java index ae9e07820f3d..c2a94b4e9cea 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.actions.generate.constructors; import com.intellij.codeInsight.generation.*; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -39,6 +40,7 @@ import java.util.List; * Date: 21.05.2008 */ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler { + private static final Logger LOG = Logger.getInstance(GroovyGenerateConstructorHandler.class); private static final String DEF_PSEUDO_ANNO = "_____intellij_idea_rulez_def_"; @@ -53,6 +55,8 @@ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler if (classMember instanceof PsiMethodMember) { final PsiMethod method = ((PsiMethodMember)classMember).getElement(); final PsiMethod copy = (PsiMethod)method.copy(); + LOG.assertTrue(copy != null, method.getClass().getName()); + if (copy instanceof GrMethod) { for (GrParameter parameter : ((GrMethod)copy).getParameterList().getParameters()) { if (parameter.getTypeElementGroovy() == null) { @@ -62,11 +66,13 @@ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler } res.add(new PsiMethodMember(factory.createMethodFromText(GroovyToJavaGenerator.generateMethodStub(copy), method))); - } else if (classMember instanceof PsiFieldMember) { - final PsiField field = ((PsiFieldMember) classMember).getElement(); + } + else if (classMember instanceof PsiFieldMember) { + final PsiField field = ((PsiFieldMember)classMember).getElement(); String prefix = field instanceof GrField && ((GrField)field).getTypeElementGroovy() == null ? DEF_PSEUDO_ANNO : ""; - res.add(new PsiFieldMember(factory.createFieldFromText(field.getType().getCanonicalText() + " " + prefix + field.getName(), aClass))); + res.add( + new PsiFieldMember(factory.createFieldFromText(field.getType().getCanonicalText() + " " + prefix + field.getName(), aClass))); } } From 1f50e72e1c2b2d98e4403700d9c36491bcdc7aeb Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 13:05:44 +0400 Subject: [PATCH 36/43] EA-40033 - CCE: GrUnresolvedAccessInspection.registerStaticImportFix --- .../daemon/impl/quickfix/QuickFixAction.java | 2 +- .../GrUnresolvedAccessInspection.java | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java index e7a18342cee7..d920e2570c72 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java @@ -94,7 +94,7 @@ public final class QuickFixAction { doRegister(info, action, null, null, fixRange, null); } - public static void unregisterQuickFixAction(HighlightInfo info, Condition condition) { + public static void unregisterQuickFixAction(@NotNull HighlightInfo info, Condition condition) { for (Iterator> it = info.quickFixActionRanges.iterator(); it.hasNext();) { Pair pair = it.next(); if (condition.value(pair.first.getAction())) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java index 8391df9b3e8a..7a166c589df3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java @@ -220,9 +220,10 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo if (cannotBeDynamic || shouldHighlightAsUnresolved(ref)) { HighlightInfo info = createAnnotationForRef(ref, cannotBeDynamic, GroovyBundle.message("cannot.resolve", ref.getReferenceName())); + LOG.assertTrue(info != null); HighlightDisplayKey displayKey = HighlightDisplayKey.find(SHORT_NAME); - if (isCall(ref)) { + if (ref.getParent() instanceof GrMethodCall) { registerStaticImportFix(ref, info, displayKey); } else { @@ -377,7 +378,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo return HighlightInfo.createHighlightInfo(highlightInfoType, refNameElement, message); } - private static void registerStaticImportFix(GrReferenceExpression referenceExpression, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerStaticImportFix(@NotNull GrReferenceExpression referenceExpression, @Nullable HighlightInfo info, @Nullable final HighlightDisplayKey key) { final String referenceName = referenceExpression.getReferenceName(); if (StringUtil.isEmpty(referenceName)) return; if (referenceExpression.getQualifier() != null) return; @@ -436,7 +437,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo } } - private static void registerAddImportFixes(GrReferenceElement refElement, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerAddImportFixes(GrReferenceElement refElement, @Nullable HighlightInfo info, final HighlightDisplayKey key) { final String referenceName = refElement.getReferenceName(); //noinspection ConstantConditions if (StringUtil.isEmpty(referenceName)) return; @@ -446,7 +447,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo QuickFixAction.registerQuickFixAction(info, new GroovyAddImportAction(refElement), key); } - private static void registerCreateClassByTypeFix(GrReferenceElement refElement, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerCreateClassByTypeFix(GrReferenceElement refElement, @Nullable HighlightInfo info, final HighlightDisplayKey key) { GrPackageDefinition packageDefinition = PsiTreeUtil.getParentOfType(refElement, GrPackageDefinition.class); if (packageDefinition != null) return; @@ -505,7 +506,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo private final HighlightInfo myInfo; private HighlightDisplayKey myKey; - public QuickFixActionRegistrarAdapter(HighlightInfo info, HighlightDisplayKey displayKey) { + public QuickFixActionRegistrarAdapter(@Nullable HighlightInfo info, HighlightDisplayKey displayKey) { myInfo = info; myKey = displayKey; } @@ -523,7 +524,9 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo @Override public void unregister(Condition condition) { - QuickFixAction.unregisterQuickFixAction(myInfo, condition); + if (myInfo != null) { + QuickFixAction.unregisterQuickFixAction(myInfo, condition); + } } } } From 401f9782840ce7a5511377de1d60cfaa38373ef5 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 13:16:38 +0400 Subject: [PATCH 37/43] EA-38182 - IAE: GroovyResolveResultImpl. --- .../psi/impl/statements/GrConstructorInvocationImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java index e26c782fdabc..611ddfd9c3ec 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java @@ -93,7 +93,10 @@ public class GrConstructorInvocationImpl extends GrCallImpl implements GrConstru } public GroovyResolveResult[] multiResolveClass() { - return new GroovyResolveResult[]{new GroovyResolveResultImpl(getDelegatedClass(), this, null, PsiSubstitutor.EMPTY, true, true)}; + PsiClass aClass = getDelegatedClass(); + if (aClass == null) return GroovyResolveResult.EMPTY_ARRAY; + + return new GroovyResolveResult[]{new GroovyResolveResultImpl(aClass, this, null, PsiSubstitutor.EMPTY, true, true)}; } public PsiMethod resolveMethod() { From f4e161f272b7bf4eaa1f5e31e217615a043060fa Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 13:23:18 +0400 Subject: [PATCH 38/43] EA-37793 diagnostics --- .../lang/psi/impl/GroovyPsiElementFactoryImpl.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index 9399ab730406..f13c1ad5a1b1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -138,8 +138,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { } public GrReferenceExpression createReferenceExpressionFromText(String idText, PsiElement context) { - PsiFile file = createGroovyFile(idText, false, context); - return (GrReferenceExpression) ((GroovyFileBase) file).getTopStatements()[0]; + GroovyFile file = createGroovyFile(idText, false, context); + GrTopStatement[] statements = file.getTopStatements(); + + if (statements.length != 1) throw new IncorrectOperationException("refText: " + idText); + if (!(statements[0] instanceof GrReferenceExpression)) throw new IncorrectOperationException("refText: " + idText); + + return (GrReferenceExpression)statements[0]; } @Override From 98a24d4d5715b76c5a8b81f147e7e7b8588c157a Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 13:38:02 +0400 Subject: [PATCH 39/43] EA-38666 diagnostics --- .../lang/psi/impl/GroovyPsiElementFactoryImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index f13c1ad5a1b1..a76b07cbad8f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -613,13 +613,15 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { @Override public GrStatement createStatementFromText(String text, @Nullable PsiElement context) { - try { - PsiFile file = createGroovyFile(text, false, context); - return (GrStatement)((GroovyFileBase)file).getTopStatements()[0]; + GroovyFile file = createGroovyFile(text, false, context); + GrTopStatement[] statements = file.getTopStatements(); + if (statements.length != 1) { + throw new IncorrectOperationException("count = " + statements.length + ", " + text); } - catch (RuntimeException e) { - throw new IncorrectOperationException(text); + if (!(statements[0] instanceof GrStatement)) { + throw new IncorrectOperationException("type = " + statements[0].getClass().getName() + ", " + text); } + return (GrStatement)statements[0]; } public GrBlockStatement createBlockStatement(@NonNls GrStatement... statements) { From 020eb4a96c8b3d37ba9e8f5e95a997c0f26a9af7 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 19 Oct 2012 14:31:06 +0400 Subject: [PATCH 40/43] EA-39269 - IOE: LightElement.replace --- .../impl/synthetic/GrSyntheticTypeElement.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java index f144f4a06026..c5833ee7c951 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java @@ -18,8 +18,10 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightElement; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; @@ -48,7 +50,7 @@ public class GrSyntheticTypeElement extends LightElement implements PsiTypeEleme @Override public PsiAnnotationOwner getOwner(PsiAnnotation annotation) { - return null; + return this; } @Override @@ -84,6 +86,17 @@ public class GrSyntheticTypeElement extends LightElement implements PsiTypeEleme return "Synthetic PsiTypeElement"; } + @Override + public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException { + if (newElement instanceof PsiTypeElement) { + GrTypeElement groovyTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(newElement.getText(), newElement); + return myElement.replace(groovyTypeElement); + } + else { + return super.replace(newElement); + } + } + @Override public TextRange getTextRange() { return myElement.getTextRange(); From 82d79a669d19f337a5ba59884b3c97ba290021d4 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 19 Oct 2012 14:33:17 +0400 Subject: [PATCH 41/43] IDEA-93167 --- .../intellij/designer/designSurface/tools/SelectionTool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java index 65e5913e6f1e..eed759966137 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java @@ -214,7 +214,7 @@ public class SelectionTool extends InputTool { } else if (myToolProvider != null && !area.isTree() && Character.isLetterOrDigit(event.getKeyChar()) && - (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK)) == 0) { + (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) == 0) { myToolProvider.startInplaceEditing(new InplaceContext(event.getKeyChar())); } } From 67179b2e37bb4a6de2a2144b211aff5d57159ba4 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 19 Oct 2012 12:40:23 +0200 Subject: [PATCH 42/43] expose "automake delay" property in registry --- .../impl/src/com/intellij/compiler/server/BuildManager.java | 3 ++- platform/platform-resources-en/src/misc/registry.properties | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 5c4f66307ede..f0c7f4f2cfad 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -360,7 +360,8 @@ public class BuildManager implements ApplicationComponent{ private void addMakeRequest(Runnable runnable) { myAlarm.cancelAllRequests(); - myAlarm.addRequest(runnable, MAKE_TRIGGER_DELAY); + final int delay = Registry.intValue("compiler.automake.trigger.delay", MAKE_TRIGGER_DELAY); + myAlarm.addRequest(runnable, delay); } private void runAutoMake() { diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 6dab52896453..d6574da722da 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -164,6 +164,9 @@ compiler.process.use.external.javac.description=Run javac compiler in a separate compiler.process.debug.port=-1 +compiler.automake.trigger.delay=3000 +compiler.automake.trigger.delay.description=Delay in milliseconds before triggering auto-make in response to file system events + vcs.show.colored.annotations=true vcs.showConsole=true From 97a9020d6ca242f1d20e5822942dd0b7e7c5d8c7 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 19 Oct 2012 12:41:49 +0200 Subject: [PATCH 43/43] lower bound for automake delay --- .../impl/src/com/intellij/compiler/server/BuildManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index f0c7f4f2cfad..adc4e58fb191 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -360,7 +360,7 @@ public class BuildManager implements ApplicationComponent{ private void addMakeRequest(Runnable runnable) { myAlarm.cancelAllRequests(); - final int delay = Registry.intValue("compiler.automake.trigger.delay", MAKE_TRIGGER_DELAY); + final int delay = Math.max(50, Registry.intValue("compiler.automake.trigger.delay", MAKE_TRIGGER_DELAY)); myAlarm.addRequest(runnable, delay); }