use of org.jetbrains.android.inspections.lint.AndroidLintQuickFix in project android by JetBrains.
the class AndroidLintAnimatorKeepInspection method getQuickFixes.
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
return new AndroidLintQuickFix[] { new AndroidLintQuickFix() {
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
if (!ObjectAnimatorDetector.isAddKeepErrorMessage(message, TextFormat.RAW)) {
return;
}
PsiModifierListOwner container = PsiTreeUtil.getParentOfType(startElement, PsiModifierListOwner.class);
if (container == null) {
return;
}
if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) {
return;
}
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(container, KEEP_ANNOTATION);
if (annotation == null) {
Project project = startElement.getProject();
new AddAnnotationFix(KEEP_ANNOTATION, container).invoke(project, null, container.getContainingFile());
}
}
}
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
return true;
}
@NotNull
@Override
public String getName() {
return "Annotate with @Keep";
}
} };
}
use of org.jetbrains.android.inspections.lint.AndroidLintQuickFix in project android by JetBrains.
the class AndroidLintConvertToWebpInspection method getQuickFixes.
@Override
@NotNull
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
return new AndroidLintQuickFix[] { new DefaultLintQuickFix("Convert images to WebP...") {
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
return AndroidFacet.getInstance(startElement) != null;
}
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
AndroidFacet facet = AndroidFacet.getInstance(startElement);
if (facet != null) {
AndroidModuleInfo info = AndroidModuleInfo.get(facet);
int minSdkVersion = info.getMinSdkVersion().getApiLevel();
List<VirtualFile> folders = facet.getResourceFolderManager().getFolders();
ConvertToWebpAction action = new ConvertToWebpAction();
action.perform(startElement.getProject(), minSdkVersion, folders.toArray(VirtualFile.EMPTY_ARRAY));
}
}
} };
}
use of org.jetbrains.android.inspections.lint.AndroidLintQuickFix 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;
}
use of org.jetbrains.android.inspections.lint.AndroidLintQuickFix in project android by JetBrains.
the class AndroidLintInvalidUsesTagAttributeInspection method getQuickFixes.
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class);
XmlAttributeValue attributeValue = attribute == null ? null : attribute.getValueElement();
if (attributeValue != null && attributeValue.getTextLength() != 0) {
String value = StringUtil.unquoteString(attributeValue.getText());
String regexp = "(" + value + ")";
String[] suggestions = AndroidAutoDetector.getAllowedAutomotiveAppTypes();
List<AndroidLintQuickFix> fixes = Lists.newArrayListWithExpectedSize(suggestions.length);
for (String suggestion : suggestions) {
fixes.add(new ReplaceStringQuickFix("Replace with \"" + suggestion + "\"", regexp, suggestion));
}
return fixes.toArray(new AndroidLintQuickFix[fixes.size()]);
} else {
return AndroidLintQuickFix.EMPTY_ARRAY;
}
}
use of org.jetbrains.android.inspections.lint.AndroidLintQuickFix 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