use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class MathDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
if (context.getEvaluator().isMemberInClass(method, "android.util.FloatMath") && context.getProject().getMinSdk() >= 8) {
String message = String.format("Use `java.lang.Math#%1$s` instead of `android.util.FloatMath#%1$s()` " + "since it is faster as of API 8", method.getName());
Location location = context.getUastLocation(call.getMethodIdentifier());
context.report(ISSUE, call, location, message);
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class OverdrawDetector method afterCheckProject.
@Override
public void afterCheckProject(@NonNull Context context) {
if (mRootAttributes != null) {
for (Pair<Location, String> pair : mRootAttributes) {
Location location = pair.getFirst();
Object clientData = location.getClientData();
if (clientData instanceof Node) {
if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) {
return;
}
}
String layoutName = location.getFile().getName();
if (endsWith(layoutName, DOT_XML)) {
layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length());
}
String theme = getTheme(context, layoutName);
if (theme == null || !isBlankTheme(theme)) {
String drawable = pair.getSecond();
String message = String.format("Possible overdraw: Root element paints background `%1$s` with " + "a theme that also paints a background (inferred theme is `%2$s`)", drawable, theme);
// TODO: Compute applicable scope node
context.report(ISSUE, location, message);
}
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class OverdrawDetector method visitAttribute.
// ---- Implements XmlScanner ----
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
// android View background attribute
if (!ANDROID_URI.equals(attribute.getNamespaceURI())) {
return;
}
// Only consider the root element's background
Element documentElement = attribute.getOwnerDocument().getDocumentElement();
if (documentElement == attribute.getOwnerElement()) {
// If the drawable is a non-repeated pattern then the overdraw might be
// intentional since the image isn't covering the whole screen
String background = attribute.getValue();
if (mValidDrawables != null && mValidDrawables.contains(background)) {
return;
}
if (background.equals(TRANSPARENT_COLOR) || background.equals(NULL_RESOURCE)) {
return;
}
if (background.startsWith("@android:drawable/")) {
// but many of these are not bitmaps, so ignore these
return;
}
String name = context.file.getName();
if (name.contains("list_") || name.contains("_item")) {
// pretty common to want to paint custom list item backgrounds
return;
}
if (!context.getProject().getReportIssues()) {
// If this is a library project not being analyzed, ignore it
return;
}
Location location = context.getLocation(attribute);
location.setClientData(attribute);
if (mRootAttributes == null) {
mRootAttributes = new ArrayList<Pair<Location, String>>();
}
mRootAttributes.add(Pair.of(location, attribute.getValue()));
String activity = documentElement.getAttributeNS(TOOLS_URI, ATTR_CONTEXT);
if (activity != null && !activity.isEmpty()) {
if (activity.startsWith(".")) {
//$NON-NLS-1$
activity = context.getProject().getPackage() + activity;
}
registerLayoutActivity(LintUtils.getLayoutName(context.file), activity);
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class ParcelDetector method checkClass.
@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
if (declaration instanceof UAnonymousClass) {
// Anonymous classes aren't parcelable
return;
}
// Only applies to concrete classes
if (declaration.isInterface()) {
return;
}
if (declaration.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
// Parceling spans is handled in TextUtils#CHAR_SEQUENCE_CREATOR
if (InheritanceUtil.isInheritor(declaration, false, "android.text.ParcelableSpan")) {
return;
}
PsiField field = declaration.findFieldByName("CREATOR", false);
if (field == null) {
Location location = context.getUastNameLocation(declaration);
context.reportUast(ISSUE, declaration, location, "This class implements `Parcelable` but does not " + "provide a `CREATOR` field");
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class PreferenceActivityDetector method checkClass.
@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
if (!context.getProject().getReportIssues()) {
return;
}
JavaEvaluator evaluator = context.getEvaluator();
String className = declaration.getQualifiedName();
if (InheritanceUtil.isInheritor(declaration, false, PREFERENCE_ACTIVITY) && mExportedActivities.containsKey(className)) {
// valid fragments.
if (context.getMainProject().getTargetSdk() >= 19 && overridesIsValidFragment(evaluator, declaration)) {
return;
}
String message = String.format("`PreferenceActivity` subclass `%1$s` should not be exported", className);
Location location = mExportedActivities.get(className).resolve();
context.reportUast(ISSUE, declaration, location, message);
}
}
Aggregations