From 12e2012bf9f68d1c6e30d5cdaa17974f6aa44714 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Tue, 2 Aug 2022 15:44:05 +0800 Subject: [PATCH] fix: Do not allow craeting new types in resource folder Signed-off-by: Sheng Chen --- src/explorerCommands/new.ts | 7 ++++--- src/views/packageRootNode.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/explorerCommands/new.ts b/src/explorerCommands/new.ts index 36a3d470..ba93aeb4 100644 --- a/src/explorerCommands/new.ts +++ b/src/explorerCommands/new.ts @@ -10,6 +10,7 @@ import { Commands } from "../../extension.bundle"; import { ExtensionName } from "../constants"; import { NodeKind } from "../java/nodeData"; import { DataNode } from "../views/dataNode"; +import { resourceRoots } from "../views/packageRootNode"; import { checkJavaQualifiedName } from "./utility"; export async function newJavaClass(node?: DataNode): Promise { @@ -35,7 +36,7 @@ export async function newJavaClass(node?: DataNode): Promise { // User canceled return; } else if (packageFsPath.length === 0) { - return newUntiledJavaFile(); + return newUntitledJavaFile(); } const className: string | undefined = await window.showInputBox({ @@ -67,7 +68,7 @@ export async function newJavaClass(node?: DataNode): Promise { workspace.applyEdit(workspaceEdit); } -async function newUntiledJavaFile(): Promise { +async function newUntitledJavaFile(): Promise { await commands.executeCommand("workbench.action.files.newUntitledFile"); const textEditor: TextEditor | undefined = window.activeTextEditor; if (!textEditor) { @@ -147,7 +148,7 @@ async function getPackageFsPath(node: DataNode): Promise { if (node.nodeData.kind === NodeKind.Project) { const childrenNodes: DataNode[] = await node.getChildren() as DataNode[]; const packageRoots: any[] = childrenNodes.filter((child) => { - return child.nodeData.kind === NodeKind.PackageRoot; + return child.nodeData.kind === NodeKind.PackageRoot && !resourceRoots.includes(child.name); }); if (packageRoots.length < 1) { // This might happen for an invisible project with "_" as its root diff --git a/src/views/packageRootNode.ts b/src/views/packageRootNode.ts index 90a6bd29..c91b39e1 100644 --- a/src/views/packageRootNode.ts +++ b/src/views/packageRootNode.ts @@ -104,4 +104,4 @@ export class PackageRootNode extends DataNode { } } -const resourceRoots: string[] = ["src/main/resources", "src/test/resources"]; +export const resourceRoots: string[] = ["src/main/resources", "src/test/resources"];