diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java
index 839c200b9a..9004aa45dd 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandler.java
@@ -232,7 +232,8 @@ private void collectCodeLenses(ITypeRoot typeRoot, IJavaElement[] elements, Coll
}
}
}
- if (preferenceManager.getPreferences().isImplementationsCodeLensEnabled() && element instanceof IType type) {
+ String implementationsPreference = preferenceManager.getPreferences().getImplementationsCodeLens();
+ if (("all".equals(implementationsPreference) || "types".equals(implementationsPreference)) && element instanceof IType type) {
if (type.isInterface() || Flags.isAbstract(type.getFlags())) {
CodeLens lens = getCodeLens(IMPLEMENTATION_TYPE, element, typeRoot);
if (lens != null) {
@@ -241,7 +242,7 @@ private void collectCodeLenses(ITypeRoot typeRoot, IJavaElement[] elements, Coll
}
}
- if (preferenceManager.getPreferences().isMethodImplementationsCodeLensEnabled() && element instanceof IMethod methodElement) {
+ if (("all".equals(implementationsPreference) || "methods".equals(implementationsPreference)) && element instanceof IMethod methodElement) {
if ((methodElement.getParent() instanceof IType parentType && parentType.isInterface()) || Flags.isAbstract(methodElement.getFlags())) {
CodeLens lens = getCodeLens(IMPLEMENTATION_TYPE, element, typeRoot);
if (lens != null) {
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
index 8e4d9e60b6..5679aa5435 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
@@ -230,14 +230,9 @@ public class Preferences {
public static final String REFERENCES_CODE_LENS_ENABLED_KEY = "java.referencesCodeLens.enabled";
/**
- * Preference key to enable/disable implementation code lenses.
+ * Preference key to set implementation code lenses.
*/
- public static final String IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY = "java.implementationsCodeLens.enabled";
-
- /**
- * Preference key to enable/disable implementation code lenses for methods.
- */
- public static final String METHOD_IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY = "java.methodImplementationsCodeLens.enabled";
+ public static final String IMPLEMENTATIONS_CODE_LENS_KEY = "java.implementationCodeLens";
/**
* Preference key to enable/disable formatter.
@@ -351,7 +346,8 @@ public class Preferences {
public static final String COMPLETION_MATCH_CASE_MODE_KEY = "java.completion.matchCase";
/**
- * Preference key to specify whether text edit of completion item can be lazily resolved.
+ * Preference key to specify whether text edit of completion item can be lazily
+ * resolved.
*/
public static final String COMPLETION_LAZY_RESOLVE_TEXT_EDIT_ENABLED_KEY = "java.completion.lazyResolveTextEdit.enabled";
@@ -545,10 +541,11 @@ public class Preferences {
public static final String CHAIN_COMPLETION_KEY = "java.completion.chain.enabled";
/**
- * Preference key to set the scope value to use when searching java code. Allowed value are
+ * Preference key to set the scope value to use when searching java code.
+ * Allowed value are
*
- * main
- Scope for main code
- * all
- Scope for both test and main code
+ * main
- Scope for main code
+ * all
- Scope for both test and main code
*
* Any other unknown value will be treated as all
.
*/
@@ -633,8 +630,7 @@ public class Preferences {
private boolean mavenDownloadSources;
private boolean eclipseDownloadSources;
private boolean mavenUpdateSnapshots;
- private boolean implementationsCodeLensEnabled;
- private boolean methodImplementationsCodeLensEnabled;
+ private String implementationsCodeLens;
private boolean javaFormatEnabled;
private String javaQuickFixShowAt;
private boolean javaFormatOnTypeEnabled;
@@ -767,7 +763,7 @@ static Severity fromString(String value, Severity defaultSeverity) {
String val = value.toLowerCase();
try {
return valueOf(val);
- } catch(Exception e) {
+ } catch (Exception e) {
//fall back to default severity
}
}
@@ -786,14 +782,14 @@ public MessageType toMessageType() {
}
public static enum FeatureStatus {
- disabled, interactive, automatic ;
+ disabled, interactive, automatic;
static FeatureStatus fromString(String value, FeatureStatus defaultStatus) {
if (value != null) {
String val = value.toLowerCase();
try {
return valueOf(val);
- } catch(Exception e) {
+ } catch (Exception e) {
//fall back to default severity
}
}
@@ -809,7 +805,7 @@ static SearchScope fromString(String value, SearchScope defaultScope) {
String val = value.toLowerCase();
try {
return valueOf(val);
- } catch(Exception e) {
+ } catch (Exception e) {
//fall back to default severity
}
}
@@ -884,9 +880,7 @@ public boolean equals(Object obj) {
return false;
}
ReferencedLibraries other = (ReferencedLibraries) obj;
- return Objects.equals(include, other.include)
- && Objects.equals(exclude, other.exclude)
- && Objects.equals(sources, other.sources);
+ return Objects.equals(include, other.include) && Objects.equals(exclude, other.exclude) && Objects.equals(sources, other.sources);
}
}
@@ -912,8 +906,7 @@ public Preferences() {
eclipseDownloadSources = false;
mavenUpdateSnapshots = false;
referencesCodeLensEnabled = true;
- implementationsCodeLensEnabled = false;
- methodImplementationsCodeLensEnabled = false;
+ implementationsCodeLens = "none";
javaFormatEnabled = true;
javaQuickFixShowAt = LINE;
javaFormatOnTypeEnabled = false;
@@ -1036,8 +1029,7 @@ public static Preferences createFrom(Map configuration) {
prefs.setIncompleteClasspathSeverity(Severity.fromString(incompleteClasspathSeverity, Severity.warning));
String updateBuildConfiguration = getString(configuration, CONFIGURATION_UPDATE_BUILD_CONFIGURATION_KEY, null);
- prefs.setUpdateBuildConfigurationStatus(
- FeatureStatus.fromString(updateBuildConfiguration, FeatureStatus.interactive));
+ prefs.setUpdateBuildConfigurationStatus(FeatureStatus.fromString(updateBuildConfiguration, FeatureStatus.interactive));
boolean importGradleEnabled = getBoolean(configuration, IMPORT_GRADLE_ENABLED, true);
prefs.setImportGradleEnabled(importGradleEnabled);
@@ -1078,10 +1070,8 @@ public static Preferences createFrom(Map configuration) {
prefs.setMavenUpdateSnapshots(updateSnapshots);
boolean referenceCodelensEnabled = getBoolean(configuration, REFERENCES_CODE_LENS_ENABLED_KEY, true);
prefs.setReferencesCodelensEnabled(referenceCodelensEnabled);
- boolean implementationCodeLensEnabled = getBoolean(configuration, IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, false);
- prefs.setImplementationCodelensEnabled(implementationCodeLensEnabled);
- boolean methodImplementationCodeLensEnabled = getBoolean(configuration, METHOD_IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, false);
- prefs.setMethodImplementationCodelensEnabled(methodImplementationCodeLensEnabled);
+ String implementationCodeLens = getString(configuration, IMPLEMENTATIONS_CODE_LENS_KEY, "none");
+ prefs.setImplementationCodelens(implementationCodeLens);
boolean javaFormatEnabled = getBoolean(configuration, JAVA_FORMAT_ENABLED_KEY, true);
prefs.setJavaFormatEnabled(javaFormatEnabled);
@@ -1133,12 +1123,10 @@ public static Preferences createFrom(Map configuration) {
Object guessMethodArguments = getValue(configuration, JAVA_COMPLETION_GUESS_METHOD_ARGUMENTS_KEY);
if (guessMethodArguments instanceof Boolean b) {
- prefs.setGuessMethodArgumentsMode(b ? CompletionGuessMethodArgumentsMode.INSERT_BEST_GUESSED_ARGUMENTS :
- CompletionGuessMethodArgumentsMode.INSERT_PARAMETER_NAMES);
+ prefs.setGuessMethodArgumentsMode(b ? CompletionGuessMethodArgumentsMode.INSERT_BEST_GUESSED_ARGUMENTS : CompletionGuessMethodArgumentsMode.INSERT_PARAMETER_NAMES);
} else {
String guessMethodArgumentsMode = getString(configuration, JAVA_COMPLETION_GUESS_METHOD_ARGUMENTS_KEY, null);
- prefs.setGuessMethodArgumentsMode(CompletionGuessMethodArgumentsMode.fromString(guessMethodArgumentsMode,
- CompletionGuessMethodArgumentsMode.INSERT_PARAMETER_NAMES));
+ prefs.setGuessMethodArgumentsMode(CompletionGuessMethodArgumentsMode.fromString(guessMethodArgumentsMode, CompletionGuessMethodArgumentsMode.INSERT_PARAMETER_NAMES));
}
boolean collapseCompletionItemsEnabled = getBoolean(configuration, JAVA_COMPLETION_COLLAPSE_KEY, false);
@@ -1362,7 +1350,7 @@ public static Preferences createFrom(Map configuration) {
prefs.setNullAnalysisMode(FeatureStatus.fromString(nullAnalysisMode, FeatureStatus.disabled));
List cleanupActionsTemp = getList(configuration, JAVA_CLEANUPS_ACTIONS_ON_SAVE_DEPRECATED, Collections.emptyList());
List cleanupActions = getList(configuration, JAVA_CLEANUPS_ACTIONS, Collections.emptyList());
- if(cleanupActions.isEmpty() && !cleanupActionsTemp.isEmpty()) {
+ if (cleanupActions.isEmpty() && !cleanupActionsTemp.isEmpty()) {
cleanupActions = cleanupActionsTemp;
}
prefs.setCleanUpActions(cleanupActions);
@@ -1587,13 +1575,8 @@ public void setSignatureHelpDescriptionEnabled(boolean signatureHelpDescriptionE
this.signatureHelpDescriptionEnabled = signatureHelpDescriptionEnabled;
}
- private Preferences setImplementationCodelensEnabled(boolean enabled) {
- this.implementationsCodeLensEnabled = enabled;
- return this;
- }
-
- private Preferences setMethodImplementationCodelensEnabled(boolean enabled) {
- this.methodImplementationsCodeLensEnabled = enabled;
+ private Preferences setImplementationCodelens(String implementationCodeLensOption) {
+ this.implementationsCodeLens = implementationCodeLensOption;
return this;
}
@@ -1922,16 +1905,12 @@ public boolean isMavenUpdateSnapshots() {
return mavenUpdateSnapshots;
}
- public boolean isImplementationsCodeLensEnabled() {
- return implementationsCodeLensEnabled;
- }
-
- public boolean isMethodImplementationsCodeLensEnabled() {
- return methodImplementationsCodeLensEnabled;
+ public String getImplementationsCodeLens() {
+ return implementationsCodeLens;
}
public boolean isCodeLensEnabled() {
- return referencesCodeLensEnabled || implementationsCodeLensEnabled || methodImplementationsCodeLensEnabled;
+ return referencesCodeLensEnabled || !implementationsCodeLens.equals("none");
}
public boolean isJavaFormatEnabled() {
@@ -2462,8 +2441,8 @@ public boolean isChainCompletionEnabled() {
}
/**
- * update the null analysis options of all projects based on the null analysis mode
- * Returns the list of enabled clean ups.
+ * update the null analysis options of all projects based on the null analysis
+ * mode Returns the list of enabled clean ups.
*
* @return the list of enabled clean ups
*/
@@ -2506,8 +2485,12 @@ private boolean updateAnnotationNullAnalysisOptions(boolean enabled) {
/**
* update the null analysis options of given project
- * @param javaProject the java project to update the annotation-based null analysis options
- * @param enabled specific whether the null analysis is enabled
+ *
+ * @param javaProject
+ * the java project to update the annotation-based null analysis
+ * options
+ * @param enabled
+ * specific whether the null analysis is enabled
* @return whether the options of the given project are changed or not
*/
public boolean updateAnnotationNullAnalysisOptions(IJavaProject javaProject, boolean enabled) {
@@ -2623,10 +2606,15 @@ private String findTypeInProject(IJavaProject javaProject, String annotationType
}
/**
- * generates the null analysis options of the given nonnull type and nullable type
- * @param nonnullType the given nonnull type
- * @param nullableType the given nullable type
- * @return the map contains the null analysis options, if both given types are null, will return default null analysis options
+ * generates the null analysis options of the given nonnull type and nullable
+ * type
+ *
+ * @param nonnullType
+ * the given nonnull type
+ * @param nullableType
+ * the given nullable type
+ * @return the map contains the null analysis options, if both given types are
+ * null, will return default null analysis options
*/
private Map generateProjectNullAnalysisOptions(String nonnullType, String nullableType, String nonnullbydefaultType) {
Map options = new HashMap<>();
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java
index 8456f3b7b4..b1a3e10a7b 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CodeLensHandlerTest.java
@@ -163,7 +163,7 @@ public void testGetCodeLensSymbols() throws Exception {
@Test
@SuppressWarnings("unchecked")
public void testGetCodeLensSymbolsForClass() throws Exception {
- Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
+ Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_KEY, "types"));
Mockito.reset(preferenceManager);
when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
handler = new CodeLensHandler(preferenceManager);
@@ -214,7 +214,7 @@ public void testDisableCodeLensSymbols() throws Exception {
@Test
public void testEnableImplementationsCodeLensSymbols() throws Exception {
- Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
+ Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_KEY, "types"));
Mockito.reset(preferenceManager);
when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
handler = new CodeLensHandler(preferenceManager);
@@ -238,7 +238,7 @@ public void testEnableImplementationsCodeLensSymbols() throws Exception {
@Test
public void testDisableImplementationsCodeLensSymbols() throws Exception {
- Preferences noImplementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "false"));
+ Preferences noImplementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_KEY, "types"));
Mockito.reset(preferenceManager);
when(preferenceManager.getPreferences()).thenReturn(noImplementationsCodeLenses);
Preferences noReferencesCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.REFERENCES_CODE_LENS_ENABLED_KEY, "false"));