Skip to content

Migrate usages of ProjectTypeService.getProjectType(..) #7872

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
Dec 20, 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
17 changes: 12 additions & 5 deletions flutter-idea/src/io/flutter/ProjectOpenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.jetbrains.android.facet.AndroidFrameworkDetector;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

/**
* Runs startup actions just after a project is opened, before it's indexed.
*
Expand Down Expand Up @@ -69,9 +71,12 @@ public void runActivity(@NotNull Project project) {
ApplicationManager.getApplication().executeOnPooledThread(() -> {
sdk.queryFlutterConfig("android-studio-dir", false);
});
if (FlutterUtils.isAndroidStudio() && !FLUTTER_PROJECT_TYPE.equals(ProjectTypeService.getProjectType(project))) {
if (!AndroidUtils.isAndroidProject(project)) {
ProjectTypeService.setProjectType(project, FLUTTER_PROJECT_TYPE);
Collection<ProjectType> projectTypes = ProjectTypeService.getProjectTypes(project);
for (ProjectType projectType : projectTypes) {
if (projectType != null && FlutterUtils.isAndroidStudio() && !FLUTTER_PROJECT_TYPE.equals(projectType)) {
if (!AndroidUtils.isAndroidProject(project)) {
ProjectTypeService.setProjectType(project, FLUTTER_PROJECT_TYPE);
}
}
}

Expand Down Expand Up @@ -102,10 +107,12 @@ private static void excludeAndroidFrameworkDetector(@NotNull Project project) {
if (!excludesConfiguration.isExcludedFromDetection(type)) {
excludesConfiguration.addExcludedFramework(type);
}
} catch (NullPointerException ignored) {
}
catch (NullPointerException ignored) {
// If the Android facet has not been configured then getFrameworkType() throws a NPE.
}
} catch (NoClassDefFoundError ignored) {
}
catch (NoClassDefFoundError ignored) {
// This should never happen. But just in case ...
}
}
Expand Down
9 changes: 7 additions & 2 deletions flutter-idea/src/io/flutter/utils/AndroidUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

// based on: org.jetbrains.android.util.AndroidUtils
@SuppressWarnings("LocalCanBeFinal")
public class AndroidUtils {
Expand Down Expand Up @@ -127,7 +129,10 @@ public static boolean isAndroidProject(@Nullable Project project) {
// IntelliJ-created Android project we need to set it. We need to allow an alternative
// name. GradleResourceCompilerConfigurationGenerator depends on "Android".
// TODO(messick) Recognize both native Android Studio and IntelliJ Android projects.
ProjectType projectType = ProjectTypeService.getProjectType(project);
return projectType != null && "Android".equals(projectType.getId());
Collection<ProjectType> projectTypes = ProjectTypeService.getProjectTypes(project);
for (ProjectType projectType : projectTypes) {
return projectType != null && "Android".equals(projectType.getId());
}
return false;
}
}
11 changes: 7 additions & 4 deletions flutter-studio/src/io/flutter/utils/AddToAppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;

import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -71,10 +72,12 @@ public void moduleAdded(@NotNull Project proj, @NotNull Module mod) {
return false;
}
else {
@Nullable ProjectType projectType = ProjectTypeService.getProjectType(project);
if (projectType != null && "Android".equals(projectType.getId())) {
// This is an add-to-app project.
connection.subscribe(DebuggerManagerListener.TOPIC, makeAddToAppAttachListener(project));
Collection<ProjectType> projectTypes = ProjectTypeService.getProjectTypes(project);
for(ProjectType projectType : projectTypes) {
if (projectType != null && "Android".equals(projectType.getId())) {
// This is an add-to-app project.
connection.subscribe(DebuggerManagerListener.TOPIC, makeAddToAppAttachListener(project));
}
}
}
return true;
Expand Down
Loading