Skip to content

Remove unused code, mostly from the utils directory #7704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions flutter-idea/src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,6 @@ public long getModificationStamp() {
private FlutterUtils() {
}

/**
* This method exists for compatibility with older IntelliJ API versions.
* <p>
* `Application.invokeAndWait(Runnable)` doesn't exist pre 2016.3.
*/
public static void invokeAndWait(@NotNull Runnable runnable) throws ProcessCanceledException {
ApplicationManager.getApplication().invokeAndWait(
runnable,
ModalityState.defaultModalityState());
}

public static boolean isFlutteryFile(@NotNull VirtualFile file) {
return isDartFile(file) || PubRoot.isPubspec(file);
}

public static boolean couldContainWidgets(@Nullable Project project, @Nullable VirtualFile file) {
// Skip nulls, temp file used to show things like files downloaded from the VM, non-local files
return file != null &&
Expand Down Expand Up @@ -155,14 +140,6 @@ public static void warn(@NotNull Logger logger, @NotNull String message, @NotNul
logger.warn(message, t);
}

private static int getBaselineVersion() {
final ApplicationInfo appInfo = ApplicationInfo.getInstance();
if (appInfo != null) {
return appInfo.getBuild().getBaselineVersion();
}
return -1;
}

public static void disableGradleProjectMigrationNotification(@NotNull Project project) {
final String showMigrateToGradlePopup = "show.migrate.to.gradle.popup";
final PropertiesComponent properties = PropertiesComponent.getInstance(project);
Expand All @@ -172,10 +149,6 @@ public static void disableGradleProjectMigrationNotification(@NotNull Project pr
}
}

public static boolean exists(@Nullable VirtualFile file) {
return file != null && file.exists();
}

/**
* Test if the given element is contained in a module with a pub root that declares a flutter dependency.
*/
Expand Down Expand Up @@ -356,41 +329,13 @@ public static boolean isXcodeWorkspaceFileName(@NotNull String name) {
return name.endsWith(".xcworkspace");
}

/**
* Checks whether the given commandline executes cleanly.
*
* @param cmd the command
* @return true if the command runs cleanly
*/
public static boolean runsCleanly(@NotNull GeneralCommandLine cmd) {
try {
return ExecUtil.execAndGetOutput(cmd).getExitCode() == 0;
}
catch (ExecutionException e) {
return false;
}
}

@NotNull
public static PluginId getPluginId() {
final PluginId pluginId = PluginId.findId("io.flutter", "");
assert pluginId != null;
return pluginId;
}

/**
* Given some plugin id, this method returns the {@link IdeaPluginDescriptor}, or null if the plugin is not installed.
*/
@Nullable
public static IdeaPluginDescriptor getPluginDescriptor(@NotNull String pluginId) {
for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) {
if (descriptor.getPluginId().getIdString().equals(pluginId)) {
return descriptor;
}
}
return null;
}

/**
* Returns a structured object with information about the Flutter properties of the given
* pubspec file.
Expand Down Expand Up @@ -493,36 +438,6 @@ protected void addImplicitResolvers() {
}
}

public static boolean isAndroidxProject(@NotNull Project project) {
@SystemIndependent final String basePath = project.getBasePath();
assert basePath != null;
final VirtualFile projectDir = LocalFileSystem.getInstance().findFileByPath(basePath);
assert projectDir != null;
VirtualFile androidDir = getFlutterManagedAndroidDir(projectDir);
if (androidDir == null) {
androidDir = getAndroidProjectDir(projectDir);
if (androidDir == null) {
return false;
}
}
final VirtualFile propFile = androidDir.findChild("gradle.properties");
if (propFile == null) {
return false;
}
final Properties properties = new Properties();
try {
properties.load(new InputStreamReader(propFile.getInputStream(), Charsets.UTF_8));
}
catch (IOException ex) {
return false;
}
final String value = properties.getProperty("android.useAndroidX");
if (value != null) {
return Boolean.parseBoolean(value);
}
return false;
}

@Nullable
private static VirtualFile getAndroidProjectDir(VirtualFile dir) {
return (dir.findChild("app") == null) ? null : dir;
Expand Down
36 changes: 0 additions & 36 deletions flutter-idea/src/io/flutter/dart/DartPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
package io.flutter.dart;

import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Version;
import com.jetbrains.lang.dart.analyzer.DartAnalysisServerService;
import com.jetbrains.lang.dart.ide.actions.DartPubActionBase;
import com.jetbrains.lang.dart.sdk.DartSdk;
import com.jetbrains.lang.dart.sdk.DartSdkLibUtil;
import com.jetbrains.lang.dart.sdk.DartSdkUpdateOption;
import com.jetbrains.lang.dart.sdk.DartSdkUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Objects;

/**
Expand All @@ -38,8 +32,6 @@ public class DartPlugin {
@NotNull
private static final DartPlugin INSTANCE = new DartPlugin();

private Version myVersion;

@NotNull
public static DartPlugin getInstance() {
return INSTANCE;
Expand All @@ -62,14 +54,6 @@ public static void ensureDartSdkConfigured(@NotNull Project project, @NotNull St
DartSdkLibUtil.ensureDartSdkConfigured(project, sdkHomePath);
}

public static void disableDartSdk(@NotNull Collection<Module> modules) {
DartSdkLibUtil.disableDartSdk(modules);
}

public static boolean isDartSdkHome(@Nullable String path) {
return DartSdkUtil.isDartSdkHome(path);
}

public static boolean isPubActionInProgress() {
return DartPubActionBase.isInProgress();
}
Expand All @@ -86,26 +70,6 @@ public static boolean isDartTestConfiguration(@NotNull ConfigurationType type) {
return type.getId().equals("DartTestRunConfigurationType");
}

public static DartSdkUpdateOption doCheckForUpdates() {
return DartSdkUpdateOption.getDartSdkUpdateOption();
}

public static void setCheckForUpdates(@NotNull DartSdkUpdateOption sdkUpdateOption) {
DartSdkUpdateOption.setDartSdkUpdateOption(sdkUpdateOption);
}

/**
* Return the {@link Version} of the currently installed Dart Plugin.
*/
public Version getVersion() {
if (myVersion == null) {
final IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("Dart"));
assert (descriptor != null);
myVersion = Objects.requireNonNull(Version.parseVersion(Objects.requireNonNull(descriptor.getVersion())));
}
return myVersion;
}

