Search in sources :

Example 21 with NonNull

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

the class PsiResourceItem method parseDeclareStyleable.

@NonNull
private ResourceValue parseDeclareStyleable(@NonNull DeclareStyleableResourceValue declareStyleable) {
    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 = declareStyleable.isFramework();
            if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
                name = name.substring(ANDROID_NS_NAME_PREFIX_LEN);
                isFrameworkAttr = true;
            }
            AttrResourceValue attr = parseAttrValue(child, new AttrResourceValue(ResourceType.ATTR, name, isFrameworkAttr, null));
            declareStyleable.addValue(attr);
        }
    }
    return declareStyleable;
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag) NonNull(com.android.annotations.NonNull)

Example 22 with NonNull

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

the class DynamicResourceValueRepository method getMap.

@Override
@NonNull
protected Map<ResourceType, ListMultimap<String, ResourceItem>> getMap() {
    if (mItems.isEmpty()) {
        // TODO: b/23032391
        AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
        if (androidModel == null) {
            return mItems;
        }
        Variant selectedVariant = androidModel.getSelectedVariant();
        // Reverse overlay order because when processing lower order ones, we ignore keys already processed
        BuildTypeContainer buildType = androidModel.findBuildType(selectedVariant.getBuildType());
        if (buildType != null) {
            addValues(buildType.getBuildType().getResValues());
        }
        // flavors and default config:
        addValues(selectedVariant.getMergedFlavor().getResValues());
    }
    return mItems;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) BuildTypeContainer(com.android.builder.model.BuildTypeContainer) NonNull(com.android.annotations.NonNull)

Example 23 with NonNull

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

the class LintIdeClient method getConfiguration.

@NonNull
@Override
public Configuration getConfiguration(@NonNull com.android.tools.lint.detector.api.Project project, @Nullable final LintDriver driver) {
    if (project.isGradleProject() && project.isAndroidProject() && !project.isLibrary()) {
        AndroidProject model = project.getGradleProjectModel();
        if (model != null) {
            try {
                LintOptions lintOptions = model.getLintOptions();
                final Map<String, Integer> overrides = lintOptions.getSeverityOverrides();
                if (overrides != null && !overrides.isEmpty()) {
                    return new DefaultConfiguration(this, project, null) {

                        @NonNull
                        @Override
                        public Severity getSeverity(@NonNull Issue issue) {
                            Integer severity = overrides.get(issue.getId());
                            if (severity != null) {
                                switch(severity.intValue()) {
                                    case LintOptions.SEVERITY_FATAL:
                                        return Severity.FATAL;
                                    case LintOptions.SEVERITY_ERROR:
                                        return Severity.ERROR;
                                    case LintOptions.SEVERITY_WARNING:
                                        return Severity.WARNING;
                                    case LintOptions.SEVERITY_INFORMATIONAL:
                                        return Severity.INFORMATIONAL;
                                    case LintOptions.SEVERITY_IGNORE:
                                    default:
                                        return Severity.IGNORE;
                                }
                            }
                            // This is a LIST lookup. I should make this faster!
                            if (!getIssues().contains(issue) && (driver == null || !driver.isCustomIssue(issue))) {
                                return Severity.IGNORE;
                            }
                            return super.getSeverity(issue);
                        }
                    };
                }
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    return new DefaultConfiguration(this, project, null) {

        @Override
        public boolean isEnabled(@NonNull Issue issue) {
            if (getIssues().contains(issue) && super.isEnabled(issue)) {
                return true;
            }
            return driver != null && driver.isCustomIssue(issue) || issue == IssueRegistry.BASELINE || issue == IssueRegistry.CANCELLED;
        }
    };
}
Also used : NonNull(com.android.annotations.NonNull) LintOptions(com.android.builder.model.LintOptions) AndroidProject(com.android.builder.model.AndroidProject) IOException(java.io.IOException) NonNull(com.android.annotations.NonNull)

Example 24 with NonNull

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

the class LintIdeGradleDetector method getPropertyKeyCookie.

@NonNull
@Override
protected Object getPropertyKeyCookie(@NonNull Object cookie) {
    PsiElement element = (PsiElement) cookie;
    PsiElement parent = element.getParent();
    if (parent instanceof GrApplicationStatement) {
        GrApplicationStatement call = (GrApplicationStatement) parent;
        return call.getInvokedExpression();
    } else if (parent instanceof GrAssignmentExpression) {
        GrAssignmentExpression assignment = (GrAssignmentExpression) parent;
        return assignment.getLValue();
    }
    return super.getPropertyKeyCookie(cookie);
}
Also used : PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) NonNull(com.android.annotations.NonNull)

Example 25 with NonNull

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

the class LintIdeJavaParser method createLocation.

@NonNull
private static Location createLocation(@NonNull JavaContext context, @Nullable PsiFile containingFile, int startOffset, int endOffset) {
    LintJavaPosition start = new LintJavaPosition(containingFile, startOffset);
    LintJavaPosition end = new LintJavaPosition(containingFile, endOffset);
    File file = context.file;
    if (containingFile != null && containingFile != context.getJavaFile()) {
        // Reporting an error in a different file.
        if (context.getDriver().getScope().size() == 1) {
            // Don't bother with this error if it's in a different file during single-file analysis
            return Location.NONE;
        }
        VirtualFile virtualFile = containingFile.getVirtualFile();
        if (virtualFile != null) {
            file = VfsUtilCore.virtualToIoFile(virtualFile);
        } else {
            return Location.NONE;
        }
    }
    return Location.create(file, start, end);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)113 File (java.io.File)38 TextRange (com.intellij.openapi.util.TextRange)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 ImmutableList (com.google.common.collect.ImmutableList)8 Nullable (com.android.annotations.Nullable)7 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 SdkConstants (com.android.SdkConstants)4 OutputFile (com.android.build.OutputFile)4 Issue (com.android.tools.klint.detector.api.Issue)4 Position (com.android.tools.lint.detector.api.Position)4 FileUtils (com.android.utils.FileUtils)4 Splitter (com.google.common.base.Splitter)4 Module (com.intellij.openapi.module.Module)4 StringReader (java.io.StringReader)4 Node (org.w3c.dom.Node)4