Skip to content

Commit

Permalink
remove additional setting and change current implementation setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hopehadfield committed Dec 10, 2024
1 parent 7a6580e commit 40793c2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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
* <ul>
* <li><code>main</code> - Scope for main code</li>
* <li><code>all</code> - Scope for both test and main code</li>
* <li><code>main</code> - Scope for main code</li>
* <li><code>all</code> - Scope for both test and main code</li>
* </ul>
* Any other unknown value will be treated as <code>all</code>.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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);
}

}
Expand All @@ -912,8 +906,7 @@ public Preferences() {
eclipseDownloadSources = false;
mavenUpdateSnapshots = false;
referencesCodeLensEnabled = true;
implementationsCodeLensEnabled = false;
methodImplementationsCodeLensEnabled = false;
implementationsCodeLens = "none";
javaFormatEnabled = true;
javaQuickFixShowAt = LINE;
javaFormatOnTypeEnabled = false;
Expand Down Expand Up @@ -1036,8 +1029,7 @@ public static Preferences createFrom(Map<String, Object> 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);
Expand Down Expand Up @@ -1078,10 +1070,8 @@ public static Preferences createFrom(Map<String, Object> 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);
Expand Down Expand Up @@ -1133,12 +1123,10 @@ public static Preferences createFrom(Map<String, Object> 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);
Expand Down Expand Up @@ -1362,7 +1350,7 @@ public static Preferences createFrom(Map<String, Object> configuration) {
prefs.setNullAnalysisMode(FeatureStatus.fromString(nullAnalysisMode, FeatureStatus.disabled));
List<String> cleanupActionsTemp = getList(configuration, JAVA_CLEANUPS_ACTIONS_ON_SAVE_DEPRECATED, Collections.emptyList());
List<String> cleanupActions = getList(configuration, JAVA_CLEANUPS_ACTIONS, Collections.emptyList());
if(cleanupActions.isEmpty() && !cleanupActionsTemp.isEmpty()) {
if (cleanupActions.isEmpty() && !cleanupActionsTemp.isEmpty()) {
cleanupActions = cleanupActionsTemp;
}
prefs.setCleanUpActions(cleanupActions);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<String, String> generateProjectNullAnalysisOptions(String nonnullType, String nullableType, String nonnullbydefaultType) {
Map<String, String> options = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
Expand Down

0 comments on commit 40793c2

Please sign in to comment.