Skip to content

Commit c350657

Browse files
travkin79rubenporras
authored andcommitted
Replace complex instanceof cascade with a switch expression
1 parent 1d52901 commit c350657

2 files changed

Lines changed: 17 additions & 27 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/symbols/internal/SymbolIconProviderRegistry.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,14 @@ private SymbolIconProvider getIconProvider(Object symbol) {
130130
}
131131

132132
private @Nullable URI getUri(Object symbol) {
133-
if (symbol instanceof SymbolInformation info)
134-
return toUri(info.getLocation().getUri());
135-
if (symbol instanceof WorkspaceSymbol ws)
136-
return toUri(ws.getLocation().map(Location::getUri, WorkspaceSymbolLocation::getUri));
137-
if (symbol instanceof DocumentSymbolWithURI s)
138-
return s.uri;
139-
if (symbol instanceof TypeHierarchyItem item) // for subclasses handling TH
140-
return toUri(item.getUri());
141-
if (symbol instanceof CallHierarchyItem item) // for subclasses handling CH
142-
return toUri(item.getUri());
143-
return null; // plain DocumentSymbol — no URI
133+
return switch (symbol) {
134+
case SymbolInformation info -> toUri(info.getLocation().getUri());
135+
case WorkspaceSymbol ws -> toUri(ws.getLocation().map(Location::getUri, WorkspaceSymbolLocation::getUri));
136+
case DocumentSymbolWithURI s -> s.uri;
137+
case TypeHierarchyItem item -> toUri(item.getUri());
138+
case CallHierarchyItem item -> toUri(item.getUri());
139+
default -> null; // plain DocumentSymbol — no URI
140+
};
144141
}
145142

146143
private @Nullable URI toUri(String uri) {

org.eclipse.lsp4e/src/org/eclipse/lsp4e/ui/SymbolIconProvider.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,15 @@ public class SymbolIconProvider {
5050
* @return the symbol's name or <code>null</code>.
5151
*/
5252
protected @Nullable String getName(Object symbol) {
53-
String name = null;
54-
if (symbol instanceof SymbolInformation info) {
55-
name = info.getName();
56-
} else if (symbol instanceof WorkspaceSymbol wpSymbol) {
57-
name = wpSymbol.getName();
58-
} else if (symbol instanceof DocumentSymbol docSymbol) {
59-
name = docSymbol.getName();
60-
} else if (symbol instanceof DocumentSymbolWithURI symbolWithURI) {
61-
name = symbolWithURI.symbol.getName();
62-
} else if (symbol instanceof CallHierarchyItem callHierItem) {
63-
name = callHierItem.getName();
64-
} else if (symbol instanceof TypeHierarchyItem typeHierItem) {
65-
name = typeHierItem.getName();
66-
}
67-
68-
return name;
53+
return switch (symbol) {
54+
case SymbolInformation info -> info.getName();
55+
case WorkspaceSymbol wpSymbol -> wpSymbol.getName();
56+
case DocumentSymbol docSymbol -> docSymbol.getName();
57+
case DocumentSymbolWithURI symbolWithURI -> symbolWithURI.symbol.getName();
58+
case CallHierarchyItem callHierItem -> callHierItem.getName();
59+
case TypeHierarchyItem typeHierItem -> typeHierItem.getName();
60+
default -> null;
61+
};
6962
}
7063

7164
/**

0 commit comments

Comments
 (0)