Search in sources :

Example 56 with NonNull

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

the class PermissionFinder method getPermissionRequirement.

@NonNull
private Result getPermissionRequirement(@NonNull PsiField field, @NonNull UAnnotation annotation) {
    PermissionRequirement requirement = PermissionRequirement.create(annotation);
    PsiClass containingClass = field.getContainingClass();
    String name = containingClass != null ? containingClass.getName() + "." + field.getName() : field.getName();
    assert name != null;
    return new Result(mOperation, requirement, name);
}
Also used : PsiClass(com.intellij.psi.PsiClass) NonNull(com.android.annotations.NonNull)

Example 57 with NonNull

use of com.android.annotations.NonNull in project android 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 LintXmlPosition(node, textRange.getStartOffset() + startDelta);
    Position end = new LintXmlPosition(node, textRange.getStartOffset() + endDelta);
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.lint.detector.api.Position) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 58 with NonNull

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

the class DomPsiParser method getLocation.

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node) {
    TextRange textRange = DomPsiConverter.getTextRange(node);
    Position start = new LintXmlPosition(node, textRange.getStartOffset());
    Position end = new LintXmlPosition(node, textRange.getEndOffset());
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.lint.detector.api.Position) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 59 with NonNull

use of com.android.annotations.NonNull in project bazel by bazelbuild.

the class FileUtils method getDirectoryNameForJar.

/**
     * Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.
     */
@NonNull
public static String getDirectoryNameForJar(@NonNull File inputFile) {
    // add a hash of the original file path.
    HashFunction hashFunction = Hashing.sha1();
    HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE);
    String name = Files.getNameWithoutExtension(inputFile.getName());
    if (name.equals("classes") && inputFile.getAbsolutePath().contains("exploded-aar")) {
        // This naming scheme is coming from DependencyManager#computeArtifactPath.
        File versionDir = inputFile.getParentFile().getParentFile();
        File artifactDir = versionDir.getParentFile();
        File groupDir = artifactDir.getParentFile();
        name = Joiner.on('-').join(groupDir.getName(), artifactDir.getName(), versionDir.getName());
    }
    name = name + "_" + hashCode.toString();
    return name;
}
Also used : HashCode(com.google.common.hash.HashCode) HashFunction(com.google.common.hash.HashFunction) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 60 with NonNull

use of com.android.annotations.NonNull in project buck by facebook.

the class XmlPrettyPrinter method prettyPrint.

/**
     * Pretty-prints the given XML document, which must be well-formed. If it is not,
     * the original unformatted XML document is returned
     *
     * @param xml the XML content to format
     * @param prefs the preferences to format with
     * @param style the style to format with
     * @param lineSeparator the line separator to use, such as "\n" (can be null, in which
     *     case the system default is looked up via the line.separator property)
     * @return the formatted document (or if a parsing error occurred, returns the
     *     unformatted document)
     */
@NonNull
public static String prettyPrint(@NonNull String xml, @NonNull XmlFormatPreferences prefs, @NonNull XmlFormatStyle style, @Nullable String lineSeparator) {
    Document document = XmlUtils.parseDocumentSilently(xml, true);
    if (document != null) {
        XmlPrettyPrinter printer = new XmlPrettyPrinter(prefs, style, lineSeparator);
        printer.setEndWithNewline(xml.endsWith(printer.getLineSeparator()));
        StringBuilder sb = new StringBuilder(3 * xml.length() / 2);
        printer.prettyPrint(-1, document, null, null, sb, false);
        return sb.toString();
    } else {
        // Parser error: just return the unformatted content
        return xml;
    }
}
Also used : Document(org.w3c.dom.Document) 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