use of com.android.tools.lint.client.api.Configuration in project android by JetBrains.
the class SuppressLintIntentionAction method invoke.
@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, @NotNull PsiFile file) throws IncorrectOperationException {
if (file instanceof XmlFile) {
final XmlTag element = PsiTreeUtil.getParentOfType(myElement, XmlTag.class);
if (element == null) {
return;
}
String lintId = getLintId(myId);
addSuppressAttribute(project, (XmlFile) file, element, lintId);
} else if (file instanceof PsiJavaFile) {
final PsiModifierListOwner container = PsiTreeUtil.getParentOfType(myElement, PsiModifierListOwner.class);
if (container == null) {
return;
}
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
String lintId = getLintId(myId);
addSuppressAnnotation(project, container, container, lintId);
}
} else if (file instanceof GroovyFile) {
Document document = PsiDocumentManager.getInstance(myElement.getProject()).getDocument(file);
if (document != null) {
int offset = myElement.getTextOffset();
int line = document.getLineNumber(offset);
int lineStart = document.getLineStartOffset(line);
if (lineStart > 0) {
int prevLineStart = document.getLineStartOffset(line - 1);
int prevLineEnd = document.getLineEndOffset(line - 1);
String prevLine = document.getText(new TextRange(prevLineStart, prevLineEnd));
int index = prevLine.indexOf(NO_INSPECTION_PREFIX);
if (index != -1) {
document.insertString(prevLineStart + index + NO_INSPECTION_PREFIX.length(), getLintId(myId) + ",");
return;
}
}
String linePrefix = document.getText(new TextRange(lineStart, offset));
int nonSpace = 0;
for (; nonSpace < linePrefix.length(); nonSpace++) {
if (!Character.isWhitespace(linePrefix.charAt(nonSpace))) {
break;
}
}
ApplicationManager.getApplication().assertWriteAccessAllowed();
document.insertString(lineStart + nonSpace, NO_INSPECTION_PREFIX + getLintId(myId) + "\n" + linePrefix.substring(0, nonSpace));
}
} else if (file instanceof PsiBinaryFile) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
File binaryFile = VfsUtilCore.virtualToIoFile(virtualFile);
// Can't suppress lint checks inside a binary file (typically an icon): use
// the lint XML facility instead
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module != null) {
//LintIdeRequest
File dir = LintIdeProject.getLintProjectDirectory(module, AndroidFacet.getInstance(module));
if (dir != null) {
LintIdeClient client = new LintIdeClient(project);
com.android.tools.lint.detector.api.Project lintProject = client.getProject(dir, dir);
Configuration configuration = client.getConfiguration(lintProject, null);
Issue issue = getIssue();
if (issue != null) {
configuration.ignore(issue, binaryFile);
}
}
}
}
}
}
Aggregations