From 5f0fb0c9e4b05e1ee27719f69a047589edd3c7b5 Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Wed, 4 Dec 2024 09:21:36 -0800 Subject: [PATCH] Cleanup: introduce some static strings into PubRoot (#7844) --- flutter-idea/src/io/flutter/pub/PubRoot.java | 14 +++++++------- flutter-idea/src/io/flutter/run/MainFile.java | 4 ++-- .../ide/FlutterCodeInsightFixtureTestCase.java | 7 ++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/flutter-idea/src/io/flutter/pub/PubRoot.java b/flutter-idea/src/io/flutter/pub/PubRoot.java index e731946dd..c5cff6fad 100644 --- a/flutter-idea/src/io/flutter/pub/PubRoot.java +++ b/flutter-idea/src/io/flutter/pub/PubRoot.java @@ -6,10 +6,9 @@ package io.flutter.pub; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -34,10 +33,11 @@ * That is, a directory containing (at a minimum) a pubspec.yaml file. */ public class PubRoot { + public static final String ANALYSIS_OPTIONS_YAML = "analysis_options.yaml"; + public static final String DOT_DART_TOOL = ".dart_tool"; + public static final String DOT_PACKAGES = ".packages"; public static final String PUBSPEC_YAML = "pubspec.yaml"; - private static final Logger LOG = Logger.getInstance(PubRoot.class); - @NotNull private final VirtualFile root; @@ -176,7 +176,7 @@ public String getRelativePath(@NotNull VirtualFile file) { return path.substring(root.length() + 1); } - private static final String /*@NotNull*/ [] TEST_DIRS = new String[] { // TODO 2022.1 + private static final String /*@NotNull*/[] TEST_DIRS = new String[]{ // TODO 2022.1 "/test/", "/integration_test/", "/test_driver/", @@ -266,7 +266,7 @@ public boolean isNonEditableFlutterModule() { @Nullable public VirtualFile getPackageConfigFile() { - final VirtualFile tools = root.findChild(".dart_tool"); + final VirtualFile tools = root.findChild(DOT_DART_TOOL); if (tools == null || !tools.isDirectory()) { return null; } @@ -280,7 +280,7 @@ public VirtualFile getPackageConfigFile() { @Nullable public VirtualFile getPackagesFile() { // Obsolete by Flutter 2.0 - final VirtualFile packages = root.findChild(".packages"); + final VirtualFile packages = root.findChild(DOT_PACKAGES); if (packages != null && !packages.isDirectory()) { return packages; } diff --git a/flutter-idea/src/io/flutter/run/MainFile.java b/flutter-idea/src/io/flutter/run/MainFile.java index 2c30b6f40..959ba9334 100644 --- a/flutter-idea/src/io/flutter/run/MainFile.java +++ b/flutter-idea/src/io/flutter/run/MainFile.java @@ -137,8 +137,8 @@ private static boolean isAppDir(@NotNull VirtualFile dir, @NotNull Project proje assert(!WorkspaceCache.getInstance(project).isBazel()); return dir.isDirectory() && ( dir.findChild(PubRoot.PUBSPEC_YAML) != null || - dir.findChild(".dart_tool") != null || - dir.findChild(".packages") != null + dir.findChild(PubRoot.DOT_DART_TOOL) != null || + dir.findChild(PubRoot.DOT_PACKAGES) != null ); } diff --git a/flutter-idea/testSrc/unit/io/flutter/ide/FlutterCodeInsightFixtureTestCase.java b/flutter-idea/testSrc/unit/io/flutter/ide/FlutterCodeInsightFixtureTestCase.java index da6899dad..4dbb886da 100644 --- a/flutter-idea/testSrc/unit/io/flutter/ide/FlutterCodeInsightFixtureTestCase.java +++ b/flutter-idea/testSrc/unit/io/flutter/ide/FlutterCodeInsightFixtureTestCase.java @@ -41,7 +41,7 @@ public void setUp() throws Exception { final VirtualFile contentRoot = allContentRoots[0]; final VirtualFile pubspec = contentRoot.createChildData(this, PubRoot.PUBSPEC_YAML); pubspec.setBinaryContent(SamplePubspec.getBytes(StandardCharsets.UTF_8)); - final VirtualFile dartTool = contentRoot.createChildDirectory(this, ".dart_tool"); + final VirtualFile dartTool = contentRoot.createChildDirectory(this, PubRoot.DOT_DART_TOOL); final VirtualFile config = dartTool.createChildData(this, "package_config.json"); config.setBinaryContent(SampleConfig.getBytes(StandardCharsets.UTF_8)); } @@ -58,7 +58,7 @@ public void tearDown() throws Exception { final VirtualFile root = Objects.requireNonNull(ModuleRootManager.getInstance(getModule())).getContentRoots()[0]; assert root != null; final VirtualFile pubspec = root.findChild(PubRoot.PUBSPEC_YAML); - final VirtualFile dartTool = root.findChild(".dart_tool"); + final VirtualFile dartTool = root.findChild(PubRoot.DOT_DART_TOOL); if (pubspec != null && dartTool != null) { final VirtualFile config = dartTool.findChild("package_config.json"); WriteAction.run(() -> { @@ -66,7 +66,8 @@ public void tearDown() throws Exception { if (config != null) config.delete(this); dartTool.delete(this); }); - final List toUnexclude = Arrays.asList(root.getUrl() + "/build", root.getUrl() + "/.pub", root.getUrl() + "/.dart_tool"); + final List toUnexclude = + Arrays.asList(root.getUrl() + "/build", root.getUrl() + "/.pub", root.getUrl() + "/" + PubRoot.DOT_DART_TOOL); ModuleRootModificationUtil.updateExcludedFolders(getModule(), root, toUnexclude, Collections.emptyList()); } }