use of com.android.tools.klint.client.api.AndroidReference in project kotlin by JetBrains.
the class ResourceEvaluator method getResourceConstant.
/** Returns a resource URL based on the field reference in the code */
@Nullable
public static ResourceUrl getResourceConstant(@NonNull UElement node) {
AndroidReference androidReference = toAndroidReferenceViaResolve(node);
if (androidReference == null) {
return null;
}
String name = androidReference.getName();
ResourceType type = androidReference.getType();
boolean isFramework = androidReference.getPackage().equals("android");
return ResourceUrl.create(type, name, isFramework, false);
}
use of com.android.tools.klint.client.api.AndroidReference in project kotlin by JetBrains.
the class LayoutInflationDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
assert method.getName().equals(INFLATE);
if (call.getReceiver() == null) {
return;
}
List<UExpression> arguments = call.getValueArguments();
if (arguments.size() < 2) {
return;
}
UExpression second = arguments.get(1);
if (!UastLiteralUtils.isNullLiteral(second)) {
return;
}
UExpression first = arguments.get(0);
AndroidReference androidReference = UastLintUtils.toAndroidReferenceViaResolve(first);
if (androidReference == null) {
return;
}
String layoutName = androidReference.getName();
if (context.getScope().contains(Scope.RESOURCE_FILE)) {
// incrementally
if (!context.getDriver().isSuppressed(context, ISSUE, call)) {
if (mPendingErrors == null) {
mPendingErrors = Lists.newArrayList();
}
Location location = context.getUastLocation(second);
mPendingErrors.add(Pair.of(layoutName, location));
}
} else if (hasLayoutParams(context, layoutName)) {
context.report(ISSUE, call, context.getUastLocation(second), ERROR_MESSAGE);
}
}
Aggregations