Skip to content

Commit

Permalink
Fixed #75: Added support for configuring type of reference to show
Browse files Browse the repository at this point in the history
Added settings to configure whether to show reference on
- class
- method
- or both

Change-Id: I787f018789c308faa41436cb3184aea6f9ef2f28
Signed-off-by: Gayan Perera <gayanper@gmail.com>
  • Loading branch information
gayanper committed Oct 3, 2018
1 parent 56457ca commit 0745573
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
Expand Up @@ -64,6 +64,10 @@ public class JavaElementCodeMiningProvider extends AbstractCodeMiningProvider im

private final boolean showReferences;

private final boolean showReferencesOnClass;

private final boolean showReferencesOnMethod;

private final boolean showReferencesAtLeastOne;

private final boolean showImplementations;
Expand All @@ -73,6 +77,10 @@ public class JavaElementCodeMiningProvider extends AbstractCodeMiningProvider im
public JavaElementCodeMiningProvider() {
showReferences = JavaPreferencesPropertyTester
.isEnabled(MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_REFERENCES);
showReferencesOnClass = JavaPreferencesPropertyTester
.isEnabled(MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_CLASS_REFERENCES);
showReferencesOnMethod = JavaPreferencesPropertyTester
.isEnabled(MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_METHOD_REFERENCES);
showReferencesAtLeastOne = JavaPreferencesPropertyTester
.isEnabled(MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_REFERENCES_AT_LEAST_ONE);
showImplementations = JavaPreferencesPropertyTester
Expand Down Expand Up @@ -129,8 +137,11 @@ private void collectMinings(ITypeRoot unit, ITextEditor textEditor, IJavaElement
}
if (showReferences) {
try {
minings.add(new JavaReferenceCodeMining(element, (JavaEditor) textEditor, viewer.getDocument(),
this, showReferencesAtLeastOne));
if ((showReferencesOnClass && (element.getElementType() == IJavaElement.TYPE))
|| (showReferencesOnMethod && (element.getElementType() == IJavaElement.METHOD))) {
minings.add(new JavaReferenceCodeMining(element, (JavaEditor) textEditor, viewer.getDocument(),
this, showReferencesAtLeastOne));
}
} catch (BadLocationException e) {
// Should never occur
}
Expand Down
Expand Up @@ -30,6 +30,12 @@ public class JavaEditorCodeMiningConfigurationBlock extends OptionsConfiguration
private static final Key PREF_SHOW_REFERENCES = getJDTUIKey(
MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_REFERENCES);

private static final Key PREF_SHOW_CLASS_REFERENCES = getJDTUIKey(
MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_CLASS_REFERENCES);

private static final Key PREF_SHOW_METHOD_REFERENCES = getJDTUIKey(
MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_METHOD_REFERENCES);

private static final Key PREF_SHOW_REFERENCES_AT_LEAST_ONE = getJDTUIKey(
MyPreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_REFERENCES_AT_LEAST_ONE);

Expand Down Expand Up @@ -116,14 +122,14 @@ public JavaEditorCodeMiningConfigurationBlock(IStatusChangeListener context,
}

public static Key[] getAllKeys() {
return new Key[] { PREF_SHOW_REFERENCES, PREF_SHOW_REFERENCES_AT_LEAST_ONE, PREF_SHOW_IMPLEMENTATIONS,
PREF_SHOW_IMPLEMENTATIONS_AT_LEAST_ONE, PREF_SHOW_END_STATEMENT,
PREF_SHOW_END_STATEMENT_MIN_LINE_NUMBER, PREF_SHOW_MAIN_RUN, PREF_SHOW_MAIN_DEBUG,
PREF_SHOW_JAVA10_VAR_TYPE, PREF_SHOW_METHOD_PARAMETER_NAMES, PREF_SHOW_METHOD_PARAMETER_TYPES,
PREF_SHOW_METHOD_PARAMETER_ONLY_FOR_LITERAL, PREF_SHOW_METHOD_PARAMETER_BY_USING_FILTERS,
PREF_SHOW_METHOD_PARAMETER_FILTERS_ENABLED, PREF_SHOW_METHOD_PARAMETER_FILTERS_DISABLED,
PREF_SHOW_JUNIT_STATUS, PREF_SHOW_JUNIT_RUN, PREF_SHOW_JUNIT_DEBUG,
PREF_SHOW_VARIABLE_VALUE_WHILE_DEBUGGING, PREF_SHOW_REVISION_RECENT_CHANGE,
return new Key[] { PREF_SHOW_REFERENCES, PREF_SHOW_CLASS_REFERENCES, PREF_SHOW_METHOD_REFERENCES,
PREF_SHOW_REFERENCES_AT_LEAST_ONE, PREF_SHOW_IMPLEMENTATIONS, PREF_SHOW_IMPLEMENTATIONS_AT_LEAST_ONE,
PREF_SHOW_END_STATEMENT, PREF_SHOW_END_STATEMENT_MIN_LINE_NUMBER, PREF_SHOW_MAIN_RUN,
PREF_SHOW_MAIN_DEBUG, PREF_SHOW_JAVA10_VAR_TYPE, PREF_SHOW_METHOD_PARAMETER_NAMES,
PREF_SHOW_METHOD_PARAMETER_TYPES, PREF_SHOW_METHOD_PARAMETER_ONLY_FOR_LITERAL,
PREF_SHOW_METHOD_PARAMETER_BY_USING_FILTERS, PREF_SHOW_METHOD_PARAMETER_FILTERS_ENABLED,
PREF_SHOW_METHOD_PARAMETER_FILTERS_DISABLED, PREF_SHOW_JUNIT_STATUS, PREF_SHOW_JUNIT_RUN,
PREF_SHOW_JUNIT_DEBUG, PREF_SHOW_VARIABLE_VALUE_WHILE_DEBUGGING, PREF_SHOW_REVISION_RECENT_CHANGE,
PREF_SHOW_REVISION_RECENT_CHANGE_WITH_AVATAR, PREF_SHOW_REVISION_RECENT_CHANGE_WITH_DATE,
PREF_SHOW_REVISION_AUTHORS };
}
Expand Down Expand Up @@ -202,6 +208,14 @@ private void createGeneralSection(int nColumns, Composite parent) {
fFilteredPrefTree.addCheckBox(inner,
MyPreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showReferences_label, PREF_SHOW_REFERENCES,
TRUE_FALSE, defaultIndent, section);
// - Show references (for Classes)
fFilteredPrefTree.addCheckBox(inner,
MyPreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showReferencesClass_label,
PREF_SHOW_CLASS_REFERENCES, TRUE_FALSE, extraIndent, section);
// - Show references (for Methods)
fFilteredPrefTree.addCheckBox(inner,
MyPreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showReferencesMethod_label,
PREF_SHOW_METHOD_REFERENCES, TRUE_FALSE, extraIndent, section);
// - Show references (Only if there is at least one reference)
fFilteredPrefTree.addCheckBox(inner,
MyPreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showReferences_atLeastOne_label,
Expand Down
Expand Up @@ -16,6 +16,26 @@ public class MyPreferenceConstants {
*/
public static final String EDITOR_JAVA_CODEMINING_SHOW_REFERENCES = "java.codemining.experimental.references"; //$NON-NLS-1$

/**
* A named preference that stores the value for "Show references > Class" codemining.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.14
*/
public static final String EDITOR_JAVA_CODEMINING_SHOW_CLASS_REFERENCES = "java.codemining.experimental.references.classes"; //$NON-NLS-1$

/**
* A named preference that stores the value for "Show references > Method" codemining.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.14
*/
public static final String EDITOR_JAVA_CODEMINING_SHOW_METHOD_REFERENCES = "java.codemining.experimental.references.method"; //$NON-NLS-1$

/**
* A named preference that stores the value for "Show references" only if there
* is at least one reference.
Expand Down
Expand Up @@ -9,6 +9,8 @@ public class MyPreferencesMessages extends NLS {
public static String JavaEditorCodeMiningConfigurationBlock_common_description;
public static String JavaEditorCodeMiningConfigurationBlock_section_general;
public static String JavaEditorCodeMiningConfigurationBlock_showReferences_label;
public static String JavaEditorCodeMiningConfigurationBlock_showReferencesClass_label;
public static String JavaEditorCodeMiningConfigurationBlock_showReferencesMethod_label;
public static String JavaEditorCodeMiningConfigurationBlock_showReferences_atLeastOne_label;
public static String JavaEditorCodeMiningConfigurationBlock_showImplementations_label;
public static String JavaEditorCodeMiningConfigurationBlock_showImplementations_atLeastOne_label;
Expand Down
Expand Up @@ -2,6 +2,8 @@
JavaEditorCodeMiningConfigurationBlock_common_description=&Select the code minings that you wish to enable/disable:
JavaEditorCodeMiningConfigurationBlock_section_general=&General
JavaEditorCodeMiningConfigurationBlock_showReferences_label=Show references
JavaEditorCodeMiningConfigurationBlock_showReferencesClass_label=On classes
JavaEditorCodeMiningConfigurationBlock_showReferencesMethod_label=On methods
JavaEditorCodeMiningConfigurationBlock_showReferences_atLeastOne_label=Only if there is at least one reference
JavaEditorCodeMiningConfigurationBlock_showImplementations_label=Show implementations
JavaEditorCodeMiningConfigurationBlock_showImplementations_atLeastOne_label=Only if there is at least one implementation
Expand Down

0 comments on commit 0745573

Please sign in to comment.