Search in sources :

Example 26 with NonNull

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

the class LintIdeJavaParser method getAnnotations.

@NonNull
private static Iterable<ResolvedAnnotation> getAnnotations(@Nullable PsiModifierListOwner owner) {
    if (owner != null) {
        PsiModifierList modifierList = owner.getModifierList();
        if (modifierList != null) {
            PsiAnnotation[] annotations = modifierList.getAnnotations();
            if (annotations.length > 0) {
                List<ResolvedAnnotation> result = Lists.newArrayListWithExpectedSize(annotations.length);
                for (PsiAnnotation method : annotations) {
                    result.add(new ResolvedPsiAnnotation(method));
                }
                return result;
            }
        }
        ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(owner.getProject());
        PsiAnnotation[] annotations = annotationsManager.findExternalAnnotations(owner);
        if (annotations != null) {
            List<ResolvedAnnotation> result = Lists.newArrayListWithExpectedSize(annotations.length);
            for (PsiAnnotation method : annotations) {
                result.add(new ResolvedPsiAnnotation(method));
            }
            return result;
        }
    }
    return Collections.emptyList();
}
Also used : ExternalAnnotationsManager(com.intellij.codeInsight.ExternalAnnotationsManager) NonNull(com.android.annotations.NonNull)

Example 27 with NonNull

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

the class LintIdeJavaParser method getRangeLocation.

@NonNull
@Override
public Location getRangeLocation(@NonNull JavaContext context, @NonNull Node from, int fromDelta, @NonNull Node to, int toDelta) {
    Position position1 = from.getPosition();
    Position position2 = to.getPosition();
    if (position1 == null) {
        return getLocation(context, to);
    } else if (position2 == null) {
        return getLocation(context, from);
    }
    int start = Math.max(0, from.getPosition().getStart() + fromDelta);
    int end = to.getPosition().getEnd() + toDelta;
    return Location.create(context.file, null, start, end);
}
Also used : Position(lombok.ast.Position) NonNull(com.android.annotations.NonNull)

Example 28 with NonNull

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

the class LintIdeProject method create.

/** Creates a set of projects for the given IntelliJ modules */
@NonNull
public static List<Project> create(@NonNull LintIdeClient 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;
    }
}
Also used : Project(com.android.tools.lint.detector.api.Project) Module(com.intellij.openapi.module.Module) NonNull(com.android.annotations.NonNull)

Example 29 with NonNull

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

the class LintIdeUtils method getLocation.

/**
   * Gets the location of the given element
   *
   * @param file the file containing the location
   * @param element the element to look up the location for
   * @return the location of the given element
   */
@NonNull
public static Location getLocation(@NonNull File file, @NonNull PsiElement element) {
    //noinspection ConstantConditions
    assert element.getContainingFile().getVirtualFile() == null || FileUtil.filesEqual(VfsUtilCore.virtualToIoFile(element.getContainingFile().getVirtualFile()), file);
    if (element instanceof PsiClass) {
        // Point to the name rather than the beginning of the javadoc
        PsiClass clz = (PsiClass) element;
        PsiIdentifier nameIdentifier = clz.getNameIdentifier();
        if (nameIdentifier != null) {
            element = nameIdentifier;
        }
    }
    TextRange textRange = element.getTextRange();
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
    Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
    return Location.create(file, start, end);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 30 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)

Aggregations

NonNull (com.android.annotations.NonNull)113 File (java.io.File)38 TextRange (com.intellij.openapi.util.TextRange)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 ImmutableList (com.google.common.collect.ImmutableList)8 Nullable (com.android.annotations.Nullable)7 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 SdkConstants (com.android.SdkConstants)4 OutputFile (com.android.build.OutputFile)4 Issue (com.android.tools.klint.detector.api.Issue)4 Position (com.android.tools.lint.detector.api.Position)4 FileUtils (com.android.utils.FileUtils)4 Splitter (com.google.common.base.Splitter)4 Module (com.intellij.openapi.module.Module)4 StringReader (java.io.StringReader)4 Node (org.w3c.dom.Node)4