Search in sources :

Example 51 with NonNull

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

the class IntellijLintUtils method getUastLocation.

/**
   * 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 getUastLocation(@NonNull File file, @NonNull UElement element) {
    //noinspection ConstantConditions
    PsiFile containingPsiFile = UastUtils.getContainingFile(element).getPsi();
    assert containingPsiFile.getVirtualFile() == null || FileUtil.filesEqual(VfsUtilCore.virtualToIoFile(containingPsiFile.getVirtualFile()), file);
    if (element instanceof UClass) {
        // Point to the name rather than the beginning of the javadoc
        UClass clz = (UClass) element;
        UElement nameIdentifier = clz.getUastAnchor();
        if (nameIdentifier != null) {
            element = nameIdentifier;
        }
    }
    TextRange textRange = null;
    PsiElement psi = element.getPsi();
    if (psi != null) {
        textRange = psi.getTextRange();
    } else if (element instanceof UElementWithLocation) {
        UElementWithLocation elementWithLocation = (UElementWithLocation) element;
        textRange = new TextRange(elementWithLocation.getStartOffset(), elementWithLocation.getEndOffset());
    }
    if (textRange == null) {
        return Location.NONE;
    }
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
    Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
    return Location.create(file, start, end);
}
Also used : UElementWithLocation(org.jetbrains.uast.psi.UElementWithLocation) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 52 with NonNull

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

the class DefaultConfiguration method getSeverity.

@Override
@NonNull
public Severity getSeverity(@NonNull Issue issue) {
    ensureInitialized();
    Severity severity = mSeverity.get(issue.getId());
    if (severity == null) {
        severity = mSeverity.get(VALUE_ALL);
    }
    if (severity != null) {
        return severity;
    }
    if (mParent != null) {
        return mParent.getSeverity(issue);
    }
    return getDefaultSeverity(issue);
}
Also used : Severity(com.android.tools.klint.detector.api.Severity) NonNull(com.android.annotations.NonNull)

Example 53 with NonNull

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

the class DefaultConfiguration method formatError.

private void formatError(String message, Object... args) {
    if (args != null && args.length > 0) {
        message = String.format(message, args);
    }
    message = "Failed to parse `lint.xml` configuration file: " + message;
    LintDriver driver = new LintDriver(new IssueRegistry() {

        @Override
        @NonNull
        public List<Issue> getIssues() {
            return Collections.emptyList();
        }
    }, mClient);
    mClient.report(new Context(driver, mProject, mProject, mConfigFile), IssueRegistry.LINT_ERROR, mProject.getConfiguration(driver).getSeverity(IssueRegistry.LINT_ERROR), Location.create(mConfigFile), message, TextFormat.RAW);
}
Also used : Context(com.android.tools.klint.detector.api.Context) NonNull(com.android.annotations.NonNull) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 54 with NonNull

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

the class ControlFlowGraph method create.

/**
     * Creates a new {@link ControlFlowGraph} and populates it with the flow
     * control for the given method. If the optional {@code initial} parameter is
     * provided with an existing graph, then the graph is simply populated, not
     * created. This allows subclassing of the graph instance, if necessary.
     *
     * @param initial usually null, but can point to an existing instance of a
     *            {@link ControlFlowGraph} in which that graph is reused (but
     *            populated with new edges)
     * @param classNode the class containing the method to be analyzed
     * @param method the method to be analyzed
     * @return a {@link ControlFlowGraph} with nodes for the control flow in the
     *         given method
     * @throws AnalyzerException if the underlying bytecode library is unable to
     *             analyze the method bytecode
     */
@NonNull
public static ControlFlowGraph create(@Nullable ControlFlowGraph initial, @NonNull ClassNode classNode, @NonNull MethodNode method) throws AnalyzerException {
    final ControlFlowGraph graph = initial != null ? initial : new ControlFlowGraph();
    final InsnList instructions = method.instructions;
    graph.mNodeMap = Maps.newHashMapWithExpectedSize(instructions.size());
    graph.mMethod = method;
    // Create a flow control graph using ASM5's analyzer. According to the ASM 4 guide
    // (download.forge.objectweb.org/asm/asm4-guide.pdf) there are faster ways to construct
    // it, but those require a lot more code.
    Analyzer analyzer = new Analyzer(new BasicInterpreter()) {

        @Override
        protected void newControlFlowEdge(int insn, int successor) {
            // Update the information as of whether the this object has been
            // initialized at the given instruction.
            AbstractInsnNode from = instructions.get(insn);
            AbstractInsnNode to = instructions.get(successor);
            graph.add(from, to);
        }

        @Override
        protected boolean newControlFlowExceptionEdge(int insn, TryCatchBlockNode tcb) {
            AbstractInsnNode from = instructions.get(insn);
            graph.exception(from, tcb);
            return super.newControlFlowExceptionEdge(insn, tcb);
        }

        @Override
        protected boolean newControlFlowExceptionEdge(int insn, int successor) {
            AbstractInsnNode from = instructions.get(insn);
            AbstractInsnNode to = instructions.get(successor);
            graph.exception(from, to);
            return super.newControlFlowExceptionEdge(insn, successor);
        }
    };
    analyzer.analyze(classNode.name, method);
    return graph;
}
Also used : TryCatchBlockNode(org.jetbrains.org.objectweb.asm.tree.TryCatchBlockNode) BasicInterpreter(org.jetbrains.org.objectweb.asm.tree.analysis.BasicInterpreter) InsnList(org.jetbrains.org.objectweb.asm.tree.InsnList) Analyzer(org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode) NonNull(com.android.annotations.NonNull)

Example 55 with NonNull

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

the class SupportAnnotationDetector method mergeAnnotationPermissions.

@NonNull
private static PermissionHolder mergeAnnotationPermissions(@NonNull PermissionHolder permissions, @Nullable UAnnotation annotation) {
    if (annotation != null) {
        PermissionRequirement requirement = PermissionRequirement.create(annotation);
        permissions = SetPermissionLookup.join(permissions, requirement);
    }
    return permissions;
}
Also used : PermissionRequirement(com.android.tools.klint.checks.PermissionRequirement) 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