Skip to content

Commit

Permalink
Stop using some deprecated methods (flutter#5994)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemessick authored Mar 28, 2022
1 parent 230fdec commit 0e65e6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.flutter.editor;

import com.intellij.AppTopics;
import com.intellij.application.options.CodeStyle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.components.ServiceManager;
Expand Down Expand Up @@ -115,15 +116,15 @@ private void handleBeforeDocumentSaving(@NotNull Document document) {

if (DartAnalysisServerService.getInstance(myProject).serverReadyForRequest()) {
if (settings.isOrganizeImportsOnSave()) {
performOrganizeThenFormat(document, file);
performOrganizeThenFormat(document, file, psiFile);
}
else {
performFormat(document, file, false);
performFormat(document, file, false, psiFile);
}
}
}

private void performOrganizeThenFormat(@NotNull Document document, @NotNull VirtualFile file) {
private void performOrganizeThenFormat(@NotNull Document document, @NotNull VirtualFile file, @NotNull PsiFile psiFile) {
final String filePath = file.getPath();
final SourceFileEdit fileEdit = DartAnalysisServerService.getInstance(myProject).edit_organizeDirectives(filePath);

Expand All @@ -148,16 +149,16 @@ protected void run() {
// Run this in an invoke later so that we don't exeucte the initial part of performFormat in a write action.
//noinspection CodeBlock2Expr
ApplicationManager.getApplication().invokeLater(() -> {
performFormat(document, file, true);
performFormat(document, file, true, psiFile);
});
}
}.execute();
});
}
}

private void performFormat(@NotNull Document document, @NotNull VirtualFile file, boolean reSave) {
final int lineLength = getRightMargin(myProject);
private void performFormat(@NotNull Document document, @NotNull VirtualFile file, boolean reSave, @NotNull PsiFile psiFile) {
final int lineLength = getRightMargin(psiFile);
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(myProject);

das.updateFilesContent();
Expand Down Expand Up @@ -206,7 +207,7 @@ protected void run() {
});
}

private static int getRightMargin(@NotNull Project project) {
return CodeStyleSettingsManager.getSettings(project).getCommonSettings(DartLanguage.INSTANCE).RIGHT_MARGIN;
private static int getRightMargin(@NotNull PsiFile psiFile) {
return CodeStyle.getLanguageSettings(psiFile, DartLanguage.INSTANCE).RIGHT_MARGIN;
}
}
4 changes: 2 additions & 2 deletions flutter-idea/src/io/flutter/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public static boolean hasJsonData(@Nullable String data) {
* Parses the specified JSON string into a JsonElement.
*/
public static JsonElement parseString(String json) throws JsonSyntaxException {
return new JsonParser().parse(json);
return JsonParser.parseString(json);
}

/**
* Parses the specified JSON string into a JsonElement.
*/
public static JsonElement parseReader(Reader reader) throws JsonIOException, JsonSyntaxException {
return new JsonParser().parse(reader);
return JsonParser.parseReader(reader);
}
}

0 comments on commit 0e65e6c

Please sign in to comment.