Search in sources :

Example 46 with NonNull

use of com.android.annotations.NonNull in project android by JetBrains.

the class EclipseProject method getManifestDoc.

@NonNull
public Document getManifestDoc() throws IOException {
    assert isAndroidProject();
    if (myManifestDoc == null) {
        File file = getManifestFile();
        myManifestDoc = myImporter.getXmlDocument(file, true);
    }
    return myManifestDoc;
}
Also used : File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 47 with NonNull

use of com.android.annotations.NonNull 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);
}
Also used : File(java.io.File) Location(com.android.tools.klint.detector.api.Location) NonNull(com.android.annotations.NonNull)

Example 48 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class DomPsiParser method getLocation.

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node, int startDelta, int endDelta) {
    TextRange textRange = DomPsiConverter.getTextRange(node);
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset() + startDelta);
    Position end = new DefaultPosition(-1, -1, textRange.getStartOffset() + endDelta);
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 49 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class IntellijLintClient method getConfiguration.

@NonNull
@Override
public Configuration getConfiguration(@NonNull com.android.tools.klint.detector.api.Project project, @Nullable final LintDriver driver) {
    if (project.isGradleProject() && project.isAndroidProject() && !project.isLibrary()) {
        AndroidProject model = project.getGradleProjectModel();
        if (model != null) {
            try {
                LintOptions lintOptions = model.getLintOptions();
                final Map<String, Integer> overrides = lintOptions.getSeverityOverrides();
                if (overrides != null && !overrides.isEmpty()) {
                    return new DefaultConfiguration(this, project, null) {

                        @NonNull
                        @Override
                        public Severity getSeverity(@NonNull Issue issue) {
                            Integer severity = overrides.get(issue.getId());
                            if (severity != null) {
                                switch(severity.intValue()) {
                                    case LintOptions.SEVERITY_FATAL:
                                        return Severity.FATAL;
                                    case LintOptions.SEVERITY_ERROR:
                                        return Severity.ERROR;
                                    case LintOptions.SEVERITY_WARNING:
                                        return Severity.WARNING;
                                    case LintOptions.SEVERITY_INFORMATIONAL:
                                        return Severity.INFORMATIONAL;
                                    case LintOptions.SEVERITY_IGNORE:
                                    default:
                                        return Severity.IGNORE;
                                }
                            }
                            // This is a LIST lookup. I should make this faster!
                            if (!getIssues().contains(issue) && (driver == null || !driver.isCustomIssue(issue))) {
                                return Severity.IGNORE;
                            }
                            return super.getSeverity(issue);
                        }
                    };
                }
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    return new DefaultConfiguration(this, project, null) {

        @Override
        public boolean isEnabled(@NonNull Issue issue) {
            if (getIssues().contains(issue) && super.isEnabled(issue)) {
                return true;
            }
            return driver != null && driver.isCustomIssue(issue);
        }
    };
}
Also used : NonNull(com.android.annotations.NonNull) LintOptions(com.android.builder.model.LintOptions) AndroidProject(com.android.builder.model.AndroidProject) IOException(java.io.IOException) NonNull(com.android.annotations.NonNull)

Example 50 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class IntellijLintProject method createForSingleFile.

/**
   * Creates a project for a single file. Also optionally creates a main project for the file, if applicable.
   *
   * @param client the lint client
   * @param file the file to create a project for
   * @param module the module to create a project for
   * @return a project for the file, as well as a project (or null) for the main Android module
   */
@NonNull
public static Pair<Project, Project> createForSingleFile(@NonNull IntellijLintClient client, @Nullable VirtualFile file, @NonNull Module module) {
    // TODO: Can make this method even more lightweight: we don't need to initialize anything in the project (source paths etc)
    // other than the metadata necessary for this file's type
    LintModuleProject project = createModuleProject(client, module);
    LintModuleProject main = null;
    Map<Project, Module> projectMap = Maps.newHashMap();
    if (project != null) {
        project.setDirectLibraries(Collections.<Project>emptyList());
        if (file != null) {
            project.addFile(VfsUtilCore.virtualToIoFile(file));
        }
        projectMap.put(project, module);
        // using the library, not "1" (the default for a module without a manifest)
        if (!project.isAndroidProject()) {
            Module androidModule = findAndroidModule(module);
            if (androidModule != null) {
                main = createModuleProject(client, androidModule);
                if (main != null) {
                    projectMap.put(main, androidModule);
                    main.setDirectLibraries(Collections.<Project>singletonList(project));
                }
            }
        }
    }
    client.setModuleMap(projectMap);
    //noinspection ConstantConditions
    return Pair.<Project, Project>create(project, main);
}
Also used : Project(com.android.tools.klint.detector.api.Project) Module(com.intellij.openapi.module.Module) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)89 File (java.io.File)23 TextRange (com.intellij.openapi.util.TextRange)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)8 OutputFile (com.android.build.OutputFile)5 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 Issue (com.android.tools.klint.detector.api.Issue)4 Position (com.android.tools.lint.detector.api.Position)4 Module (com.intellij.openapi.module.Module)4 StringReader (java.io.StringReader)4 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 InputSource (org.xml.sax.InputSource)4 Nullable (com.android.annotations.Nullable)3 AaptPackageProcessBuilder (com.android.builder.core.AaptPackageProcessBuilder)3 AtlasBuilder (com.android.builder.core.AtlasBuilder)3 AndroidProject (com.android.builder.model.AndroidProject)3