use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class LayoutConsistencyDetector method chainLocations.
@NonNull
private static Location chainLocations(@NonNull List<Location> locations) {
assert !locations.isEmpty();
// Sort locations by the file parent folders
if (locations.size() > 1) {
Collections.sort(locations, new Comparator<Location>() {
@Override
public int compare(Location location1, Location location2) {
File file1 = location1.getFile();
File file2 = location2.getFile();
String folder1 = file1.getParentFile().getName();
String folder2 = file2.getParentFile().getName();
return folder1.compareTo(folder2);
}
});
// Chain locations together
Iterator<Location> iterator = locations.iterator();
assert iterator.hasNext();
Location prev = iterator.next();
while (iterator.hasNext()) {
Location next = iterator.next();
prev.setSecondary(next);
prev = next;
}
}
return locations.get(0);
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class LayoutConsistencyDetector method lookupLocations.
private static void lookupLocations(@NonNull XmlContext context, @NonNull Element element, @NonNull Map<String, List<Location>> map) {
String id = getId(element);
if (id != null) {
if (map.containsKey(id)) {
if (context.getDriver().isSuppressed(context, INCONSISTENT_IDS, element)) {
map.remove(id);
return;
}
List<Location> locations = map.get(id);
if (locations == null) {
locations = Lists.newArrayList();
map.put(id, locations);
}
Attr attr = element.getAttributeNodeNS(ANDROID_URI, ATTR_ID);
assert attr != null;
Location location = context.getLocation(attr);
String folder = context.file.getParentFile().getName();
location.setMessage(String.format("Occurrence in %1$s", folder));
locations.add(location);
}
}
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
lookupLocations(context, (Element) child, map);
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class LayoutInflationDetector method afterCheckProject.
@Override
public void afterCheckProject(@NonNull Context context) {
if (mPendingErrors != null) {
for (Pair<String, Location> pair : mPendingErrors) {
String inflatedLayout = pair.getFirst();
if (mLayoutsWithRootLayoutParams == null || !mLayoutsWithRootLayoutParams.contains(inflatedLayout)) {
// No root layout parameters on the inflated layout: no need to complain
continue;
}
Location location = pair.getSecond();
context.report(ISSUE, location, ERROR_MESSAGE);
}
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class LocaleDetector method checkFormat.
private static void checkFormat(@NonNull JavaContext context, @NonNull PsiMethod method, @NonNull UCallExpression call) {
// Only check the non-locale version of String.format
if (method.getParameterList().getParametersCount() == 0 || !context.getEvaluator().parameterHasType(method, 0, TYPE_STRING)) {
return;
}
List<UExpression> expressions = call.getValueArguments();
if (expressions.isEmpty()) {
return;
}
// Find the formatting string
UExpression first = expressions.get(0);
Object value = ConstantEvaluator.evaluate(context, first);
if (!(value instanceof String)) {
return;
}
String format = (String) value;
if (StringFormatDetector.isLocaleSpecific(format)) {
if (isLoggingParameter(call)) {
return;
}
Location location = context.getUastLocation(call);
String message = "Implicitly using the default locale is a common source of bugs: " + "Use `String.format(Locale, ...)` instead";
context.report(STRING_LOCALE, call, location, message);
}
}
use of com.android.tools.klint.detector.api.Location in project kotlin by JetBrains.
the class BadHostnameVerifierDetector method checkClass.
@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
JavaEvaluator evaluator = context.getEvaluator();
for (PsiMethod method : declaration.findMethodsByName("verify", false)) {
if (evaluator.methodMatches(method, null, false, TYPE_STRING, "javax.net.ssl.SSLSession")) {
ComplexVisitor visitor = new ComplexVisitor(context);
declaration.accept(visitor);
if (visitor.isComplex()) {
return;
}
Location location = context.getNameLocation(method);
String message = String.format("`%1$s` always returns `true`, which " + "could cause insecure network traffic due to trusting " + "TLS/SSL server certificates for wrong hostnames", method.getName());
context.report(ISSUE, location, message);
break;
}
}
}
Aggregations