Search in sources :

Example 1 with SetAttributeQuickFix

use of org.jetbrains.android.inspections.lint.SetAttributeQuickFix in project android by JetBrains.

the class AndroidLintGoogleAppIndexingApiWarningInspection method getAppIndexingQuickFix.

@NotNull
static AndroidLintQuickFix[] getAppIndexingQuickFix(PsiElement startElement, String message) {
    AppIndexingApiDetector.IssueType type = AppIndexingApiDetector.IssueType.parse(message);
    switch(type) {
        case SCHEME_MISSING:
        case URL_MISSING:
            return new AndroidLintQuickFix[] { new SetAttributeQuickFix("Set scheme", ATTR_SCHEME, "http") };
        case HOST_MISSING:
            return new AndroidLintQuickFix[] { new SetAttributeQuickFix("Set host", ATTR_HOST, null) };
        case MISSING_SLASH:
            PsiElement parent = startElement.getParent();
            if (parent instanceof XmlAttribute) {
                XmlAttribute attr = (XmlAttribute) parent;
                String path = attr.getValue();
                if (path != null) {
                    return new AndroidLintQuickFix[] { new ReplaceStringQuickFix("Replace with /" + path, path, "/" + path) };
                }
            }
            break;
        default:
            break;
    }
    return AndroidLintQuickFix.EMPTY_ARRAY;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AppIndexingApiDetector(com.android.tools.lint.checks.AppIndexingApiDetector) SetAttributeQuickFix(org.jetbrains.android.inspections.lint.SetAttributeQuickFix) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SetAttributeQuickFix

use of org.jetbrains.android.inspections.lint.SetAttributeQuickFix in project android by JetBrains.

the class AndroidLintRtlCompatInspection method getQuickFixes.

@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull String message) {
    if (message.startsWith("To support older versions than API 17")) {
        Matcher matcher = QUOTED_PARAMETER.matcher(message);
        if (matcher.find()) {
            final String name = matcher.group(1);
            final String value = matcher.group(2);
            return new AndroidLintQuickFix[] { new SetAttributeQuickFix(String.format("Set %s", name), name, value) };
        }
    }
    return AndroidLintQuickFix.EMPTY_ARRAY;
}
Also used : Matcher(java.util.regex.Matcher) SetAttributeQuickFix(org.jetbrains.android.inspections.lint.SetAttributeQuickFix) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidLintQuickFix (org.jetbrains.android.inspections.lint.AndroidLintQuickFix)2 SetAttributeQuickFix (org.jetbrains.android.inspections.lint.SetAttributeQuickFix)2 NotNull (org.jetbrains.annotations.NotNull)2 AppIndexingApiDetector (com.android.tools.lint.checks.AppIndexingApiDetector)1 PsiElement (com.intellij.psi.PsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 Matcher (java.util.regex.Matcher)1