Skip to content

Commit 8a124c8

Browse files
committed
Replace complex instanceof cascade with a switch expression
1 parent 44962f2 commit 8a124c8

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

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)