/**
* Return the {@link DartAnalysisServerService} instance for the passed {@link Project}.
*/
Expand Down
1 change: 0 additions & 1 deletion flutter-idea/src/io/flutter/dart/DartPsiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static PsiElement getNamedArgumentExpression(@NotNull DartArguments argum
assert namedArgument != null;
final DartExpression nameExpression = namedArgument.getParameterReferenceExpression();
assert nameExpression != null;
final PsiElement childId = nameExpression.getFirstChild();
final PsiElement child = nameExpression.getFirstChild();
if (name.equals(child != null ? child.getText() : "")) {
return namedArgument.getExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ private void updateActiveEditors() {

// Remove obsolete outline listeners.
final List<String> obsoletePaths = new ArrayList<>();
FlutterDartAnalysisServer analysisServer = getAnalysisServer();

synchronized (outlineListeners) {
for (final String path : outlineListeners.keySet()) {
Expand Down
13 changes: 0 additions & 13 deletions flutter-idea/src/io/flutter/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ public boolean deleteFile(String path) {
}
return true;
}

public void loadClass(ClassLoader classLoader, String path) throws Exception {
final UrlClassLoader urlClassLoader = (UrlClassLoader) classLoader;

final File file = new File(path);
if (!file.exists()) {
throw new Exception("File does not exist: " + file.getAbsolutePath());
}

final URL url = file.toURI().toURL();
urlClassLoader.addURL(url);
}

/**
* Loads a list of file paths with a class loader.
*
Expand Down
54 changes: 0 additions & 54 deletions flutter-idea/src/io/flutter/utils/HtmlBuilder.java

This file was deleted.

30 changes: 0 additions & 30 deletions flutter-idea/src/io/flutter/utils/IconPreviewGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,6 @@ private void drawGlyph(String codepoint, Graphics2D graphics, FontRenderContext
graphics.drawString(codepoint, x0, y0);
}

@Nullable
public static VirtualFile findAssetMapFor(@NotNull DartComponent dartClass) {
final ASTNode node = dartClass.getNode();
if (DartTokenTypes.CLASS_DEFINITION != node.getElementType()) {
return null;
}
final DartFile psiElement = (DartFile)node.getPsi().getParent();
final VirtualFile file = psiElement.getVirtualFile();
VirtualFile map = findAssetMapIn(file.getParent());
if (map != null) {
return map;
}
final PsiElement identifier = dartClass.getNameIdentifier();
if (identifier == null) {
return null;
}
final String className = AstBufferUtil.getTextSkippingWhitespaceComments(identifier.getNode());
final URL resource = IconPreviewGenerator.class.getResource("/iconAssetMaps/" + className + "/asset_map.yaml");
if (resource == null) {
return null;
}
try {
final URI uri = resource.toURI();
return LocalFileSystem.getInstance().findFileByNioFile(Paths.get(uri));
}
catch (URISyntaxException e) {
return null;
}
}

@Nullable
public static VirtualFile findAssetMapIn(@NotNull VirtualFile dartClass) {
VirtualFile dir = dartClass.getParent();
Expand Down
17 changes: 0 additions & 17 deletions flutter-idea/src/io/flutter/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ public static int getIntMember(@NotNull JsonObject json, @NotNull String memberN
return value instanceof JsonNull ? -1 : value.getAsInt();
}

@NotNull
public static List<String> getValues(@NotNull JsonObject json, @NotNull String member) {
if (!json.has(member)) {
return Collections.emptyList();
}

final JsonArray rawValues = json.getAsJsonArray(member);
final ArrayList<String> values = new ArrayList<>(rawValues.size());
rawValues.forEach(element -> values.add(element.getAsString()));

return values;
}

// JsonObject.keySet() is defined in 2.8.6 but not 2.7.
// The 2020.3 version of Android Studio includes both, and 2.7 is first on the class path.
public static Set<String> getKeySet(JsonObject obj) {
Expand All @@ -63,10 +50,6 @@ public static Set<String> getKeySet(JsonObject obj) {
return strings;
}

public static boolean hasJsonData(@Nullable String data) {
return StringUtils.isNotEmpty(data) && !Objects.equals(data, "null");
}

/**
* Parses the specified JSON string into a JsonElement.
*/
Expand Down
Loading
Loading