use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.
the class RtlDetector method rtlApplies.
private boolean rtlApplies(@NonNull Context context) {
Project project = context.getMainProject();
if (project.getTargetSdk() < RTL_API) {
return false;
}
int buildTarget = project.getBuildSdk();
if (buildTarget != -1 && buildTarget < RTL_API) {
return false;
}
//noinspection RedundantIfStatement
if (mEnabledRtlSupport != null && !mEnabledRtlSupport) {
return false;
}
return true;
}
use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.
the class PrivateResourceDetector method visitResourceReference.
@Override
public void visitResourceReference(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UElement node, @NonNull ResourceType resourceType, @NonNull String name, boolean isFramework) {
if (context.getProject().isGradleProject() && !isFramework) {
Project project = context.getProject();
if (project.getGradleProjectModel() != null && project.getCurrentVariant() != null) {
if (isPrivate(context, resourceType, name)) {
String message = createUsageErrorMessage(context, resourceType, name);
context.report(ISSUE, node, context.getUastLocation(node), message);
}
}
}
}
use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.
the class IntellijLintProject method create.
/** Creates a set of projects for the given IntelliJ modules */
@NonNull
public static List<Project> create(@NonNull IntellijLintClient client, @Nullable List<VirtualFile> files, @NonNull Module... modules) {
List<Project> projects = Lists.newArrayList();
Map<Project, Module> projectMap = Maps.newHashMap();
Map<Module, Project> moduleMap = Maps.newHashMap();
Map<AndroidLibrary, Project> libraryMap = Maps.newHashMap();
if (files != null && !files.isEmpty()) {
// Wrap list with a mutable list since we'll be removing the files as we see them
files = Lists.newArrayList(files);
}
for (Module module : modules) {
addProjects(client, module, files, moduleMap, libraryMap, projectMap, projects);
}
client.setModuleMap(projectMap);
if (projects.size() > 1) {
// Partition the projects up such that we only return projects that aren't
// included by other projects (e.g. because they are library projects)
Set<Project> roots = new HashSet<Project>(projects);
for (Project project : projects) {
roots.removeAll(project.getAllLibraries());
}
return Lists.newArrayList(roots);
} else {
return projects;
}
}
use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.
the class IntellijLintProject method addProjects.
/**
* Recursively add lint projects for the given module, and any other module or library it depends on, and also
* populate the reverse maps so we can quickly map from a lint project to a corresponding module/library (used
* by the lint client
*/
private static void addProjects(@NonNull LintClient client, @NonNull Module module, @Nullable List<VirtualFile> files, @NonNull Map<Module, Project> moduleMap, @NonNull Map<AndroidLibrary, Project> libraryMap, @NonNull Map<Project, Module> projectMap, @NonNull List<Project> projects) {
if (moduleMap.containsKey(module)) {
return;
}
LintModuleProject project = createModuleProject(client, module);
if (project == null) {
// It's possible for the module to *depend* on Android code, e.g. in a Gradle
// project there will be a top-level non-Android module
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(module, false);
for (AndroidFacet dependentFacet : dependentFacets) {
addProjects(client, dependentFacet.getModule(), files, moduleMap, libraryMap, projectMap, projects);
}
return;
}
projects.add(project);
moduleMap.put(module, project);
projectMap.put(project, module);
if (processFileFilter(module, files, project)) {
// No need to process dependencies when doing single file analysis
return;
}
List<Project> dependencies = Lists.newArrayList();
// No, this shouldn't use getAllAndroidDependencies; we may have non-Android dependencies that this won't include
// (e.g. Java-only modules)
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(module, true);
for (AndroidFacet dependentFacet : dependentFacets) {
Project p = moduleMap.get(dependentFacet.getModule());
if (p != null) {
dependencies.add(p);
} else {
addProjects(client, dependentFacet.getModule(), files, moduleMap, libraryMap, projectMap, dependencies);
}
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
AndroidGradleModel androidGradleModel = AndroidGradleModel.get(facet);
if (androidGradleModel != null) {
addGradleLibraryProjects(client, files, libraryMap, projects, facet, androidGradleModel, project, projectMap, dependencies);
}
}
project.setDirectLibraries(dependencies);
}
use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.
the class IntellijLintProject method addGradleLibraryProjects.
/** Adds any gradle library projects to the dependency list */
private static void addGradleLibraryProjects(@NonNull LintClient client, @Nullable List<VirtualFile> files, @NonNull Map<AndroidLibrary, Project> libraryMap, @NonNull List<Project> projects, @NonNull AndroidFacet facet, @NonNull AndroidGradleModel androidGradleModel, @NonNull LintModuleProject project, @NonNull Map<Project, Module> projectMap, @NonNull List<Project> dependencies) {
Collection<AndroidLibrary> libraries = androidGradleModel.getMainArtifact().getDependencies().getLibraries();
for (AndroidLibrary library : libraries) {
Project p = libraryMap.get(library);
if (p == null) {
File dir = library.getFolder();
p = new LintGradleLibraryProject(client, dir, dir, library);
libraryMap.put(library, p);
projectMap.put(p, facet.getModule());
projects.add(p);
if (files != null) {
VirtualFile libraryDir = LocalFileSystem.getInstance().findFileByIoFile(dir);
if (libraryDir != null) {
ListIterator<VirtualFile> iterator = files.listIterator();
while (iterator.hasNext()) {
VirtualFile file = iterator.next();
if (VfsUtilCore.isAncestor(libraryDir, file, false)) {
project.addFile(VfsUtilCore.virtualToIoFile(file));
iterator.remove();
}
}
}
if (files.isEmpty()) {
// No more work in other modules
files = null;
}
}
}
dependencies.add(p);
}
}
Aggregations