use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method runExtraPhases.
private void runExtraPhases(@NonNull Project project, @NonNull Project main) {
// Did any detectors request another phase?
if (mRepeatingDetectors != null) {
// Yes. Iterate up to MAX_PHASES times.
// During the extra phases, we might be narrowing the scope, and setting it in the
// scope field such that detectors asking about the available scope will get the
// correct result. However, we need to restore it to the original scope when this
// is done in case there are other projects that will be checked after this, since
// the repeated phases is done *per project*, not after all projects have been
// processed.
EnumSet<Scope> oldScope = mScope;
do {
mPhase++;
fireEvent(EventType.NEW_PHASE, new Context(this, project, null, project.getDir()));
// the rules.
if (mRepeatScope == null) {
mRepeatScope = Scope.ALL;
}
mScope = Scope.intersect(mScope, mRepeatScope);
if (mScope.isEmpty()) {
break;
}
// Compute the detectors to use for this pass.
// Unlike the normal computeDetectors(project) call,
// this is going to use the existing instances, and include
// those that apply for the configuration.
computeRepeatingDetectors(mRepeatingDetectors, project);
if (mApplicableDetectors.isEmpty()) {
// No detectors enabled in this project: skip it
continue;
}
checkProject(project, main);
if (mCanceled) {
break;
}
} while (mPhase < MAX_PHASES && mRepeatingDetectors != null);
mScope = oldScope;
}
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method checkPropertyFile.
private void checkPropertyFile(Project project, Project main, List<Detector> detectors, String relativePath) {
File file = new File(project.getDir(), relativePath);
if (file.exists()) {
Context context = new Context(this, project, main, file);
fireEvent(EventType.SCANNING_FILE, context);
for (Detector detector : detectors) {
if (detector.appliesTo(context, file)) {
detector.beforeCheckFile(context);
detector.run(context);
detector.afterCheckFile(context);
}
}
}
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method checkProject.
private void checkProject(@NonNull Project project, @NonNull Project main) {
File projectDir = project.getDir();
Context projectContext = new Context(this, project, null, projectDir);
fireEvent(EventType.SCANNING_PROJECT, projectContext);
List<Project> allLibraries = project.getAllLibraries();
Set<Project> allProjects = new HashSet<Project>(allLibraries.size() + 1);
allProjects.add(project);
allProjects.addAll(allLibraries);
mCurrentProjects = allProjects.toArray(new Project[allProjects.size()]);
mCurrentProject = project;
for (Detector check : mApplicableDetectors) {
check.beforeCheckProject(projectContext);
if (mCanceled) {
return;
}
}
assert mCurrentProject == project;
runFileDetectors(project, main);
if (!Scope.checkSingleFile(mScope)) {
List<Project> libraries = project.getAllLibraries();
for (Project library : libraries) {
Context libraryContext = new Context(this, library, project, projectDir);
fireEvent(EventType.SCANNING_LIBRARY_PROJECT, libraryContext);
mCurrentProject = library;
for (Detector check : mApplicableDetectors) {
check.beforeCheckLibraryProject(libraryContext);
if (mCanceled) {
return;
}
}
assert mCurrentProject == library;
runFileDetectors(library, main);
if (mCanceled) {
return;
}
assert mCurrentProject == library;
for (Detector check : mApplicableDetectors) {
check.afterCheckLibraryProject(libraryContext);
if (mCanceled) {
return;
}
}
}
}
mCurrentProject = project;
for (Detector check : mApplicableDetectors) {
check.afterCheckProject(projectContext);
if (mCanceled) {
return;
}
}
if (mCanceled) {
mClient.report(projectContext, // Must provide an issue since API guarantees that the issue parameter
IssueRegistry.CANCELLED, Severity.INFORMATIONAL, Location.create(project.getDir()), "Lint canceled by user", TextFormat.RAW);
}
mCurrentProjects = null;
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method checkClasses.
/** Check the classes in this project (and if applicable, in any library projects */
private void checkClasses(Project project, Project main) {
List<File> files = project.getSubset();
if (files != null) {
checkIndividualClassFiles(project, main, files);
return;
}
// We need to read in all the classes up front such that we can initialize
// the parent chains (such that for example for a virtual dispatch, we can
// also check the super classes).
List<File> libraries = project.getJavaLibraries(false);
List<ClassEntry> libraryEntries = ClassEntry.fromClassPath(mClient, libraries, true);
List<File> classFolders = project.getJavaClassFolders();
List<ClassEntry> classEntries;
if (classFolders.isEmpty()) {
String message = String.format("No `.class` files were found in project \"%1$s\", " + "so none of the classfile based checks could be run. " + "Does the project need to be built first?", project.getName());
Location location = Location.create(project.getDir());
mClient.report(new Context(this, project, main, project.getDir()), IssueRegistry.LINT_ERROR, project.getConfiguration(this).getSeverity(IssueRegistry.LINT_ERROR), location, message, TextFormat.RAW);
classEntries = Collections.emptyList();
} else {
classEntries = ClassEntry.fromClassPath(mClient, classFolders, true);
}
// Actually run the detectors. Libraries should be called before the
// main classes.
runClassDetectors(Scope.JAVA_LIBRARIES, libraryEntries, project, main);
if (mCanceled) {
return;
}
runClassDetectors(Scope.CLASS_FILE, classEntries, project, main);
runClassDetectors(Scope.ALL_CLASS_FILES, classEntries, project, main);
}
Aggregations