Search in sources :

Example 71 with NonNull

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

the class DomPsiParser method getValueLocation.

@NonNull
@Override
public Location getValueLocation(@NonNull XmlContext context, @NonNull Attr node) {
    TextRange textRange = DomPsiConverter.getTextValueRange(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 72 with NonNull

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

the class DomPsiParser method getNameLocation.

@NonNull
@Override
public Location getNameLocation(@NonNull XmlContext context, @NonNull Node node) {
    TextRange textRange = DomPsiConverter.getTextNameRange(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 73 with NonNull

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

the class LintIdeProject 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 LintIdeClient 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.lint.detector.api.Project) Module(com.intellij.openapi.module.Module) NonNull(com.android.annotations.NonNull)

Example 74 with NonNull

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

the class LocalResourceRepository method getMatchingFiles.

@NonNull
public List<VirtualFile> getMatchingFiles(@NonNull VirtualFile file, @NonNull ResourceType type, @NonNull FolderConfiguration config) {
    List<ResourceFile> matches = super.getMatchingFiles(ResourceHelper.getResourceName(file), type, config);
    List<VirtualFile> matchesFiles = new ArrayList<VirtualFile>(matches.size());
    for (ResourceFile match : matches) {
        if (match != null) {
            if (match instanceof PsiResourceFile) {
                matchesFiles.add(((PsiResourceFile) match).getPsiFile().getVirtualFile());
            } else {
                matchesFiles.add(LocalFileSystem.getInstance().findFileByIoFile(match.getFile()));
            }
        }
    }
    return matchesFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) ArrayList(java.util.ArrayList) NonNull(com.android.annotations.NonNull)

Example 75 with NonNull

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

the class PsiResourceItem method parseStyleValue.

@NonNull
private ResourceValue parseStyleValue(@NonNull StyleResourceValue styleValue) {
    assert myTag != null;
    for (XmlTag child : myTag.getSubTags()) {
        String name = getAttributeValue(child, ATTR_NAME);
        if (name != null) {
            // is the attribute in the android namespace?
            boolean isFrameworkAttr = styleValue.isFramework();
            if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
                name = name.substring(ANDROID_NS_NAME_PREFIX_LEN);
                isFrameworkAttr = true;
            }
            ItemResourceValue resValue = new ItemResourceValue(name, isFrameworkAttr, styleValue.isFramework(), styleValue.getLibraryName());
            resValue.setValue(ValueXmlHelper.unescapeResourceString(ResourceHelper.getTextContent(child), true, true));
            styleValue.addItem(resValue);
        }
    }
    return styleValue;
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) 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