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;
}
}
Aggregations