From effe1217f477713a027e2a24f868797460e1be4d Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 20 Nov 2024 15:39:07 +0100 Subject: [PATCH] Reinstanting the smartType handling for static members, to aid code completion over non-sealed types. --- .../org-netbeans-modules-java-completion.sig | 16 ++++++-- .../java/completion/JavaCompletionTask.java | 20 +++++----- .../17/nonSealedTypeSwitch.pass | 16 ++++++++ .../data/SwitchWithNonSealedType.java | 38 +++++++++++++++++++ .../java/completion/CompletionTestBase.java | 6 +-- .../JavaCompletionTask121FeaturesTest.java | 4 ++ .../editor/java/JavaCompletionCollector.java | 6 +-- .../editor/java/JavaCompletionItem.java | 10 +++-- .../java/JavaCompletionItemFactory.java | 8 ++-- .../editor/java/LazyJavaCompletionItem.java | 10 +++-- 10 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/17/nonSealedTypeSwitch.pass create mode 100644 java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/SwitchWithNonSealedType.java diff --git a/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig b/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig index 21d34200b392..8fddca9ab799 100644 --- a/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig +++ b/java/java.completion/nbproject/org-netbeans-modules-java-completion.sig @@ -1,5 +1,5 @@ #Signature file v4.1 -#Version 2.11.0 +#Version 2.13.0 CLSS public abstract interface java.io.Serializable @@ -8,8 +8,10 @@ meth public abstract int compareTo({java.lang.Comparable%0}) CLSS public abstract java.lang.Enum<%0 extends java.lang.Enum<{java.lang.Enum%0}>> cons protected init(java.lang.String,int) +innr public final static EnumDesc intf java.io.Serializable intf java.lang.Comparable<{java.lang.Enum%0}> +intf java.lang.constant.Constable meth protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException meth protected final void finalize() meth public final boolean equals(java.lang.Object) @@ -18,6 +20,7 @@ meth public final int hashCode() meth public final int ordinal() meth public final java.lang.Class<{java.lang.Enum%0}> getDeclaringClass() meth public final java.lang.String name() +meth public final java.util.Optional> describeConstable() meth public java.lang.String toString() meth public static <%0 extends java.lang.Enum<{%%0}>> {%%0} valueOf(java.lang.Class<{%%0}>,java.lang.String) supr java.lang.Object @@ -32,6 +35,7 @@ CLSS public java.lang.Object cons public init() meth protected java.lang.Object clone() throws java.lang.CloneNotSupportedException meth protected void finalize() throws java.lang.Throwable + anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="9") meth public boolean equals(java.lang.Object) meth public final java.lang.Class getClass() meth public final void notify() @@ -68,6 +72,9 @@ CLSS public abstract interface !annotation java.lang.annotation.Target intf java.lang.annotation.Annotation meth public abstract java.lang.annotation.ElementType[] value() +CLSS public abstract interface java.lang.constant.Constable +meth public abstract java.util.Optional describeConstable() + CLSS public final org.netbeans.modules.java.completion.JavaCompletionTask<%0 extends java.lang.Object> fld protected final int caretOffset fld protected final java.util.concurrent.Callable cancel @@ -88,7 +95,8 @@ meth public static <%0 extends java.lang.Object> org.netbeans.modules.java.compl anno 4 org.netbeans.api.annotations.common.NullAllowed() meth public void run(org.netbeans.modules.parsing.api.ResultIterator) throws java.lang.Exception supr org.netbeans.modules.parsing.api.UserTask -hfds ABSTRACT_KEYWORD,ASSERT_KEYWORD,BLOCK_KEYWORDS,BOOLEAN_KEYWORD,BREAK_KEYWORD,BYTE_KEYWORD,CASE_KEYWORD,CATCH_KEYWORD,CHAR_KEYWORD,CLASS_BODY_KEYWORDS,CLASS_KEYWORD,COLON,CONTINUE_KEYWORD,DEFAULT_KEYWORD,DOUBLE_KEYWORD,DO_KEYWORD,ELSE_KEYWORD,EMPTY,ENUM_KEYWORD,ERROR,EXPORTS_KEYWORD,EXTENDS_KEYWORD,FALSE_KEYWORD,FINALLY_KEYWORD,FINAL_KEYWORD,FLOAT_KEYWORD,FOR_KEYWORD,IF_KEYWORD,IMPLEMENTS_KEYWORD,IMPORT_KEYWORD,INIT,INSTANCEOF_KEYWORD,INTERFACE_KEYWORD,INT_KEYWORD,JAVA_LANG_CLASS,JAVA_LANG_ITERABLE,JAVA_LANG_OBJECT,LONG_KEYWORD,MODULE_BODY_KEYWORDS,MODULE_KEYWORD,NATIVE_KEYWORD,NEW_KEYWORD,NON_SEALED_KEYWORD,NULL_KEYWORD,OPENS_KEYWORD,OPEN_KEYWORD,PACKAGE_KEYWORD,PERMITS_KEYWORD,PRIM_KEYWORDS,PRIVATE_KEYWORD,PROTECTED_KEYWORD,PROVIDES_KEYWORD,PUBLIC_KEYWORD,RECORD_KEYWORD,REQUIRES_KEYWORD,RETURN_KEYWORD,SEALED_KEYWORD,SEMI,SHORT_KEYWORD,SPACE,STATEMENT_KEYWORDS,STATEMENT_SPACE_KEYWORDS,STATIC_KEYWORD,STRICT_KEYWORD,SUPER_KEYWORD,SWITCH_KEYWORD,SYNCHRONIZED_KEYWORD,THIS_KEYWORD,THROWS_KEYWORD,THROW_KEYWORD,TO_KEYWORD,TRANSIENT_KEYWORD,TRANSITIVE_KEYWORD,TRUE_KEYWORD,TRY_KEYWORD,USES_KEYWORD,VAR_KEYWORD,VOID_KEYWORD,VOLATILE_KEYWORD,WHEN_KEYWORD,WHILE_KEYWORD,WITH_KEYWORD,YIELD_KEYWORD,anchorOffset,hasAdditionalClasses,hasAdditionalMembers,itemFactory,options,results +hfds ABSTRACT_KEYWORD,ASSERT_KEYWORD,BLOCK_KEYWORDS,BOOLEAN_KEYWORD,BREAK_KEYWORD,BYTE_KEYWORD,CASE_KEYWORD,CATCH_KEYWORD,CHAR_KEYWORD,CLASS_BODY_KEYWORDS,CLASS_KEYWORD,COLON,CONTINUE_KEYWORD,DEFAULT_KEYWORD,DOUBLE_KEYWORD,DO_KEYWORD,ELSE_KEYWORD,EMPTY,ENUM_KEYWORD,ERROR,EXPORTS_KEYWORD,EXTENDS_KEYWORD,FALSE_KEYWORD,FINALLY_KEYWORD,FINAL_KEYWORD,FLOAT_KEYWORD,FOR_KEYWORD,IF_KEYWORD,IMPLEMENTS_KEYWORD,IMPORT_KEYWORD,INIT,INSTANCEOF_KEYWORD,INTERFACE_KEYWORD,INT_KEYWORD,JAVA_LANG_CLASS,JAVA_LANG_ITERABLE,JAVA_LANG_OBJECT,JAVA_LANG_STRING,LONG_KEYWORD,MODULE_BODY_KEYWORDS,MODULE_KEYWORD,NATIVE_KEYWORD,NEW_KEYWORD,NON_SEALED_KEYWORD,NULL_KEYWORD,OPENS_KEYWORD,OPEN_KEYWORD,PACKAGE_KEYWORD,PERMITS_KEYWORD,PRIM_KEYWORDS,PRIVATE_KEYWORD,PROTECTED_KEYWORD,PROVIDES_KEYWORD,PUBLIC_KEYWORD,RECORD_KEYWORD,REQUIRES_KEYWORD,RETURN_KEYWORD,SEALED_KEYWORD,SEMI,SHORT_KEYWORD,SPACE,STATEMENT_KEYWORDS,STATEMENT_SPACE_KEYWORDS,STATIC_KEYWORD,STRICT_KEYWORD,SUPER_KEYWORD,SWITCH_KEYWORD,SYNCHRONIZED_KEYWORD,THIS_KEYWORD,THROWS_KEYWORD,THROW_KEYWORD,TO_KEYWORD,TRANSIENT_KEYWORD,TRANSITIVE_KEYWORD,TRUE_KEYWORD,TRY_KEYWORD,USES_KEYWORD,VAR_KEYWORD,VOID_KEYWORD,VOLATILE_KEYWORD,WHEN_KEYWORD,WHILE_KEYWORD,WITH_KEYWORD,YIELD_KEYWORD,addSwitchItemDefault,anchorOffset,hasAdditionalClasses,hasAdditionalMembers,itemFactory,options,results +hcls AddSwitchRelatedItem CLSS public abstract interface static org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory<%0 extends java.lang.Object> outer org.netbeans.modules.java.completion.JavaCompletionTask @@ -105,8 +113,8 @@ meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$It meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createOverrideMethodItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.element.ExecutableElement,javax.lang.model.type.ExecutableType,int,boolean) meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createPackageItem(java.lang.String,int,boolean) meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createParametersItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.element.ExecutableElement,javax.lang.model.type.ExecutableType,int,boolean,int,java.lang.String) -meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createStaticMemberItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.type.DeclaredType,javax.lang.model.element.Element,javax.lang.model.type.TypeMirror,boolean,int,boolean,boolean) -meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createStaticMemberItem(org.netbeans.api.java.source.ElementHandle,java.lang.String,int,boolean,org.netbeans.api.java.source.support.ReferencesCount,org.netbeans.modules.parsing.api.Source) +meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createStaticMemberItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.type.DeclaredType,javax.lang.model.element.Element,javax.lang.model.type.TypeMirror,boolean,int,boolean,boolean,boolean) +meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createStaticMemberItem(org.netbeans.api.java.source.ElementHandle,java.lang.String,int,boolean,org.netbeans.api.java.source.support.ReferencesCount,org.netbeans.modules.parsing.api.Source,boolean) meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createThisOrSuperConstructorItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.element.ExecutableElement,javax.lang.model.type.ExecutableType,int,boolean,java.lang.String) meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createTypeItem(org.netbeans.api.java.source.CompilationInfo,javax.lang.model.element.TypeElement,javax.lang.model.type.DeclaredType,int,org.netbeans.api.java.source.support.ReferencesCount,boolean,boolean,boolean,boolean,boolean,boolean) meth public abstract {org.netbeans.modules.java.completion.JavaCompletionTask$ItemFactory%0} createTypeItem(org.netbeans.api.java.source.ElementHandle,java.util.EnumSet,int,org.netbeans.api.java.source.support.ReferencesCount,org.netbeans.modules.parsing.api.Source,boolean,boolean,boolean) diff --git a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java index fb03fd583e45..ac22658fe54f 100644 --- a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java +++ b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java @@ -107,9 +107,9 @@ public static interface ItemFactory { T createAttributeValueItem(CompilationInfo info, String value, String documentation, TypeElement element, int substitutionOffset, ReferencesCount referencesCount); - T createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon); + T createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType); - T createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source); + T createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType); T createChainedMembersItem(CompilationInfo info, List chainedElems, List chainedTypes, int substitutionOffset, boolean isDeprecated, boolean addSemicolon); @@ -2622,7 +2622,9 @@ private AddSwitchRelatedItem itemAdderForSwitchOrNull(Env env, TreePath switchPa //type String, give up and show all types: return null; } else { - if (selectorTypeElement.getModifiers().contains(Modifier.SEALED)) { + boolean selectorSealed = selectorTypeElement.getModifiers().contains(Modifier.SEALED); + + if (selectorSealed) { options.add(Options.ALL_COMPLETION); } @@ -2652,7 +2654,7 @@ public void addTypeItem(CompilationInfo info, TypeElement elem, DeclaredType typ continue; } //not filtering deprecated, etc., as those may be needed for exhaustiveness: - results.add(itemFactory.createStaticMemberItem(info, type, enumConstant, enumConstant.asType(), false, anchorOffset, info.getElements().isDeprecated(enumConstant), false)); + results.add(itemFactory.createStaticMemberItem(info, type, enumConstant, enumConstant.asType(), false, anchorOffset, info.getElements().isDeprecated(enumConstant), false, selectorSealed)); } } } @@ -3577,7 +3579,7 @@ public boolean accept(Element e, TypeMirror t) { }; for (Element ee : controller.getElementUtilities().getMembers(type, acceptor)) { if (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(ee)) { - results.add(itemFactory.createStaticMemberItem(env.getController(), type, ee, asMemberOf(ee, type, types), false, anchorOffset, elements.isDeprecated(ee), false)); + results.add(itemFactory.createStaticMemberItem(env.getController(), type, ee, asMemberOf(ee, type, types), false, anchorOffset, elements.isDeprecated(ee), false, true)); } } } @@ -3661,7 +3663,7 @@ public boolean accept(Element e, TypeMirror t) { }; for (Element ee : controller.getElementUtilities().getMembers(type, acceptor)) { if (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(ee)) { - results.add(itemFactory.createStaticMemberItem(env.getController(), type, ee, asMemberOf(ee, type, types), false, anchorOffset, elements.isDeprecated(ee), env.addSemicolon())); + results.add(itemFactory.createStaticMemberItem(env.getController(), type, ee, asMemberOf(ee, type, types), false, anchorOffset, elements.isDeprecated(ee), env.addSemicolon(), true)); } } } @@ -3698,7 +3700,7 @@ public boolean accept(Element e, TypeMirror t) { } ExecutableType et = (ExecutableType) asMemberOf(e, enclClass != null ? enclClass.asType() : null, types); if (e.getEnclosingElement() != enclClass && conflictsWithLocalMethods(e.getSimpleName(), enclClass, methodsIn)) { - results.add(itemFactory.createStaticMemberItem(env.getController(), (DeclaredType)e.getEnclosingElement().asType(), e, et, false, anchorOffset, elements.isDeprecated(e), env.addSemicolon())); + results.add(itemFactory.createStaticMemberItem(env.getController(), (DeclaredType)e.getEnclosingElement().asType(), e, et, false, anchorOffset, elements.isDeprecated(e), env.addSemicolon(), true)); } else { results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, null, env.getScope().getEnclosingClass() != e.getEnclosingElement(), elements.isDeprecated(e), false, env.addSemicolon(), isOfSmartType(env, getCorrectedReturnType(env, et, (ExecutableElement) e, enclClass != null ? enclClass.asType() : null), smartTypes), env.assignToVarPos(), false)); } @@ -3870,7 +3872,7 @@ public boolean accept(Element e, TypeMirror t) { for (DeclaredType dt : dts) { if (startsWith(env, dt.asElement().getSimpleName().toString())) { for (Element ee : controller.getElementUtilities().getMembers(dt, acceptor)) { - results.add(itemFactory.createStaticMemberItem(env.getController(), dt, ee, asMemberOf(ee, dt, types), false, anchorOffset, elements.isDeprecated(ee), env.addSemicolon())); + results.add(itemFactory.createStaticMemberItem(env.getController(), dt, ee, asMemberOf(ee, dt, types), false, anchorOffset, elements.isDeprecated(ee), env.addSemicolon(), true)); } } } @@ -3967,7 +3969,7 @@ private void addAllStaticMemberNames(final Env env) { } for (String name : symbols.getSymbols()) { if (!Utilities.isExcludeMethods() || !Utilities.isExcluded(symbols.getEnclosingType().getQualifiedName() + '.' + name)) { - results.add(itemFactory.createStaticMemberItem(symbols.getEnclosingType(), name, anchorOffset, env.addSemicolon(), env.getReferencesCount(), controller.getSnapshot().getSource())); + results.add(itemFactory.createStaticMemberItem(symbols.getEnclosingType(), name, anchorOffset, env.addSemicolon(), env.getReferencesCount(), controller.getSnapshot().getSource(), true)); } } } diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/17/nonSealedTypeSwitch.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/17/nonSealedTypeSwitch.pass new file mode 100644 index 000000000000..8f2b5b04798b --- /dev/null +++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/17/nonSealedTypeSwitch.pass @@ -0,0 +1,16 @@ +null +public static final EJ EJ.A +public static final EJ EJ.B +public static final EJ EJ.C +CI +CJ1 +CJ2 +EJ +I +J +Test +com +java +javax +org +sun diff --git a/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/SwitchWithNonSealedType.java b/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/SwitchWithNonSealedType.java new file mode 100644 index 000000000000..f8101c41fec7 --- /dev/null +++ b/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/SwitchWithNonSealedType.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 test; + +public class Test { + + interface I {} + interface J extends I {} + final class CI implements I {} + final class CJ1 implements J {} + final enum EJ implements J {A, B, C} + + public void op(I i) { + switch (i) { + case + + } + } +} + +final class CJ2 implements Test.J {} diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java index 1a611aab224f..1dd98f80c89c 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBase.java @@ -525,7 +525,7 @@ public CI createAttributeValueItem(CompilationInfo info, String value, String do } @Override - public CI createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon) { + public CI createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType) { switch (memberElem.getKind()) { case METHOD: case ENUM_CONSTANT: @@ -577,14 +577,14 @@ public CI createStaticMemberItem(CompilationInfo info, DeclaredType type, Elemen sb.append(')'); sortParams.append(')'); } - return new CI(sb.toString(), (memberElem.getKind().isField() ? 720 : 750) - SMART_TYPE, memberElem.getKind().isField() ? memberName + "#" + typeName : memberName + "#" + ((cnt < 10 ? "0" : "") + cnt) + "#" + sortParams.toString() + "#" + typeName); //NOI18N + return new CI(sb.toString(), (memberElem.getKind().isField() ? 720 : 750) - (smartType ? SMART_TYPE : 0), memberElem.getKind().isField() ? memberName + "#" + typeName : memberName + "#" + ((cnt < 10 ? "0" : "") + cnt) + "#" + sortParams.toString() + "#" + typeName); //NOI18N default: throw new IllegalArgumentException("kind=" + memberElem.getKind()); } } @Override - public CI createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source) { + public CI createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType) { String fqn = handle.getQualifiedName(); int weight = 50; if (fqn.startsWith("java.lang") || fqn.startsWith("java.util")) { // NOI18N diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java index e1141f2f7268..5237ac4e88f7 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java @@ -163,6 +163,10 @@ public void testSealedTypeSwitchEnumFilteringQualified2() throws Exception { performTest("SwitchWithSealedType", 1084, "EJ.A -> {} case test.Test.EJ.", "sealedTypeSwitchEJAFilteredQualified2.pass", SOURCE_LEVEL); } + public void testNonSealedTypeSwitch1() throws Exception { + performTest("SwitchWithNonSealedType", 1070, null, "nonSealedTypeSwitch.pass", SOURCE_LEVEL); + } + @Override protected void afterTestSetup() throws Exception { if (getName().startsWith("testSealed")) { diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java index a68dc91894fa..bddc6dbc8e8c 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionCollector.java @@ -665,7 +665,7 @@ public Completion createAttributeValueItem(CompilationInfo info, String value, S private static final Object KEY_IMPORT_TEXT_EDITS = new Object(); @Override - public Completion createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon) { + public Completion createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType) { //TODO: prefer static imports (but would be much slower?) //TODO: should be resolveImport instead of addImports: Map imports = (Map) info.getCachedValue(KEY_IMPORT_TEXT_EDITS); @@ -740,7 +740,7 @@ public Completion createStaticMemberItem(CompilationInfo info, DeclaredType type .labelDescription(memberTypeName) .insertText(insertText.toString()) .insertTextFormat(asTemplate ? Completion.TextFormat.Snippet : Completion.TextFormat.PlainText) - .sortText(String.format("%04d%s", memberElem.getKind().isField() ? 720 : 750, sortText)); + .sortText(String.format("%04d%s", (memberElem.getKind().isField() ? 720 : 750) + (smartType ? 1000 : 0), sortText)); if (labelDetail.length() > 0) { builder.labelDetail(labelDetail.toString()); } @@ -758,7 +758,7 @@ public Completion createStaticMemberItem(CompilationInfo info, DeclaredType type } @Override - public Completion createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source) { + public Completion createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType) { return null; //TODO: fill } diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java index 40555e740711..09945ede0eaa 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java @@ -248,12 +248,12 @@ public static JavaCompletionItem createAttributeValueItem(CompilationInfo info, return new AttributeValueItem(info, value, documentation, element, substitutionOffset, referencesCount, whiteList); } - public static JavaCompletionItem createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, WhiteListQuery.WhiteList whiteList) { + public static JavaCompletionItem createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType, WhiteListQuery.WhiteList whiteList) { switch (memberElem.getKind()) { case METHOD: case ENUM_CONSTANT: case FIELD: - return new StaticMemberItem(info, type, memberElem, memberType, multipleVersions, substitutionOffset, isDeprecated, addSemicolon, whiteList); + return new StaticMemberItem(info, type, memberElem, memberType, multipleVersions, substitutionOffset, isDeprecated, addSemicolon, smartType, whiteList); default: throw new IllegalArgumentException("kind=" + memberElem.getKind()); } @@ -3357,8 +3357,9 @@ static class StaticMemberItem extends WhiteListJavaCompletionItem { private String sortText; private String leftText; private String rightText; + private final boolean smartType; - private StaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, WhiteListQuery.WhiteList whiteList) { + private StaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType, WhiteListQuery.WhiteList whiteList) { super(substitutionOffset, ElementHandle.create(memberElem), whiteList); type = (DeclaredType) info.getTypes().erasure(type); this.typeHandle = TypeMirrorHandle.create(type); @@ -3378,11 +3379,12 @@ private StaticMemberItem(CompilationInfo info, DeclaredType type, Element member this.params.add(new ParamDesc(tm.toString(), Utilities.getTypeName(info, tm, false, ((ExecutableElement)memberElem).isVarArgs() && !tIt.hasNext()).toString(), it.next().getSimpleName().toString())); } } + this.smartType = smartType; } @Override public int getSortPriority() { - int p = (getElementHandle().getKind().isField() ? 720 : 750) - SMART_TYPE; + int p = (getElementHandle().getKind().isField() ? 720 : 750) - (smartType ? SMART_TYPE : 0); return isDeprecated ? p + DEPRECATED : p; } diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItemFactory.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItemFactory.java index 41836d865f4e..ac08274cb7e4 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItemFactory.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItemFactory.java @@ -158,13 +158,13 @@ public JavaCompletionItem createAttributeValueItem(CompilationInfo info, String } @Override - public JavaCompletionItem createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon) { - return JavaCompletionItem.createStaticMemberItem(info, type, memberElem, memberType, multipleVersions, substitutionOffset, isDeprecated, addSemicolon, whiteList); + public JavaCompletionItem createStaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, boolean multipleVersions, int substitutionOffset, boolean isDeprecated, boolean addSemicolon, boolean smartType) { + return JavaCompletionItem.createStaticMemberItem(info, type, memberElem, memberType, multipleVersions, substitutionOffset, isDeprecated, addSemicolon, smartType, whiteList); } @Override - public JavaCompletionItem createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source) { - return LazyJavaCompletionItem.createStaticMemberItem(handle, name, substitutionOffset, addSemicolon, referencesCount, source, whiteList); + public JavaCompletionItem createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType) { + return LazyJavaCompletionItem.createStaticMemberItem(handle, name, substitutionOffset, addSemicolon, referencesCount, source, smartType, whiteList); } @Override diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/LazyJavaCompletionItem.java b/java/java.editor/src/org/netbeans/modules/editor/java/LazyJavaCompletionItem.java index d798704f42f1..4d422555b2fc 100644 --- a/java/java.editor/src/org/netbeans/modules/editor/java/LazyJavaCompletionItem.java +++ b/java/java.editor/src/org/netbeans/modules/editor/java/LazyJavaCompletionItem.java @@ -64,8 +64,8 @@ public static JavaCompletionItem createTypeItem(ElementHandle handl return new TypeItem(handle, kinds, substitutionOffset, referencesCount, source, insideNew, addTypeVars, afterExtends, whiteList); } - public static JavaCompletionItem createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, WhiteListQuery.WhiteList whiteList) { - return new StaticMemberItem(handle, name, substitutionOffset, addSemicolon, referencesCount, source, whiteList); + public static JavaCompletionItem createStaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType, WhiteListQuery.WhiteList whiteList) { + return new StaticMemberItem(handle, name, substitutionOffset, addSemicolon, referencesCount, source, smartType, whiteList); } private LazyJavaCompletionItem(int substitutionOffset, ElementHandle handle, Source source, WhiteListQuery.WhiteList whiteList) { @@ -241,12 +241,14 @@ private static class StaticMemberItem extends LazyJavaCompletionItem handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, WhiteListQuery.WhiteList whiteList) { + private StaticMemberItem(ElementHandle handle, String name, int substitutionOffset, boolean addSemicolon, ReferencesCount referencesCount, Source source, boolean smartType, WhiteListQuery.WhiteList whiteList) { super(substitutionOffset, handle, source, whiteList); this.name = name; this.sortText = new LazySortText(this.name, handle.getQualifiedName(), handle, referencesCount); this.addSemicolon = addSemicolon; + this.smartType = smartType; } @Override @@ -271,7 +273,7 @@ protected JavaCompletionItem getDelegate(CompilationInfo info, Scope scope, Type } if (element != null) { name = element.getSimpleName().toString(); - return createStaticMemberItem(info, (DeclaredType) te.asType(), element, element.asType(), multiVersion, substitutionOffset, elements.isDeprecated(element), addSemicolon, getWhiteList()); + return createStaticMemberItem(info, (DeclaredType) te.asType(), element, element.asType(), multiVersion, substitutionOffset, elements.isDeprecated(element), addSemicolon, smartType, getWhiteList()); } } return null;