Skip to content

Commit

Permalink
Simplify and clean-up code as suggested by @rubenporras
Browse files Browse the repository at this point in the history
  • Loading branch information
travkin79 committed Aug 13, 2024
1 parent 4073214 commit 206d0b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,8 @@ public void uninstall() {

@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (viewer == null || outlineViewerInput == null) {
return;
}

if (event.getKey().startsWith(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX)) {
if (viewer != null
&& event.getKey().startsWith(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX)) {
viewer.getControl().getDisplay().asyncExec(() -> {
if(viewer.getTree().isDisposed()) {
return;
Expand Down Expand Up @@ -341,33 +338,18 @@ public Object[] getChildren(Object parentElement) {
.toArray(Object[]::new);
}

/**
* Decide whether to hide the given element or not.
* Default implementation hides elements depending on a preference
* that determines which {@link SymbolKind}s
* (property in {@link DocumentSymbol}, {@link DocumentSymbolWithURI}s, and {@link SymbolInformation})
* are to be hidden in the outline view.
* Sub-classes may override this method to add language-specific filtering.
*
* @param element an outline view contents element to be checked
* @return <code>true</code> if the given element is not to be shown in the outline view
*/
protected boolean hideElement(Object element) {
private boolean hideElement(Object element) {
SymbolKind kind = null;

if (element instanceof DocumentSymbol) {
kind = ((DocumentSymbol) element).getKind();
} else if (element instanceof DocumentSymbolWithURI) {
kind = ((DocumentSymbolWithURI) element).symbol.getKind();
} else if (element instanceof SymbolInformation) {
kind = ((SymbolInformation) element).getKind();
}

if (OutlineViewHideSymbolKindMenuContributor.isHideSymbolKind(kind)) {
return true;
if (element instanceof DocumentSymbol documentSymbol) {
kind = documentSymbol.getKind();
} else if (element instanceof DocumentSymbolWithURI documentSymbolWithURI) {
kind = documentSymbolWithURI.symbol.getKind();
} else if (element instanceof SymbolInformation symbolInformation) {
kind = symbolInformation.getKind();
}

return false;
return OutlineViewHideSymbolKindMenuContributor.isHideSymbolKind(kind);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected IContributionItem[] getContributionItems() {

@Override
public int compare(SymbolKind sk1, SymbolKind sk2) {
return sk1.name().compareToIgnoreCase(sk2.name());
return sk1.name().compareTo(sk2.name());
}

})
Expand Down

0 comments on commit 206d0b9

Please sign in to comment.