use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class DateFormatDetector method visitConstructor.
@Override
public void visitConstructor(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression node, @NonNull UMethod constructor) {
if (!specifiesLocale(constructor)) {
Location location = context.getUastLocation(node);
String message = "To get local formatting use `getDateInstance()`, `getDateTimeInstance()`, " + "or `getTimeInstance()`, or use `new SimpleDateFormat(String template, " + "Locale locale)` with for example `Locale.US` for ASCII dates.";
context.report(DATE_FORMAT, node, location, message);
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class TrustAllX509TrustManagerDetector method checkMethod.
private static void checkMethod(@NonNull JavaContext context, @NonNull UClass cls, @NonNull String methodName) {
JavaEvaluator evaluator = context.getEvaluator();
for (PsiMethod method : cls.findMethodsByName(methodName, true)) {
if (evaluator.isAbstract(method)) {
continue;
}
// For now very simple; only checks if nothing is done.
// Future work: Improve this check to be less sensitive to irrelevant
// instructions/statements/invocations (e.g. System.out.println) by
// looking for calls that could lead to a CertificateException being
// thrown, e.g. throw statement within the method itself or invocation
// of another method that may throw a CertificateException, and only
// reporting an issue if none of these calls are found. ControlFlowGraph
// may be useful here.
UExpression body = context.getUastContext().getMethodBody(method);
ComplexBodyVisitor visitor = new ComplexBodyVisitor();
body.accept(visitor);
if (!visitor.isComplex()) {
Location location = context.getNameLocation(method);
String message = getErrorMessage(methodName);
context.report(ISSUE, method, location, message);
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class PrivateResourceDetector method visitElement.
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
if (TAG_RESOURCES.equals(element.getTagName())) {
for (Element item : LintUtils.getChildren(element)) {
Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
if (nameAttribute != null) {
String name = getResourceFieldName(nameAttribute.getValue());
String type = item.getTagName();
if (type.equals(TAG_ITEM)) {
type = item.getAttribute(ATTR_TYPE);
if (type == null || type.isEmpty()) {
type = RESOURCE_CLZ_ID;
}
} else if (type.equals("declare-styleable")) {
//$NON-NLS-1$
type = RESOURCE_CLR_STYLEABLE;
} else if (type.contains("array")) {
//$NON-NLS-1$
// <string-array> etc
type = RESOURCE_CLZ_ARRAY;
}
ResourceType t = ResourceType.getEnum(type);
if (t != null && isPrivate(context, t, name) && !VALUE_TRUE.equals(item.getAttributeNS(TOOLS_URI, ATTR_OVERRIDE))) {
String message = createOverrideErrorMessage(context, t, name);
Location location = context.getValueLocation(nameAttribute);
context.report(ISSUE, nameAttribute, location, message);
}
}
}
} else {
assert TAG_STYLE.equals(element.getTagName()) || TAG_ARRAY.equals(element.getTagName()) || TAG_PLURALS.equals(element.getTagName()) || TAG_INTEGER_ARRAY.equals(element.getTagName()) || TAG_STRING_ARRAY.equals(element.getTagName());
for (Element item : LintUtils.getChildren(element)) {
checkChildRefs(context, item);
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class PrivateResourceDetector method beforeCheckFile.
@Override
public void beforeCheckFile(@NonNull Context context) {
File file = context.file;
boolean isXmlFile = LintUtils.isXmlFile(file);
if (!isXmlFile && !LintUtils.isBitmapFile(file)) {
return;
}
String parentName = file.getParentFile().getName();
int dash = parentName.indexOf('-');
if (dash != -1 || FD_RES_VALUES.equals(parentName)) {
return;
}
ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
if (folderType == null) {
return;
}
List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
if (types.isEmpty()) {
return;
}
ResourceType type = types.get(0);
String resourceName = getResourceFieldName(getBaseName(file.getName()));
if (isPrivate(context, type, resourceName)) {
String message = createOverrideErrorMessage(context, type, resourceName);
Location location = Location.create(file);
context.report(ISSUE, location, message);
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class RegistrationDetector method reportWrongTag.
private static void reportWrongTag(@NonNull JavaContext context, @NonNull PsiClass node, @NonNull String rightTag, @NonNull String className, @NonNull String framework) {
String wrongTag = classToTag(framework);
if (wrongTag == null) {
return;
}
Location location = context.getNameLocation(node);
String message = String.format("`%1$s` is %2$s but is registered " + "in the manifest as %3$s", className, describeTag(rightTag), describeTag(wrongTag));
context.report(ISSUE, node, location, message);
}
Aggregations