Skip to content

Commit

Permalink
refactor: set display name on java server side
Browse files Browse the repository at this point in the history
  • Loading branch information
mamilic committed Oct 27, 2024
1 parent 18527a1 commit ecced17
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -273,11 +274,32 @@ public static PackageRootNode createNodeForPackageFragmentRoot(IPackageFragmentR
for (IClasspathAttribute attribute : resolvedClasspathEntry.getExtraAttributes()) {
node.setMetaDataValue(attribute.getName(), attribute.getValue());
}

String computedDisplayName = computeDisplayName(node);
if (StringUtils.isNotBlank(computedDisplayName)) {
node.setDisplayName(computedDisplayName);
}
}

return node;
}

private static String computeDisplayName(PackageRootNode node) {
if (node.getMetaData() == null || node.getMetaData().isEmpty()) {
return node.getName();
}

String version = (String) node.getMetaData().get("maven.version");
String groupId = (String) node.getMetaData().get("maven.groupId");
String artifactId = (String) node.getMetaData().get("maven.artifactId");

if (StringUtils.isBlank(version) || StringUtils.isBlank(groupId) || StringUtils.isBlank(artifactId)) {
return node.getName();
}

return groupId + ":" + artifactId + ":" + version;
}

/**
* Get the correspond node of classpath, it may be container or a package root.
*
Expand Down
4 changes: 2 additions & 2 deletions src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class ContainerNode extends DataNode {
return this._containerType;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
public isMavenType(): boolean {
return this._containerType == ContainerType.Maven;
}

protected async loadData(): Promise<INodeData[]> {
Expand Down
6 changes: 5 additions & 1 deletion src/views/dataNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class DataNode extends ExplorerNode {

public getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(
this.getLabel(),
this._nodeData.displayName || this._nodeData.name,
this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None,
);
item.description = this.description;
Expand All @@ -42,6 +42,10 @@ export abstract class DataNode extends ExplorerNode {
return item;
}

public getDisplayName(): string {
return this._nodeData.displayName || this._nodeData.name;
}

public get nodeData(): INodeData {
return this._nodeData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RelativePattern, TreeDataProvider, TreeItem, Uri, window, workspace,
} from "vscode";
import { instrumentOperationAsVsCodeCommand, sendError } from "vscode-extension-telemetry-wrapper";
import { contextManager } from "../../extension.bundle";
import { ContainerNode, contextManager } from "../../extension.bundle";

Check failure on line 10 in src/views/dependencyDataProvider.ts

View workflow job for this annotation

GitHub Actions / Linux-UI

'ContainerNode' is declared but its value is never read.

Check failure on line 10 in src/views/dependencyDataProvider.ts

View workflow job for this annotation

GitHub Actions / Linux

'ContainerNode' is declared but its value is never read.

Check failure on line 10 in src/views/dependencyDataProvider.ts

View workflow job for this annotation

GitHub Actions / macOS

'ContainerNode' is declared but its value is never read.
import { Commands } from "../commands";
import { Context } from "../constants";
import { appendOutput, executeExportJarTask } from "../tasks/buildArtifact/BuildArtifactTaskProvider";
Expand Down Expand Up @@ -126,7 +126,7 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {

if (children) {
children.sort((a, b) => {
return a.getLabel().localeCompare(b.getLabel());
return a.getDisplayName().localeCompare(b.getDisplayName());
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/documentSymbolNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DocumentSymbolNode extends ExplorerNode {
super(parent);
}

public getLabel(): string {
public getDisplayName(): string {
return this.symbolInfo.name;
}

Expand All @@ -43,7 +43,7 @@ export class DocumentSymbolNode extends ExplorerNode {
}

public getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(this.getLabel(),
const item = new TreeItem(this.getDisplayName(),
this.symbolInfo?.children?.length ? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None);
item.iconPath = this.iconPath;
Expand Down
2 changes: 1 addition & 1 deletion src/views/explorerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export abstract class ExplorerNode {

public abstract computeContextValue(): string | undefined;

public abstract getLabel(): string;
public abstract getDisplayName(): string;
}
4 changes: 0 additions & 4 deletions src/views/fileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export class FileNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected hasChildren(): boolean {
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/folderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export class FolderNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({
kind: NodeKind.Folder,
Expand Down
4 changes: 0 additions & 4 deletions src/views/packageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export class PackageNode extends DataNode {
return parentData.entryKind === PackageRootKind.K_SOURCE || parentData.kind === NodeKind.Project;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({
kind: NodeKind.Package,
Expand Down
9 changes: 1 addition & 8 deletions src/views/packageRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { INodeData, NodeKind } from "../java/nodeData";
import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData";
import { Settings } from "../settings";
import { isTest } from "../utility";
import { ContainerNode, ContainerType } from "./containerNode";
import { ContainerNode } from "./containerNode";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { ProjectNode } from "./projectNode";
Expand All @@ -20,13 +20,6 @@ export class PackageRootNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
if (this._nodeData.metaData?.['maven.groupId']) {
return `${this._nodeData.metaData?.['maven.groupId']}:${this._nodeData.metaData?.['maven.artifactId']}:${this._nodeData.metaData?.['maven.version']}`;
}
return this._nodeData.displayName ?? this._nodeData.name;
}

public isSourceRoot(): boolean {
return (<IPackageRootNodeData>this.nodeData).entryKind === PackageRootKind.K_SOURCE;
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/projectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ export class ProjectNode extends DataNode {
return false;
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({ kind: NodeKind.Project, projectUri: this.nodeData.uri });
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/workspaceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export class WorkspaceNode extends DataNode {
super(nodeData, parent);
}

public getLabel(): string {
return this._nodeData.displayName ?? this._nodeData.name;
}

protected async loadData(): Promise<INodeData[] | undefined> {
if (!this.nodeData.uri) {
return undefined;
Expand Down

0 comments on commit ecced17

Please sign in to comment.