From c05c58cf4c4aa0d4c3c72c52037510efac6ffc2c Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 31 Jan 2011 17:12:19 +0100 Subject: [PATCH] completion: diamonds; inspection: collapse to diamond --- .../completion/JavaInheritorsGetter.java | 17 ++- .../JavaPsiClassReferenceElement.java | 5 +- .../codeInsight/lookup/PsiTypeLookupItem.java | 15 +++ .../ExplicitTypeCanBeDiamondInspection.java | 104 ++++++++++++++++++ .../ex/StandardInspectionToolsProvider.java | 9 +- .../java/JavaSpacePropertyProcessor.java | 2 +- .../smartType/DiamondCollapsed-out.java | 8 ++ .../smartType/DiamondCollapsed.java | 8 ++ .../advHighlighting7/DiamondNeg1.java | 16 +-- .../advHighlighting7/DiamondNeg2.java | 32 +++--- .../advHighlighting7/DiamondNeg3.java | 48 ++++---- .../advHighlighting7/DiamondNeg4.java | 16 +-- .../quickFix/explicit2diamond/after1.java | 6 + .../quickFix/explicit2diamond/after2.java | 7 ++ .../quickFix/explicit2diamond/after3.java | 11 ++ .../quickFix/explicit2diamond/before1.java | 6 + .../quickFix/explicit2diamond/before2.java | 7 ++ .../quickFix/explicit2diamond/before3.java | 11 ++ .../completion/CompletionStyleTest.java | 5 + .../LightFixtureCompletionTestCase.java | 7 ++ .../completion/SmartType17CompletionTest.java | 63 +++++++++++ .../SmartTypeCompletionOrderingTest.java | 6 + .../Simplify2DiamondInspectionsTest.java | 55 +++++++++ .../src/com/intellij/psi/PsiDiamondType.java | 74 ++++++++++++- .../LightCodeInsightTestCase.java | 6 +- .../LightCodeInsightFixtureTestCase.java | 16 +++ .../codeInsight/lookup/LookupItem.java | 1 + .../Convert2Diamond.html | 5 + 28 files changed, 497 insertions(+), 69 deletions(-) create mode 100644 java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed-out.java create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType17CompletionTest.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Simplify2DiamondInspectionsTest.java create mode 100644 resources-en/src/inspectionDescriptions/Convert2Diamond.html diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java index bcd7081347f4..baa48c694966 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtil; import com.intellij.codeInsight.ExpectedTypeInfo; import com.intellij.codeInsight.lookup.*; import com.intellij.openapi.util.Condition; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.filters.getters.ExpectedTypesGetter; import com.intellij.psi.statistics.JavaStatisticsManager; @@ -26,6 +27,7 @@ import com.intellij.psi.statistics.StatisticsInfo; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.Consumer; import com.intellij.util.ProcessingContext; import com.intellij.util.Processor; @@ -124,7 +126,20 @@ public class JavaInheritorsGetter extends CompletionProvider()", parameters.getOriginalFile()); + final PsiVariable declaredVar = (PsiVariable)((PsiDeclarationStatement)statement).getDeclaredElements()[0]; + final PsiExpression initializer = declaredVar.getInitializer(); + psiType = initializer.getType(); + } + } + final LookupItem item = PsiTypeLookupItem.createLookupItem(psiType, parameters.getPosition()); JavaCompletionUtil.setShowFQN(item); if (psiClass.isInterface() || psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java index f5f85d97b81c..a5e29494e8fa 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java @@ -97,7 +97,8 @@ public class JavaPsiClassReferenceElement extends LookupItem { final boolean bold = item.getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null; boolean strikeout = JavaElementLookupRenderer.isToStrikeout(item); - presentation.setItemText(getName(psiClass, item)); + final boolean forceLookupString = item.getAttribute(LookupItem.FORCE_LOOKUP_STRING) != null; + presentation.setItemText(forceLookupString ? item.getLookupString() : getName(psiClass, item)); presentation.setStrikeout(strikeout); presentation.setItemTextBold(bold); @@ -108,7 +109,7 @@ public class JavaPsiClassReferenceElement extends LookupItem { (psiClass.isInterface() || psiClass.hasModifierProperty(PsiModifier.ABSTRACT))) { tailText = "{...}" + tailText; } - if (substitutor == null && psiClass.getTypeParameters().length > 0) { + if (substitutor == null && !forceLookupString && psiClass.getTypeParameters().length > 0) { tailText = "<" + StringUtil.join(psiClass.getTypeParameters(), new Function() { public String fun(PsiTypeParameter psiTypeParameter) { return psiTypeParameter.getName(); diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java index f7ece9fe94fb..a268b4339513 100644 --- a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java @@ -19,6 +19,8 @@ import com.intellij.codeInsight.completion.DefaultInsertHandler; import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement; import com.intellij.psi.*; +import com.intellij.psi.impl.source.PsiClassReferenceType; +import com.intellij.psi.util.TypeConversionUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,6 +83,19 @@ public class PsiTypeLookupItem extends LookupItem { if (type instanceof PsiClassType) { PsiClassType.ClassResolveResult classResolveResult = ((PsiClassType)type).resolveGenerics(); final PsiClass psiClass = classResolveResult.getElement(); + if (type instanceof PsiClassReferenceType && psiClass != null) { + final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType)type).getReference(); + final PsiReferenceParameterList parameterList = reference.getParameterList(); + if (parameterList != null) { + final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements(); + if (typeParameterElements.length == 1 && typeParameterElements[0].getType() instanceof PsiDiamondType) { + final String lookupString = psiClass.getName() + "<>"; + final PsiTypeLookupItem item = new PsiTypeLookupItem(psiClass, lookupString); + item.setAttribute(FORCE_LOOKUP_STRING, lookupString); + return item; + } + } + } final PsiSubstitutor substitutor = classResolveResult.getSubstitutor(); String text = type.getCanonicalText(); if (text == null) { diff --git a/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java b/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java new file mode 100644 index 000000000000..bd276ce13bf2 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInspection/ExplicitTypeCanBeDiamondInspection.java @@ -0,0 +1,104 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection; + +import com.intellij.codeInsight.daemon.GroupNames; +import com.intellij.openapi.project.Project; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiUtil; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + * Date: 1/28/11 + */ +public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionTool { + @Nls + @NotNull + @Override + public String getGroupDisplayName() { + return GroupNames.JDK15_SPECIFIC_GROUP_NAME; + } + + @Nls + @NotNull + @Override + public String getDisplayName() { + return "Explicit type can be replaced with <>"; + } + + @Override + public boolean isEnabledByDefault() { + return true; + } + + @NotNull + @Override + public String getShortName() { + return "Convert2Diamond"; + } + + @NotNull + @Override + public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { + return new JavaElementVisitor() { + @Override + public void visitReferenceExpression(PsiReferenceExpression expression) { + } + + @Override + public void visitNewExpression(PsiNewExpression expression) { + if (PsiUtil.getLanguageLevel(expression).isAtLeast(LanguageLevel.JDK_1_7)) { + final PsiJavaCodeReferenceElement classReference = expression.getClassReference(); + 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, "Can be replaced", + new LocalQuickFix() { + @NotNull + @Override + public String getName() { + return "Replace with <>"; + } + + @NotNull + @Override + public String getFamilyName() { + return getName(); + } + + @Override + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + final PsiElement psiElement = descriptor.getPsiElement(); + if (psiElement instanceof PsiReferenceParameterList) { + final PsiTypeElement[] parameterElements = ((PsiReferenceParameterList)psiElement).getTypeParameterElements(); + psiElement.deleteChildRange(parameterElements[0], parameterElements[parameterElements.length - 1]); + } + } + }); + } + } + } + } + } + }; + } +} diff --git a/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java b/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java index 84f7f4b08e5a..37851daa6c94 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java +++ b/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java @@ -15,10 +15,7 @@ */ package com.intellij.codeInspection.ex; -import com.intellij.codeInspection.InspectionToolProvider; -import com.intellij.codeInspection.LossyEncodingInspection; -import com.intellij.codeInspection.NumericOverflowInspection; -import com.intellij.codeInspection.RedundantSuppressInspection; +import com.intellij.codeInspection.*; import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; import com.intellij.codeInspection.canBeFinal.CanBeFinalInspection; import com.intellij.codeInspection.concurrencyAnnotations.*; @@ -118,7 +115,9 @@ public class StandardInspectionToolsProvider implements InspectionToolProvider { NonFinalFieldInImmutableInspection.class, NonFinalGuardInspection.class, StaticGuardedByInstanceInspection.class, - UnknownGuardInspection.class + UnknownGuardInspection.class, + + ExplicitTypeCanBeDiamondInspection.class }; } } diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java index 53fbf0f4e68c..a49294e704ce 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java @@ -1198,7 +1198,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { createSpaceInCode(false); } else if (myRole1 == ChildRole.LT_IN_TYPE_LIST && myRole2 == ChildRole.GT_IN_TYPE_LIST) { - createSpaceInCode(true); + createSpaceInCode(false); } else if (myRole1 == ChildRole.TYPE_IN_REFERENCE_PARAMETER_LIST && myRole2 == ChildRole.COMMA) { createSpaceInCode(false); diff --git a/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed-out.java b/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed-out.java new file mode 100644 index 000000000000..7b91bc8c1162 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed-out.java @@ -0,0 +1,8 @@ +class MyClass { + public void foo() { + MyDD d = new MyDD<>() + } +} + +class MyDD { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed.java b/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed.java new file mode 100644 index 000000000000..9ff1b4ac440f --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/DiamondCollapsed.java @@ -0,0 +1,8 @@ +class MyClass { + public void foo() { + MyDD d = new MyD + } +} + +class MyDD { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg1.java index 88e094ca9665..ddf456df1746 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/DiamondNeg2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondNeg2.java index 7503936b1d6c..635dc5bd9798 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 d699f6314fb2..8d770ab57870 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 9f05af301260..30b124f56668 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/quickFix/explicit2diamond/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after1.java new file mode 100644 index 000000000000..a2577bbaa479 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after1.java @@ -0,0 +1,6 @@ +// "Replace with <>" "true" +public class Test { + F f = new F<>(); +} + +class F {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java new file mode 100644 index 000000000000..0a5023e89f44 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after2.java @@ -0,0 +1,7 @@ +// "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 new file mode 100644 index 000000000000..2e9b69d52d2e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/after3.java @@ -0,0 +1,11 @@ +// "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/before1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before1.java new file mode 100644 index 000000000000..d3bd2c228502 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before1.java @@ -0,0 +1,6 @@ +// "Replace with <>" "true" +public class Test { + F f = new Fing>(); +} + +class F {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java new file mode 100644 index 000000000000..79e9cbcaad8e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before2.java @@ -0,0 +1,7 @@ +// "Replace with <>" "true" +public class Test { + F> f = new FFing>(); +} + +class FF extends F{} +class F {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java new file mode 100644 index 000000000000..d6d74cdc0908 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond/before3.java @@ -0,0 +1,11 @@ +// "Replace with <>" "true" +public class Test { + void bar() { + foo(new FFing>()); + } + + void foo(F> p) {} +} + +class FF extends F{} +class F {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java index eedded73f146..159085becd76 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java @@ -31,6 +31,11 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ ((StatisticsManagerImpl)StatisticsManager.getInstance()).clearStatistics(); } + @Override + protected LanguageLevel getLanguageLevel() { + return LanguageLevel.JDK_1_6; + } + @Override protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java index 70aa4e34a73a..70c79ed8de79 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java @@ -7,7 +7,9 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.psi.statistics.impl.StatisticsManagerImpl; +import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; /** * @author peter @@ -21,6 +23,11 @@ public abstract class LightFixtureCompletionTestCase extends LightCodeInsightFix ((StatisticsManagerImpl)StatisticsManager.getInstance()).clearStatistics(); } + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_1_6; + } @Override protected void tearDown() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType17CompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType17CompletionTest.java new file mode 100644 index 000000000000..bd05bbca53c3 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType17CompletionTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.lookup.Lookup; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.PsiTypeLookupItem; +import com.intellij.codeInsight.template.SmartCompletionContextType; +import com.intellij.codeInsight.template.Template; +import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.codeInsight.template.TemplateManager; +import com.intellij.codeInsight.template.impl.TemplateImpl; +import com.intellij.codeInsight.template.impl.TemplateSettings; +import com.intellij.openapi.util.Condition; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +public class SmartType17CompletionTest extends LightFixtureCompletionTestCase { + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/smartType/"; + } + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_LATEST; + } + + public void testDiamondCollapsed() throws Exception { + doTest(); + } + + + private void doTest() throws Exception { + configureByFile("/" + getTestName(false) + ".java"); + if (myItems != null && myItems.length == 1) { + final Lookup lookup = getLookup(); + if (lookup != null) { + selectItem(lookup.getCurrentItem(), Lookup.NORMAL_SELECT_CHAR); + } + } + checkResultByFile("/" + getTestName(false) + "-out.java"); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.java index a5744049073d..2443bd43a63c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.java @@ -5,6 +5,7 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.statistics.StatisticsManager; public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { @@ -14,6 +15,11 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { super(CompletionType.SMART); } + @Override + protected LanguageLevel getLanguageLevel() { + return LanguageLevel.JDK_1_6; + } + public void testJComponentAdd() throws Throwable { checkPreferredItems(0, "name", "b", "fooBean239", "this", "getName"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Simplify2DiamondInspectionsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Simplify2DiamondInspectionsTest.java new file mode 100644 index 000000000000..de19e1fc48b4 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Simplify2DiamondInspectionsTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon.quickFix; + +import com.intellij.codeInspection.ExplicitTypeCanBeDiamondInspection; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; +import com.intellij.codeInspection.deprecation.DeprecationInspection; +import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; +import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection; +import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection; +import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; +import com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration; +import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; + + +//todo test3 should be checked if it compiles - as now javac infers Object instead of String?! +public class Simplify2DiamondInspectionsTest extends LightQuickFixTestCase { + + @Override + protected Sdk getProjectJDK() { + return JavaSdkImpl.getMockJdk17(); + } + + @Override + protected LocalInspectionTool[] configureLocalInspectionTools() { + return new LocalInspectionTool[]{ + new ExplicitTypeCanBeDiamondInspection(), + }; + } + + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/explicit2diamond"; + } + +} \ No newline at end of file diff --git a/java/openapi/src/com/intellij/psi/PsiDiamondType.java b/java/openapi/src/com/intellij/psi/PsiDiamondType.java index ef18355c0ab2..c19564505700 100644 --- a/java/openapi/src/com/intellij/psi/PsiDiamondType.java +++ b/java/openapi/src/com/intellij/psi/PsiDiamondType.java @@ -15,11 +15,15 @@ */ package com.intellij.psi; +import com.intellij.openapi.diagnostic.Logger; 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 org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * User: anna @@ -29,6 +33,7 @@ public class PsiDiamondType extends PsiType { private static final PsiType[] NULL_TYPES = new PsiType[]{NULL}; private PsiManager myManager; private final PsiTypeElement myTypeElement; + private static final Logger LOG = Logger.getInstance("#" + PsiDiamondType.class.getName()); public PsiDiamondType(PsiManager manager, PsiTypeElement psiTypeElement) { super(PsiAnnotation.EMPTY_ARRAY); @@ -82,7 +87,7 @@ public class PsiDiamondType extends PsiType { if (declarationStatement != null) { final PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); if (declaredElements.length > 0 && declaredElements[0] instanceof PsiVariable) { - return getComponentTypes(((PsiVariable)declaredElements[0]).getType()); + return getComponentTypes((PsiVariable)declaredElements[0]); } } @@ -92,7 +97,7 @@ public class PsiDiamondType extends PsiType { if (lExpression instanceof PsiReferenceExpression) { final PsiElement resolved = ((PsiReferenceExpression)lExpression).resolve(); if (resolved instanceof PsiVariable) { - return getComponentTypes(((PsiVariable)resolved).getType()); + return getComponentTypes(((PsiVariable)resolved)); } } } @@ -124,12 +129,75 @@ public class PsiDiamondType extends PsiType { } } } else if (parent instanceof PsiVariable) { - return getComponentTypes(((PsiVariable)parent).getType()); + return getComponentTypes((PsiVariable)parent); } } return NULL_TYPES; } + private static PsiType[] getComponentTypes(PsiVariable declaredElement) { + PsiType lType = declaredElement.getType(); + final PsiExpression initializer = declaredElement.getInitializer(); + 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(declaredElement.getProject()).getResolveHelper().resolveReferencedClass(text, initializer); + final PsiType substitute = substitute(psiClass, lType); + if (substitute != null) { + lType = substitute; + } + } + } + } + return getComponentTypes(lType); + } + + @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; + } + } + + 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(); diff --git a/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java b/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java index 2b9bf7c3f3ed..32a13288f3dd 100644 --- a/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/LightCodeInsightTestCase.java @@ -41,7 +41,11 @@ public abstract class LightCodeInsightTestCase extends LightPlatformCodeInsightT protected void setUp() throws Exception { super.setUp(); myOldLanguageLevel = LanguageLevelProjectExtension.getInstance(getProject()).getLanguageLevel(); - setLanguageLevel(LanguageLevel.HIGHEST); + setLanguageLevel(getLanguageLevel()); + } + + protected LanguageLevel getLanguageLevel() { + return LanguageLevel.HIGHEST; } @Override diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java index 09d9a3f054f0..4861b0c9ffa4 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java @@ -73,6 +73,22 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{ model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_5); } }; + public static final LightProjectDescriptor JAVA_1_6 = new DefaultLightProjectDescriptor() { + @Override + public ModuleType getModuleType() { + return StdModuleTypes.JAVA; + } + + @Override + public Sdk getSdk() { + return JavaSdkImpl.getMockJdk17("java 1.6"); + } + + @Override + public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_6); + } + }; public static final LightProjectDescriptor JAVA_LATEST = new DefaultLightProjectDescriptor(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java index 54026d204970..2583e8b97c13 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java @@ -53,6 +53,7 @@ public class LookupItem extends MutableLookupElement implements Comparable public static final Key OVERWRITE_ON_AUTOCOMPLETE_ATTR = Key.create("OVERWRITE_ON_AUTOCOMPLETE_ATTR"); public static final Object FORCE_QUALIFY = Key.create("FORCE_QUALIFY"); public static final Object SUBSTITUTOR = Key.create("SUBSTITUTOR"); + public static final Object FORCE_LOOKUP_STRING = Key.create("FORCE_LOOKUP_STRING"); public static final Object TYPE = Key.create("TYPE"); public static final Object INDICATE_ANONYMOUS = Key.create("INDICATE ANONYMOUS"); public static final Key DEPRECATED_ATTR = Key.create("DEPRECATED"); diff --git a/resources-en/src/inspectionDescriptions/Convert2Diamond.html b/resources-en/src/inspectionDescriptions/Convert2Diamond.html new file mode 100644 index 000000000000..2acd7557a951 --- /dev/null +++ b/resources-en/src/inspectionDescriptions/Convert2Diamond.html @@ -0,0 +1,5 @@ + + +Write your description here + +