Search in sources :

Example 16 with NonNull

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

the class Project method getResourceFolders.

/**
     * Returns the resource folders.
     *
     * @return a list of files pointing to the resource folders, which might be empty if the project
     * does not provide any resources.
     */
@NonNull
public List<File> getResourceFolders() {
    if (mResourceFolders == null) {
        List<File> folders = mClient.getResourceFolders(this);
        if (folders.size() == 1 && isAospFrameworksRelatedProject(mDir)) {
            // No manifest file for this project: just init the manifest values here
            mManifestMinSdk = mManifestTargetSdk = new AndroidVersion(HIGHEST_KNOWN_API, null);
            File folder = new File(folders.get(0), RES_FOLDER);
            if (!folder.exists()) {
                folders = Collections.emptyList();
            }
        }
        mResourceFolders = folders;
    }
    return mResourceFolders;
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) OutputFile(com.android.build.OutputFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 17 with NonNull

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

the class IssueRegistry method createCategoryList.

@NonNull
private List<Category> createCategoryList() {
    Set<Category> categorySet = Sets.newHashSetWithExpectedSize(20);
    for (Issue issue : getIssues()) {
        categorySet.add(issue.getCategory());
    }
    List<Category> sorted = new ArrayList<Category>(categorySet);
    Collections.sort(sorted);
    return sorted;
}
Also used : Category(com.android.tools.klint.detector.api.Category) Issue(com.android.tools.klint.detector.api.Issue) ArrayList(java.util.ArrayList) NonNull(com.android.annotations.NonNull)

Example 18 with NonNull

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

the class IssueRegistry method getIssuesForScope.

/**
     * Returns all available issues of a given scope (regardless of whether
     * they are actually enabled for a given configuration etc)
     *
     * @param scope the applicable scope set
     * @return a list of issues
     */
@NonNull
protected List<Issue> getIssuesForScope(@NonNull EnumSet<Scope> scope) {
    List<Issue> list = sScopeIssues.get(scope);
    if (list == null) {
        List<Issue> issues = getIssues();
        if (scope.equals(Scope.ALL)) {
            list = issues;
        } else {
            list = new ArrayList<Issue>(getIssueCapacity(scope));
            for (Issue issue : issues) {
                // Determine if the scope matches
                if (issue.getImplementation().isAdequate(scope)) {
                    list.add(issue);
                }
            }
        }
        sScopeIssues.put(scope, list);
    }
    return list;
}
Also used : Issue(com.android.tools.klint.detector.api.Issue) NonNull(com.android.annotations.NonNull)

Example 19 with NonNull

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

the class JavaParser method getLocation.

/**
     * Returns a {@link Location} for the given element
     *
     * @param context information about the file being parsed
     * @param element the element to create a location for
     * @return a location for the given node
     */
// subclasses may want to override/optimize
@SuppressWarnings("MethodMayBeStatic")
@NonNull
public Location getLocation(@NonNull JavaContext context, @NonNull PsiElement element) {
    TextRange range = element.getTextRange();
    UFile uFile = (UFile) getUastContext().convertElementWithParent(element.getContainingFile(), UFile.class);
    if (uFile == null) {
        return Location.NONE;
    }
    PsiFile containingFile = uFile.getPsi();
    File file = context.file;
    if (containingFile != context.getUFile().getPsi()) {
        // Reporting an error in a different file.
        if (context.getDriver().getScope().size() == 1) {
            // Don't bother with this error if it's in a different file during single-file analysis
            return Location.NONE;
        }
        VirtualFile virtualFile = containingFile.getVirtualFile();
        if (virtualFile == null) {
            return Location.NONE;
        }
        file = VfsUtilCore.virtualToIoFile(virtualFile);
    }
    return Location.create(file, context.getContents(), range.getStartOffset(), range.getEndOffset());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UFile(org.jetbrains.uast.UFile) PsiJavaFile(com.intellij.psi.PsiJavaFile) File(java.io.File) UFile(org.jetbrains.uast.UFile) NonNull(com.android.annotations.NonNull)

Example 20 with NonNull

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

the class JavaParser method getNameLocation.

/**
     * Returns a {@link Location} for the given node. This attempts to pick a shorter
     * location range than the entire node; for a class or method for example, it picks
     * the name node (if found). For statement constructs such as a {@code switch} statement
     * it will highlight the keyword, etc.
     *
     * @param context information about the file being parsed
     * @param node the node to create a location for
     * @return a location for the given node
     * @deprecated Use {@link #getNameLocation(JavaContext, PsiElement)} instead
     */
@Deprecated
@NonNull
public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) {
    Node nameNode = JavaContext.findNameNode(node);
    if (nameNode != null) {
        node = nameNode;
    } else {
        if (node instanceof Switch || node instanceof For || node instanceof If || node instanceof While || node instanceof Throw || node instanceof Return) {
            // Lint doesn't want to highlight the entire statement/block associated
            // with this node, it wants to just highlight the keyword.
            Location location = getLocation(context, node);
            Position start = location.getStart();
            if (start != null) {
                // The Lombok classes happen to have the same length as the target keyword
                int length = node.getClass().getSimpleName().length();
                return Location.create(location.getFile(), start, new DefaultPosition(start.getLine(), start.getColumn() + length, start.getOffset() + length));
            }
        }
    }
    return getLocation(context, node);
}
Also used : Return(lombok.ast.Return) Switch(lombok.ast.Switch) Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) Throw(lombok.ast.Throw) Node(lombok.ast.Node) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) For(lombok.ast.For) While(lombok.ast.While) If(lombok.ast.If) Location(com.android.tools.klint.detector.api.Location) 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