Code review changes
This commit is contained in:
@@ -1504,8 +1504,8 @@ public class LintDriver {
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = file.getPath();
|
||||
if (!path.endsWith(DOT_JAVA) && !UastConverterUtils.isFileSupported(plugins, path)) {
|
||||
String filename = file.getName();
|
||||
if (!filename.endsWith(DOT_JAVA) && !UastConverterUtils.isFileSupported(plugins, filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -29,10 +29,10 @@ public abstract class LintLanguageExtension implements UastLanguagePlugin {
|
||||
public static final ExtensionPointName<LintLanguageExtension> EP_NAME =
|
||||
ExtensionPointName.create("com.android.tools.klint.client.api.lintLanguageExtension");
|
||||
|
||||
public static boolean isFileSupported(@Nullable Project project, String path) {
|
||||
public static boolean isFileSupported(@Nullable Project project, String name) {
|
||||
LintLanguageExtension[] extensions = getExtensions(project);
|
||||
for (LintLanguageExtension ext : extensions) {
|
||||
if (ext.getConverter().isFileSupported(path)) {
|
||||
if (ext.getConverter().isFileSupported(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-8
@@ -96,24 +96,23 @@ public class AppCompatCallDetector extends Detector implements UastScanner {
|
||||
@Override
|
||||
public void visitFunctionCall(UastAndroidContext context, UCallExpression node) {
|
||||
if (mDependsOnAppCompat && isAppBarActivityCall(context, node)) {
|
||||
String name = node.getFunctionName();
|
||||
String replace = null;
|
||||
if (GET_ACTION_BAR.equals(name)) {
|
||||
if (node.functionNameMatches(GET_ACTION_BAR)) {
|
||||
replace = "getSupportActionBar";
|
||||
} else if (START_ACTION_MODE.equals(name)) {
|
||||
} else if (node.functionNameMatches(START_ACTION_MODE)) {
|
||||
replace = "startSupportActionMode";
|
||||
} else if (SET_PROGRESS_BAR_VIS.equals(name)) {
|
||||
} else if (node.functionNameMatches(SET_PROGRESS_BAR_VIS)) {
|
||||
replace = "setSupportProgressBarVisibility";
|
||||
} else if (SET_PROGRESS_BAR_IN_VIS.equals(name)) {
|
||||
} else if (node.functionNameMatches(SET_PROGRESS_BAR_IN_VIS)) {
|
||||
replace = "setSupportProgressBarIndeterminateVisibility";
|
||||
} else if (SET_PROGRESS_BAR_INDETERMINATE.equals(name)) {
|
||||
} else if (node.functionNameMatches(SET_PROGRESS_BAR_INDETERMINATE)) {
|
||||
replace = "setSupportProgressBarIndeterminate";
|
||||
} else if (REQUEST_WINDOW_FEATURE.equals(name)) {
|
||||
} else if (node.functionNameMatches(REQUEST_WINDOW_FEATURE)) {
|
||||
replace = "supportRequestWindowFeature";
|
||||
}
|
||||
|
||||
if (replace != null) {
|
||||
String message = String.format(ERROR_MESSAGE_FORMAT, replace, name);
|
||||
String message = String.format(ERROR_MESSAGE_FORMAT, replace, node.getFunctionName());
|
||||
context.report(ISSUE, node, UastAndroidUtils.getLocation(node), message);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class CipherGetInstanceDetector extends Detector implements UastScanner {
|
||||
UExpression expression = argumentList.get(0);
|
||||
if (expression instanceof ULiteralExpression) {
|
||||
ULiteralExpression argument = (ULiteralExpression)expression;
|
||||
String parameter = argument.getText();
|
||||
String parameter = argument.asString();
|
||||
checkParameter(context, node, argument, parameter, false);
|
||||
} else if (expression instanceof UResolvable) {
|
||||
UDeclaration declaration = ((UResolvable)expression).resolve(context);
|
||||
|
||||
@@ -157,11 +157,10 @@ public class CleanupDetector extends Detector implements UastScanner {
|
||||
|
||||
@Override
|
||||
public void visitFunctionCall(UastAndroidContext context, UCallExpression node) {
|
||||
String name = node.getFunctionName();
|
||||
if (BEGIN_TRANSACTION.equals(name)) {
|
||||
if (node.functionNameMatches(BEGIN_TRANSACTION)) {
|
||||
checkTransactionCommits(context, node);
|
||||
} else {
|
||||
checkResourceRecycled(context, node, name);
|
||||
checkResourceRecycled(context, node, node.getFunctionName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,8 +245,7 @@ public class CleanupDetector extends Detector implements UastScanner {
|
||||
FinishVisitor visitor = new FinishVisitor(context, boundVariable) {
|
||||
@Override
|
||||
protected boolean isCleanupCall(@NonNull UCallExpression call) {
|
||||
String methodName = call.getFunctionName();
|
||||
if (!recycleName.equals(methodName)) {
|
||||
if (!call.functionNameMatches(recycleName)) {
|
||||
return false;
|
||||
}
|
||||
UDeclaration resolved = call.resolve(mContext);
|
||||
@@ -385,8 +383,7 @@ public class CleanupDetector extends Detector implements UastScanner {
|
||||
private static boolean isTransactionCommitMethodCall(@NonNull UastAndroidContext context,
|
||||
@NonNull UCallExpression call) {
|
||||
|
||||
String methodName = call.getFunctionName();
|
||||
return (COMMIT.equals(methodName) || COMMIT_ALLOWING_LOSS.equals(methodName)) &&
|
||||
return (call.functionNameMatches(COMMIT) || call.functionNameMatches(COMMIT_ALLOWING_LOSS)) &&
|
||||
isMethodOnFragmentClass(context, call,
|
||||
FRAGMENT_TRANSACTION_CLS,
|
||||
FRAGMENT_TRANSACTION_V4_CLS);
|
||||
@@ -394,8 +391,7 @@ public class CleanupDetector extends Detector implements UastScanner {
|
||||
|
||||
private static boolean isShowFragmentMethodCall(@NonNull UastAndroidContext context,
|
||||
@NonNull UCallExpression call) {
|
||||
String methodName = call.getFunctionName();
|
||||
return SHOW.equals(methodName)
|
||||
return call.functionNameMatches(SHOW)
|
||||
&& isMethodOnFragmentClass(context, call,
|
||||
DIALOG_FRAGMENT, DIALOG_V4_FRAGMENT);
|
||||
}
|
||||
@@ -439,9 +435,8 @@ public class CleanupDetector extends Detector implements UastScanner {
|
||||
|
||||
private static boolean isBeginTransaction(@NonNull UastAndroidContext context,
|
||||
@NonNull UCallExpression node) {
|
||||
String methodName = node.getFunctionName();
|
||||
assert BEGIN_TRANSACTION.equals(methodName) : methodName;
|
||||
if (BEGIN_TRANSACTION.equals(methodName)) {
|
||||
assert node.functionNameMatches(BEGIN_TRANSACTION) : node.renderString();
|
||||
if (node.functionNameMatches(BEGIN_TRANSACTION)) {
|
||||
UFunction method = node.resolve(context);
|
||||
if (method != null) {
|
||||
UClass containingClass = UastUtils.getContainingClassOrEmpty(method);
|
||||
|
||||
+9
-7
@@ -46,6 +46,7 @@ import com.android.utils.XmlUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import kotlin.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.check.UastAndroidContext;
|
||||
@@ -1103,9 +1104,9 @@ public class SupportAnnotationDetector extends Detector implements UastScanner {
|
||||
private static void checkTypeDefConstant(@NonNull UastAndroidContext context,
|
||||
@NonNull UAnnotation annotation, @NonNull UElement argument,
|
||||
@Nullable UElement errorNode, boolean flag, Object value) {
|
||||
List<Object> valueArguments = annotation.getValues();
|
||||
for (Object o : valueArguments) {
|
||||
if (o.equals(value)) {
|
||||
List<Pair<String, Object>> valueArguments = annotation.getValues();
|
||||
for (Pair<String, Object> o : valueArguments) {
|
||||
if (o.getSecond().equals(value)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1115,12 +1116,12 @@ public class SupportAnnotationDetector extends Detector implements UastScanner {
|
||||
private static void reportTypeDef(@NonNull UastAndroidContext context,
|
||||
@NonNull UAnnotation annotation, @NonNull UElement argument,
|
||||
@Nullable UElement errorNode) {
|
||||
List<Object> allowed = annotation.getValues();
|
||||
List<Pair<String, Object>> allowed = annotation.getValues();
|
||||
reportTypeDef(context, argument, errorNode, false, allowed);
|
||||
}
|
||||
|
||||
private static void reportTypeDef(@NonNull UastAndroidContext context, @NonNull UElement node,
|
||||
@Nullable UElement errorNode, boolean flag, @NonNull List<Object> allowedValues) {
|
||||
@Nullable UElement errorNode, boolean flag, @NonNull List<Pair<String, Object>> allowedValues) {
|
||||
String values = listAllowedValues(allowedValues);
|
||||
String message;
|
||||
if (flag) {
|
||||
@@ -1134,9 +1135,10 @@ public class SupportAnnotationDetector extends Detector implements UastScanner {
|
||||
context.report(TYPE_DEF, errorNode, context.getLocation(errorNode), message);
|
||||
}
|
||||
|
||||
private static String listAllowedValues(@NonNull List<Object> allowedValues) {
|
||||
private static String listAllowedValues(@NonNull List<Pair<String, Object>> allowedValues) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object allowedValue : allowedValues) {
|
||||
for (Pair<String, Object> namedValue : allowedValues) {
|
||||
Object allowedValue = namedValue.getSecond();
|
||||
String s;
|
||||
if (allowedValue instanceof Integer) {
|
||||
s = allowedValue.toString();
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator<State, State
|
||||
} else if (fileType == StdFileTypes.PROPERTIES) {
|
||||
scope = Scope.PROPERTY_SCOPE;
|
||||
} else {
|
||||
if (UastConverterUtils.isFileSupported(client.getLanguagePlugins(), mainFile.getPath())) {
|
||||
if (UastConverterUtils.isFileSupported(client.getLanguagePlugins(), mainFile.getName())) {
|
||||
scope = Scope.JAVA_FILE_SCOPE;
|
||||
} else {
|
||||
// #collectionInformation above should have prevented this
|
||||
|
||||
Reference in New Issue
Block a user