Skip to content

Commit 6c9d156

Browse files
authored
fix: Do not allow craeting new types in resource folder (#685)
Signed-off-by: Sheng Chen <[email protected]>
1 parent 118eb96 commit 6c9d156

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/explorerCommands/new.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Commands } from "../../extension.bundle";
1010
import { ExtensionName } from "../constants";
1111
import { NodeKind } from "../java/nodeData";
1212
import { DataNode } from "../views/dataNode";
13+
import { resourceRoots } from "../views/packageRootNode";
1314
import { checkJavaQualifiedName } from "./utility";
1415

1516
export async function newJavaClass(node?: DataNode): Promise<void> {
@@ -35,7 +36,7 @@ export async function newJavaClass(node?: DataNode): Promise<void> {
3536
// User canceled
3637
return;
3738
} else if (packageFsPath.length === 0) {
38-
return newUntiledJavaFile();
39+
return newUntitledJavaFile();
3940
}
4041

4142
const className: string | undefined = await window.showInputBox({
@@ -67,7 +68,7 @@ export async function newJavaClass(node?: DataNode): Promise<void> {
6768
workspace.applyEdit(workspaceEdit);
6869
}
6970

70-
async function newUntiledJavaFile(): Promise<void> {
71+
async function newUntitledJavaFile(): Promise<void> {
7172
await commands.executeCommand("workbench.action.files.newUntitledFile");
7273
const textEditor: TextEditor | undefined = window.activeTextEditor;
7374
if (!textEditor) {
@@ -147,7 +148,7 @@ async function getPackageFsPath(node: DataNode): Promise<string | undefined> {
147148
if (node.nodeData.kind === NodeKind.Project) {
148149
const childrenNodes: DataNode[] = await node.getChildren() as DataNode[];
149150
const packageRoots: any[] = childrenNodes.filter((child) => {
150-
return child.nodeData.kind === NodeKind.PackageRoot;
151+
return child.nodeData.kind === NodeKind.PackageRoot && !resourceRoots.includes(child.name);
151152
});
152153
if (packageRoots.length < 1) {
153154
// This might happen for an invisible project with "_" as its root

src/views/packageRootNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ export class PackageRootNode extends DataNode {
104104
}
105105
}
106106

107-
const resourceRoots: string[] = ["src/main/resources", "src/test/resources"];
107+
export const resourceRoots: string[] = ["src/main/resources", "src/test/resources"];

0 commit comments

Comments
 (0)