use of com.android.tools.klint.detector.api.ResourceEvaluator in project kotlin by JetBrains.
the class RequiredAttributeDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
// Handle
// View#inflate(Context context, int resource, ViewGroup root)
// LayoutInflater#inflate(int resource, ViewGroup root)
// LayoutInflater#inflate(int resource, ViewGroup root, boolean attachToRoot)
List<UExpression> args = call.getValueArguments();
String layout = null;
int index = 0;
ResourceEvaluator evaluator = new ResourceEvaluator(context);
for (UExpression expression : args) {
ResourceUrl url = evaluator.getResource(expression);
if (url != null && url.type == ResourceType.LAYOUT) {
layout = url.toString();
break;
}
index++;
}
if (layout == null) {
// Flow analysis didn't succeed
return;
}
// In all the applicable signatures, the view root argument is immediately after
// the layout resource id.
int viewRootPos = index + 1;
if (viewRootPos < args.size()) {
UExpression viewRoot = args.get(viewRootPos);
if (UastLiteralUtils.isNullLiteral(viewRoot)) {
// Yep, this one inflates the given view with a null parent:
// Tag it as such. For now just use the include data structure since
// it has the same net effect
recordIncludeWidth(layout, true);
recordIncludeHeight(layout, true);
}
}
}
Aggregations