Skip to content

Commit 2f11f24

Browse files
authored
Fix various performance and cleanup issues (flutter#6944)
Java syntax changes include: - inclusion of @NotNull - making downcasts explict - use of amend instead of the string `+` operator
1 parent 50ccd09 commit 2f11f24

19 files changed

+51
-50
lines changed

flutter-idea/src/io/flutter/actions/FlutterAppAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public FlutterAppAction(@NotNull FlutterApp app,
4747
}
4848

4949
@Override
50-
public ActionUpdateThread getActionUpdateThread() {
50+
public @NotNull ActionUpdateThread getActionUpdateThread() {
5151
return ActionUpdateThread.BGT;
5252
}
5353

flutter-idea/src/io/flutter/analytics/FlutterAnalysisServerListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private HashMap<String, Integer> getTotalAnalysisErrorCounts() {
277277
// errorCountsArray[*]
278278
for (int i = 0; i < ERROR_TYPES.length; i++) {
279279
final int j = i;
280-
errorCountsArray[j] += errors.stream().filter(e -> {
280+
errorCountsArray[j] += (int) errors.stream().filter(e -> {
281281
assert e != null;
282282
return Objects.equals(e.getType(), ERROR_TYPES[j]);
283283
}).count();

flutter-idea/src/io/flutter/console/FlutterConsoleFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static class OpenExternalFileHyperlink implements HyperlinkInfo {
4949
}
5050

5151
@Override
52-
public void navigate(Project project) {
52+
public void navigate(@NotNull Project project) {
5353
try {
5454
final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(myPath);
5555
final ColoredProcessHandler handler = new ColoredProcessHandler(cmd);
@@ -257,7 +257,7 @@ private static Result getFlutterDoctorResult(final String line, final int lineSt
257257

258258
private static class FlutterDoctorHyperlinkInfo implements HyperlinkInfo {
259259
@Override
260-
public void navigate(final Project project) {
260+
public void navigate(final @NotNull Project project) {
261261
// TODO(skybrian) analytics for clicking the link? (We do log the command.)
262262
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
263263
if (sdk == null) {

flutter-idea/src/io/flutter/editor/FlutterColorProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ else if (parent.getNode().getElementType() == DartTokenTypes.SIMPLE_TYPE) {
8686
}
8787
final PsiElement reference = resolveReferencedElement(refExpr);
8888
if (reference != null && reference.getLastChild() != null) {
89-
Color tryParseColor = null;
89+
Color tryParseColor;
9090
if (reference instanceof DartCallExpression) {
9191
final DartExpression expression = ((DartCallExpression)reference).getExpression();
9292
if (expression != null && expression.getLastChild() instanceof DartReferenceExpression) {

flutter-idea/src/io/flutter/editor/PreviewViewControllerBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public void paint(@NotNull Graphics g, int lineHeight) {
656656
}
657657
g2d.setColor(JBColor.BLACK);
658658

659-
drawMultilineString(g2d, getNoScreenshotMessage(), screenshotBounds.x + 4, screenshotBounds.y + +lineHeight - 4, lineHeight);
659+
drawMultilineString(g2d, getNoScreenshotMessage(), screenshotBounds.x + 4, screenshotBounds.y + lineHeight - 4, lineHeight);
660660
}
661661
g2d.setClip(clip);
662662

flutter-idea/src/io/flutter/editor/PropertyEditorPanel.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public PropertyEnumComboBoxModel(FlutterWidgetProperty property) {
9898
String expression = property.getExpression();
9999
if (expression == null) {
100100
mySelected = null;
101-
expression = "";
102101
return;
103102
}
104103
if (property.getValue() != null) {
@@ -489,7 +488,7 @@ protected void rebuildUi() {
489488
continue;
490489
}
491490
final String documentation = property.getDocumentation();
492-
JComponent field = null;
491+
JComponent field;
493492

494493
if (property.getEditor() == null) {
495494
// TODO(jacobr): detect color properties more robustly.

flutter-idea/src/io/flutter/inspector/InspectorService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ private void onVmServiceReceived(String streamId, Event event) {
440440
if (path == null) return;
441441

442442
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
443-
final Integer line = JsonUtils.getIntMember(json, "line");
444-
final Integer column = JsonUtils.getIntMember(json, "column");;
443+
final int line = JsonUtils.getIntMember(json, "line");
444+
final int column = JsonUtils.getIntMember(json, "column");;
445445

446446
ApplicationManager.getApplication().invokeLater(() -> {
447447
if (file != null && line >= 0 && column >= 0) {

flutter-idea/src/io/flutter/inspector/TreeScrollAnimator.java

+1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ public void animateTo(List<TreePath> targets) {
402402
for (TreePath target : targets) {
403403
if (this.targets.contains(target)) {
404404
newTarget = false;
405+
break;
405406
}
406407
}
407408
}

flutter-idea/src/io/flutter/test/DartTestEventsConverterZ.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public DartTestEventsConverterZ(@NotNull final String testFrameworkName,
112112
}
113113

114114
@Override
115-
protected boolean processServiceMessages(final String text, final Key outputType, final ServiceMessageVisitor visitor)
115+
protected boolean processServiceMessages(final String text, final @NotNull Key outputType, final @NotNull ServiceMessageVisitor visitor)
116116
throws ParseException {
117117
LOG.debug("<<< " + text.trim());
118118
myCurrentOutputType = outputType;

flutter-idea/src/io/flutter/vmService/DartVmServiceDebugProcess.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public XDebuggerEditorsProvider getEditorsProvider() {
280280

281281
@Override
282282
@NotNull
283-
public XBreakpointHandler<?>[] getBreakpointHandlers() {
283+
public XBreakpointHandler<?> @NotNull [] getBreakpointHandlers() {
284284
return myBreakpointHandlers;
285285
}
286286

flutter-idea/src/io/flutter/vmService/FlutterFramesMonitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public boolean hasFps() {
9999
*/
100100
public double getFPS() {
101101
int frameCount = 0;
102-
int costCount = 0;
102+
long costCount = 0;
103103

104104
synchronized (this) {
105105
for (FlutterFrameEvent frame : frames) {

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterOutline.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -336,29 +336,29 @@ public String toString() {
336336
final StringBuilder builder = new StringBuilder();
337337
builder.append("[");
338338
builder.append("kind=");
339-
builder.append(kind + ", ");
339+
builder.append(kind).append(", ");
340340
builder.append("offset=");
341-
builder.append(offset + ", ");
341+
builder.append(offset).append(", ");
342342
builder.append("length=");
343-
builder.append(length + ", ");
343+
builder.append(length).append(", ");
344344
builder.append("codeOffset=");
345-
builder.append(codeOffset + ", ");
345+
builder.append(codeOffset).append(", ");
346346
builder.append("codeLength=");
347-
builder.append(codeLength + ", ");
347+
builder.append(codeLength).append(", ");
348348
builder.append("label=");
349-
builder.append(label + ", ");
349+
builder.append(label).append(", ");
350350
builder.append("dartElement=");
351-
builder.append(dartElement + ", ");
351+
builder.append(dartElement).append(", ");
352352
if (attributes != null) {
353353
builder.append("attributes=");
354-
builder.append(join(attributes, ", ") + ", ");
354+
builder.append(join(attributes, ", ")).append(", ");
355355
}
356356
builder.append("className=");
357-
builder.append(className + ", ");
357+
builder.append(className).append(", ");
358358
builder.append("parentAssociationLabel=");
359-
builder.append(parentAssociationLabel + ", ");
359+
builder.append(parentAssociationLabel).append(", ");
360360
builder.append("variableName=");
361-
builder.append(variableName + ", ");
361+
builder.append(variableName).append(", ");
362362
if (children != null) {
363363
builder.append("children=");
364364
builder.append(join(children, ", "));

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterOutlineAttribute.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ public String toString() {
231231
StringBuilder builder = new StringBuilder();
232232
builder.append("[");
233233
builder.append("name=");
234-
builder.append(name + ", ");
234+
builder.append(name).append(", ");
235235
builder.append("label=");
236-
builder.append(label + ", ");
236+
builder.append(label).append(", ");
237237
builder.append("literalValueBoolean=");
238-
builder.append(literalValueBoolean + ", ");
238+
builder.append(literalValueBoolean).append(", ");
239239
builder.append("literalValueInteger=");
240-
builder.append(literalValueInteger + ", ");
240+
builder.append(literalValueInteger).append(", ");
241241
builder.append("literalValueString=");
242-
builder.append(literalValueString + ", ");
242+
builder.append(literalValueString).append(", ");
243243
builder.append("nameLocation=");
244-
builder.append(nameLocation + ", ");
244+
builder.append(nameLocation).append(", ");
245245
builder.append("valueLocation=");
246246
builder.append(valueLocation);
247247
builder.append("]");

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterWidgetProperty.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,21 @@ public String toString() {
273273
StringBuilder builder = new StringBuilder();
274274
builder.append("[");
275275
builder.append("documentation=");
276-
builder.append(documentation + ", ");
276+
builder.append(documentation).append(", ");
277277
builder.append("expression=");
278-
builder.append(expression + ", ");
278+
builder.append(expression).append(", ");
279279
builder.append("id=");
280-
builder.append(id + ", ");
280+
builder.append(id).append(", ");
281281
builder.append("isRequired=");
282-
builder.append(isRequired + ", ");
282+
builder.append(isRequired).append(", ");
283283
builder.append("isSafeToUpdate=");
284-
builder.append(isSafeToUpdate + ", ");
284+
builder.append(isSafeToUpdate).append(", ");
285285
builder.append("name=");
286-
builder.append(name + ", ");
286+
builder.append(name).append(", ");
287287
builder.append("children=");
288-
builder.append(join(children, ", ") + ", ");
288+
builder.append(join(children, ", ")).append(", ");
289289
builder.append("editor=");
290-
builder.append(editor + ", ");
290+
builder.append(editor).append(", ");
291291
builder.append("value=");
292292
builder.append(value);
293293
builder.append("]");

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterWidgetPropertyEditor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public String toString() {
110110
StringBuilder builder = new StringBuilder();
111111
builder.append("[");
112112
builder.append("kind=");
113-
builder.append(kind + ", ");
113+
builder.append(kind).append(", ");
114114
builder.append("enumItems=");
115115
builder.append(join(enumItems, ", "));
116116
builder.append("]");

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterWidgetPropertyValue.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ public String toString() {
170170
StringBuilder builder = new StringBuilder();
171171
builder.append("[");
172172
builder.append("boolValue=");
173-
builder.append(boolValue + ", ");
173+
builder.append(boolValue).append(", ");
174174
builder.append("doubleValue=");
175-
builder.append(doubleValue + ", ");
175+
builder.append(doubleValue).append(", ");
176176
builder.append("intValue=");
177-
builder.append(intValue + ", ");
177+
builder.append(intValue).append(", ");
178178
builder.append("stringValue=");
179-
builder.append(stringValue + ", ");
179+
builder.append(stringValue).append(", ");
180180
builder.append("enumValue=");
181-
builder.append(enumValue + ", ");
181+
builder.append(enumValue).append(", ");
182182
builder.append("expression=");
183183
builder.append(expression);
184184
builder.append("]");

flutter-idea/src/org/dartlang/analysis/server/protocol/FlutterWidgetPropertyValueEnumItem.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ public String toString() {
152152
StringBuilder builder = new StringBuilder();
153153
builder.append("[");
154154
builder.append("libraryUri=");
155-
builder.append(libraryUri + ", ");
155+
builder.append(libraryUri).append(", ");
156156
builder.append("className=");
157-
builder.append(className + ", ");
157+
builder.append(className).append(", ");
158158
builder.append("name=");
159-
builder.append(name + ", ");
159+
builder.append(name).append(", ");
160160
builder.append("documentation=");
161161
builder.append(documentation);
162162
builder.append("]");

flutter-idea/testSrc/unit/io/flutter/logging/FlutterConsoleLogManagerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void scrollTo(int i) {
204204
}
205205

206206
@Override
207-
public void attachToProcess(ProcessHandler handler) {
207+
public void attachToProcess(@NotNull ProcessHandler handler) {
208208

209209
}
210210

@@ -255,7 +255,7 @@ public boolean canPause() {
255255

256256
@NotNull
257257
@Override
258-
public AnAction[] createConsoleActions() {
258+
public AnAction @NotNull [] createConsoleActions() {
259259
return new AnAction[0];
260260
}
261261

flutter-idea/testSrc/unit/io/flutter/testing/AdaptedFixture.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.flutter.testing;
77

88
import com.intellij.testFramework.fixtures.IdeaTestFixture;
9+
import org.jetbrains.annotations.NotNull;
910
import org.junit.rules.TestRule;
1011
import org.junit.runner.Description;
1112
import org.junit.runners.model.Statement;
@@ -30,7 +31,7 @@ public T getInner() {
3031
}
3132

3233
@Override
33-
public Statement apply(Statement base, Description description) {
34+
public Statement apply(@NotNull Statement base, @NotNull Description description) {
3435
return new Statement() {
3536
public void evaluate() throws Throwable {
3637
inner = factory.create(description.getClassName());

0 commit comments

Comments
 (0)