Search in sources :

Example 36 with Nullable

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

the class ApiLookup method get.

/**
     * Returns an instance of the API database
     *
     * @param client the client to associate with this database - used only for
     *            logging. The database object may be shared among repeated invocations,
     *            and in that case client used will be the one originally passed in.
     *            In other words, this parameter may be ignored if the client created
     *            is not new.
     * @return a (possibly shared) instance of the API database, or null
     *         if its data can't be found
     */
@Nullable
public static ApiLookup get(@NonNull LintClient client) {
    synchronized (ApiLookup.class) {
        ApiLookup db = sInstance.get();
        if (db == null) {
            File file = client.findResource(XML_FILE_PATH);
            if (file == null) {
                // AOSP build environment?
                //$NON-NLS-1$
                String build = System.getenv("ANDROID_BUILD_TOP");
                if (build != null) {
                    file = new File(build, //$NON-NLS-1$
                    "development/sdk/api-versions.xml".replace('/', File.separatorChar));
                }
            }
            if (file == null || !file.exists()) {
                return null;
            } else {
                db = get(client, file);
            }
            sInstance = new WeakReference<ApiLookup>(db);
        }
        return db;
    }
}
Also used : File(java.io.File) Nullable(com.android.annotations.Nullable)

Example 37 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 38 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 39 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 40 with Nullable

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

the class LombokPsiConverterTest method parse.

@Nullable
private static Node parse(String code) {
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
    options.parseLiteralExpressionsAsConstants = true;
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
    Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
    parser.javadocParser.checkDocComment = false;
    EcjTreeConverter converter = new EcjTreeConverter();
    org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
    CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
    CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
    if (unit == null) {
        return null;
    }
    converter.visit(code, unit);
    List<? extends Node> nodes = converter.getAll();
    for (lombok.ast.Node node : nodes) {
        if (node instanceof lombok.ast.CompilationUnit) {
            return node;
        }
    }
    return null;
}
Also used : CompilationUnit(lombok.ast.CompilationUnit) ProblemReporter(org.eclipse.jdt.internal.compiler.problem.ProblemReporter) Node(lombok.ast.Node) Parser(org.eclipse.jdt.internal.compiler.parser.Parser) EcjTreeConverter(lombok.ast.ecj.EcjTreeConverter) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) 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