From 773481a3a453a1d015b46b3b5c3fd6dcbcade642 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:37 +0400 Subject: [PATCH 01/24] EA-27709 - NPE EqualsAndHashcode$1 compute --- .../equalsAndHashcode/EqualsAndHashcode.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java b/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java index 599b1b344daf..d20ed00ce671 100644 --- a/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java +++ b/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,21 +37,20 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool { private PsiMethod myHashCode; private PsiMethod myEquals; - private JavaPsiFacade myPsiFacade; private final AtomicBoolean myInitialized = new AtomicBoolean(); public void projectOpened(Project project) { - myPsiFacade = JavaPsiFacade.getInstance(project); } @NotNull public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { if (!myInitialized.getAndSet(true)) { + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(holder.getProject()); final PsiClass psiObjectClass = ApplicationManager.getApplication().runReadAction( new Computable() { @Nullable public PsiClass compute() { - return myPsiFacade.findClass("java.lang.Object"); + return psiFacade.findClass("java.lang.Object"); } } ); @@ -124,6 +123,5 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool { public void projectClosed(Project project) { myEquals = null; myHashCode = null; - myPsiFacade = null; } } From bc27633d89c63a2ac7f2b514fff30f820783005b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:45 +0400 Subject: [PATCH 02/24] do not reformat the whole file on method generation --- .../intellij/codeInsight/generation/PsiGenerationInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java b/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java index a6a21e6eeebc..ddac6ea27ce8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class PsiGenerationInfo extends GenerationInfo { return myMember; } - public void insert(PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException { + public void insert(final PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException { final PsiMember existingMember; if (myMember instanceof PsiField) { existingMember = aClass.findFieldByName(myMember.getName(), false); From dde22ea05ec63c1582563f4cd5e01b5838a162ee Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:53 +0400 Subject: [PATCH 03/24] do not insert final if final checkbox is disabled --- .../introduceVariable/IntroduceVariableDialog.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java index 52e3d71b2661..07c216f48e1b 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java @@ -104,11 +104,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable } public boolean isDeclareFinal() { - if (myCbFinal.isEnabled()) { - return myCbFinalState; - } else { - return true; - } + return myCbFinal.isEnabled() && myCbFinalState; } public boolean isReplaceLValues() { From b2f23f2eb97c0ac5ddb21b6efb16968b8c2ead6b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:00 +0400 Subject: [PATCH 04/24] condition to insert final tweaks --- .../refactoring/introduceVariable/IntroduceVariableBase.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 6605d527652c..8bbcae485a23 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -771,9 +771,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme final String variableName = suggestedName.names[0]; final boolean replaceAll = replaceChoice == OccurrencesChooser.ReplaceChoice.ALL || replaceChoice == OccurrencesChooser.ReplaceChoice.NO_WRITE; - final boolean declareFinal = - !anyAssignmentLHS && (replaceAll && - declareFinalIfAll || createFinals(project)); + final boolean declareFinal = replaceAll && (declareFinalIfAll || !anyAssignmentLHS) || createFinals(project); final boolean replaceWrite = anyAssignmentLHS && replaceChoice == OccurrencesChooser.ReplaceChoice.ALL; return new IntroduceVariableSettings() { @Override From df8a0ecfc34bbd9d3a7d9649b9146ad82e49c32a Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:09 +0400 Subject: [PATCH 05/24] cannot modify read only file --- .../codeInspection/javaDoc/JavaDocReferenceInspection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java index 4cf4d7f9bc6e..cc67b4e8826f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection.javaDoc; import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix; import com.intellij.codeInsight.lookup.LookupElement; @@ -327,6 +328,7 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool { public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiDocTag myTag = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiDocTag.class); if (myTag == null) return; + if (!CodeInsightUtilBase.preparePsiElementForWrite(myTag)) return; myTag.delete(); } } From 866db199b8c35051dbe4545464b6170579ef3f92 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:16 +0400 Subject: [PATCH 06/24] assertion --- .../src/com/intellij/execution/junit/TestDirectory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java index 9292631300f5..9f616cf59249 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java @@ -17,10 +17,7 @@ package com.intellij.execution.junit; import com.intellij.execution.CantRunException; import com.intellij.execution.ExecutionBundle; -import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; -import com.intellij.execution.configurations.RunnerSettings; -import com.intellij.execution.configurations.RuntimeConfigurationException; -import com.intellij.execution.configurations.RuntimeConfigurationWarning; +import com.intellij.execution.configurations.*; import com.intellij.execution.testframework.SourceScope; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; @@ -93,7 +90,7 @@ class TestDirectory extends TestPackage { } final String dirName = myConfiguration.getPersistentData().getDirName(); if (dirName == null || dirName.isEmpty()) { - throw new RuntimeConfigurationWarning("Directory is not specified"); + throw new RuntimeConfigurationError("Directory is not specified"); } final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName)); if (file == null) { @@ -101,7 +98,7 @@ class TestDirectory extends TestPackage { } final Module module = myConfiguration.getConfigurationModule().getModule(); if (module == null) { - throw new RuntimeConfigurationWarning("Module to choose classpath from is not specified"); + throw new RuntimeConfigurationError("Module to choose classpath from is not specified"); } } From a7ea388df29c5c68aed5bc71b26f03790b2c99d0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:24 +0400 Subject: [PATCH 07/24] add command to slightly undo --- .../InplaceIntroduceConstantPopup.java | 17 ++++++++----- .../InplaceIntroduceFieldPopup.java | 24 ++++++++++++++----- .../InplaceIntroduceParameterPopup.java | 21 +++++++++------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index ac814659dcc8..31ffb0844496 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -549,12 +549,17 @@ public class InplaceIntroduceConstantPopup { myReplaceAllCb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - templateState.gotoEnd(true); - myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences); - startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType()); - } + Runnable restartTemplateRunnable = new Runnable() { + public void run() { + final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + templateState.gotoEnd(true); + myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences); + startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType()); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME); } }); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index acf8d5349d7a..9c99c07722a4 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -15,11 +15,14 @@ */ package com.intellij.refactoring.introduceField; +import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.intention.impl.TypeExpression; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ScrollType; @@ -309,12 +312,21 @@ public class InplaceIntroduceFieldPopup { myIntroduceFieldPanel.addOccurrenceListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - templateState.gotoEnd(true); - myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences); - startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType()); - } + final Runnable restartTemplate = new Runnable() { + @Override + public void run() { + final TemplateState templateState = + TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + templateState.gotoEnd(true); + myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences); + startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType()); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplate, + IntroduceFieldHandler.REFACTORING_NAME, + IntroduceFieldHandler.REFACTORING_NAME); } }); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 9761f74e80b1..a5a116df7c12 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -424,14 +424,19 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected void updateControls(JCheckBox[] removeParamsCb) { super.updateControls(removeParamsCb); if (myParameterIndex < 0) return; - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); - final PsiParameter parameter = getParameter(); - final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL); - templateState.gotoEnd(true); - startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier); - } + Runnable restartTemplateRunnable = new Runnable() { + public void run() { + final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); + final PsiParameter parameter = getParameter(); + final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL); + templateState.gotoEnd(true); + startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME); } From 63c005729e899066648f0d0f621878ca0408111b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:31:29 +0400 Subject: [PATCH 08/24] NPE (cherry picked from commit 0368e329d4ca1041a43fd07cd168a7e234b7e8f0) --- .../InplaceIntroduceParameterPopup.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index a5a116df7c12..2bc3a08d026c 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -257,12 +257,14 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected JComponent getComponent() { if (!myInitialized) { myInitialized = true; - myWholePanel.add(myCanBeFinalCb, - new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0)); - if (myHasWriteAccess) { - myCanBeFinalCb.setSelected(false); - myCanBeFinalCb.setEnabled(false); + if (myCanBeFinalCb != null) { + myWholePanel.add(myCanBeFinalCb, + new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0)); + if (myHasWriteAccess) { + myCanBeFinalCb.setSelected(false); + myCanBeFinalCb.setEnabled(false); + } } } return myWholePanel; @@ -298,7 +300,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected void saveSettings(PsiVariable psiVariable) { final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); InplaceIntroduceParameterPopup.super.saveSettings(settings); - if (myCanBeFinalCb.isEnabled()) { + if (myCanBeFinalCb != null && myCanBeFinalCb.isEnabled()) { settings.INTRODUCE_PARAMETER_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL); } TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultParameterTypePointer.getType()); From 75e1f36acad0a8ae35cfd7688d96dc2438893c30 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:31:37 +0400 Subject: [PATCH 09/24] no need to select current visibility second time (first time null => no selection) (cherry picked from commit cd185298ab590714e319061d7e2d4379b52a8eb5) --- .../introduceField/IntroduceFieldPopupPanel.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index 5ee70e5b413c..5aa768e45b33 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -52,13 +52,6 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { occurrences, allowInitInMethod, allowInitInMethodIfAll, typeSelectorManager); } - protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { - super.initializeControls(initializerExpression, ourLastInitializerPlace); - - String ourLastVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; - setVisibility(ourLastVisibility); - } - protected void initializeInitializerPlace(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { if (initializerExpression != null) { From d849acf84848494d49a6c46e7732034090a6f2ea Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:26:14 +0200 Subject: [PATCH 10/24] fix the tests --- .../src/com/intellij/openapi/extensions/Extensions.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index ba6e11113c73..593101a33646 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -68,6 +68,7 @@ public class Extensions { public static void cleanRootArea(@NotNull Disposable parentDisposable) { final ExtensionsAreaImpl oldRootArea = (ExtensionsAreaImpl)getRootArea(); final ExtensionsAreaImpl newArea = createRootArea(); + ourRootArea = newArea; oldRootArea.notifyAreaReplaced(); Disposer.register(parentDisposable, new Disposable() { public void dispose() { From ac4b49dd98691c0204688b22dde20335b1f447ac Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:43:14 +0200 Subject: [PATCH 11/24] fail-fast on invalid lookup (EA-26138, EA-24113) --- .../codeInsight/lookup/impl/LookupImpl.java | 21 ++++++++++++------- .../lookup/impl/LookupManagerImpl.java | 6 ++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 31a78737355f..4dd8f4e8f52a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -336,7 +336,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable void appendPrefix(char c) { checkReused(); - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); myAdditionalPrefix += c; myInitialPrefix = null; myFrozenItems.clear(); @@ -378,7 +378,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!ApplicationManager.getApplication().isUnitTestMode()) { ApplicationManager.getApplication().assertIsDispatchThread(); } - assert !myDisposed : disposeTrace; + checkValid(); final Pair,Iterable>> snapshot = myModel.getModelSnapshot(); @@ -756,7 +756,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } public void performGuardedChange(Runnable change) { - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); assert myLookupStartMarker.isValid(); assert !myChangeGuard; @@ -770,13 +770,13 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable marker.trackInvalidation(false); myChangeGuard = false; } - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start"); LOG.assertTrue(marker.isValid(), "invalid marker"); if (isVisible()) { updateLookupBounds(); } - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); } @Override @@ -791,7 +791,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable public void show(){ ApplicationManager.getApplication().assertIsDispatchThread(); - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); LOG.assertTrue(!myShown); myShown = true; myStampShown = System.currentTimeMillis(); @@ -1319,11 +1319,16 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable return myDisposed; } + public void checkValid() { + if (myDisposed) { + throw new AssertionError("Disposed at: " + disposeTrace); + } + } + @Override public void showItemPopup(JBPopup hint) { final Rectangle bounds = getCurrentItemBounds(); - hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width, - bounds.y))); + hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width, bounds.y))); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java index 7c9de1ce5125..4c56449b6059 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java @@ -225,6 +225,12 @@ public class LookupManagerImpl extends LookupManager { } public LookupEx getActiveLookup() { + if (myActiveLookup != null && myActiveLookup.isLookupDisposed()) { + LookupImpl lookup = myActiveLookup; + myActiveLookup = null; + lookup.checkValid(); + } + return myActiveLookup; } From e3f8e0553479e23efe2884dc1c5cf768aa8298aa Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:55:05 +0200 Subject: [PATCH 12/24] correct matching for final * in some cases --- .../util/src/com/intellij/psi/codeStyle/NameUtil.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java index 0af1ceaa513d..d28c11119826 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java @@ -539,10 +539,12 @@ public class NameUtil { } // there's more in the pattern, but no more words if (nextStart == name.length()) { - if (patternIndex + i == myPattern.length - 1 && - ' ' == myPattern[patternIndex + i] && - (i == 1 && isWordStart(myPattern[patternIndex]) || i + nameIndex == name.length())) { - return FList.emptyList().prepend(TextRange.from(nameIndex, i)); + if (patternIndex + i == myPattern.length - 1) { + char last = myPattern[patternIndex + i]; + if (' ' == last && (i == 1 && isWordStart(myPattern[patternIndex]) || i + nameIndex == name.length()) || + '*' == last) { + return FList.emptyList().prepend(TextRange.from(nameIndex, i)); + } } return null; From 0b314627b39289dad00ab6fd4ad2efa937bffce2 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 13:38:49 +0200 Subject: [PATCH 13/24] constructors, don't return a value, a test for IDEA-69571: Static nested class in Groovy 1.7+: "this" keyword gives inspection 'Cannot reference nonstatic symbol 'a' from static context' --- .../assignment/GroovyResultOfAssignmentUsedInspection.java | 3 ++- .../plugins/groovy/lang/GroovyHighlightingTest.java | 5 +++++ .../testdata/highlighting/InnerClassConstructorThis.groovy | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java index c50ec4a7e69e..8432754b922e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java @@ -69,7 +69,8 @@ public class GroovyResultOfAssignmentUsedInspection extends BaseInspection { //check for method that has void return type. so it does not matter what return statements are. if (flowOwner instanceof GrOpenBlock) { final PsiElement flowParent = flowOwner.getParent(); - if (flowParent instanceof PsiMethod && ((PsiMethod)flowParent).getReturnType() == PsiType.VOID) { + if (flowParent instanceof PsiMethod && + (((PsiMethod)flowParent).getReturnType() == PsiType.VOID || ((PsiMethod)flowParent).isConstructor())) { return; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 6e01beb56b3a..fa1112c49f61 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -404,6 +404,11 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { doTest(new GroovyAssignabilityCheckInspection()); } + public void _testInnerClassConstructorThis() { + myFixture.enableInspections(new GroovyResultOfAssignmentUsedInspection()); + myFixture.testHighlighting(true, true, true, getTestName(false) + ".groovy"); + } + public void testCurrying(){ doTest(new GroovyAssignabilityCheckInspection()); } diff --git a/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy b/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy new file mode 100644 index 000000000000..392a9e5ba9f7 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy @@ -0,0 +1,6 @@ +class A { + static private class B { + int i + B () { this.i = 42 } + } +} \ No newline at end of file From 87b67d662462c59d26e10112e541b871bd822ea1 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 12 May 2011 13:38:54 +0200 Subject: [PATCH 14/24] IDEA-69532 (CVS: history view is empty; CompareWith... dialog shows no revisions) --- .../com/intellij/util/WaitForProgressToShow.java | 16 ++++++++++++++++ .../cvsExecution/ModalityContextImpl.java | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java b/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java index 9d2ef62a0a05..1a1bd088b2fa 100644 --- a/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java +++ b/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java @@ -46,6 +46,22 @@ public class WaitForProgressToShow { } } + public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) { + final Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread()) { + command.run(); + } else { + final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator(); + if (pi != null) { + execute(pi); + application.invokeAndWait(command, pi.getModalityState()); + } else { + final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState; + application.invokeAndWait(command, notNullModalityState); + } + } + } + public static void runOrInvokeLaterAboveProgress(final Runnable command, @Nullable final ModalityState modalityState, @NotNull final Project project) { final Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java index ca9c2dac949b..b88a34982bdb 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java @@ -47,8 +47,7 @@ public class ModalityContextImpl implements ModalityContext { action.run(); } else { - ModalityState modalityState = getCurrentModalityState(); - WaitForProgressToShow.runOrInvokeLaterAboveProgress(action, modalityState, project); + WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(action, getCurrentModalityState()); } } From be32735e2cf94845d4616b0b3825baceac92a21f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 12 May 2011 13:39:59 +0200 Subject: [PATCH 15/24] cleanup --- .../history/CvsHistoryProvider.java | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java index 4b6ad47caba7..abb7e08cd20b 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java @@ -20,7 +20,6 @@ import com.intellij.cvsSupport2.CvsUtil; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.changeBrowser.CvsChangeList; import com.intellij.cvsSupport2.connections.CvsConnectionSettings; -import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutorCallback; import com.intellij.cvsSupport2.cvsExecution.ModalityContext; @@ -37,7 +36,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.TreeItem; import com.intellij.util.ui.AbstractTableCellEditor; import com.intellij.util.ui.ColumnInfo; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.netbeans.lib.cvsclient.admin.Entry; import org.netbeans.lib.cvsclient.command.log.LogInformation; @@ -216,24 +214,23 @@ public class CvsHistoryProvider implements VcsHistoryProvider { else { return new CvsRevisionNumber(entryFor.getRevision()); } - } @Nullable public List createRevisions(final FilePath filePath) { final ArrayList result = new ArrayList(); - final VirtualFile root = CvsVfsUtil.refreshAndFindFileByIoFile(filePath.getIOFile().getParentFile()); + final File file = filePath.getIOFile(); + final VirtualFile root = CvsVfsUtil.refreshAndFindFileByIoFile(file.getParentFile()); // check if we have a history pane open for a file in a package which has just been deleted if (root == null) return null; - final LocalPathIndifferentLogOperation logOperation = - new LocalPathIndifferentLogOperation(filePath.getIOFile()); + final LocalPathIndifferentLogOperation logOperation = new LocalPathIndifferentLogOperation(file); CvsOperationExecutor executor = new CvsOperationExecutor(myProject); executor.performActionSync(new CommandCvsHandler(CvsBundle.message("operation.name.load.file.content"), logOperation), new CvsOperationExecutorCallback() { public void executionFinished(boolean successfully) { } - public void executeInProgressAfterAction(ModalityContext modaityContext) { + public void executeInProgressAfterAction(ModalityContext modalityContext) { } public void executionFinishedSuccessfully() { @@ -241,26 +238,15 @@ public class CvsHistoryProvider implements VcsHistoryProvider { .getCvsConnectionSettingsFor(filePath.getVirtualFileParent()); final LogInformation firstLogInformation = logOperation.getFirstLogInformation(); if (firstLogInformation != null) { - result.addAll(createRevisionListOn(CvsUtil.getCvsLightweightFileForFile(filePath.getIOFile()), - firstLogInformation, env, myProject)); + final List revisionList = firstLogInformation.getRevisionList(); + for (Revision revision : revisionList) { + result.add(new CvsFileRevisionImpl(revision, CvsUtil.getCvsLightweightFileForFile(file), + firstLogInformation, env, myProject)); + } } } }); return result; - - } - - private static List createRevisionListOn(File file, - @NotNull LogInformation logInformation, - CvsEnvironment env, - Project project) { - List revisionList = logInformation.getRevisionList(); - ArrayList result = new ArrayList(); - for (final Object aRevisionList : revisionList) { - Revision revision = (Revision)aRevisionList; - result.add(new CvsFileRevisionImpl(revision, file, logInformation, env, project)); - } - return result; } public AnAction[] getAdditionalActions(final Runnable refresher) { From 865c7b0bcc85e402a99b159f6ce8e242e89acb11 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:13:56 +0400 Subject: [PATCH 16/24] EA-27650 - IAE: ChangeSignatureProcessor. --- ...reateConstructorParameterFromFieldFix.java | 10 ++++++-- .../afterVarargs.java | 24 +++++++++++++++++++ .../beforeVarargs.java | 23 ++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java index fd62c6b0b77e..f5227741f464 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.jsp.jspJava.JspClass; import com.intellij.psi.util.PsiTypesUtil; import com.intellij.refactoring.util.RefactoringUtil; +import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -109,11 +110,16 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction { expressions[i] = factory.createExpressionFromText(value, parameter); } expressions[parameters.length] = factory.createExpressionFromText(getField().getName(), constructor); + if (constructor.isVarArgs()) { + ArrayUtil.swap(expressions, expressions.length - 1, expressions.length - 2); + } final SmartPointerManager manager = SmartPointerManager.getInstance(getField().getProject()); final SmartPsiElementPointer constructorPointer = manager.createSmartPsiElementPointer(constructor); final ChangeMethodSignatureFromUsageFix addParamFix = new ChangeMethodSignatureFromUsageFix(constructor, expressions, PsiSubstitutor.EMPTY, constructor, true, 1); - addParamFix.invoke(project, editor, file); + if (addParamFix.isAvailable(project, editor, file)) { + addParamFix.invoke(project, editor, file); + } return ApplicationManager.getApplication().runWriteAction(new Computable() { public Boolean compute() { return doCreate(project, editor, parameters, constructorPointer, addParamFix); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java new file mode 100644 index 000000000000..e5b4cce48a2c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// "Add constructor parameter" "true" +class A { + private final int field; + A(int field, String... strs) { + this.field = field; + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java new file mode 100644 index 000000000000..eeca05c7e8dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// "Add constructor parameter" "true" +class A { + private final int field; + A(String... strs) { + } + +} \ No newline at end of file From 9df040a6979fc3a3eb41bef5a97c805ba948a480 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:15:19 +0400 Subject: [PATCH 17/24] EA-27730 - AIOOBE: VariableInplaceIntroducer.getVariable --- .../introduceVariable/VariableInplaceIntroducer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 9394c10aabec..5cddf59d6f00 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -151,7 +151,11 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { @Nullable protected PsiVariable getVariable() { final PsiDeclarationStatement declarationStatement = myPointer.getElement(); - return declarationStatement != null ? (PsiVariable)declarationStatement.getDeclaredElements()[0] : null; + if (declarationStatement != null) { + PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); + return declaredElements.length == 0 ? null : (PsiVariable)declaredElements[0]; + } + return null; } @Override From 68acfaa4f0eef782d21316d4b4c6fdafe97fea17 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:45:51 +0400 Subject: [PATCH 18/24] diagnostics EA-27736 - assert: CopyClassesHandler.doClone --- .../src/com/intellij/refactoring/copy/CopyClassesHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java index 1d33a133626b..50d158d41084 100644 --- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -158,7 +158,7 @@ public class CopyClassesHandler implements CopyHandlerDelegate { public void doClone(PsiElement element) { FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.copyClass"); PsiClass[] classes = getTopLevelClasses(element); - LOG.assertTrue(classes != null && classes.length == 1); + LOG.assertTrue(classes != null && classes.length == 1, Arrays.toString(classes)); Project project = element.getProject(); CopyClassDialog dialog = new CopyClassDialog(classes[0], null, project, true); From 60ea556c14dcf646d413c7e79077da6aee8cc8aa Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Thu, 12 May 2011 13:52:14 +0200 Subject: [PATCH 19/24] AppCode:Formatter: indent members of @interface/@implementation/@protocol (OC-824) --- .../options/JavaIndentOptionsEditor.java | 8 +--- .../options/IndentOptionsEditor.java | 40 +++++++++---------- .../options/SmartIndentOptionsEditor.java | 10 +---- .../src/com/intellij/formatting/Indent.java | 15 +++++++ .../intellij/formatting/IndentFactory.java | 3 +- .../intellij/formatting/FormatterImpl.java | 11 +++-- 6 files changed, 48 insertions(+), 39 deletions(-) diff --git a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java b/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java index 19ae70407ef6..0ffca45d2401 100644 --- a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java +++ b/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java @@ -61,12 +61,8 @@ public class JavaIndentOptionsEditor extends SmartIndentOptionsEditor { public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) { super.apply(settings, options); - try { - options.LABEL_INDENT_SIZE = Integer.parseInt(myLabelIndent.getText()); - } - catch (NumberFormatException e) { - //stay with default - } + options.LABEL_INDENT_SIZE = getFieldValue(myLabelIndent, 0, options.LABEL_INDENT_SIZE); + options.LABEL_INDENT_ABSOLUTE = myLabelIndentAbsolute.isSelected(); settings.DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = myCbDontIndentTopLevelMembers.isSelected(); options.USE_RELATIVE_INDENTS = myCbUseRelativeIndent.isSelected(); diff --git a/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java b/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java index 040ad4d4f166..d88c79a6d307 100644 --- a/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java +++ b/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java @@ -41,17 +41,21 @@ public class IndentOptionsEditor extends OptionGroup { protected void addComponents() { addTabOptions(); - myTabSizeField = new JTextField(4); - myTabSizeField.setMinimumSize(myTabSizeField.getPreferredSize()); + myTabSizeField = createIndentTextField(); myTabSizeLabel = new JLabel(ApplicationBundle.message("editbox.indent.tab.size")); add(myTabSizeLabel, myTabSizeField); - myIndentField = new JTextField(4); - myIndentField.setMinimumSize(myTabSizeField.getPreferredSize()); + myIndentField = createIndentTextField(); myIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.indent")); add(myIndentLabel, myIndentField); } + protected JTextField createIndentTextField() { + JTextField field = new JTextField(4); + field.setMinimumSize(field.getPreferredSize()); + return field; + } + protected void addTabOptions() { myCbUseTab = new JCheckBox(ApplicationBundle.message("checkbox.indent.use.tab.character")); add(myCbUseTab); @@ -71,6 +75,15 @@ public class IndentOptionsEditor extends OptionGroup { } } + protected int getFieldValue(JTextField field, int minValue, int defValue) { + try { + return Math.max(Integer.parseInt(field.getText()), minValue); + } + catch (NumberFormatException e) { + return defValue; + } + } + public boolean isModified(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) { boolean isModified; isModified = isFieldModified(myTabSizeField, options.TAB_SIZE); @@ -81,26 +94,11 @@ public class IndentOptionsEditor extends OptionGroup { } protected int getUIIndent() { - final String indentText = myIndentField.getText(); - try { - return Math.max(Integer.parseInt(indentText), 1); - } - catch (NumberFormatException e) { - //stay with default - } - - return 4; + return getFieldValue(myIndentField, 1, 4); } protected int getUITabSize() { - try { - return Math.max(Integer.parseInt(myTabSizeField.getText()), 1); - } - catch (NumberFormatException e) { - //stay with default - } - - return 4; + return getFieldValue(myTabSizeField, 1, 4); } public void apply(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) { diff --git a/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java b/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java index 927cb3d514c0..a66e270207b1 100644 --- a/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java +++ b/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java @@ -40,8 +40,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor { protected void addComponents() { super.addComponents(); - myContinuationIndentField = new JTextField(4); - myContinuationIndentField.setMinimumSize(myContinuationIndentField.getPreferredSize()); + myContinuationIndentField = createIndentTextField(); myContinuationIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.continuation.indent")); add(myContinuationIndentLabel, myContinuationIndentField); } @@ -55,12 +54,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor { public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) { super.apply(settings, options); - try { - options.CONTINUATION_INDENT_SIZE = Math.max(Integer.parseInt(myContinuationIndentField.getText()), 0); - } - catch (NumberFormatException e) { - //stay with default - } + options.CONTINUATION_INDENT_SIZE = getFieldValue(myContinuationIndentField, 0, options.CONTINUATION_INDENT_SIZE); options.SMART_TABS = isSmartTabValid(options.INDENT_SIZE, options.TAB_SIZE) && myCbSmartTabs.isSelected(); } diff --git a/platform/lang-api/src/com/intellij/formatting/Indent.java b/platform/lang-api/src/com/intellij/formatting/Indent.java index a69a47bc08c7..6840af811c61 100644 --- a/platform/lang-api/src/com/intellij/formatting/Indent.java +++ b/platform/lang-api/src/com/intellij/formatting/Indent.java @@ -252,6 +252,21 @@ public abstract class Indent { return myFactory.getIndent(type, relativeToDirectParent, enforceIndentToChildren); } + /** + * Base factory method for {@link Indent} objects construction, i.e. all other methods may be expressed in terms of this method. + * + * @param type indent type + * @param spaces the number of spaces in the indent + * @param relativeToDirectParent flag the indicates if current indent object anchors direct block parent (feel free + * to get more information about that at class-level javadoc) + * @param enforceIndentToChildren flag the indicates if current indent object should be enforced for multiline block children + * (feel free to get more information about that at class-level javadoc) + * @return newly created indent configured in accordance with the given arguments + */ + public static Indent getIndent(@NotNull Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return myFactory.getIndent(type, spaces, relativeToDirectParent, enforceIndentToChildren); + } + public static class Type { private final String myName; diff --git a/platform/lang-api/src/com/intellij/formatting/IndentFactory.java b/platform/lang-api/src/com/intellij/formatting/IndentFactory.java index ff544121235d..b18949adf2bb 100644 --- a/platform/lang-api/src/com/intellij/formatting/IndentFactory.java +++ b/platform/lang-api/src/com/intellij/formatting/IndentFactory.java @@ -32,5 +32,6 @@ interface IndentFactory { Indent getContinuationIndent(boolean relativeToDirectParent); Indent getContinuationWithoutFirstIndent(boolean relativeToDirectParent); Indent getSpaceIndent(final int spaces, boolean relativeToDirectParent); - Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceParentIndent); + Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren); + Indent getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren); } diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java index 5be50492e66e..1847bca0d027 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java @@ -656,12 +656,17 @@ public class FormatterImpl extends FormatterEx } public Indent getSpaceIndent(final int spaces, final boolean relative) { - return new IndentImpl(Indent.Type.SPACES, false, spaces, relative, false); + return getIndent(Indent.Type.SPACES, spaces, relative, false); } @Override - public Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndent) { - return new IndentImpl(type, false, 0, relativeToDirectParent, enforceIndent); + public Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return getIndent(type, 0, relativeToDirectParent, enforceIndentToChildren); + } + + @Override + public Indent getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return new IndentImpl(type, false, spaces, relativeToDirectParent, enforceIndentToChildren); } public Indent getAbsoluteLabelIndent() { From 123e3e04ba12d03ad3f2e7425e9e663b91d4fba2 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 11:21:24 +0400 Subject: [PATCH 20/24] PsiReferenceProviderBean per language --- .../psi/PsiReferenceProviderBean.java | 25 +++++++- .../reference/ReferenceProvidersRegistry.java | 58 +++++++++---------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java index 643ff81c622d..a45f911d6c03 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java @@ -16,6 +16,7 @@ package com.intellij.psi; +import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AbstractExtensionPointBean; @@ -23,6 +24,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.patterns.ElementPattern; import com.intellij.patterns.ElementPatternBean; import com.intellij.patterns.StandardPatterns; +import com.intellij.util.KeyedLazyInstance; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.annotations.AbstractCollection; @@ -31,13 +33,19 @@ import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Tag; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** * Registers a {@link PsiReferenceProvider} in plugin.xml */ -public class PsiReferenceProviderBean extends AbstractExtensionPointBean { +public class PsiReferenceProviderBean extends AbstractExtensionPointBean implements KeyedLazyInstance { public static final ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.psi.referenceProvider"); + + @Attribute("language") + public String language = Language.ANY.getID(); + @Attribute("providerClass") public String className; @@ -74,8 +82,9 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { @Nullable public ElementPattern createElementPattern() { if (patterns.length > 1) { - return StandardPatterns.or(ContainerUtil.mapNotNull(patterns, - PATTERN_NULLABLE_FUNCTION).toArray(new ElementPattern[0])); + List> list = ContainerUtil.mapNotNull(patterns, PATTERN_NULLABLE_FUNCTION); + //noinspection unchecked + return StandardPatterns.or(list.toArray(new ElementPattern[list.size()])); } else if (patterns.length == 1) { return patterns[0].compilePattern(); @@ -85,4 +94,14 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { return null; } } + + @Override + public String getKey() { + return language; + } + + @Override + public PsiReferenceProviderBean getInstance() { + return this; + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java index b89a486980e7..2ec49f581abb 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java @@ -44,7 +44,8 @@ import java.util.Map; */ public class ReferenceProvidersRegistry { - private static final LanguageExtension EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); + private static final LanguageExtension CONTRIBUTOR_EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); + private static final LanguageExtension REFERENCE_PROVIDER_EXTENSION = new LanguageExtension(PsiReferenceProviderBean.EP_NAME.getName()); private static final Comparator> PRIORITY_COMPARATOR = new Comparator>() { @@ -66,10 +67,33 @@ public class ReferenceProvidersRegistry { @Override protected PsiReferenceRegistrarImpl create(Language language) { PsiReferenceRegistrarImpl registrar = new PsiReferenceRegistrarImpl(); - List contributors = EXTENSION.allForLanguage(language); - for (PsiReferenceContributor contributor : contributors) { + for (PsiReferenceContributor contributor : CONTRIBUTOR_EXTENSION.allForLanguage(language)) { contributor.registerReferenceProviders(registrar); } + + List referenceProviderBeans = REFERENCE_PROVIDER_EXTENSION.allForLanguage(language); + for (final PsiReferenceProviderBean providerBean : referenceProviderBeans) { + final ElementPattern pattern = providerBean.createElementPattern(); + if (pattern != null) { + registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { + + PsiReferenceProvider myProvider; + + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + if (myProvider == null) { + + myProvider = providerBean.instantiate(); + if (myProvider == null) { + myProvider = NULL_REFERENCE_PROVIDER; + } + } + return myProvider.getReferencesByElement(element, context); + } + }); + } + } return registrar; } }; @@ -78,34 +102,6 @@ public class ReferenceProvidersRegistry { return ServiceManager.getService(ReferenceProvidersRegistry.class); } - public ReferenceProvidersRegistry() { - - PsiReferenceRegistrarImpl registrar = getRegistrar(Language.ANY); - for (final PsiReferenceProviderBean providerBean : PsiReferenceProviderBean.EP_NAME.getExtensions()) { - final ElementPattern pattern = providerBean.createElementPattern(); - if (pattern != null) { - registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { - - PsiReferenceProvider myProvider; - - @NotNull - @Override - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { - if (myProvider == null) { - - myProvider = providerBean.instantiate(); - if (myProvider == null) { - myProvider = NULL_REFERENCE_PROVIDER; - } - } - return myProvider.getReferencesByElement(element, context); - } - }); - } - } - - } - public PsiReferenceRegistrarImpl getRegistrar(Language language) { return myRegistrars.get(language); } From 25a02745c4b767698b0be585988ac57e4afe5cc5 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 11:37:00 +0400 Subject: [PATCH 21/24] CustomActionsSchema converted to service --- .../ui/customization/CustomActionsSchema.java | 20 +++++-------------- .../src/META-INF/PlatformExtensions.xml | 2 ++ .../src/componentSets/Platform.xml | 3 --- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java index fd2d3d70fca6..0fd6ac8846b8 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java @@ -20,9 +20,9 @@ import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.components.ExportableApplicationComponent; +import com.intellij.openapi.components.ExportableComponent; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.keymap.impl.ui.ActionsTreeUtil; import com.intellij.openapi.keymap.impl.ui.Group; @@ -48,7 +48,8 @@ import java.util.List; * User: anna * Date: Jan 20, 2005 */ -public class CustomActionsSchema implements ExportableApplicationComponent, NamedJDOMExternalizable { +public class CustomActionsSchema implements ExportableComponent, NamedJDOMExternalizable { + @NonNls private static final String ACTIONS_SCHEMA = "custom_actions_schema"; @NonNls private static final String ACTIVE = "active"; @NonNls private static final String ELEMENT_ACTION = "action"; @@ -79,7 +80,7 @@ public class CustomActionsSchema implements ExportableApplicationComponent, Name private static final Logger LOG = Logger.getInstance("#" + CustomActionsSchema.class.getName()); public static CustomActionsSchema getInstance() { - return ApplicationManager.getApplication().getComponent(CustomActionsSchema.class); + return ServiceManager.getService(CustomActionsSchema.class); } public void addAction(ActionUrl url) { @@ -338,17 +339,6 @@ public void removeIconCustomization(String actionId) { return IdeBundle.message("title.custom.actions.schemas"); } - @NotNull - public String getComponentName() { - return "com.intellij.ide.ui.customization.CustomizableActionsSchemas"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - public String getExternalFileName() { return "customization"; } diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 3aa7e19f8cc3..415c3390a7b0 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -20,6 +20,8 @@ + + diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index d3c8dd3fdf75..5244b44a9b35 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -75,9 +75,6 @@ com.intellij.ide.TipOfTheDayManager - - com.intellij.ide.ui.customization.CustomActionsSchema - com.intellij.ide.ui.LafManager com.intellij.ide.ui.LafManagerImpl From 7fba0c7ae2b81827732ff6710b8b3b0eb974cfcd Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 15:41:19 +0400 Subject: [PATCH 22/24] lazy bundle loading --- platform/lang-api/src/com/intellij/facet/FacetType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/facet/FacetType.java b/platform/lang-api/src/com/intellij/facet/FacetType.java index e1a96fcc79e7..37b63f3ff272 100644 --- a/platform/lang-api/src/com/intellij/facet/FacetType.java +++ b/platform/lang-api/src/com/intellij/facet/FacetType.java @@ -88,12 +88,12 @@ public abstract class FacetType { } @NotNull - public final String getPresentableName() { + public String getPresentableName() { return myPresentableName; } /** - * Default name wich will be used then user creates a facet of this type + * Default name which will be used then user creates a facet of this type * @return */ @NotNull @NonNls From 38131f60b53fa297d8a83e04a37e2c8676feae14 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 16:01:05 +0400 Subject: [PATCH 23/24] IDEA-69527: IDEA 10.0.3 hangs when trying to open folder or file [rev. by max] --- .../ide/projectView/impl/ClassesTreeStructureProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java index d7ba93b430ae..fd5c7aa0085a 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java @@ -27,6 +27,7 @@ import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.jsp.JspFile; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -43,7 +44,7 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv ArrayList result = new ArrayList(); for (final AbstractTreeNode child : children) { Object o = child.getValue(); - if (o instanceof PsiClassOwner) { + if (o instanceof PsiClassOwner && !(o instanceof JspFile)) { final ViewSettings settings1 = ((ProjectViewNode)parent).getSettings(); final PsiClassOwner classOwner = (PsiClassOwner)o; final VirtualFile file = classOwner.getVirtualFile(); @@ -64,8 +65,8 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv } } - PsiClass[] classes = classOwner.getClasses(); if (fileInRoots(file)) { + PsiClass[] classes = classOwner.getClasses(); if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) && (file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) { result.add(new ClassTreeNode(myProject, classes[0], settings1)); From e5d5e1704833c07a7e83641ecc4c00d14852a378 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Thu, 12 May 2011 16:16:00 +0400 Subject: [PATCH 24/24] [mac] show window preview for minimized frame --- .../src/com/intellij/openapi/wm/impl/IdeFrameImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index eacd43b86de8..0ab6b564d752 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -103,6 +103,10 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { setFocusableWindowState(false); } + // to show window thumbnail under Macs + // http://lists.apple.com/archives/java-dev/2009/Dec/msg00240.html + if (SystemInfo.isMac) setIconImage(null); + MouseGestureManager.getInstance().add(this); }