From 361d7d0b9abdfa1f997e04fe10bfe58a206937e7 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Fri, 18 Feb 2011 16:26:36 +0300 Subject: [PATCH 01/17] EA-25165 - PIEAE: ASTDelegatePsiElement.getManager --- .../org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index 14caa5c9b638..1e2ae47a3710 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -521,6 +521,7 @@ public class ResolveUtil { } public static boolean isInUseScope(PsiElement context) { + if (!context.isValid()) return false; if (context instanceof GrMethodCall) { final GrExpression expression = ((GrMethodCall)context).getInvokedExpression(); if (expression instanceof GrReferenceExpression) { From f9a615ee35bff1a513e5ccd6da75e3c64d78e3c0 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 21 Feb 2011 10:33:22 +0300 Subject: [PATCH 02/17] VCS: platform vcs detector: invoke later always --- .../src/com/intellij/platform/PlatformVcsDetector.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/platform/PlatformVcsDetector.java b/platform/vcs-impl/src/com/intellij/platform/PlatformVcsDetector.java index 82604dd6c195..39a37e9213a6 100644 --- a/platform/vcs-impl/src/com/intellij/platform/PlatformVcsDetector.java +++ b/platform/vcs-impl/src/com/intellij/platform/PlatformVcsDetector.java @@ -15,10 +15,12 @@ */ package com.intellij.platform; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; @@ -42,7 +44,7 @@ public class PlatformVcsDetector implements ProjectComponent { public void projectOpened() { StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new DumbAwareRunnable() { public void run() { - AppUIUtil.invokeLaterIfProjectAlive(myProject, new DumbAwareRunnable() { + final DumbAwareRunnable runnable = new DumbAwareRunnable() { @Override public void run() { VirtualFile file = ProjectBaseDirectory.getInstance(myProject).getBaseDir(myProject.getBaseDir()); @@ -56,6 +58,12 @@ public class PlatformVcsDetector implements ProjectComponent { } } } + }; + ApplicationManager.getApplication().invokeLater(runnable, new Condition() { + @Override + public boolean value(Object o) { + return (! myProject.isOpen()) || myProject.isDisposed(); + } }); } }); From 872d8ddef2659171b0cb583aec365db480077738 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 21 Feb 2011 11:55:05 +0300 Subject: [PATCH 03/17] IDEA-65601 Scroll after zoom bug Vertical scrollbar of editor scroll pane recalculates its bounds on font size change now --- .../src/com/intellij/openapi/editor/impl/EditorImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index e003cb69d206..e2e5963c3d03 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -765,6 +765,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int oldFontSize = myScheme.getEditorFontSize(); myScheme.setEditorFontSize(fontSize); myPropertyChangeSupport.firePropertyChange(PROP_FONT_SIZE, oldFontSize, fontSize); + // Update vertical scroll bar bounds if necessary (we had a problem that use increased editor font size and it was not possible + // to scroll to the bottom of the document). + myScrollPane.getViewport().invalidate(); } public ActionCallback type(final String text) { From 5a5e84f3ef8c4dceb8c1b1ca452dc7b31b66a413 Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 19 Feb 2011 15:11:06 +0100 Subject: [PATCH 04/17] complex inference algorithm for diamond --- .../impl/analysis/GenericsHighlightUtil.java | 18 +- .../ExplicitTypeCanBeDiamondInspection.java | 31 +- .../com/intellij/psi/impl/PsiImplUtil.java | 2 +- .../source/resolve/PsiResolveHelperImpl.java | 14 +- .../advHighlighting7/DiamondMisc.java | 2 +- .../advHighlighting7/DiamondNeg1.java | 16 +- .../advHighlighting7/DiamondNeg10.java | 7 + .../advHighlighting7/DiamondNeg11.java | 8 + .../advHighlighting7/DiamondNeg2.java | 32 +- .../advHighlighting7/DiamondNeg3.java | 48 +-- .../advHighlighting7/DiamondNeg4.java | 16 +- .../advHighlighting7/DiamondNeg6.java | 11 + .../advHighlighting7/DiamondNeg7.java | 9 + .../advHighlighting7/DiamondNeg8.java | 20 ++ .../advHighlighting7/DiamondNeg9.java | 12 + .../advHighlighting7/DiamondPos5.java | 12 + .../quickFix/explicit2diamond/after2.java | 7 - .../quickFix/explicit2diamond/after3.java | 11 - .../quickFix/explicit2diamond/after5.java | 16 + .../quickFix/explicit2diamond/after6.java | 16 + .../quickFix/explicit2diamond/after8.java | 16 + .../quickFix/explicit2diamond/after9.java | 16 + .../quickFix/explicit2diamond/before2.java | 2 +- .../quickFix/explicit2diamond/before3.java | 2 +- .../quickFix/explicit2diamond/before4.java | 16 + .../quickFix/explicit2diamond/before5.java | 16 + .../quickFix/explicit2diamond/before6.java | 16 + .../quickFix/explicit2diamond/before7.java | 16 + .../quickFix/explicit2diamond/before8.java | 16 + .../quickFix/explicit2diamond/before9.java | 16 + .../daemon/LightAdvHighlightingJdk7Test.java | 30 ++ .../src/com/intellij/psi/PsiDiamondType.java | 334 +++++++++++------- 32 files changed, 580 insertions(+), 224 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg10.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg11.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg6.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg7.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg8.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg9.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondPos5.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java delete mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after5.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after6.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after8.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after9.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before4.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before5.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before6.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before7.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before8.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before9.java 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 d915d14f4bc3..519151b2189f 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 @@ -107,6 +107,19 @@ public class GenericsHighlightUtil { } } + PsiDiamondType.DiamondInferenceResult inferenceResult = null; + PsiTypeElement[] referenceElements = null; + if (referenceParameterList != null) { + referenceElements = referenceParameterList.getTypeParameterElements(); + if (referenceElements.length == 1 && referenceElements[0].getType() instanceof PsiDiamondType) { + inferenceResult = ((PsiDiamondType)referenceElements[0].getType()).resolveInferredTypes(); + final String errorMessage = inferenceResult.getErrorMessage(); + if (errorMessage != null) { + return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, referenceElements[0], errorMessage); + } + } + } + final PsiTypeParameter[] typeParameters = typeParameterListOwner.getTypeParameters(); final int targetParametersNum = typeParameters.length; final int refParametersNum = referenceParameterList == null ? 0 : referenceParameterList.getTypeArguments().length; @@ -140,9 +153,8 @@ public class GenericsHighlightUtil { // bounds check if (targetParametersNum > 0 && refParametersNum != 0) { - final PsiTypeElement[] referenceElements = referenceParameterList.getTypeParameterElements(); - if (referenceElements.length == 1 && referenceElements[0].getType() instanceof PsiDiamondType) { - final PsiType[] types = ((PsiDiamondType)referenceElements[0].getType()).getInferredTypes(); + if (inferenceResult != null) { + final PsiType[] types = inferenceResult.getTypes(); for (int i = 0; i < typeParameters.length; i++) { final PsiType type = types[i]; final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, type, referenceElements[0]); diff --git a/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java b/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java index afd8c91f32b5..57c3d2a43852 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.TypeConversionUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -65,15 +66,39 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionT @Override public void visitNewExpression(PsiNewExpression expression) { if (PsiUtil.getLanguageLevel(expression).isAtLeast(LanguageLevel.JDK_1_7)) { - final PsiJavaCodeReferenceElement classReference = expression.getClassReference(); + final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); if (classReference != null) { final PsiReferenceParameterList parameterList = classReference.getParameterList(); if (parameterList != null) { final PsiTypeElement[] typeElements = parameterList.getTypeParameterElements(); if (typeElements.length > 0) { if (typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return; - holder.registerProblem(parameterList, "Redundant type argument #ref #loc", - ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithDiamondFix()); + final PsiDiamondType.DiamondInferenceResult inferenceResult = PsiDiamondType.resolveInferredTypes(expression); + if (inferenceResult.getErrorMessage() == null) { + final PsiType[] types = inferenceResult.getTypes(); + final PsiType[] typeArguments = parameterList.getTypeArguments(); + if (types.length == typeArguments.length) { + for (int i = 0, typeArgumentsLength = typeArguments.length; i < typeArgumentsLength; i++) { + PsiType typeArgument = typeArguments[i]; + if (types[i] instanceof PsiWildcardType) { + final PsiWildcardType wildcardType = (PsiWildcardType)types[i]; + final PsiType bound = wildcardType.getBound(); + if (bound != null) { + if (wildcardType.isExtends()) { + if (bound.isAssignableFrom(typeArgument)) continue; + } else { + if (typeArgument.isAssignableFrom(bound)) continue; + } + } + } + if (!typeArgument.equals(types[i])) { + return; + } + } + } + holder.registerProblem(parameterList, "Redundant type argument #ref #loc", + ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithDiamondFix()); + } } } } diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java b/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java index c2a7fa637c26..aaa1450e159d 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java @@ -233,7 +233,7 @@ public class PsiImplUtil { types[i] = typeElements[i].getType(); } if (types.length == 1 && types[0] instanceof PsiDiamondType) { - return ((PsiDiamondType)types[0]).getInferredTypes(); + return ((PsiDiamondType)types[0]).resolveInferredTypes().getTypes(); } return types; } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index fdcdc3a5ceb9..551b95ac8ba4 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -403,8 +403,8 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { final boolean forCompletion) { PsiTypeParameterListOwner owner = typeParameter.getOwner(); Pair substitution = null; - if (owner instanceof PsiMethod && parent instanceof PsiMethodCallExpression) { - PsiMethodCallExpression methodCall = (PsiMethodCallExpression)parent; + if (owner instanceof PsiMethod && parent instanceof PsiCallExpression) { + PsiCallExpression methodCall = (PsiCallExpression)parent; substitution = inferMethodTypeParameterFromParent(methodCall.getParent(), methodCall, typeParameter, substitutor, forCompletion); } return substitution; @@ -604,7 +604,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { } private static Pair inferMethodTypeParameterFromParent(PsiElement parent, - PsiMethodCallExpression methodCall, + PsiCallExpression methodCall, final PsiTypeParameter typeParameter, PsiSubstitutor substitutor, final boolean forCompletion) { @@ -701,13 +701,13 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { return result; } - private static final ThreadLocal> myBlockedForInferenceMethodCalls = new ThreadLocal>() { - protected List initialValue() { - return new ArrayList(2); + private static final ThreadLocal> myBlockedForInferenceMethodCalls = new ThreadLocal>() { + protected List initialValue() { + return new ArrayList(2); } }; - private static Pair inferTypeForCompletionFromCallContext(final PsiMethodCallExpression innerMethodCall, + private static Pair inferTypeForCompletionFromCallContext(final PsiCallExpression innerMethodCall, final PsiExpressionList expressionList, final PsiCallExpression contextCall, final PsiTypeParameter typeParameter) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java index a3c496807427..30b750e35c9f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java @@ -35,7 +35,7 @@ class P { class Test1 { void bar() { - foo(new FF<>()); + foo(new FF<>()); } void foo(F> p) {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java index ddf456df1746..220e99fd850a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java @@ -8,29 +8,29 @@ class Neg01 { void test() { Neg01<String> n1 = new Neg01<>("" ); //new Foo created - Neg01<? extends String> n2 = new Neg01<>(""); //new Foo created - Neg01 n3 = new Neg01<>(""); //new Foo created + Neg01<? extends String> n2 = new Neg01<>(""); //new Foo created + Neg01 n3 = new Neg01<>(""); //new Foo created Neg01<? super String> n4 = new Neg01<>(""); //new Foo created Neg01<String> n5 = new Neg01<>("") { }; //new Foo created - Neg01<? extends String> n6 = new Neg01<>("") { + Neg01<? extends String> n6 = new Neg01<>("") { }; //new Foo created - Neg01 n7 = new Neg01<>("") { + Neg01 n7 = new Neg01<>("") { }; //new Foo created Neg01<? super String> n8 = new Neg01<>("") { }; //new Foo created Neg01<String> n9 = new Neg01<>("", ""); //new Foo created - Neg01<? extends String> n10 = new Neg01<>("", ""); //new Foo created - Neg01 n11 = new Neg01<>("", ""); //new Foo created + Neg01<? extends String> n10 = new Neg01<>("", ""); //new Foo created + Neg01 n11 = new Neg01<>("", ""); //new Foo created Foo n12 = new Neg01<>("", ""); //new Foo created Neg01<String> n13 = new Neg01<>("", "") { }; //new Foo created - Neg01<? extends String> n14 = new Neg01<>("", "") { + Neg01<? extends String> n14 = new Neg01<>("", "") { }; //new Foo created - Neg01 n15 = new Neg01<>("", "") { + Neg01 n15 = new Neg01<>("", "") { }; //new Foo created Neg01<? super String> n16 = new Neg01<>("", "") { }; //new Foo created diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg10.java new file mode 100644 index 000000000000..e5efd0968f05 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg10.java @@ -0,0 +1,7 @@ +class Neg10 { + static class Foo { + Foo(X x) {} + } + + Foo fw = new Foo<>(1); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg11.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg11.java new file mode 100644 index 000000000000..3e32e1a49071 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg11.java @@ -0,0 +1,8 @@ +class Neg11 { + + void test() { + class Foo { } + Foo f1 = new UndeclaredName<>(); //this is deliberate: aim is to test erroneous path + Foo f2 = new UndeclaredName<>() {}; //this is deliberate: aim is to test erroneous path + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg2.java index 635dc5bd9798..9a218866a1ce 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg2.java @@ -10,29 +10,29 @@ class Neg02 { void testSimple() { Foo<String> f1 = new Foo<>(""); //new Foo created - Foo<? extends String> f2 = new Foo<>(""); //new Foo created - Foo f3 = new Foo<>(""); //new Foo created + Foo<? extends String> f2 = new Foo<>(""); //new Foo created + Foo f3 = new Foo<>(""); //new Foo created Foo<? super String> f4 = new Foo<>(""); //new Foo created Foo<String> f5 = new Foo<>("") { }; //new Foo created - Foo<? extends String> f6 = new Foo<>("") { + Foo<? extends String> f6 = new Foo<>("") { }; //new Foo created - Foo f7 = new Foo< >("") { + Foo f7 = new Foo< >("") { }; //new Foo created Foo<? super String> f8 = new Foo<>("") { }; //new Foo created Foo<String> f9 = new Foo<>("", ""); //new Foo created - Foo<? extends String> f10 = new Foo<>("", ""); //new Foo created - Foo f11 = new Foo< >("", ""); //new Foo created + Foo<? extends String> f10 = new Foo<>("", ""); //new Foo created + Foo f11 = new Foo< >("", ""); //new Foo created Foo<? super String> f12 = new Foo<>("", ""); //new Foo created Foo<String> f13 = new Foo<>("", "") { }; //new Foo created - Foo<? extends String> f14 = new Foo<>("", "") { + Foo<? extends String> f14 = new Foo<>("", "") { }; //new Foo created - Foo f15 = new Foo< >("", "") { + Foo f15 = new Foo< >("", "") { }; //new Foo created Foo<? super String> f16 = new Foo<>("", "") { }; //new Foo created @@ -40,29 +40,29 @@ class Neg02 { void testQualified() { Foo<String> f1 = new Neg02.Foo<>(""); //new Foo created - Foo<? extends String> f2 = new Neg02.Foo<>(""); //new Foo created - Foo f3 = new Neg02.Foo< >(""); //new Foo created + Foo<? extends String> f2 = new Neg02.Foo<>(""); //new Foo created + Foo f3 = new Neg02.Foo< >(""); //new Foo created Foo<? super String> f4 = new Neg02.Foo<>(""); //new Foo created Foo<String> f5 = new Neg02.Foo<>("") { }; //new Foo created - Foo<? extends String> f6 = new Neg02.Foo<>("") { + Foo<? extends String> f6 = new Neg02.Foo<>("") { }; //new Foo created - Foo f7 = new Neg02.Foo< >("") { + Foo f7 = new Neg02.Foo< >("") { }; //new Foo created Foo<? super String> f8 = new Neg02.Foo<>("") { }; //new Foo created Foo<String> f9 = new Neg02.Foo<>("", ""); //new Foo created - Foo<? extends String> f10 = new Neg02.Foo<>("", ""); //new Foo created - Foo f11 = new Neg02.Foo< >("", ""); //new Foo created + Foo<? extends String> f10 = new Neg02.Foo<>("", ""); //new Foo created + Foo f11 = new Neg02.Foo< >("", ""); //new Foo created Foo<? super String> f12 = new Neg02.Foo<>("", ""); //new Foo created Foo<String> f13 = new Neg02.Foo<>("", "") { }; //new Foo created - Foo<? extends String> f14 = new Neg02.Foo<>("", "") { + Foo<? extends String> f14 = new Neg02.Foo<>("", "") { }; //new Foo created - Foo f15 = new Neg02.Foo< >("", "") { + Foo f15 = new Neg02.Foo< >("", "") { }; //new Foo created Foo<? super String> f16 = new Neg02.Foo<>("", "") { }; //new Foo created diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg3.java index 8d770ab57870..6b2a82b9227d 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg3.java @@ -7,67 +7,67 @@ class Neg03 { void testSimple() { Foo<String> f1 = new Foo<>(""); //new Foo created - Foo<? extends String> f2 = new Foo<>(""); //new Foo created - Foo f3 = new Foo<>(""); //new Foo created + Foo<? extends String> f2 = new Foo<>(""); //new Foo created + Foo f3 = new Foo<>(""); //new Foo created Foo<? super String> f4 = new Foo<>(""); //new Foo created Foo<String> f5 = new Foo<>(""){}; //new Foo created - Foo<? extends String> f6 = new Foo<>(""){}; //new Foo created - Foo f7 = new Foo<>(""){}; //new Foo created + Foo<? extends String> f6 = new Foo<>(""){}; //new Foo created + Foo f7 = new Foo<>(""){}; //new Foo created Foo<? super String> f8 = new Foo<>(""){}; //new Foo created Foo<String> f9 = new Foo<>("", ""); //new Foo created - Foo<? extends String> f10 = new Foo<>("", ""); //new Foo created - Foo f11 = new Foo<>("", ""); //new Foo created + Foo<? extends String> f10 = new Foo<>("", ""); //new Foo created + Foo f11 = new Foo<>("", ""); //new Foo created Foo<? super String> f12 = new Foo<>("", ""); //new Foo created Foo<String> f13 = new Foo<>("", ""){}; //new Foo created - Foo<? extends String> f14 = new Foo<>("", ""){}; //new Foo created - Foo f15 = new Foo<>("", ""){}; //new Foo created + Foo<? extends String> f14 = new Foo<>("", ""){}; //new Foo created + Foo f15 = new Foo<>("", ""){}; //new Foo created Foo<? super String> f16 = new Foo<>("", ""){}; //new Foo created } void testQualified_1() { Foo<String> f1 = new Neg03.Foo<>(""); //new Foo created - Foo<? extends String> f2 = new Neg03.Foo<>(""); //new Foo created - Foo f3 = new Neg03.Foo<>(""); //new Foo created + Foo<? extends String> f2 = new Neg03.Foo<>(""); //new Foo created + Foo f3 = new Neg03.Foo<>(""); //new Foo created Foo<? super String> f4 = new Neg03.Foo<>(""); //new Foo created Foo<String> f5 = new Neg03.Foo<>(""){}; //new Foo created - Foo<? extends String> f6 = new Neg03.Foo<>(""){}; //new Foo created - Foo f7 = new Neg03.Foo<>(""){}; //new Foo created + Foo<? extends String> f6 = new Neg03.Foo<>(""){}; //new Foo created + Foo f7 = new Neg03.Foo<>(""){}; //new Foo created Foo<? super String> f8 = new Neg03.Foo<>(""){}; //new Foo created Foo<String> f9 = new Neg03.Foo<>("", ""); //new Foo created - Foo<? extends String> f10 = new Neg03.Foo<>("", ""); //new Foo created - Foo f11 = new Neg03.Foo<>("", ""); //new Foo created + Foo<? extends String> f10 = new Neg03.Foo<>("", ""); //new Foo created + Foo f11 = new Neg03.Foo<>("", ""); //new Foo created Foo<? super String> f12 = new Neg03.Foo<>("", ""); //new Foo created Foo<String> f13 = new Neg03.Foo<>("", ""){}; //new Foo created - Foo<? extends String> f14 = new Neg03.Foo<>("", ""){}; //new Foo created - Foo f15 = new Neg03.Foo<>("", ""){}; //new Foo created + Foo<? extends String> f14 = new Neg03.Foo<>("", ""){}; //new Foo created + Foo f15 = new Neg03.Foo<>("", ""){}; //new Foo created Foo<? super String> f16 = new Neg03.Foo<>("", ""){}; //new Foo created } void testQualified_2(Neg03 n) { Foo<String> f1 = n.new Foo<>(""); //new Foo created - Foo<? extends String> f2 = n.new Foo<>(""); //new Foo created - Foo f3 = n.new Foo<>(""); //new Foo created + Foo<? extends String> f2 = n.new Foo<>(""); //new Foo created + Foo f3 = n.new Foo<>(""); //new Foo created Foo<? super String> f4 = n.new Foo<>(""); //new Foo created Foo<String> f5 = n.new Foo<>(""){}; //new Foo created - Foo<? extends String> f6 = n.new Foo<>(""){}; //new Foo created - Foo f7 = n.new Foo<>(""){}; //new Foo created + Foo<? extends String> f6 = n.new Foo<>(""){}; //new Foo created + Foo f7 = n.new Foo<>(""){}; //new Foo created Foo<? super String> f8 = n.new Foo<>(""){}; //new Foo created Foo<String> f9 = n.new Foo<>("", ""); //new Foo created - Foo<? extends String> f10 = n.new Foo<>("", ""); //new Foo created - Foo f11 = n.new Foo<>("", ""); //new Foo created + Foo<? extends String> f10 = n.new Foo<>("", ""); //new Foo created + Foo f11 = n.new Foo<>("", ""); //new Foo created Foo<? super String> f12 = n.new Foo<>("", ""); //new Foo created Foo<String> f13 = n.new Foo<>("", ""){}; //new Foo created - Foo<? extends String> f14 = n.new Foo<>("", ""){}; //new Foo created - Foo f15 = n.new Foo<>("", ""){}; //new Foo created + Foo<? extends String> f14 = n.new Foo<>("", ""){}; //new Foo created + Foo f15 = n.new Foo<>("", ""){}; //new Foo created Foo<? super String> f16 = n.new Foo<>("", ""){}; //new Foo created } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg4.java index 30b124f56668..204dd9fcc155 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg4.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg4.java @@ -6,23 +6,23 @@ class Neg04 { Foo(V x, Z z) {} } Foo<String> n1 = new Foo<>(""); //new Foo created - Foo<? extends String> n2 = new Foo<>(""); //new Foo created - Foo n3 = new Foo<>(""); //new Foo created + Foo<? extends String> n2 = new Foo<>(""); //new Foo created + Foo n3 = new Foo<>(""); //new Foo created Foo<? super String> n4 = new Foo<>(""); //new Foo created Foo<String> n5 = new Foo<>(""){}; //new Foo created - Foo<? extends String> n6 = new Foo<>(""){}; //new Foo created - Foo n7 = new Foo<>(""){}; //new Foo created + Foo<? extends String> n6 = new Foo<>(""){}; //new Foo created + Foo n7 = new Foo<>(""){}; //new Foo created Foo<? super String> n8 = new Foo<>(""){}; //new Foo created Foo<String> n9 = new Foo<>("", ""); //new Foo created - Foo<? extends String> n10 = new Foo<>("", ""); //new Foo created - Foo n11 = new Foo<>("", ""); //new Foo created + Foo<? extends String> n10 = new Foo<>("", ""); //new Foo created + Foo n11 = new Foo<>("", ""); //new Foo created Foo<? super String> n12 = new Foo<>("", ""); //new Foo created Foo<String> n13 = new Foo<>("", ""){}; //new Foo created - Foo<? extends String> n14 = new Foo<>("", ""){}; //new Foo created - Foo n15 = new Foo<>("", ""){}; //new Foo created + Foo<? extends String> n14 = new Foo<>("", ""){}; //new Foo created + Foo n15 = new Foo<>("", ""){}; //new Foo created Foo<? super String> n16 = new Foo<>("", ""){}; //new Foo created } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg6.java new file mode 100644 index 000000000000..585761fb8216 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg6.java @@ -0,0 +1,11 @@ +class Neg06 { + interface ISuperFoo {} + interface IFoo extends ISuperFoo {} + + static class CSuperFoo {} + static class CFoo extends CSuperFoo {} + + ISuperFoo isf = new IFoo<>() {}; + CSuperFoo csf1 = new CFoo<>(); + CSuperFoo csf2 = new CFoo<>() {}; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg7.java new file mode 100644 index 000000000000..5bdbff54f378 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg7.java @@ -0,0 +1,9 @@ +class Neg07 { + static class SuperFoo {} + static class Foo extends SuperFoo { + Foo(X x) {} + } + + SuperFoo sf1 = new Foo<>(""); + SuperFoo sf2 = new Foo<>("") {}; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg8.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg8.java new file mode 100644 index 000000000000..060efa6ebe7b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg8.java @@ -0,0 +1,20 @@ +class Neg08 { + static class Foo { + Foo(X x) { } + } + + static class DoubleFoo { + DoubleFoo(X x,Y y) { } + } + + static class TripleFoo { + TripleFoo(X x,Y y,Z z) { } + } + + Foo fi = new Foo<>(1); + Foo fw = new Foo<>(fi); + Foo fd = new Foo<>(3.0); + DoubleFoo dw = new DoubleFoo<>(fi,fd); + Foo fs = new Foo<>("one"); + TripleFoo tw = new TripleFoo<>(fi,fd,fs); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg9.java new file mode 100644 index 000000000000..5bca169e0f2d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg9.java @@ -0,0 +1,12 @@ +class Neg09 { + static class Foo> {} + static class DoubleFoo, + Y extends Number & Comparable> {} + static class TripleFoo, + Y extends Number & Comparable, + Z> {} + + Foo fw = new Foo<>(); + DoubleFoo dw = new DoubleFoo<>(); + TripleFoo tw = new TripleFoo<>(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondPos5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondPos5.java new file mode 100644 index 000000000000..1f60451ae16d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondPos5.java @@ -0,0 +1,12 @@ +public class Pos05 { + + static class Foo { + Foo(X x) {} + } + + void m(Foo fi) {} + + void test() { + m(new Foo<>(1)); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java deleted file mode 100644 index 0a5023e89f44..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java +++ /dev/null @@ -1,7 +0,0 @@ -// "Replace with <>" "true" -public class Test { - F> f = new FF<>(); -} - -class FF extends F{} -class F {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java deleted file mode 100644 index 2e9b69d52d2e..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java +++ /dev/null @@ -1,11 +0,0 @@ -// "Replace with <>" "true" -public class Test { - void bar() { - foo(new FF<>()); - } - - void foo(F> p) {} -} - -class FF extends F{} -class F {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after5.java new file mode 100644 index 000000000000..dcc744c23ae5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after5.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo<>(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after6.java new file mode 100644 index 000000000000..3f9bf24dbb06 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after6.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo<>(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after8.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after8.java new file mode 100644 index 000000000000..06cc7b7973bb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after8.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo<>() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after9.java new file mode 100644 index 000000000000..550518376f67 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after9.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo<>() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java index 79e9cbcaad8e..eb4a2cf0e6e5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java @@ -1,4 +1,4 @@ -// "Replace with <>" "true" +// "Replace with <>" "false" public class Test { F> f = new FFing>(); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java index d6d74cdc0908..8a08536a3ef5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java @@ -1,4 +1,4 @@ -// "Replace with <>" "true" +// "Replace with <>" "false" public class Test { void bar() { foo(new FFing>()); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before4.java new file mode 100644 index 000000000000..35cf27363787 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before4.java @@ -0,0 +1,16 @@ +// "Replace with <>" "false" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foomber>(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before5.java new file mode 100644 index 000000000000..6f8c5068e0e0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before5.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foober>(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before6.java new file mode 100644 index 000000000000..48666f4d3c4a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before6.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Fooger>(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before7.java new file mode 100644 index 000000000000..1a0c0d45f200 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before7.java @@ -0,0 +1,16 @@ +// "Replace with <>" "false" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foomber>(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before8.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before8.java new file mode 100644 index 000000000000..0ce27b5983a4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before8.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Fooer>() {}; + Foo f6 = new Foo() {}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before9.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before9.java new file mode 100644 index 000000000000..cd3b71989f5c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before9.java @@ -0,0 +1,16 @@ +// "Replace with <>" "true" +class Test { + + void test() { + class Foo { + Foo() {} + Foo(X x) {} + } + Foo f1 = new Foo(1); + Foo f2 = new Foo(); + Foo f3 = new Foo(); + Foo f4 = new Foo(1) {}; + Foo f5 = new Foo() {}; + Foo f6 = new Footeger>() {}; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 6b64c70d82de..beba5cc637db 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -58,6 +58,10 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { doTest(false, false); } + public void testDiamondPos5() throws Exception { + doTest(false, false); + } + public void testDiamondNeg1() throws Exception { doTest(false, false); } @@ -78,6 +82,32 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { doTest(false, false); } + public void testDiamondNeg6() throws Exception { + doTest(false, false); + } + + public void testDiamondNeg7() throws Exception { + doTest(false, false); + } + + public void testDiamondNeg8() throws Exception { + doTest(false, false); + } + + public void testDiamondNeg9() throws Exception { + doTest(false, false); + } + + public void testDiamondNeg10() throws Exception { + doTest(false, false); + } + + public void testDiamondNeg11() throws Exception { + doTest(false, false); + } + + + public void testDiamondMisc() throws Exception { doTest(false, false); } diff --git a/java/openapi/src/com/intellij/psi/PsiDiamondType.java b/java/openapi/src/com/intellij/psi/PsiDiamondType.java index 926fbd99ef6b..96e6ed80cbe4 100644 --- a/java/openapi/src/com/intellij/psi/PsiDiamondType.java +++ b/java/openapi/src/com/intellij/psi/PsiDiamondType.java @@ -16,15 +16,19 @@ package com.intellij.psi; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.util.PsiUtil; -import com.intellij.psi.util.TypeConversionUtil; -import com.intellij.util.ArrayUtil; +import com.intellij.util.Function; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.*; + /** * User: anna * Date: Jul 30, 2010 @@ -82,152 +86,216 @@ public class PsiDiamondType extends PsiType { return new PsiType[]{getJavaLangObject(myManager, getResolveScope())}; } - public PsiType[] getInferredTypes() { - final PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(myTypeElement, PsiDeclarationStatement.class); - if (declarationStatement != null) { - final PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); - if (declaredElements.length > 0 && declaredElements[0] instanceof PsiVariable) { - return getComponentTypes((PsiVariable)declaredElements[0]); - } + public DiamondInferenceResult resolveInferredTypes() { + final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(myTypeElement, PsiNewExpression.class); + if (newExpression == null) { + return PsiDiamondType.DiamondInferenceResult.NULL_RESULT; } - final PsiAssignmentExpression assignmentExpression = PsiTreeUtil.getParentOfType(myTypeElement, PsiAssignmentExpression.class); - if (assignmentExpression != null) { - final PsiExpression lExpression = assignmentExpression.getLExpression(); - if (lExpression instanceof PsiReferenceExpression) { - final PsiElement resolved = ((PsiReferenceExpression)lExpression).resolve(); - if (resolved instanceof PsiVariable) { - return getComponentTypes(((PsiVariable)resolved)); - } - } - } - - PsiExpression psiExpression = PsiTreeUtil.getParentOfType(myTypeElement, PsiExpression.class); - while (psiExpression != null) { - final PsiElement parent = psiExpression.getParent(); - if (parent instanceof PsiExpression) { - psiExpression = (PsiExpression)parent; - continue; - } - break; - } - if (psiExpression != null) { - final PsiElement parent = psiExpression.getParent(); - if (parent instanceof PsiExpressionList) { - final PsiElement parentParent = parent.getParent(); - if (parentParent instanceof PsiCallExpression) { - final JavaResolveResult resolveResult = ((PsiCallExpression)parentParent).resolveMethodGenerics(); - final PsiSubstitutor substitutor = resolveResult.getSubstitutor(); - final PsiElement element = resolveResult.getElement(); - if (element instanceof PsiMethod) { - final int paramIdx = ArrayUtil.find(((PsiExpressionList)parent).getExpressions(), psiExpression); - if (paramIdx > -1) { - final PsiParameter parameter = - ((PsiMethod)element).getParameterList().getParameters()[paramIdx]; - return getComponentTypes(substitutor.substitute(parameter.getType())); - } - } - } - } else if (parent instanceof PsiVariable) { - return getComponentTypes((PsiVariable)parent); - } else if (parent instanceof PsiReturnStatement) { - final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class); - if (containingMethod != null) { - final PsiType returnType = containingMethod.getReturnType(); - if (returnType != null) { - final PsiExpression returnValue = ((PsiReturnStatement)parent).getReturnValue(); - if (returnValue instanceof PsiNewExpression) { - return getComponentTypes(returnType, returnValue); - } - return getComponentTypes(returnType); - } - } - } - } - return NULL_TYPES; + return resolveInferredTypes(newExpression); } - private static PsiType[] getComponentTypes(PsiVariable declaredElement) { - final PsiType lType = declaredElement.getType(); - final PsiExpression initializer = declaredElement.getInitializer(); - return getComponentTypes(lType, initializer); - } - - private static PsiType[] getComponentTypes(PsiType lType, PsiExpression initializer) { - if (initializer instanceof PsiNewExpression) { - final PsiNewExpression newExpression = (PsiNewExpression)initializer; - final PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference(); - if (classReference != null) { - final String text = classReference.getReferenceName(); - if (text != null) { - final PsiClass psiClass = - JavaPsiFacade.getInstance(initializer.getProject()).getResolveHelper().resolveReferencedClass(text, initializer); - final PsiType substitute = substitute(psiClass, lType); - if (substitute != null) { - lType = substitute; - } + public static DiamondInferenceResult resolveInferredTypes(PsiNewExpression newExpression) { + final PsiClass psiClass = findClass(newExpression); + if (psiClass == null) return DiamondInferenceResult.NULL_RESULT; + final PsiMethod constructor = findConstructor(psiClass, newExpression); + PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass); + PsiMethod staticFactory = generateStaticFactory(constructor, psiClass, params); + if (staticFactory == null) { + return DiamondInferenceResult.NULL_RESULT; + } + final PsiSubstitutor inferredSubstitutor = inferTypeParametersForStaticFactory(staticFactory, newExpression); + final PsiTypeParameter[] parameters = staticFactory.getTypeParameters(); + final PsiTypeParameter[] classParameters = psiClass.getTypeParameters(); + final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference(); + LOG.assertTrue(classOrAnonymousClassReference != null); + final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>"); + for (PsiTypeParameter parameter : parameters) { + for (PsiTypeParameter classParameter : classParameters) { + if (Comparing.strEqual(classParameter.getName(), parameter.getName())) { + result.addInferredType(inferredSubstitutor.substitute(parameter)); + break; } } } - return getComponentTypes(lType); + return result; + } + + + @Nullable + private static PsiMethod findConstructor(PsiClass containingClass, PsiNewExpression newExpression) { + final PsiExpressionList argumentList = newExpression.getArgumentList(); + if (argumentList == null) return null; + final Project project = newExpression.getProject(); + final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); + final PsiResolveHelper resolveHelper = facade.getResolveHelper(); + final JavaResolveResult result = + resolveHelper.resolveConstructor(facade.getElementFactory().createType(containingClass), argumentList, argumentList); + return (PsiMethod)result.getElement(); } @Nullable - private static PsiType substitute(PsiClass inheritor, PsiType baseType) { - if (inheritor == null) return null; - final JavaPsiFacade facade = JavaPsiFacade.getInstance(inheritor.getProject()); - final PsiResolveHelper resolveHelper = facade.getResolveHelper(); - final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(baseType); - final PsiClass baseClass = resolveResult.getElement(); - if (baseClass == null) return null; - - PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(baseClass, inheritor, PsiSubstitutor.EMPTY); - if (superSubstitutor == null) return null; - - final PsiSubstitutor baseSubstitutor = resolveResult.getSubstitutor(); - - PsiSubstitutor inheritorSubstitutor = PsiSubstitutor.EMPTY; - for (PsiTypeParameter inheritorParameter : PsiUtil.typeParametersIterable(inheritor)) { - for (PsiTypeParameter baseParameter : PsiUtil.typeParametersIterable(baseClass)) { - final PsiType substituted = superSubstitutor.substitute(baseParameter); - PsiType arg = baseSubstitutor.substitute(baseParameter); - if (arg instanceof PsiWildcardType) arg = ((PsiWildcardType)arg).getExtendsBound(); - PsiType substitution = resolveHelper.getSubstitutionForTypeParameter(inheritorParameter, - substituted, - arg, - true, - PsiUtil.getLanguageLevel(inheritor)); - if (PsiType.NULL.equals(substitution) || substitution instanceof PsiWildcardType) continue; - if (substitution == null) { - continue; - } - inheritorSubstitutor = inheritorSubstitutor.put(inheritorParameter, substitution); - break; + private static PsiClass findClass(PsiNewExpression newExpression) { + final PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference(); + if (classReference != null) { + final String text = classReference.getReferenceName(); + if (text != null) { + final Project project = newExpression.getProject(); + final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); + final PsiResolveHelper resolveHelper = facade.getResolveHelper(); + return resolveHelper.resolveReferencedClass(text, newExpression); + } else { + return null; } } - - PsiType toAdd = facade.getElementFactory().createType(inheritor, inheritorSubstitutor); - if (baseType.isAssignableFrom(toAdd)) { - return toAdd; - } - return null; } - private static PsiType[] getComponentTypes(PsiType type) { - if (type instanceof PsiClassType) { - final PsiType[] types = ((PsiClassType)type).getParameters(); - for (int i = 0; i < types.length; i++) { - PsiType currentType = types[i]; - if (currentType instanceof PsiWildcardType) { - final PsiType bound = ((PsiWildcardType)currentType).getBound(); - if (bound != null) { - types[i] = bound; - } - } + @Nullable + private static PsiMethod generateStaticFactory(@Nullable PsiMethod constructor, PsiClass containingClass, PsiTypeParameter[] params) { + final StringBuilder buf = new StringBuilder(); + buf.append("public static "); + buf.append("<"); + buf.append(StringUtil.join(params, new Function() { + @Override + public String fun(PsiTypeParameter psiTypeParameter) { + return psiTypeParameter.getName(); } - return types; + }, ", ")); + buf.append(">"); + + final String qualifiedName = containingClass.getQualifiedName(); + buf.append(qualifiedName != null ? qualifiedName : containingClass.getName()); + final PsiTypeParameter[] parameters = containingClass.getTypeParameters(); + buf.append("<"); + buf.append(StringUtil.join(parameters, new Function() { + @Override + public String fun(PsiTypeParameter psiTypeParameter) { + return psiTypeParameter.getName(); + } + }, ", ")); + buf.append("> "); + + String staticFactoryName = "staticFactory"; + final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(containingClass.getProject()); + staticFactoryName = styleManager.suggestUniqueVariableName(staticFactoryName, containingClass, false); + buf.append(staticFactoryName); + if (constructor == null) { + buf.append("()"); + } + else { + buf.append("(").append(StringUtil.join(constructor.getParameterList().getParameters(), new Function() { + @Override + public String fun(PsiParameter psiParameter) { + return psiParameter.getType().getCanonicalText() + " " + psiParameter.getName(); + } + }, ",")).append(")"); + } + buf.append("{}"); + + return JavaPsiFacade.getElementFactory(containingClass.getProject()).createMethodFromText(buf.toString(), constructor != null ? constructor : containingClass); + } + + private static PsiTypeParameter[] getAllTypeParams(PsiTypeParameterListOwner listOwner, PsiClass containingClass) { + Set params = new LinkedHashSet(); + if (listOwner != null) { + Collections.addAll(params, listOwner.getTypeParameters()); + } + Collections.addAll(params, containingClass.getTypeParameters()); + return params.toArray(new PsiTypeParameter[params.size()]); + } + + + private static PsiSubstitutor inferTypeParametersForStaticFactory(@NotNull PsiMethod staticFactoryMethod, + PsiNewExpression expression) { + final JavaPsiFacade facade = JavaPsiFacade.getInstance(staticFactoryMethod.getProject()); + final PsiResolveHelper resolveHelper = facade.getResolveHelper(); + final PsiParameter[] parameters = staticFactoryMethod.getParameterList().getParameters(); + final PsiExpression[] expressions = expression.getArgumentList().getExpressions(); + return resolveHelper + .inferTypeArguments(staticFactoryMethod.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, expression, false); + } + + public static class DiamondInferenceResult { + public static final DiamondInferenceResult NULL_RESULT = new DiamondInferenceResult() { + @Override + public PsiType[] getTypes() { + return NULL_TYPES; + } + + @Override + public String getErrorMessage() { + return "Cannot infer arguments"; + } + }; + + private List myInferredTypes = new ArrayList(); + private String myErrorMessage; + + private String myNewExpressionPresentableText; + + public DiamondInferenceResult() { + } + + public DiamondInferenceResult(String expressionPresentableText) { + myNewExpressionPresentableText = expressionPresentableText; + } + + public PsiType[] getTypes() { + if (myErrorMessage != null) { + return NULL_TYPES; + } + return myInferredTypes.toArray(new PsiType[myInferredTypes.size()]); + } + + public String getErrorMessage() { + return myErrorMessage; + } + + public void addInferredType(PsiType psiType) { + if (myErrorMessage != null) return; + if (psiType == null) { + myErrorMessage = "Cannot infer type arguments for " + myNewExpressionPresentableText; + } else if (!isValid(psiType)) { + myErrorMessage = "Cannot infer type arguments for " + + myNewExpressionPresentableText + " because type " + psiType.getPresentableText() + " inferred is not allowed in current context"; + } else { + myInferredTypes.add(psiType); + } + } + + private static Boolean isValid(PsiType type) { + return type.accept(new PsiTypeVisitor() { + @Override + public Boolean visitType(PsiType type) { + return !(type instanceof PsiIntersectionType); + } + + @Override + public Boolean visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) { + return false; + } + + @Override + public Boolean visitWildcardType(PsiWildcardType wildcardType) { + final PsiType bound = wildcardType.getBound(); + if (bound != null) { + if (bound instanceof PsiIntersectionType) return false; + return bound.accept(this); + } + return true; + } + + @Override + public Boolean visitClassType(PsiClassType classType) { + for (PsiType psiType : classType.getParameters()) { + if (!psiType.accept(this)) { + return false; + } + } + return true; + } + }); } - return NULL_TYPES; } } From 0e8d8869475791810e9892c6a711edcb09f5f857 Mon Sep 17 00:00:00 2001 From: anna Date: Sat, 19 Feb 2011 15:34:39 +0100 Subject: [PATCH 05/17] NPE (cannot infer without argument list) --- java/openapi/src/com/intellij/psi/PsiDiamondType.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java/openapi/src/com/intellij/psi/PsiDiamondType.java b/java/openapi/src/com/intellij/psi/PsiDiamondType.java index 96e6ed80cbe4..084e408129e0 100644 --- a/java/openapi/src/com/intellij/psi/PsiDiamondType.java +++ b/java/openapi/src/com/intellij/psi/PsiDiamondType.java @@ -98,6 +98,8 @@ public class PsiDiamondType extends PsiType { public static DiamondInferenceResult resolveInferredTypes(PsiNewExpression newExpression) { final PsiClass psiClass = findClass(newExpression); if (psiClass == null) return DiamondInferenceResult.NULL_RESULT; + final PsiExpressionList argumentList = newExpression.getArgumentList(); + if (argumentList == null) return DiamondInferenceResult.NULL_RESULT; final PsiMethod constructor = findConstructor(psiClass, newExpression); PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass); PsiMethod staticFactory = generateStaticFactory(constructor, psiClass, params); @@ -125,7 +127,6 @@ public class PsiDiamondType extends PsiType { @Nullable private static PsiMethod findConstructor(PsiClass containingClass, PsiNewExpression newExpression) { final PsiExpressionList argumentList = newExpression.getArgumentList(); - if (argumentList == null) return null; final Project project = newExpression.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); @@ -211,7 +212,8 @@ public class PsiDiamondType extends PsiType { final JavaPsiFacade facade = JavaPsiFacade.getInstance(staticFactoryMethod.getProject()); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); final PsiParameter[] parameters = staticFactoryMethod.getParameterList().getParameters(); - final PsiExpression[] expressions = expression.getArgumentList().getExpressions(); + final PsiExpressionList argumentList = expression.getArgumentList(); + final PsiExpression[] expressions = argumentList.getExpressions(); return resolveHelper .inferTypeArguments(staticFactoryMethod.getTypeParameters(), parameters, expressions, PsiSubstitutor.EMPTY, expression, false); } From 1901ac53269af7f81f1ac8e30bfdd139d0de74cb Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 21 Feb 2011 12:17:00 +0300 Subject: [PATCH 06/17] fix test --- .../actions/generate/constructors/GroovyGenerationInfo.java | 2 +- .../jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerationInfo.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerationInfo.java index 87929cbb6865..6e36d660ffe5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerationInfo.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerationInfo.java @@ -61,7 +61,7 @@ public class GroovyGenerationInfo extends PsiGenerationInfo } final IElementType type = element.getNode().getElementType(); - if (GroovyTokenTypes.WHITE_SPACES_SET.contains(type)) { + if (type == GroovyTokenTypes.mNLS || type == GroovyTokenTypes.mWS) { return element.getNextSibling(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index 1e2ae47a3710..ae581d9070f4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -520,9 +520,8 @@ public class ResolveUtil { return resolveResult != null && isInUseScope(resolveResult.getCurrentFileResolveContext()); } - public static boolean isInUseScope(PsiElement context) { - if (!context.isValid()) return false; - if (context instanceof GrMethodCall) { + public static boolean isInUseScope(@Nullable PsiElement context) { + if (context instanceof GrMethodCall && context.isValid()) { final GrExpression expression = ((GrMethodCall)context).getInvokedExpression(); if (expression instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)expression).resolve(); From 6da30b8e533f51f61b93a4e44ee3a8e2cda27576 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 21 Feb 2011 12:46:56 +0300 Subject: [PATCH 07/17] IDEA-65686 Rectangular selection contracts width incorrectly Allow caret to be located after the end of line when block selection is present --- .../src/com/intellij/openapi/editor/impl/CaretModelImpl.java | 2 +- .../src/com/intellij/openapi/editor/impl/EditorImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index c8a218c3a956..91d6c9fb3ab1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -365,7 +365,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, EditorSettings editorSettings = myEditor.getSettings(); - if (!editorSettings.isVirtualSpace() && line < lineCount) { + if (!editorSettings.isVirtualSpace() && line < lineCount && !myEditor.getSelectionModel().hasBlockSelection()) { int lineEndOffset = doc.getLineEndOffset(line); int lineEndColumnNumber = myEditor.offsetToLogicalPosition(lineEndOffset).column; if (column > lineEndColumnNumber) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index e2e5963c3d03..917e8d449be9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -3258,7 +3258,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return; } - if (!mySettings.isVirtualSpace()) { + if (!mySettings.isVirtualSpace() && !mySelectionModel.hasBlockSelection()) { int lineEndOffset = myDocument.getLineEndOffset(lineNumber); int lineEndColumnNumber = calcColumnNumber(lineEndOffset, lineNumber); if (columnNumber > lineEndColumnNumber) { From a26fab124cdfef9ade921f6898370a7ae0911af9 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Mon, 21 Feb 2011 13:57:20 +0300 Subject: [PATCH 08/17] More consistent API RUBY-7865 feature request: ability to collapse commented out code --- .../impl/actions/SuppressWarningsFoldingBuilder.java | 3 ++- .../codeInsight/folding/impl/JavaFoldingBuilder.java | 2 +- .../intellij/lang/folding/CompositeFoldingBuilder.java | 7 ++++--- .../src/com/intellij/lang/folding/FoldingBuilder.java | 5 ++++- .../src/com/intellij/lang/folding/FoldingBuilderEx.java | 5 ++++- .../src/com/intellij/lang/folding/FoldingDescriptor.java | 8 ++++---- .../intellij/indentation/IndentationFoldingBuilder.java | 3 ++- .../plugins/groovy/lang/folding/GroovyFoldingBuilder.java | 2 +- .../i18n/folding/PropertyFoldingBuilder.java | 3 ++- .../relaxNG/compact/folding/RncFoldingBuilder.java | 2 +- .../uiDesigner/binding/GeneratedCodeFoldingBuilder.java | 2 +- xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java | 2 +- 12 files changed, 27 insertions(+), 17 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java index 0c90b896ece3..608b66e3186e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java @@ -26,6 +26,7 @@ import com.intellij.lang.folding.FoldingBuilderEx; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtil; @@ -59,7 +60,7 @@ public class SuppressWarningsFoldingBuilder extends FoldingBuilderEx { } @Override - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final PsiElement element = node.getPsi(); if (element instanceof PsiAnnotation) { return "/" + StringUtil.join(((PsiAnnotation)element).getParameterList().getAttributes(), new Function() { diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java index 975ac746d471..43d759fa8430 100644 --- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java @@ -166,7 +166,7 @@ public class JavaFoldingBuilder extends FoldingBuilderEx implements DumbAware { } @NotNull - public String getPlaceholderText(@NotNull final ASTNode node) { + public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) { return getPlaceholderText(SourceTreeToPsiMap.treeElementToPsi(node)); } diff --git a/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java b/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java index 92f563b0cceb..2c973ff89161 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java @@ -18,8 +18,9 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.util.Key; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; @@ -56,9 +57,9 @@ public class CompositeFoldingBuilder extends FoldingBuilderEx implements DumbAwa return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER); - return builder == null ? node.getText() : builder.getPlaceholderText(node); + return builder == null ? node.getText() : builder.getPlaceholderText(node, range); } public boolean isCollapsedByDefault(@NotNull ASTNode node) { diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java index 2e527cb7cbc0..3225f1c8d43d 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java @@ -18,6 +18,7 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.TextRange; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,11 +46,13 @@ public interface FoldingBuilder { * Returns the text which is displayed in the editor for the folding region related to the * specified node when the folding region is collapsed. * + * * @param node the node for which the placeholder text is requested. + * @param range folded range * @return the placeholder text. */ @Nullable - String getPlaceholderText(@NotNull ASTNode node); + String getPlaceholderText(@NotNull ASTNode node, TextRange range); /** * Returns the default collapsed state for the folding region related to the specified node. diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java index 9c874f70b6b1..603b1cd9f4d1 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java @@ -18,6 +18,7 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,11 +55,13 @@ public abstract class FoldingBuilderEx implements FoldingBuilder { * Returns the text which is displayed in the editor for the folding region related to the * specified node when the folding region is collapsed. * + * * @param node the node for which the placeholder text is requested. + * @param range * @return the placeholder text. */ @Nullable - public abstract String getPlaceholderText(@NotNull ASTNode node); + public abstract String getPlaceholderText(@NotNull ASTNode node, TextRange range); /** * Returns the default collapsed state for the folding region related to the specified node. diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java index 5833f4621267..d1c9dbb1f564 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java @@ -47,7 +47,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and + * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and * {@link FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. */ @@ -67,7 +67,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and + * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and * {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. * @param group Regions with the same group instance expand and collapse together. @@ -82,7 +82,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and + * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and * {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. * @param group Regions with the same group instance expand and collapse together. @@ -134,7 +134,7 @@ public class FoldingDescriptor { final Language lang = psiElement.getLanguage(); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang); if (foldingBuilder != null) { - return foldingBuilder.getPlaceholderText(myElement); + return foldingBuilder.getPlaceholderText(myElement, myRange); } return null; } diff --git a/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java b/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java index 5322803129ac..e2024bd96078 100644 --- a/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java +++ b/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java @@ -5,6 +5,7 @@ import com.intellij.lang.folding.FoldingBuilder; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,7 +43,7 @@ public abstract class IndentationFoldingBuilder implements FoldingBuilder, DumbA } @Nullable - public String getPlaceholderText(@NotNull final ASTNode node) { + public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) { final StringBuilder builder = new StringBuilder(); ASTNode child = node.getFirstChildNode(); String text; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java index 7551466bd588..1b2ee13fbeff 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java @@ -223,7 +223,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes, return text.contains("\n") || text.contains("\r") || text.contains("\r\n"); } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final IElementType elemType = node.getElementType(); if (BLOCK_SET.contains(elemType) || elemType == CLOSABLE_BLOCK) { return "{...}"; diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java index 97ad87b3771c..65b1119d5fee 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java @@ -28,6 +28,7 @@ import com.intellij.lang.properties.psi.impl.PropertyImpl; import com.intellij.lang.properties.psi.impl.PropertyStubImpl; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.JavaConstantExpressionEvaluator; @@ -112,7 +113,7 @@ public class PropertyFoldingBuilder extends FoldingBuilderEx { } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node); if (element instanceof PsiLiteralExpression) { return getI18nMessage((PsiLiteralExpression)element); diff --git a/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java b/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java index 94ddafe1aa76..928b8783fb05 100644 --- a/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java +++ b/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java @@ -52,7 +52,7 @@ public class RncFoldingBuilder implements FoldingBuilder { : FoldingDescriptor.EMPTY; } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final IElementType type = node.getElementType(); if (type == RncTokenTypes.LBRACE) { return "{ ... }"; diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java index cc8a8836180a..be21555ff911 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java @@ -40,7 +40,7 @@ public class GeneratedCodeFoldingBuilder extends FoldingBuilderEx { return visitor.myFoldingData.toArray(new FoldingDescriptor[visitor.myFoldingData.size()]); } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { return UIDesignerBundle.message("uidesigner.generated.code.folding.placeholder.text"); } diff --git a/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java b/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java index 32d44782ca7f..fca7eb082d1f 100644 --- a/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java +++ b/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java @@ -206,7 +206,7 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware { return false; } - public String getPlaceholderText(@NotNull ASTNode node) { + public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { final PsiElement psi = node.getPsi(); if (psi instanceof XmlTag || psi instanceof XmlComment || From 53bdabd7105ac1814e7ae2248083f2c09202fae1 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Mon, 21 Feb 2011 14:10:55 +0300 Subject: [PATCH 09/17] Revert "More consistent API" Prevent language API changes This reverts commit a26fab124cdfef9ade921f6898370a7ae0911af9. --- .../impl/actions/SuppressWarningsFoldingBuilder.java | 3 +-- .../codeInsight/folding/impl/JavaFoldingBuilder.java | 2 +- .../intellij/lang/folding/CompositeFoldingBuilder.java | 7 +++---- .../src/com/intellij/lang/folding/FoldingBuilder.java | 5 +---- .../src/com/intellij/lang/folding/FoldingBuilderEx.java | 5 +---- .../src/com/intellij/lang/folding/FoldingDescriptor.java | 8 ++++---- .../intellij/indentation/IndentationFoldingBuilder.java | 3 +-- .../plugins/groovy/lang/folding/GroovyFoldingBuilder.java | 2 +- .../i18n/folding/PropertyFoldingBuilder.java | 3 +-- .../relaxNG/compact/folding/RncFoldingBuilder.java | 2 +- .../uiDesigner/binding/GeneratedCodeFoldingBuilder.java | 2 +- xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java | 2 +- 12 files changed, 17 insertions(+), 27 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java index 608b66e3186e..0c90b896ece3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java @@ -26,7 +26,6 @@ import com.intellij.lang.folding.FoldingBuilderEx; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtil; @@ -60,7 +59,7 @@ public class SuppressWarningsFoldingBuilder extends FoldingBuilderEx { } @Override - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final PsiElement element = node.getPsi(); if (element instanceof PsiAnnotation) { return "/" + StringUtil.join(((PsiAnnotation)element).getParameterList().getAttributes(), new Function() { diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java index 43d759fa8430..975ac746d471 100644 --- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java @@ -166,7 +166,7 @@ public class JavaFoldingBuilder extends FoldingBuilderEx implements DumbAware { } @NotNull - public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull final ASTNode node) { return getPlaceholderText(SourceTreeToPsiMap.treeElementToPsi(node)); } diff --git a/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java b/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java index 2c973ff89161..92f563b0cceb 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java @@ -18,9 +18,8 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.project.DumbAware; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; @@ -57,9 +56,9 @@ public class CompositeFoldingBuilder extends FoldingBuilderEx implements DumbAwa return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER); - return builder == null ? node.getText() : builder.getPlaceholderText(node, range); + return builder == null ? node.getText() : builder.getPlaceholderText(node); } public boolean isCollapsedByDefault(@NotNull ASTNode node) { diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java index 3225f1c8d43d..2e527cb7cbc0 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilder.java @@ -18,7 +18,6 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.util.TextRange; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,13 +45,11 @@ public interface FoldingBuilder { * Returns the text which is displayed in the editor for the folding region related to the * specified node when the folding region is collapsed. * - * * @param node the node for which the placeholder text is requested. - * @param range folded range * @return the placeholder text. */ @Nullable - String getPlaceholderText(@NotNull ASTNode node, TextRange range); + String getPlaceholderText(@NotNull ASTNode node); /** * Returns the default collapsed state for the folding region related to the specified node. diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java index 603b1cd9f4d1..9c874f70b6b1 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingBuilderEx.java @@ -18,7 +18,6 @@ package com.intellij.lang.folding; import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,13 +54,11 @@ public abstract class FoldingBuilderEx implements FoldingBuilder { * Returns the text which is displayed in the editor for the folding region related to the * specified node when the folding region is collapsed. * - * * @param node the node for which the placeholder text is requested. - * @param range * @return the placeholder text. */ @Nullable - public abstract String getPlaceholderText(@NotNull ASTNode node, TextRange range); + public abstract String getPlaceholderText(@NotNull ASTNode node); /** * Returns the default collapsed state for the folding region related to the specified node. diff --git a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java index d1c9dbb1f564..5833f4621267 100644 --- a/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java +++ b/platform/lang-api/src/com/intellij/lang/folding/FoldingDescriptor.java @@ -47,7 +47,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and + * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and * {@link FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. */ @@ -67,7 +67,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and + * {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and * {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. * @param group Regions with the same group instance expand and collapse together. @@ -82,7 +82,7 @@ public class FoldingDescriptor { * Creates a folding region related to the specified AST node and covering the specified * text range. * @param node The node to which the folding region is related. The node is then passed to - * {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and + * {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and * {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}. * @param range The folded text range. * @param group Regions with the same group instance expand and collapse together. @@ -134,7 +134,7 @@ public class FoldingDescriptor { final Language lang = psiElement.getLanguage(); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang); if (foldingBuilder != null) { - return foldingBuilder.getPlaceholderText(myElement, myRange); + return foldingBuilder.getPlaceholderText(myElement); } return null; } diff --git a/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java b/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java index e2024bd96078..5322803129ac 100644 --- a/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java +++ b/platform/lang-impl/src/com/intellij/indentation/IndentationFoldingBuilder.java @@ -5,7 +5,6 @@ import com.intellij.lang.folding.FoldingBuilder; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.util.TextRange; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,7 +42,7 @@ public abstract class IndentationFoldingBuilder implements FoldingBuilder, DumbA } @Nullable - public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull final ASTNode node) { final StringBuilder builder = new StringBuilder(); ASTNode child = node.getFirstChildNode(); String text; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java index 1b2ee13fbeff..7551466bd588 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/folding/GroovyFoldingBuilder.java @@ -223,7 +223,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes, return text.contains("\n") || text.contains("\r") || text.contains("\r\n"); } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final IElementType elemType = node.getElementType(); if (BLOCK_SET.contains(elemType) || elemType == CLOSABLE_BLOCK) { return "{...}"; diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java index 65b1119d5fee..97ad87b3771c 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/PropertyFoldingBuilder.java @@ -28,7 +28,6 @@ import com.intellij.lang.properties.psi.impl.PropertyImpl; import com.intellij.lang.properties.psi.impl.PropertyStubImpl; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.JavaConstantExpressionEvaluator; @@ -113,7 +112,7 @@ public class PropertyFoldingBuilder extends FoldingBuilderEx { } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node); if (element instanceof PsiLiteralExpression) { return getI18nMessage((PsiLiteralExpression)element); diff --git a/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java b/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java index 928b8783fb05..94ddafe1aa76 100644 --- a/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java +++ b/plugins/relaxng/src/org/intellij/plugins/relaxNG/compact/folding/RncFoldingBuilder.java @@ -52,7 +52,7 @@ public class RncFoldingBuilder implements FoldingBuilder { : FoldingDescriptor.EMPTY; } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final IElementType type = node.getElementType(); if (type == RncTokenTypes.LBRACE) { return "{ ... }"; diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java index be21555ff911..cc8a8836180a 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/GeneratedCodeFoldingBuilder.java @@ -40,7 +40,7 @@ public class GeneratedCodeFoldingBuilder extends FoldingBuilderEx { return visitor.myFoldingData.toArray(new FoldingDescriptor[visitor.myFoldingData.size()]); } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { return UIDesignerBundle.message("uidesigner.generated.code.folding.placeholder.text"); } diff --git a/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java b/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java index fca7eb082d1f..32d44782ca7f 100644 --- a/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java +++ b/xml/impl/src/com/intellij/lang/xml/XmlFoldingBuilder.java @@ -206,7 +206,7 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware { return false; } - public String getPlaceholderText(@NotNull ASTNode node, TextRange range) { + public String getPlaceholderText(@NotNull ASTNode node) { final PsiElement psi = node.getPsi(); if (psi instanceof XmlTag || psi instanceof XmlComment || From 284490f44f9e55fde4b594b8189e52cf487aff4a Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 21 Feb 2011 12:25:20 +0100 Subject: [PATCH 10/17] fix assertions when hitting ctrl+space with hint autopopup active --- .../codeInsight/completion/CodeCompletionHandlerBase.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 106e016d7b86..c2f09f4c935c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -239,11 +239,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { @NotNull private LookupImpl obtainLookup(Editor editor) { LookupImpl existing = (LookupImpl)LookupManager.getActiveLookup(editor); - if (existing != null && existing.isCompletion()) { + if (existing != null && existing.isCompletion() && !existing.isHintMode()) { existing.markReused(); if (!autopopup) { existing.setFocused(true); - existing.setHintMode(false); } return existing; } From a831a7cd1230fe8b9742ff1182a6132688a286d0 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 21 Feb 2011 12:40:25 +0100 Subject: [PATCH 11/17] [rev=yole] revert up/down arrows in non-focused lookups to the old behavior --- .../codeInsight/completion/JavaAutoPopupTest.groovy | 6 +++--- .../codeInsight/lookup/impl/LookupActionHandler.java | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 1439b3b55f83..64ed0eedb9e9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -429,9 +429,9 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase { public void testVerticalArrows() { testArrows false, false, 0, -1 - testArrows false, true, -1, 1 - testArrows true, false, 0, -1 - testArrows true, true, -1, 1 + testArrows false, true, 0, -1 + testArrows true, false, 0, 1 + testArrows true, true, 0, 1 } public void testHideOnOnePrefixVariant() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java index de8e1eb23ab0..b00d961853ef 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.lookup.impl; import com.intellij.codeInsight.lookup.LookupManager; +import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; @@ -73,11 +74,6 @@ public abstract class LookupActionHandler extends EditorActionHandler { protected void executeInLookup(final LookupImpl lookup, DataContext context) { if (!lookup.isFocused()) { - if (lookup.isPositionedAboveCaret()) { - myOriginalHandler.execute(lookup.getEditor(), context); - return; - } - lookup.setFocused(true); lookup.getList().setSelectedIndex(0); lookup.refreshUi(); @@ -94,16 +90,14 @@ public abstract class LookupActionHandler extends EditorActionHandler { protected void executeInLookup(final LookupImpl lookup, DataContext context) { if (!lookup.isFocused()) { - if (!lookup.isPositionedAboveCaret()) { + if (!UISettings.getInstance().CYCLE_SCROLLING) { myOriginalHandler.execute(lookup.getEditor(), context); return; } lookup.setFocused(true); - final int index = ApplicationManager.getApplication().isUnitTestMode() ? lookup.getItems().size() - 1 : lookup.getList().getLastVisibleIndex(); - lookup.getList().setSelectedIndex(index); + lookup.getList().setSelectedIndex(0); lookup.refreshUi(); - return; } ListScrollingUtil.moveUp(lookup.getList(), 0); } From 57697fb7d087485e8822ccfb3dcd4664d45ca6bb Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 21 Feb 2011 13:07:41 +0100 Subject: [PATCH 12/17] do not fail with OOME when rendering large strings --- .../intellij/debugger/ui/tree/render/ToStringRenderer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java index 363e7ef64adb..75830bc64d23 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java @@ -15,9 +15,8 @@ */ package com.intellij.debugger.ui.tree.render; -import com.intellij.ui.classFilter.ClassFilter; -import com.intellij.debugger.DebuggerContext; import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.DebuggerContext; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContext; @@ -29,6 +28,7 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiExpression; +import com.intellij.ui.classFilter.ClassFilter; import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants; import com.sun.jdi.*; import org.jdom.Element; @@ -73,7 +73,7 @@ public class ToStringRenderer extends NodeRendererImpl { final Value value = valueDescriptor.getValue(); BatchEvaluator.getBatchEvaluator(evaluationContext.getDebugProcess()).invoke(new ToStringCommand(evaluationContext, value) { public void evaluationResult(String message) { - valueDescriptor.setValueLabel(message != null ? "\"" + message + "\"" : ""); + valueDescriptor.setValueLabel(message != null ? "\"" + DebuggerUtilsEx.truncateString(message) + "\"" : ""); labelListener.labelChanged(); } From fcea023d50d34399688246443b15f34fb61f7bc8 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 18 Feb 2011 17:49:28 +0300 Subject: [PATCH 13/17] dependencies --- .../openapi/vfs/LocalFileSystemTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java index 820ddfd6d8d6..017070824b74 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java @@ -1,14 +1,19 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.IdeaTestUtil; +import org.jetbrains.annotations.NonNls; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; import java.util.Arrays; public class LocalFileSystemTest extends IdeaTestCase{ @@ -219,4 +224,20 @@ public class LocalFileSystemTest extends IdeaTestCase{ ); } + + public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException { + FileOutputStream stream = new FileOutputStream(file); + stream.write(bom); + OutputStreamWriter writer = new OutputStreamWriter(stream, charset); + writer.write(content); + writer.close(); + } + + public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException { + File temp = FileUtil.createTempFile("copy", "." + ext); + setContentOnDisk(temp, bom, content, charset); + + myFilesToDelete.add(temp); + return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp); + } } From 76f2bcfc0dbae64406d97219fd8a245d3fe6da29 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 18 Feb 2011 18:48:28 +0300 Subject: [PATCH 14/17] duplicate usage fixed --- .../usageView/src/com/intellij/usages/impl/GroupNode.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/usageView/src/com/intellij/usages/impl/GroupNode.java b/platform/usageView/src/com/intellij/usages/impl/GroupNode.java index 583fce9f8caa..991a365e5f9c 100644 --- a/platform/usageView/src/com/intellij/usages/impl/GroupNode.java +++ b/platform/usageView/src/com/intellij/usages/impl/GroupNode.java @@ -105,7 +105,10 @@ public class GroupNode extends Node implements Navigatable, Comparable Date: Mon, 21 Feb 2011 14:07:53 +0300 Subject: [PATCH 15/17] assertions added --- .../openapi/editor/impl/MarkupModelImpl.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java index ecce8d321218..04812916c5e3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java @@ -24,6 +24,7 @@ */ package com.intellij.openapi.editor.impl; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.ex.MarkupModelEx; @@ -54,11 +55,13 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx private final RangeHighlighterTree myHighlighterTree; MarkupModelImpl(DocumentImpl document) { + ApplicationManager.getApplication().assertIsDispatchThread(); myDocument = document; myHighlighterTree = new RangeHighlighterTree(myDocument); } public void dispose() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.dispose(); } @@ -98,9 +101,11 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @NotNull public RangeHighlighter[] getAllHighlighters() { + ApplicationManager.getApplication().assertIsDispatchThread(); if (myCachedHighlighters == null) { - if (myHighlighterTree.size() == 0) return RangeHighlighter.EMPTY_ARRAY; - List list = new ArrayList(); + int size = myHighlighterTree.size(); + if (size == 0) return RangeHighlighter.EMPTY_ARRAY; + List list = new ArrayList(size); myHighlighterTree.process(new CommonProcessors.CollectProcessor(list)); myCachedHighlighters = list.toArray(new RangeHighlighter[list.size()]); } @@ -115,6 +120,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @NotNull HighlighterTargetArea targetArea, boolean isPersistent, @Nullable Consumer changeAttributesAction) { + ApplicationManager.getApplication().assertIsDispatchThread(); RangeHighlighterEx highlighter = isPersistent ? new PersistentRangeHighlighterImpl(this, startOffset, layer, targetArea, textAttributes) : new RangeHighlighterImpl(this, startOffset, endOffset, layer, targetArea, textAttributes); @@ -134,6 +140,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @Override public void changeAttributesInBatch(@NotNull RangeHighlighterEx highlighter, @NotNull Consumer changeAttributesAction) { + ApplicationManager.getApplication().assertIsDispatchThread(); boolean changed = highlighter instanceof PersistentRangeHighlighterImpl ? ((PersistentRangeHighlighterImpl)highlighter).changeAttributesInBatch(changeAttributesAction) : ((RangeHighlighterImpl)highlighter).changeAttributesInBatch(changeAttributesAction); @@ -143,6 +150,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } void addRangeHighlighter(RangeHighlighterEx marker, int start, int end, RangeHighlighterData data) { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.addInterval(marker, start, end, data); } @@ -156,6 +164,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void removeHighlighter(@NotNull RangeHighlighter segmentHighlighter) { + ApplicationManager.getApplication().assertIsDispatchThread(); myCachedHighlighters = null; if (!segmentHighlighter.isValid()) return; @@ -166,6 +175,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void removeAllHighlighters() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.process(new Processor() { public boolean process(RangeMarkerEx rangeMarkerEx) { fireBeforeRemoved((RangeHighlighterEx)rangeMarkerEx); @@ -191,6 +201,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void setRangeHighlighterAttributes(@NotNull final RangeHighlighter highlighter, final TextAttributes textAttributes) { + ApplicationManager.getApplication().assertIsDispatchThread(); ((RangeHighlighterImpl)highlighter).setTextAttributes(textAttributes); } @@ -211,6 +222,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public boolean containsHighlighter(@NotNull final RangeHighlighter highlighter) { + ApplicationManager.getApplication().assertIsDispatchThread(); return !myHighlighterTree.processOverlappingWith(highlighter.getStartOffset(), highlighter.getEndOffset(), new Processor() { public boolean process(RangeHighlighterEx h) { return h.getId() != ((RangeHighlighterEx)highlighter).getId(); @@ -236,6 +248,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void normalize() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.normalize(); } } From b43904cb354f175c3323b64ae207b3b7d631603d Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 21 Feb 2011 15:37:41 +0300 Subject: [PATCH 16/17] tree tests --- .../StructureViewUpdatingTest.java | 180 +++++++++--------- .../projectView/BaseProjectViewTestCase.java | 7 +- .../ide/fileTemplates/FileTemplateUtil.java | 5 +- .../testFramework/PlatformTestUtil.java | 25 ++- .../util/containers/TransferToEDTQueue.java | 2 +- 5 files changed, 116 insertions(+), 103 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java index d7ee434b124c..81a61b14b0ad 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java @@ -34,11 +34,9 @@ package com.intellij.projectView; import com.intellij.JavaTestUtil; import com.intellij.ide.structureView.impl.java.InheritedMembersFilter; import com.intellij.ide.structureView.newStructureView.StructureViewComponent; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; -import com.intellij.testFramework.IdeaTestUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -48,6 +46,7 @@ import com.intellij.psi.JavaDirectoryService; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiField; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.TestSourceBasedTestCase; import com.intellij.util.IncorrectOperationException; @@ -69,55 +68,55 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { final StructureViewComponent structureViewComponent = (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject); final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), - "-Class1.java\n" + - " -Class1\n" + - " getValue():int\n" + - " getClass():Class\n" + - " hashCode():int\n" + - " equals(Object):boolean\n" + - " clone():Object\n" + - " toString():String\n" + - " notify():void\n" + - " notifyAll():void\n" + - " wait(long):void\n" + - " wait(long, int):void\n" + - " wait():void\n" + - " finalize():void\n" + - " myField1:boolean\n" + - " myField2:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), + "-Class1.java\n" + + " -Class1\n" + + " getValue():int\n" + + " getClass():Class\n" + + " hashCode():int\n" + + " equals(Object):boolean\n" + + " clone():Object\n" + + " toString():String\n" + + " notify():void\n" + + " notifyAll():void\n" + + " wait(long):void\n" + + " wait(long, int):void\n" + + " wait():void\n" + + " finalize():void\n" + + " myField1:boolean\n" + + " myField2:boolean\n"); - CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { + new WriteCommandAction.Simple(getProject()) { @Override - public void run() { - + protected void run() throws Throwable { final int offset = document.getLineStartOffset(5); document.insertString(offset, " boolean myNewField = false;\n"); } - }, null, null); + }.execute().throwException(); + PsiDocumentManager.getInstance(myProject).commitDocument(document); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); //TreeUtil.expand(structureViewComponent.getTree(), 3); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + - " -Class1\n" + " getValue():int\n" + - " getClass():Class\n" + - " hashCode():int\n" + - " equals(Object):boolean\n" + - " clone():Object\n" + - " toString():String\n" + - " notify():void\n" + - " notifyAll():void\n" + - " wait(long):void\n" + - " wait(long, int):void\n" + - " wait():void\n" + - " finalize():void\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myNewField:boolean = false\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + + " -Class1\n" + " getValue():int\n" + + " getClass():Class\n" + + " hashCode():int\n" + + " equals(Object):boolean\n" + + " clone():Object\n" + + " toString():String\n" + + " notify():void\n" + + " notifyAll():void\n" + + " wait(long):void\n" + + " wait(long, int):void\n" + + " wait():void\n" + + " finalize():void\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myNewField:boolean = false\n"); Disposer.dispose(structureViewComponent); @@ -138,31 +137,31 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { try { structureViewComponent.setActionActive(InheritedMembersFilter.ID, true); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " +InnerClass1\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " +InnerClass1\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0]; structureViewComponent.select(innerClassField, true); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " -InnerClass1\n" + - " +InnerClass12\n" + - " myInnerClassField:int\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " -InnerClass1\n" + + " +InnerClass12\n" + + " myInnerClassField:int\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override @@ -175,25 +174,25 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { innerClassField.delete(); } catch (IncorrectOperationException e) { - assertTrue(e.getLocalizedMessage(), false); + fail(e.getLocalizedMessage()); } } }); } }, null, null); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " -InnerClass1\n" + - " +InnerClass12\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " -InnerClass1\n" + + " +InnerClass12\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); } finally { @@ -213,26 +212,26 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject); final JTree tree = structureViewComponent.getTree(); - IdeaTestUtil.assertTreeEqual(tree, "-test.xml\n" + - " -test\n" + - " +level1\n" + - " +level1\n" + - " +level1\n" + - " +level1\n"); + PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" + + " -test\n" + + " +level1\n" + + " +level1\n" + + " +level1\n" + + " +level1\n"); tree.expandPath(tree.getPathForRow(3)); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); - IdeaTestUtil.assertTreeEqual(tree, - "-test.xml\n" + - " -test\n" + - " +level1\n" + - " -level1\n" + - " +level2\n" + - " +level1\n" + - " +level1\n"); + PlatformTestUtil.assertTreeEqual(tree, + "-test.xml\n" + + " -test\n" + + " +level1\n" + + " -level1\n" + + " +level2\n" + + " +level1\n" + + " +level1\n"); Disposer.dispose(structureViewComponent); } @@ -246,4 +245,9 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath(); } + + @Override + protected boolean isRunInWriteAction() { + return false; + } } diff --git a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java index cbe0eb8c9a30..c1c6510b24d3 100644 --- a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java +++ b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java @@ -25,8 +25,6 @@ import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode; import com.intellij.ide.util.treeView.*; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.project.DumbAwareRunnable; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.util.Disposer; @@ -300,4 +298,9 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { protected String getTestDataPath() { return PathManagerEx.getTestDataPath(getClass()); } + + @Override + protected boolean isRunInWriteAction() { + return false; + } } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java index 77a277ac7546..92badac379be 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java @@ -311,7 +311,7 @@ public class FileTemplateUtil{ final Properties finalProps = props; CommandProcessor.getInstance().executeCommand(project, new Runnable(){ public void run(){ - final Runnable run = new Runnable(){ + ApplicationManager.getApplication().runWriteAction(new Runnable(){ public void run(){ try{ CreateFromTemplateHandler handler = findHandler(template); @@ -321,8 +321,7 @@ public class FileTemplateUtil{ commandException[0] = ex; } } - }; - ApplicationManager.getApplication().runWriteAction(run); + }); } }, template.isJavaClassTemplate() ? IdeBundle.message("command.create.class.from.template") diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index ee6627924f92..e455ec2534fe 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -15,7 +15,8 @@ */ package com.intellij.testFramework; -import com.intellij.ide.*; +import com.intellij.ide.DataManager; +import com.intellij.ide.IdeEventQueue; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.AbstractTreeStructure; import com.intellij.idea.Bombed; @@ -48,9 +49,10 @@ import org.jetbrains.annotations.TestOnly; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; -import java.util.*; import java.awt.*; import java.awt.event.InvocationEvent; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; /** @@ -99,14 +101,14 @@ public class PlatformTestUtil { } public static String print(JTree tree, boolean withSelection, Condition nodePrintCondition) { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); Object root = tree.getModel().getRoot(); printImpl(tree, root, buffer, 0, withSelection, nodePrintCondition); return buffer.toString(); } - private static void printImpl(JTree tree, Object root, StringBuffer buffer, int level, boolean withSelection, @Nullable Condition nodePrintCondition) { + private static void printImpl(JTree tree, Object root, StringBuilder buffer, int level, boolean withSelection, @Nullable Condition nodePrintCondition) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)root; @@ -116,7 +118,7 @@ public class PlatformTestUtil { nodeText = toString(userObject, null); } else { - nodeText = defaultMutableTreeNode + ""; + nodeText = String.valueOf(defaultMutableTreeNode); } @@ -163,8 +165,10 @@ public class PlatformTestUtil { Assert.assertEquals(expected, treeStringPresentation); } + @TestOnly public static void waitForAlarm(final int delay) throws InterruptedException { - final boolean[] invoked = new boolean[]{false}; + assert !ApplicationManager.getApplication().isWriteAccessAllowed(): "It's a bad idea to wait for an alarm under the write action. Somebody creates an alarm which requires read action and you are deadlocked."; + final AtomicBoolean invoked = new AtomicBoolean(); final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); alarm.addRequest(new Runnable() { @Override @@ -175,7 +179,7 @@ public class PlatformTestUtil { alarm.addRequest(new Runnable() { @Override public void run() { - invoked[0] = true; + invoked.set(true); } }, delay); } @@ -185,10 +189,13 @@ public class PlatformTestUtil { UIUtil.dispatchAllInvocationEvents(); - while (!invoked[0]) { + boolean sleptAlready = false; + while (!invoked.get()) { UIUtil.dispatchAllInvocationEvents(); - Thread.sleep(delay); + Thread.sleep(sleptAlready ? 10 : delay); + sleptAlready = true; } + UIUtil.dispatchAllInvocationEvents(); } @TestOnly diff --git a/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java b/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java index 4f374caaa6c0..abe2edbb296e 100644 --- a/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java +++ b/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java @@ -52,7 +52,7 @@ public class TransferToEDTQueue { T thing = myQueue.poll(); if (thing == null) break; if (!myProcessor.process(thing)) { - myQueue.clear(); + stop(); return; } processed++; From c0eb2f31081013559acb974c42294a339677a616 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 21 Feb 2011 15:41:45 +0300 Subject: [PATCH 17/17] cleanup --- .../impl/quickfix/CreateMethodQuickFix.java | 26 ++++---- .../daemon/impl/quickfix/OrderEntryFix.java | 10 +--- .../impl/StructureNodeRenderer.java | 26 ++++---- .../impl/java/JavaClassTreeElement.java | 5 +- .../impl/java/JavaFileTreeElement.java | 1 - .../pom/java/impl/PomJavaAspectImpl.java | 2 +- .../java/events/PomJavaAspectChangeSet.java | 13 +--- .../util/indexing/FileBasedIndex.java | 9 ++- .../util/treeView/AbstractTreeUpdater.java | 21 +++---- .../util/ui/update/MergingUpdateQueue.java | 7 +-- .../BreadcrumbsLoaderComponent.java | 30 ++++------ .../breadcrumbs/BreadcrumbsXmlWrapper.java | 59 ++++++++++++------- 12 files changed, 92 insertions(+), 117 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java index b232cb7dce86..2826cec4c910 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java @@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; -import com.intellij.psi.impl.JavaPsiFacadeEx; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; @@ -61,23 +60,18 @@ public class CreateMethodQuickFix implements LocalQuickFix { } public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { - try { - if (!CodeInsightUtilBase.preparePsiElementForWrite(myTargetClass.getContainingFile())) return; + if (!CodeInsightUtilBase.preparePsiElementForWrite(myTargetClass.getContainingFile())) return; - PsiMethod method = createMethod(project); - List> arguments = - ContainerUtil.map2List(method.getParameterList().getParameters(), new Function>() { - public Pair fun(PsiParameter psiParameter) { - return Pair.create(null, psiParameter.getType()); - } - }); + PsiMethod method = createMethod(project); + List> arguments = + ContainerUtil.map2List(method.getParameterList().getParameters(), new Function>() { + public Pair fun(PsiParameter psiParameter) { + return Pair.create(null, psiParameter.getType()); + } + }); - method = (PsiMethod)JavaCodeStyleManager.getInstance(project).shortenClassReferences((PsiMethod)myTargetClass.add(method)); - CreateMethodFromUsageFix.doCreate(myTargetClass, method, arguments, PsiSubstitutor.EMPTY, ExpectedTypeInfo.EMPTY_ARRAY, method); - } - catch (IncorrectOperationException e) { - throw new RuntimeException(e); - } + method = (PsiMethod)JavaCodeStyleManager.getInstance(project).shortenClassReferences((PsiMethod)myTargetClass.add(method)); + CreateMethodFromUsageFix.doCreate(myTargetClass, method, arguments, PsiSubstitutor.EMPTY, ExpectedTypeInfo.EMPTY_ARRAY, method); } private PsiMethod createMethod(Project project) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java index 0c1b429466db..9c9e93c96193 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.impl.actions.AddImportAction; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.compiler.ModuleCompilerUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.Result; @@ -42,8 +43,6 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.compiler.ModuleCompilerUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -72,12 +71,7 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix { } public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { - try { - invoke(project, null, descriptor.getPsiElement().getContainingFile()); - } - catch (IncorrectOperationException e) { - throw new RuntimeException(e); - } + invoke(project, null, descriptor.getPsiElement().getContainingFile()); } @Nullable diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java b/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java index 74af60cec239..35cc77e12166 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java @@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ui.util.ModifiableCellAppearance; import com.intellij.openapi.util.Iconable; import com.intellij.psi.*; import com.intellij.psi.util.PsiFormatUtil; +import com.intellij.psi.util.PsiFormatUtilBase; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; @@ -51,7 +52,8 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { ModifiableCellAppearance result; if (psiElement instanceof PsiElement && !((PsiElement)psiElement).isValid()) { result = CompositeAppearance.single(name); - } else { + } + else { PsiClass psiClass = getContainingClass(psiElement); if (isInheritedMember(node, psiClass) && psiClass != null) { CompositeAppearance.DequeEnd ending = new CompositeAppearance().getEnding(); @@ -84,13 +86,13 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { } } - public static String getNameOf(PsiElement psiElement) { + private static String getNameOf(PsiElement psiElement) { if (psiElement instanceof PsiMethod) return PsiFormatUtil.formatMethod((PsiMethod)psiElement, PsiSubstitutor.EMPTY, - PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | - PsiFormatUtil.SHOW_PARAMETERS, - PsiFormatUtil.SHOW_TYPE + PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | + PsiFormatUtilBase.SHOW_PARAMETERS, + PsiFormatUtilBase.SHOW_TYPE ); return psiElement.toString(); } @@ -109,23 +111,17 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { return new SimpleTextAttributes(nameAttributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT, nameAttributes.getFgColor()); } - public static boolean isDeprecated(Object psiElement) { - if (psiElement instanceof PsiDocCommentOwner) - return ((PsiDocCommentOwner) psiElement).isDeprecated(); - return false; + private static boolean isDeprecated(Object psiElement) { + return psiElement instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)psiElement).isDeprecated(); } - public static PsiClass getContainingClass(Object element) { + private static PsiClass getContainingClass(Object element) { if (element instanceof PsiMember) return ((PsiMember) element).getContainingClass(); - if (element instanceof PsiClass) { - PsiElement parent = ((PsiClass) element).getParent(); - return (PsiClass) (parent instanceof PsiClass ? parent : null); - } return null; } - public static PsiClass getTreeParentClass(Object value) { + private static PsiClass getTreeParentClass(Object value) { if (!(value instanceof TreeNode)) return null; for (TreeNode treeNode = ((TreeNode) value).getParent(); treeNode != null; treeNode = treeNode.getParent()) { diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java index b97433a98ca3..80951de253bd 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java @@ -35,10 +35,8 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { } private Collection getClassChildren() { - ArrayList array = new ArrayList(); - final PsiClass aClass = getElement(); - if (aClass == null) return array; + if (aClass == null) return Collections.emptyList(); List children = Arrays.asList(aClass.getChildren()); Collection ownChildren = new THashSet(); @@ -47,6 +45,7 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { ContainerUtil.addAll(ownChildren, aClass.getInnerClasses()); ContainerUtil.addAll(ownChildren, aClass.getInitializers()); Collection inherited = new LinkedHashSet(children); + List array = new ArrayList(inherited.size()); aClass.processDeclarations(new AddAllMembersProcessor(inherited, aClass), ResolveState.initial(), null, aClass); diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java index 1a5bb59cf538..98a587a369c2 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collection; public class JavaFileTreeElement extends PsiTreeElementBase implements ItemPresentation { - public JavaFileTreeElement(PsiJavaFile file) { super(file); } diff --git a/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java b/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java index 9d128cb0c178..e3d0276469e1 100644 --- a/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java +++ b/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java @@ -68,7 +68,7 @@ public class PomJavaAspectImpl extends PomJavaAspect implements ProjectComponent if(changeSet == null) return; final PsiFile containingFile = changeSet.getRootElement().getPsi().getContainingFile(); if(!(containingFile.getLanguage() instanceof JavaLanguage)) return; - final PomJavaAspectChangeSet set = new PomJavaAspectChangeSet(myPomModel, containingFile); + final PomJavaAspectChangeSet set = new PomJavaAspectChangeSet(myPomModel); set.addChange(new JavaTreeChanged(containingFile)); event.registerChangeSet(this, set); } diff --git a/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java b/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java index d1e2792219f9..2625a48a6144 100644 --- a/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java +++ b/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java @@ -20,7 +20,6 @@ import com.intellij.pom.PomModel; import com.intellij.pom.PomModelAspect; import com.intellij.pom.event.PomChangeSet; import com.intellij.pom.java.PomJavaAspect; -import com.intellij.psi.PsiFile; import java.util.ArrayList; import java.util.List; @@ -28,22 +27,16 @@ import java.util.List; public class PomJavaAspectChangeSet implements PomChangeSet{ private final PomModel myModel; private final List myChanges = new ArrayList(); - private final PsiFile myChangedFile; - public PomJavaAspectChangeSet(PomModel model, PsiFile fileChanged) { + public PomJavaAspectChangeSet(PomModel model) { myModel = model; - myChangedFile = fileChanged; } public void addChange(PomJavaChange change) { myChanges.add(change); } - public List getChanges() { - return myChanges; - } - public PomModelAspect getAspect() { return myModel.getModelAspect(PomJavaAspect.class); } @@ -53,8 +46,4 @@ public class PomJavaAspectChangeSet implements PomChangeSet{ final PomJavaAspectChangeSet blockedJavaChange = (PomJavaAspectChangeSet)blocked; myChanges.addAll(blockedJavaChange.myChanges); } - - public PsiFile getChangedFile() { - return myChangedFile; - } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index d54a659b2deb..07591f7c4d6f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -102,8 +102,9 @@ public class FileBasedIndex implements ApplicationComponent { private final Set myNoLimitCheckTypes = new HashSet(); private final PerIndexDocumentMap myLastIndexedDocStamps = new PerIndexDocumentMap() { + @NotNull @Override - protected Long createDefault(Document document) { + protected Long createDefault(@NotNull Document document) { return 0L; } }; @@ -1161,7 +1162,7 @@ public class FileBasedIndex implements ApplicationComponent { } // returns false if doc was not indexed because the file does not fit in scope - private boolean indexUnsavedDocument(final Document document, final ID requestedIndexId, final Project project, GlobalSearchScope filter) throws StorageException { + private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID requestedIndexId, final Project project, GlobalSearchScope filter) throws StorageException { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; @@ -1253,9 +1254,7 @@ public class FileBasedIndex implements ApplicationComponent { } private void cleanupMemoryStorage() { - synchronized (myLastIndexedDocStamps) { - myLastIndexedDocStamps.clear(); - } + myLastIndexedDocStamps.clear(); for (ID indexId : myIndices.keySet()) { final MapReduceIndex index = (MapReduceIndex)getIndex(indexId); assert index != null; diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java index c076a99d3013..a6bfe1507455 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java @@ -86,7 +86,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { } public boolean hasNodesToUpdate() { - return myNodeQueue.size() > 0 || !myUpdateQueue.isEmpty(); + return !myNodeQueue.isEmpty() || !myUpdateQueue.isEmpty(); } public void dispose() { @@ -114,15 +114,15 @@ public class AbstractTreeUpdater implements Disposable, Activatable { toAdd.expire(); break; } - else if (passInQueue.getNode() == toAdd.getNode()) { + if (passInQueue.getNode() == toAdd.getNode()) { toAdd.expire(); break; } - else if (toAdd.getNode().isNodeAncestor(passInQueue.getNode())) { + if (toAdd.getNode().isNodeAncestor(passInQueue.getNode())) { toAdd.expire(); break; } - else if (passInQueue.getNode().isNodeAncestor(toAdd.getNode())) { + if (passInQueue.getNode().isNodeAncestor(toAdd.getNode())) { iterator.remove(); passInQueue.expire(); } @@ -133,9 +133,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { if (!toAdd.isExpired()) { final Collection yielding = ui.getYeildingPasses(); - for (Iterator iterator = yielding.iterator(); iterator.hasNext();) { - TreeUpdatePass eachYielding = iterator.next(); - + for (TreeUpdatePass eachYielding : yielding) { final DefaultMutableTreeNode eachNode = eachYielding.getCurrentNode(); if (eachNode != null) { if (eachNode.isNodeAncestor(toAdd.getNode())) { @@ -228,8 +226,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { try { myTreeBuilder.getUi().updateSubtreeNow(eachPass, false); } - catch (ProcessCanceledException e) { - return; + catch (ProcessCanceledException ignored) { } } }); @@ -348,10 +345,8 @@ public class AbstractTreeUpdater implements Disposable, Activatable { } public boolean isEnqueuedToUpdate(DefaultMutableTreeNode node) { - Iterator nodes = myNodeQueue.iterator(); - while (nodes.hasNext()) { - TreeUpdatePass each = nodes.next(); - if (each.willUpdate(node)) return true; + for (TreeUpdatePass pass : myNodeQueue) { + if (pass.willUpdate(node)) return true; } return false; } diff --git a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java index bcb2e34055f7..c6fec60254d8 100644 --- a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java +++ b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java @@ -123,8 +123,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { try { each.setRejected(); } - catch (ProcessCanceledException e) { - continue; + catch (ProcessCanceledException ignored) { } } myScheduledUpdates.clear(); @@ -237,7 +236,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { } }; - if (myExecuteInDispatchThread && invokeLaterIfNotDispatch && !ApplicationManager.getApplication().isDispatchThread()) { + if (myExecuteInDispatchThread && invokeLaterIfNotDispatch) { UIUtil.invokeLaterIfNeeded(toRun); } else { @@ -394,7 +393,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { public boolean isEmpty() { synchronized (myScheduledUpdates) { - return myScheduledUpdates.size() == 0; + return myScheduledUpdates.isEmpty(); } } diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java index 236d5cd730c4..17d5aa1007da 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java @@ -48,20 +48,20 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { return webEditorOptions.isBreadcrumbsEnabled() || webEditorOptions.isBreadcrumbsEnabledInXml(); } - private static class MyFileEditorManagerListener implements FileEditorManagerListener { + private static class MyFileEditorManagerListener extends FileEditorManagerAdapter { public void fileOpened(final FileEditorManager source, final VirtualFile file) { if (isEnabled() && isSuitable(source.getProject(), file)) { final FileEditor[] fileEditors = source.getEditors(file); - for (final FileEditor each : fileEditors) { - if (each instanceof TextEditor) { - final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(((TextEditor)each).getEditor()); + for (final FileEditor fileEditor : fileEditors) { + if (fileEditor instanceof TextEditor) { + final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(((TextEditor)fileEditor).getEditor()); final JComponent c = wrapper.getComponent(); - source.addTopComponent(each, c); + source.addTopComponent(fileEditor, c); - Disposer.register(each, wrapper); - Disposer.register(each, new Disposable() { + Disposer.register(fileEditor, wrapper); + Disposer.register(fileEditor, new Disposable() { public void dispose() { - source.removeTopComponent(each, c); + source.removeTopComponent(fileEditor, c); } }); } @@ -74,11 +74,11 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { return false; } - final FileViewProvider psiFile = PsiManager.getInstance(project).findViewProvider(file); + final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); - return psiFile != null - && hasNonEmptyHtml(psiFile) - && BreadcrumbsXmlWrapper.findInfoProvider(psiFile) != null; + return provider != null + && hasNonEmptyHtml(provider) + && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; } public static boolean hasNonEmptyHtml(FileViewProvider viewProvider) { @@ -94,11 +94,5 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { } return false; } - - public void fileClosed(final FileEditorManager source, final VirtualFile file) { - } - - public void selectionChanged(final FileEditorManagerEvent event) { - } } } diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java index 95b2b2815ecd..ea00e02f2023 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java @@ -34,13 +34,6 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vcs.FileStatusListener; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.pom.PomManager; -import com.intellij.pom.PomModelAspect; -import com.intellij.pom.event.PomChangeSet; -import com.intellij.pom.event.PomModelEvent; -import com.intellij.pom.event.PomModelListener; -import com.intellij.pom.xml.XmlAspect; -import com.intellij.pom.xml.XmlChangeSet; import com.intellij.psi.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -103,8 +96,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener(); myComponent.addBreadcrumbsItemListener(this); @@ -140,8 +153,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener