Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java completion enhanced to support no insertion of method parameters #7747

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,13 @@ private EditorPreferencesKeys() {
public static final String JAVADOC_PREFERRED_SIZE = SimpleValueNames.JAVADOC_PREFERRED_SIZE;
public static final String POPUP_MENU_ENABLED = SimpleValueNames.POPUP_MENU_ENABLED;
public static final String SHOW_DEPRECATED_MEMBERS = SimpleValueNames.SHOW_DEPRECATED_MEMBERS;


/**
* Whether the code completion should insert text for the parameters of executable items.
* Values: java.lang.Boolean
*/
public static final String COMPLETION_INSERT_TEXT_PARAMETERS = "completion-insert-text-parameters"; // NOI18N

/** List of the action names that should be shown in the popup menu.
* Null name means separator.
* Values: java.util.List containing java.lang.String instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<entry category="private" javaType="java.lang.Boolean" name="completion-case-sensitive" xml:space="preserve">
<value><![CDATA[false]]></value>
</entry>
<entry category="private" javaType="java.lang.Boolean" name="completion-insert-text-parameters" xml:space="preserve">
<value><![CDATA[true]]></value>
</entry>
<entry category="private" javaType="java.lang.Boolean" name="completion-instant-substitution" xml:space="preserve">
<value><![CDATA[true]]></value>
</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static interface ItemFactory<T> {

T createVariableItem(CompilationInfo info, String varName, int substitutionOffset, boolean newVarName, boolean smartType);

T createExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef);
T createExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef, boolean insertTextParams);

T createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name);
T createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name, boolean insertTextParams);

T createOverrideMethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean implement);

Expand Down Expand Up @@ -119,7 +119,7 @@ public static interface TypeCastableItemFactory<T> extends ItemFactory<T> {

T createTypeCastableVariableItem(CompilationInfo info, VariableElement elem, TypeMirror type, TypeMirror castType, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean smartType, int assignToVarOffset);

T createTypeCastableExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, TypeMirror castType, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef);
T createTypeCastableExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, TypeMirror castType, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef, boolean insertTextParams);
}

public static interface LambdaItemFactory<T> extends ItemFactory<T> {
Expand Down Expand Up @@ -3562,7 +3562,7 @@ public boolean accept(Element e, TypeMirror t) {
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()));
} 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));
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, Utilities.isCompletionInsertTextParameters()));
}
break;
}
Expand Down Expand Up @@ -3926,7 +3926,7 @@ public boolean accept(Element e, TypeMirror t) {
switch (e.getKind()) {
case METHOD:
ExecutableType et = (ExecutableType) asMemberOf(e, type, types);
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), false, false, isOfSmartType(env, et, smartTypes), env.assignToVarPos(), true));
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), false, false, isOfSmartType(env, et, smartTypes), env.assignToVarPos(), true, false)); // insertTextParams is hard-coded to false because memberRef is true for method-references, thus, irrelevant.
break;
}
}
Expand Down Expand Up @@ -4076,16 +4076,16 @@ && isOfKindAndType(e.getEnclosingElement().asType(), e, kinds, baseType, scope,
break;
case CONSTRUCTOR:
ExecutableType et = (ExecutableType) asMemberOf(e, actualType, types);
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, false, isOfSmartType(env, actualType, smartTypes), env.assignToVarPos(), false));
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, false, isOfSmartType(env, actualType, smartTypes), env.assignToVarPos(), false, Utilities.isCompletionInsertTextParameters()));
break;
case METHOD:
et = (ExecutableType) asMemberOf(e, actualType, types);
if (addCast && itemFactory instanceof TypeCastableItemFactory
&& !types.isSubtype(type, e.getEnclosingElement().asType())
&& type.getKind() == TypeKind.DECLARED && !hasBaseMethod(elements, (DeclaredType) type, (ExecutableElement) e)) {
results.add(((TypeCastableItemFactory<T>)itemFactory).createTypeCastableExecutableItem(env.getController(), (ExecutableElement) e, et, actualType, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, env.addSemicolon(), isOfSmartType(env, getCorrectedReturnType(env, et, (ExecutableElement) e, actualType), smartTypes), env.assignToVarPos(), false));
results.add(((TypeCastableItemFactory<T>)itemFactory).createTypeCastableExecutableItem(env.getController(), (ExecutableElement) e, et, actualType, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, env.addSemicolon(), isOfSmartType(env, getCorrectedReturnType(env, et, (ExecutableElement) e, actualType), smartTypes), env.assignToVarPos(), false, Utilities.isCompletionInsertTextParameters()));
} else {
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, env.addSemicolon(), isOfSmartType(env, getCorrectedReturnType(env, et, (ExecutableElement) e, actualType), smartTypes), env.assignToVarPos(), false));
results.add(itemFactory.createExecutableItem(env.getController(), (ExecutableElement) e, et, anchorOffset, autoImport ? env.getReferencesCount() : null, typeElem != e.getEnclosingElement(), elements.isDeprecated(e), inImport, env.addSemicolon(), isOfSmartType(env, getCorrectedReturnType(env, et, (ExecutableElement) e, actualType), smartTypes), env.assignToVarPos(), false, Utilities.isCompletionInsertTextParameters()));
}
break;
case CLASS:
Expand Down Expand Up @@ -4144,7 +4144,7 @@ public boolean accept(Element e, TypeMirror t) {
for (Element e : controller.getElementUtilities().getMembers(type, acceptor)) {
if (e.getKind() == CONSTRUCTOR) {
ExecutableType et = (ExecutableType) asMemberOf(e, type, types);
results.add(itemFactory.createThisOrSuperConstructorItem(env.getController(), (ExecutableElement) e, et, anchorOffset, elements.isDeprecated(e), name));
results.add(itemFactory.createThisOrSuperConstructorItem(env.getController(), (ExecutableElement) e, et, anchorOffset, elements.isDeprecated(e), name, Utilities.isCompletionInsertTextParameters()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public final class Utilities {
private static final String ERROR = "<error>"; //NOI18N
private static final String COMPLETION_CASE_SENSITIVE = "completion-case-sensitive"; // NOI18N
private static final boolean COMPLETION_CASE_SENSITIVE_DEFAULT = true;
private static final String COMPLETION_INSERT_TEXT_PARAMETERS = "completion-insert-text-parameters"; // NOI18N
private static final boolean COMPLETION_INSERT_TEXT_PARAMETERS_DEFAULT = true;
private static final String SHOW_DEPRECATED_MEMBERS = "show-deprecated-members"; // NOI18N
private static final boolean SHOW_DEPRECATED_MEMBERS_DEFAULT = true;
private static final String JAVA_COMPLETION_WHITELIST = "javaCompletionWhitelist"; //NOI18N
Expand All @@ -62,6 +64,7 @@ public final class Utilities {
private static final boolean JAVA_COMPLETION_SUBWORDS_DEFAULT = false;

private static boolean caseSensitive = COMPLETION_CASE_SENSITIVE_DEFAULT;
private static boolean completionInsertTextParameters = COMPLETION_INSERT_TEXT_PARAMETERS_DEFAULT;
private static boolean showDeprecatedMembers = SHOW_DEPRECATED_MEMBERS_DEFAULT;
private static boolean javaCompletionExcluderMethods = JAVA_COMPLETION_EXCLUDER_METHODS_DEFAULT;
private static boolean javaCompletionSubwords = JAVA_COMPLETION_SUBWORDS_DEFAULT;
Expand Down Expand Up @@ -92,6 +95,9 @@ public void preferenceChange(PreferenceChangeEvent evt) {
if (settingName == null || JAVA_COMPLETION_SUBWORDS.equals(settingName)) {
javaCompletionSubwords = preferences.getBoolean(JAVA_COMPLETION_SUBWORDS, JAVA_COMPLETION_SUBWORDS_DEFAULT);
}
if (settingName == null || COMPLETION_INSERT_TEXT_PARAMETERS.equals(settingName)) {
completionInsertTextParameters = preferences.getBoolean(COMPLETION_INSERT_TEXT_PARAMETERS, COMPLETION_INSERT_TEXT_PARAMETERS_DEFAULT);
}
}
};

Expand Down Expand Up @@ -208,6 +214,11 @@ public static boolean isShowDeprecatedMembers() {
return showDeprecatedMembers;
}

public static boolean isCompletionInsertTextParameters() {
lazyInit();
return completionInsertTextParameters;
}

private static final AtomicReference<Collection<String>> excludeRef = new AtomicReference<>();
private static final AtomicReference<Collection<String>> includeRef = new AtomicReference<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public CI createVariableItem(CompilationInfo info, String varName, int substitut
}

@Override
public CI createExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef) {
public CI createExecutableItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarOffset, boolean memberRef, boolean insertTextParams) {
String simpleName = elem.getKind() == ElementKind.CONSTRUCTOR ? elem.getEnclosingElement().getSimpleName().toString() : elem.getSimpleName().toString();
StringBuilder sb = new StringBuilder();
StringBuilder sortParams = new StringBuilder();
Expand Down Expand Up @@ -294,7 +294,7 @@ public CI createExecutableItem(CompilationInfo info, ExecutableElement elem, Exe
}

@Override
public CI createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name) {
public CI createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name, boolean insertTextParams) {
if (elem.getKind() == ElementKind.CONSTRUCTOR) {
StringBuilder sb = new StringBuilder();
StringBuilder sortParams = new StringBuilder();
Expand Down
Loading