From a49ba3ac12df5affc26c25ac8740f74ca44850b7 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 16 Oct 2020 20:38:38 -0600 Subject: Trivial refactor for consistent naming. This gives all our various new performance-related checkers a consistent "EfficientFooChecker" naming style. Bug: 155703208 Test: atest error_prone_android_framework_test Change-Id: I8809fe46d20357201c8559037b468d717319afb9 --- .../android/EfficientParcelableChecker.java | 123 +++++++++++++++++++++ .../android/ParcelablePerformanceChecker.java | 123 --------------------- 2 files changed, 123 insertions(+), 123 deletions(-) create mode 100644 errorprone/java/com/google/errorprone/bugpatterns/android/EfficientParcelableChecker.java delete mode 100644 errorprone/java/com/google/errorprone/bugpatterns/android/ParcelablePerformanceChecker.java (limited to 'errorprone/java') diff --git a/errorprone/java/com/google/errorprone/bugpatterns/android/EfficientParcelableChecker.java b/errorprone/java/com/google/errorprone/bugpatterns/android/EfficientParcelableChecker.java new file mode 100644 index 000000000000..c29a095ecc1b --- /dev/null +++ b/errorprone/java/com/google/errorprone/bugpatterns/android/EfficientParcelableChecker.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.errorprone.bugpatterns.android; + +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.enclosingClass; +import static com.google.errorprone.matchers.Matchers.enclosingMethod; +import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static com.google.errorprone.matchers.Matchers.isSubtypeOf; +import static com.google.errorprone.matchers.Matchers.methodInvocation; +import static com.google.errorprone.matchers.Matchers.methodIsNamed; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.Tree; + +/** + * Parcelable data can be transported in many ways (some of which can be very + * inefficient) so this checker guides developers towards using high-performance + * best-practices. + */ +@AutoService(BugChecker.class) +@BugPattern( + name = "AndroidFrameworkEfficientParcelable", + summary = "Verifies Parcelable performance best-practices", + severity = WARNING) +public final class EfficientParcelableChecker extends BugChecker + implements MethodInvocationTreeMatcher { + private static final Matcher INSIDE_WRITE_TO_PARCEL = allOf( + enclosingClass(isSubtypeOf("android.os.Parcelable")), + enclosingMethod(methodIsNamed("writeToParcel"))); + + private static final Matcher WRITE_STRING = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeString")); + private static final Matcher WRITE_STRING_ARRAY = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeStringArray")); + + private static final Matcher WRITE_VALUE = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeValue")); + private static final Matcher WRITE_PARCELABLE = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeParcelable")); + + private static final Matcher WRITE_LIST = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeList")); + private static final Matcher WRITE_PARCELABLE_LIST = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeParcelableList")); + private static final Matcher WRITE_PARCELABLE_ARRAY = methodInvocation( + instanceMethod().onExactClass("android.os.Parcel").named("writeParcelableArray")); + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (INSIDE_WRITE_TO_PARCEL.matches(tree, state)) { + if (WRITE_STRING.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'writeString8()' to improve " + + "efficiency; sending as UTF-8 can double throughput") + .build(); + } + if (WRITE_STRING_ARRAY.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'writeString8Array()' to improve " + + "efficiency; sending as UTF-8 can double throughput") + .build(); + } + + if (WRITE_VALUE.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use strongly-typed methods to improve " + + "efficiency; saves 4 bytes for type and overhead of " + + "Parcelable class name") + .build(); + } + if (WRITE_PARCELABLE.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'item.writeToParcel()' to improve " + + "efficiency; saves overhead of Parcelable class name") + .build(); + } + + if (WRITE_LIST.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'writeTypedList()' to improve " + + "efficiency; saves overhead of repeated Parcelable class name") + .build(); + } + if (WRITE_PARCELABLE_LIST.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'writeTypedList()' to improve " + + "efficiency; saves overhead of repeated Parcelable class name") + .build(); + } + if (WRITE_PARCELABLE_ARRAY.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Recommended to use 'writeTypedArray()' to improve " + + "efficiency; saves overhead of repeated Parcelable class name") + .build(); + } + } + return Description.NO_MATCH; + } +} diff --git a/errorprone/java/com/google/errorprone/bugpatterns/android/ParcelablePerformanceChecker.java b/errorprone/java/com/google/errorprone/bugpatterns/android/ParcelablePerformanceChecker.java deleted file mode 100644 index d5243164abdc..000000000000 --- a/errorprone/java/com/google/errorprone/bugpatterns/android/ParcelablePerformanceChecker.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.errorprone.bugpatterns.android; - -import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; -import static com.google.errorprone.matchers.Matchers.allOf; -import static com.google.errorprone.matchers.Matchers.enclosingClass; -import static com.google.errorprone.matchers.Matchers.enclosingMethod; -import static com.google.errorprone.matchers.Matchers.instanceMethod; -import static com.google.errorprone.matchers.Matchers.isSubtypeOf; -import static com.google.errorprone.matchers.Matchers.methodInvocation; -import static com.google.errorprone.matchers.Matchers.methodIsNamed; - -import com.google.auto.service.AutoService; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.sun.source.tree.ExpressionTree; -import com.sun.source.tree.MethodInvocationTree; -import com.sun.source.tree.Tree; - -/** - * Parcelable data can be transported in many ways (some of which can be very - * inefficient) so this checker guides developers towards using high-performance - * best-practices. - */ -@AutoService(BugChecker.class) -@BugPattern( - name = "AndroidFrameworkParcelablePerformance", - summary = "Verifies Parcelable performance best-practices", - severity = WARNING) -public final class ParcelablePerformanceChecker extends BugChecker - implements MethodInvocationTreeMatcher { - private static final Matcher INSIDE_WRITE_TO_PARCEL = allOf( - enclosingClass(isSubtypeOf("android.os.Parcelable")), - enclosingMethod(methodIsNamed("writeToParcel"))); - - private static final Matcher WRITE_STRING = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeString")); - private static final Matcher WRITE_STRING_ARRAY = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeStringArray")); - - private static final Matcher WRITE_VALUE = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeValue")); - private static final Matcher WRITE_PARCELABLE = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeParcelable")); - - private static final Matcher WRITE_LIST = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeList")); - private static final Matcher WRITE_PARCELABLE_LIST = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeParcelableList")); - private static final Matcher WRITE_PARCELABLE_ARRAY = methodInvocation( - instanceMethod().onExactClass("android.os.Parcel").named("writeParcelableArray")); - - @Override - public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - if (INSIDE_WRITE_TO_PARCEL.matches(tree, state)) { - if (WRITE_STRING.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'writeString8()' to improve " - + "efficiency; sending as UTF-8 can double throughput") - .build(); - } - if (WRITE_STRING_ARRAY.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'writeString8Array()' to improve " - + "efficiency; sending as UTF-8 can double throughput") - .build(); - } - - if (WRITE_VALUE.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use strongly-typed methods to improve " - + "efficiency; saves 4 bytes for type and overhead of " - + "Parcelable class name") - .build(); - } - if (WRITE_PARCELABLE.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'item.writeToParcel()' to improve " - + "efficiency; saves overhead of Parcelable class name") - .build(); - } - - if (WRITE_LIST.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'writeTypedList()' to improve " - + "efficiency; saves overhead of repeated Parcelable class name") - .build(); - } - if (WRITE_PARCELABLE_LIST.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'writeTypedList()' to improve " - + "efficiency; saves overhead of repeated Parcelable class name") - .build(); - } - if (WRITE_PARCELABLE_ARRAY.matches(tree, state)) { - return buildDescription(tree) - .setMessage("Recommended to use 'writeTypedArray()' to improve " - + "efficiency; saves overhead of repeated Parcelable class name") - .build(); - } - } - return Description.NO_MATCH; - } -} -- cgit v1.2.3-59-g8ed1b