use of com.android.tools.klint.detector.api.ResourceContext in project kotlin by JetBrains.
the class LintDriver method checkIndividualResources.
/** Checks individual resources */
private void checkIndividualResources(@NonNull Project project, @Nullable Project main, @NonNull List<ResourceXmlDetector> xmlDetectors, @Nullable List<Detector> dirChecks, @Nullable List<Detector> binaryChecks, @NonNull List<File> files) {
for (File file : files) {
if (file.isDirectory()) {
// Is it a resource folder?
ResourceFolderType type = ResourceFolderType.getFolderType(file.getName());
if (type != null && new File(file.getParentFile(), RES_FOLDER).exists()) {
// Yes.
checkResourceFolder(project, main, file, type, xmlDetectors, dirChecks, binaryChecks);
} else if (file.getName().equals(RES_FOLDER)) {
// Is it the res folder?
// Yes
checkResFolder(project, main, file, xmlDetectors, dirChecks, binaryChecks);
} else {
mClient.log(null, "Unexpected folder %1$s; should be project, " + "\"res\" folder or resource folder", file.getPath());
}
} else if (file.isFile() && LintUtils.isXmlFile(file)) {
// Yes, find out its resource type
String folderName = file.getParentFile().getName();
ResourceFolderType type = ResourceFolderType.getFolderType(folderName);
if (type != null) {
ResourceVisitor visitor = getVisitor(type, xmlDetectors, binaryChecks);
if (visitor != null) {
XmlContext context = new XmlContext(this, project, main, file, type, visitor.getParser());
fireEvent(EventType.SCANNING_FILE, context);
visitor.visitFile(context, file);
}
}
} else if (binaryChecks != null && file.isFile() && LintUtils.isBitmapFile(file)) {
// Yes, find out its resource type
String folderName = file.getParentFile().getName();
ResourceFolderType type = ResourceFolderType.getFolderType(folderName);
if (type != null) {
ResourceVisitor visitor = getVisitor(type, xmlDetectors, binaryChecks);
if (visitor != null) {
ResourceContext context = new ResourceContext(this, project, main, file, type);
fireEvent(EventType.SCANNING_FILE, context);
visitor.visitBinaryResource(context);
if (mCanceled) {
return;
}
}
}
}
}
}
use of com.android.tools.klint.detector.api.ResourceContext in project kotlin by JetBrains.
the class LintDriver method checkResourceFolder.
private void checkResourceFolder(@NonNull Project project, @Nullable Project main, @NonNull File dir, @NonNull ResourceFolderType type, @NonNull List<ResourceXmlDetector> xmlChecks, @Nullable List<Detector> dirChecks, @Nullable List<Detector> binaryChecks) {
if (dirChecks != null && !dirChecks.isEmpty()) {
ResourceContext context = new ResourceContext(this, project, main, dir, type);
String folderName = dir.getName();
fireEvent(EventType.SCANNING_FILE, context);
for (Detector check : dirChecks) {
if (check.appliesTo(type)) {
check.beforeCheckFile(context);
check.checkFolder(context, folderName);
check.afterCheckFile(context);
}
}
if (binaryChecks == null && xmlChecks.isEmpty()) {
return;
}
}
File[] files = dir.listFiles();
if (files == null || files.length <= 0) {
return;
}
ResourceVisitor visitor = getVisitor(type, xmlChecks, binaryChecks);
if (visitor != null) {
// if not, there are no applicable rules in this folder
// Process files in alphabetical order, to ensure stable output
// (for example for the duplicate resource detector)
Arrays.sort(files);
for (File file : files) {
if (LintUtils.isXmlFile(file)) {
XmlContext context = new XmlContext(this, project, main, file, type, visitor.getParser());
fireEvent(EventType.SCANNING_FILE, context);
visitor.visitFile(context, file);
} else if (binaryChecks != null && (LintUtils.isBitmapFile(file) || type == ResourceFolderType.RAW)) {
ResourceContext context = new ResourceContext(this, project, main, file, type);
fireEvent(EventType.SCANNING_FILE, context);
visitor.visitBinaryResource(context);
}
if (mCanceled) {
return;
}
}
}
}
Aggregations