Search in sources :

Example 1 with RenameAttributeQuickFix

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

the class AndroidLintNetworkSecurityConfigInspection method getQuickFixes.

@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    if (NetworkSecurityConfigDetector.isInvalidDigestAlgorithmMessage(message)) {
        List<String> digestAlgs = NetworkSecurityConfigDetector.getSupportedPinDigestAlgorithms();
        AndroidLintQuickFix[] digestFixes = new AndroidLintQuickFix[digestAlgs.size()];
        for (int i = 0; i < digestFixes.length; i++) {
            String algorithm = digestAlgs.get(i);
            digestFixes[i] = new ReplaceStringQuickFix(String.format("Set digest to \"%1$s\"", algorithm), null, algorithm);
        }
        return digestFixes;
    } else if (NetworkSecurityConfigDetector.isAttributeSpellingError(message)) {
        XmlTag parentTag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false);
        XmlAttribute currentAttr = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class, false);
        assert parentTag != null;
        assert currentAttr != null;
        List<String> suggestions = NetworkSecurityConfigDetector.getAttributeSpellingSuggestions(currentAttr.getName(), parentTag.getName());
        AndroidLintQuickFix[] attrFixes = new AndroidLintQuickFix[suggestions.size()];
        for (int i = 0; i < attrFixes.length; i++) {
            attrFixes[i] = new RenameAttributeQuickFix(null, /* no namespace */
            suggestions.get(i));
        }
        return attrFixes;
    } else if (NetworkSecurityConfigDetector.isTagSpellingError(message)) {
        XmlTag currentTag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false);
        assert currentTag != null;
        XmlTag parentTag = currentTag.getParentTag();
        assert parentTag != null;
        List<String> suggestions = NetworkSecurityConfigDetector.getTagSpellingSuggestions(currentTag.getName(), parentTag.getName());
        AndroidLintQuickFix[] elementQuickFixes = new AndroidLintQuickFix[suggestions.size()];
        for (int i = 0; i < elementQuickFixes.length; i++) {
            elementQuickFixes[i] = new RenameXmlTagQuickFix(suggestions.get(i));
        }
        return elementQuickFixes;
    } else {
        return AndroidLintQuickFix.EMPTY_ARRAY;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) List(java.util.List) RenameAttributeQuickFix(org.jetbrains.android.inspections.lint.RenameAttributeQuickFix) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 List (java.util.List)1 AndroidLintQuickFix (org.jetbrains.android.inspections.lint.AndroidLintQuickFix)1 RenameAttributeQuickFix (org.jetbrains.android.inspections.lint.RenameAttributeQuickFix)1 NotNull (org.jetbrains.annotations.NotNull)1