Search in sources :

Example 21 with Nullable

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

the class UastLintUtils method toAndroidReference.

@Nullable
private static AndroidReference toAndroidReference(UQualifiedReferenceExpression expression) {
    List<String> path = UastUtils.asQualifiedPath(expression);
    String packageNameFromResolved = null;
    PsiClass containingClass = UastUtils.getContainingClass(expression.resolve());
    if (containingClass != null) {
        String containingClassFqName = containingClass.getQualifiedName();
        if (containingClassFqName != null) {
            int i = containingClassFqName.lastIndexOf(".R.");
            if (i >= 0) {
                packageNameFromResolved = containingClassFqName.substring(0, i);
            }
        }
    }
    if (path == null) {
        return null;
    }
    int size = path.size();
    if (size < 3) {
        return null;
    }
    String r = path.get(size - 3);
    if (!r.equals(SdkConstants.R_CLASS)) {
        return null;
    }
    String packageName = packageNameFromResolved != null ? packageNameFromResolved : Joiner.on('.').join(path.subList(0, size - 3));
    String type = path.get(size - 2);
    String name = path.get(size - 1);
    ResourceType resourceType = null;
    for (ResourceType value : ResourceType.values()) {
        if (value.getName().equals(type)) {
            resourceType = value;
            break;
        }
    }
    if (resourceType == null) {
        return null;
    }
    return new AndroidReference(expression, packageName, resourceType, name);
}
Also used : ResourceType(com.android.resources.ResourceType) Nullable(com.android.annotations.Nullable)

Example 22 with Nullable

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

the class ViewTypeDetector method getViewTags.

@Nullable
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
    // Check view tag in this file. Can I do it cheaply? Try with
    // an XML pull parser. Or DOM if we have multiple resources looked
    // up?
    ResourceFile source = item.getSource();
    if (source != null) {
        File file = source.getFile();
        Multimap<String, String> map = getIdToTagsIn(context, file);
        if (map != null) {
            return map.get(item.getName());
        }
    }
    return null;
}
Also used : ResourceFile(com.android.ide.common.res2.ResourceFile) File(java.io.File) ResourceFile(com.android.ide.common.res2.ResourceFile) Nullable(com.android.annotations.Nullable)

Example 23 with Nullable

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

the class IntellijLintUtils method getPsiFile.

/**
   * Returns the {@link PsiFile} associated with a given lint {@link Context}
   *
   * @param context the context to look up the file for
   * @return the corresponding {@link PsiFile}, or null
   */
@Nullable
public static PsiFile getPsiFile(@NonNull Context context) {
    VirtualFile file = VfsUtil.findFileByIoFile(context.file, false);
    if (file == null) {
        return null;
    }
    LintRequest request = context.getDriver().getRequest();
    Project project = ((IntellijLintRequest) request).getProject();
    if (project.isDisposed()) {
        return null;
    }
    return AndroidPsiUtils.getPsiFileSafely(project, file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LintRequest(com.android.tools.klint.client.api.LintRequest) Project(com.intellij.openapi.project.Project) Nullable(com.android.annotations.Nullable)

Example 24 with Nullable

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

the class IntellijViewTypeDetector method getViewTags.

@Nullable
@Override
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
    AbstractResourceRepository projectResources = context.getClient().getProjectResources(context.getMainProject(), true);
    assert projectResources instanceof LocalResourceRepository : projectResources;
    LocalResourceRepository repository = (LocalResourceRepository) projectResources;
    String viewTag = repository.getViewTag(item);
    if (viewTag != null) {
        return Collections.singleton(viewTag);
    }
    return super.getViewTags(context, item);
}
Also used : AbstractResourceRepository(com.android.ide.common.res2.AbstractResourceRepository) LocalResourceRepository(com.android.tools.idea.rendering.LocalResourceRepository) Nullable(com.android.annotations.Nullable)

Example 25 with Nullable

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

the class TypoLookup method get.

/**
     * Returns an instance of the typo database
     *
     * @param client the client to associate with this database - used only for
     *            logging
     * @param xmlFile the XML file containing configuration data to use for this
     *            database
     * @return a (possibly shared) instance of the typo database, or null
     *         if its data can't be found
     */
@Nullable
private static TypoLookup get(LintClient client, File xmlFile) {
    if (!xmlFile.exists()) {
        client.log(null, "The typo database file %1$s does not exist", xmlFile);
        return null;
    }
    String name = xmlFile.getName();
    if (LintUtils.endsWith(name, DOT_XML)) {
        name = name.substring(0, name.length() - DOT_XML.length());
    }
    File cacheDir = client.getCacheDir(true);
    if (cacheDir == null) {
        cacheDir = xmlFile.getParentFile();
    }
    File binaryData = new File(cacheDir, name + // conflicts on Windows (such as issue #26663)
    '-' + BINARY_FORMAT_VERSION + //$NON-NLS-1$
    ".bin");
    if (DEBUG_FORCE_REGENERATE_BINARY) {
        System.err.println("\nTemporarily regenerating binary data unconditionally \nfrom " + xmlFile + "\nto " + binaryData);
        if (!createCache(client, xmlFile, binaryData)) {
            return null;
        }
    } else if (!binaryData.exists() || binaryData.lastModified() < xmlFile.lastModified()) {
        if (!createCache(client, xmlFile, binaryData)) {
            return null;
        }
    }
    if (!binaryData.exists()) {
        client.log(null, "The typo database file %1$s does not exist", binaryData);
        return null;
    }
    return new TypoLookup(client, xmlFile, binaryData);
}
Also used : File(java.io.File) Nullable(com.android.annotations.Nullable)

Aggregations

Nullable (com.android.annotations.Nullable)83 File (java.io.File)21 IOException (java.io.IOException)9 ResourceType (com.android.resources.ResourceType)8 PsiClass (com.intellij.psi.PsiClass)7 PsiElement (com.intellij.psi.PsiElement)7 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)7 ResourceUrl (com.android.ide.common.resources.ResourceUrl)6 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)6 PsiExpression (com.intellij.psi.PsiExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiStatement (com.intellij.psi.PsiStatement)6 ArrayList (java.util.ArrayList)6 PsiField (com.intellij.psi.PsiField)5 PsiFile (com.intellij.psi.PsiFile)4 Node (lombok.ast.Node)4 UReferenceExpression (org.jetbrains.uast.UReferenceExpression)4 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)3