Skip to content

[cq] Java cleanup, remove constant values #8470

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 7 additions & 10 deletions src/io/flutter/FlutterErrorReportSubmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,20 @@ public boolean submit(@NotNull IdeaLoggingEvent @NotNull [] events,
if (stackTraceText.startsWith(DaemonApi.FLUTTER_ERROR_PREFIX)) {
final String message = stackTraceText.substring(DaemonApi.FLUTTER_ERROR_PREFIX.length());
final int start = message.indexOf(": ") + 2;
if (start == 0) continue;
int end = message.indexOf('\n');
if (end < 0) end = message.length();
final String error = message.substring(start, end);
stackTrace = message.substring(end + 1);
for (String err : KNOWN_ERRORS) {
if (error.contains(err)) {
if (end != message.length()) {
// Dart stack trace included so extract it and set the issue target to the Flutter repo.
errorMessage = err;
final int endOfDartStack = stackTrace.indexOf("\\n\"\n");
if (endOfDartStack > 0) {
// Get only the part between quotes. If the format is wrong just use the whole thing.
stackTrace = stackTrace.substring(1, endOfDartStack);
}
break;
// Dart stack trace included so extract it and set the issue target to the Flutter repo.
errorMessage = err;
final int endOfDartStack = stackTrace.indexOf("\\n\"\n");
if (endOfDartStack > 0) {
// Get only the part between quotes. If the format is wrong just use the whole thing.
stackTrace = stackTrace.substring(1, endOfDartStack);
}
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/flutter/FlutterInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void checkSdkVersionNotification(@NotNull Project project) {
// See FlutterSdkVersion.MIN_SDK_SUPPORTED.
if (version.isValid() && !version.isSDKSupported()) {
final FlutterSettings settings = FlutterSettings.getInstance();
if (settings == null || settings.isSdkVersionOutdatedWarningAcknowledged(version.getVersionText(), false)) return;
if (settings.isSdkVersionOutdatedWarningAcknowledged(version.getVersionText(), false)) return;
OpenApiUtils.safeInvokeLater(() -> {
final Notification notification = new Notification(FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID,
"Flutter SDK requires update",
Expand All @@ -339,7 +339,7 @@ public void actionPerformed(@NotNull AnActionEvent event) {
// See FlutterSdkVersion.MIN_SDK_WITHOUT_SUNSET_WARNING.
if (version.isValid() && version.isSDKAboutToSunset()) {
final FlutterSettings settings = FlutterSettings.getInstance();
if (settings == null || settings.isSdkVersionOutdatedWarningAcknowledged(version.getVersionText(), true)) return;
if (settings.isSdkVersionOutdatedWarningAcknowledged(version.getVersionText(), true)) return;

OpenApiUtils.safeInvokeLater(() -> {
final Notification notification = new Notification(FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID,
Expand Down
3 changes: 1 addition & 2 deletions src/io/flutter/FlutterStudioStartupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ private static Void doNonBlockingStartup(@NotNull Project project) {
//FlutterProjectCreator.disableUserConfig(project);
// Monitor Android dependencies.
FlutterSettings flutterSettings = FlutterSettings.getInstance();
if (flutterSettings != null && flutterSettings.isSyncingAndroidLibraries() ||
System.getProperty("flutter.android.library.sync", null) != null) {
if (flutterSettings.isSyncingAndroidLibraries() || System.getProperty("flutter.android.library.sync", null) != null) {
// TODO(messick): Remove the flag once this sync mechanism is stable.
AndroidModuleLibraryManager.startWatching(project);
}
Expand Down
3 changes: 0 additions & 3 deletions src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,6 @@ public static EmbeddedBrowser embeddedBrowser(Project project) {
}

FlutterSettings settings = FlutterSettings.getInstance();
if (settings == null) {
return null;
}

return settings.isEnableJcefBrowser()
? EmbeddedJcefBrowser.getInstance(project)
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/actions/OpenInAndroidStudioAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ protected static boolean isProjectFileName(@NotNull String name) {
for (PubRoot root : PubRoots.forProject(project)) {
if (root.isFlutterPlugin()) {
final VirtualFile rootFile = root.getRoot();
if (rootFile == null) continue;
VirtualFile aFile = file;
while (aFile != null) {
if (aFile.equals(rootFile)) {
Expand Down
24 changes: 11 additions & 13 deletions src/io/flutter/console/FlutterConsoleFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,17 @@ public VirtualFile fileAtPath(@NotNull String pathPart) {
final VirtualFile[] roots = OpenApiUtils.getContentRoots(module);
for (VirtualFile root : roots) {
if (root == null) continue;
if (!pathPart.isEmpty()) {
final String baseDirPath = root.getPath();
final String path = baseDirPath + "/" + pathPart;
VirtualFile file = findFile(path);
if (file == null) {
// check example dir too
// TODO(pq): remove when `example` is a content root: https://github.com/flutter/flutter-intellij/issues/2519
final String exampleDirRelativePath = baseDirPath + "/example/" + pathPart;
file = findFile(exampleDirRelativePath);
}
if (file != null) {
return file;
}
final String baseDirPath = root.getPath();
final String path = baseDirPath + "/" + pathPart;
VirtualFile file = findFile(path);
if (file == null) {
// check example dir too
// TODO(pq): remove when `example` is a content root: https://github.com/flutter/flutter-intellij/issues/2519
final String exampleDirRelativePath = baseDirPath + "/example/" + pathPart;
file = findFile(exampleDirRelativePath);
}
if (file != null) {
return file;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/flutter/dart/FlutterRequestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ private static JsonObject buildJsonObjectRequest(String idValue, String methodVa
*/
@NotNull
private static String getClassName(@Nullable Object object) {
return object != null && object.getClass().getName() != null ? object.getClass().getName() : "null";
return object != null ? object.getClass().getName() : "null";
}
}
3 changes: 0 additions & 3 deletions src/io/flutter/editor/FlutterIconLineMarkerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private IconInfo findStandardDefinition(@NotNull String className,

@Nullable
private Icon findStandardIconFromDef(@NotNull String name, @NotNull IconInfo iconDef, @NotNull String path) {
assert LocalFileSystem.getInstance() != null;
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
if (virtualFile == null) return null;
final IconPreviewGenerator generator = new IconPreviewGenerator(virtualFile.getPath());
Expand Down Expand Up @@ -310,7 +309,6 @@ private LineMarkerInfo<PsiElement> createLineMarker(@Nullable PsiElement element

@Nullable
private IconInfo findDefinition(@NotNull String className, @NotNull String iconName, @NotNull Project project, @NotNull String path) {
assert LocalFileSystem.getInstance() != null;
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
if (virtualFile == null) return null;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
Expand All @@ -324,7 +322,6 @@ private IconInfo findDefinition(@NotNull String className, @NotNull String iconN

@Nullable
private Icon findIconFromDef(@NotNull String iconClassName, @NotNull IconInfo iconDef, @NotNull String path) {
assert LocalFileSystem.getInstance() != null;
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
if (virtualFile == null) return null;
VirtualFile parent = virtualFile;
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/jxbrowser/EmbeddedJxBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ private EmbeddedJxBrowser(@NotNull Project project) {
private @Nullable String jxBrowserErrorFromFailedReason(@Nullable InstallationFailedReason failedReason) {
if (failedReason == null) return null;
final FailureType failureType = failedReason.failureType;
if (failureType == null) return null;
return switch (failureType) {
case SYSTEM_INCOMPATIBLE -> "System is incompatible with JX Browser";
case FILE_DOWNLOAD_FAILED -> "JX Browser file download failed";
Expand Down
4 changes: 1 addition & 3 deletions src/io/flutter/run/FlutterReloadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ private void restartApp(@NotNull FlutterApp app, @NotNull String reason) {
});

final FlutterDevice device = app.device();
if (device != null) {
device.bringToFront();
}
device.bringToFront();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/run/bazelTest/BazelTestFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ GeneralCommandLine getLaunchCommand(@NotNull final Project project,
final Workspace workspace = getWorkspace(project);

final String launchingScript = getTestScriptFromWorkspace(project);
assert launchingScript != null; // already checked

final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(workspace.getRoot().getPath());
commandLine.setCharset(StandardCharsets.UTF_8);
Expand Down
2 changes: 1 addition & 1 deletion src/io/flutter/run/daemon/DevToolsServerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private CompletableFuture<DevToolsInstance> checkForDartPluginInitiatedDevToolsW
String[] parts = dartPluginUri.split(":");
String host = parts[0];
Integer port = Integer.parseInt(parts[1]);
if (host == null || port == null) {
if (host == null) {
return null;
}

Expand Down
7 changes: 2 additions & 5 deletions src/io/flutter/run/daemon/DevToolsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ private void startServer(boolean forceRestart) {
}

private boolean devToolsInstanceExists() {
if (devToolsFutureRef != null) {
final CompletableFuture<DevToolsInstance> devToolsFuture = devToolsFutureRef.get();
return devToolsFuture != null && devToolsFuture.isDone() && !devToolsFuture.isCompletedExceptionally();
}
return false;
final CompletableFuture<DevToolsInstance> devToolsFuture = devToolsFutureRef.get();
return devToolsFuture != null && devToolsFuture.isDone() && !devToolsFuture.isCompletedExceptionally();
}

private CompletableFuture<Boolean> pubActivateDevTools(FlutterSdk sdk) {
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/sdk/FlutterPluginsLibraryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private void updateFlutterPluginsImpl() {
ReadAction.nonBlocking(() -> getFlutterPluginPaths(PubRoots.forProject(project)))
.expireWith(FlutterDartAnalysisServer.getInstance(project))
.finishOnUiThread(ModalityState.nonModal(), flutterPluginPaths -> {
if (flutterPluginPaths == null) return;
final Set<String> flutterPluginUrls = new HashSet<>();
for (String path : flutterPluginPaths) {
flutterPluginUrls.add(VfsUtilCore.pathToUrl(path));
Expand Down
2 changes: 1 addition & 1 deletion src/io/flutter/sdk/FlutterSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public FlutterCommand flutterRun(@NotNull PubRoot root,
final List<String> args = new ArrayList<>();
args.add("--machine");
FlutterSettings settings = FlutterSettings.getInstance();
if (settings != null && settings.isVerboseLogging()) {
if (settings.isVerboseLogging()) {
args.add("--verbose");
}

Expand Down
10 changes: 4 additions & 6 deletions src/io/flutter/utils/AddToAppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ public void modulesAdded(@NotNull Project proj, @NotNull List<? extends Module>
}
else {
Collection<ProjectType> projectTypes = ProjectTypeService.getProjectTypes(project);
if (projectTypes != null) {
for (ProjectType projectType : projectTypes) {
if (projectType != null && "Android".equals(projectType.getId())) {
// This is an add-to-app project.
connection.subscribe(DebuggerManagerListener.TOPIC, makeAddToAppAttachListener(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));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/utils/FlutterModuleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ public static List<Module> findModulesWithFlutterContents(@NotNull Project proje
// Return true if there is a module with the same name as the project plus the Android suffix.
public static boolean hasAndroidModule(@NotNull Project project) {
for (PubRoot root : PubRoots.forProject(project)) {
assert root != null;
String name = PubspecYamlUtil.getDartProjectName(root.getPubspec());
String moduleName = name + "_android";
for (Module module : FlutterModuleUtils.getModules(project)) {
Expand Down
5 changes: 4 additions & 1 deletion src/io/flutter/vmService/DartVmServiceDebugProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ public void logError(final String message) {

@Override
public void logError(final String message, final Throwable exception) {
if (!getVmConnected() || getSession() == null) {
if (!getVmConnected()) {
return;
}
else {
getSession();
}
if (message != null) {
getSession().getConsoleView().print(message.trim() + "\n", ConsoleViewContentType.ERROR_OUTPUT);
}
Expand Down
11 changes: 4 additions & 7 deletions src/io/flutter/vmService/VmServiceWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ public void received(final Isolate isolate) {
});

FlutterSdkVersion flutterSdkVersion = null;
if (myDebugProcess.getSession() != null) {
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(myDebugProcess.getSession().getProject());
if (flutterSdk != null) {
flutterSdkVersion = flutterSdk.getVersion();
}
myDebugProcess.getSession();
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(myDebugProcess.getSession().getProject());
if (flutterSdk != null) {
flutterSdkVersion = flutterSdk.getVersion();
}

if (flutterSdkVersion != null && flutterSdkVersion.canUseToolEventStream()) {
Expand Down Expand Up @@ -407,7 +406,6 @@ public void received(Isolate response) {
}

Set<CanonicalBreakpoint> mappedCanonicalBreakpoints = new HashSet<>();
assert breakpoints != null;
for (Breakpoint breakpoint : breakpoints) {
Object location = breakpoint.getLocation();
// In JIT mode, locations will be unresolved at this time since files aren't compiled until they are used.
Expand Down Expand Up @@ -613,7 +611,6 @@ public void onError(RPCError error) {

private String getResolvedUri(@NotNull XSourcePosition position) {
XDebugSession session = myDebugProcess.getSession();
assert session != null;
VirtualFile file =
WorkspaceCache.getInstance(session.getProject()).isBazel() ? position.getFile() : position.getFile().getCanonicalFile();
assert file != null;
Expand Down
Loading