use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.
the class XmlImportOptimizer method processFile.
@NotNull
@Override
public CollectingInfoRunnable processFile(final PsiFile file) {
return new CollectingInfoRunnable() {
int myRemovedNameSpaces = 0;
@Override
public void run() {
XmlFile xmlFile = (XmlFile) file;
Project project = xmlFile.getProject();
HighlightDisplayKey key = HighlightDisplayKey.find(myInspection.getShortName());
if (!InspectionProjectProfileManager.getInstance(project).getCurrentProfile().isToolEnabled(key, xmlFile))
return;
ProblemsHolder holder = new ProblemsHolder(InspectionManager.getInstance(project), xmlFile, false);
final XmlElementVisitor visitor = (XmlElementVisitor) myInspection.buildVisitor(holder, false);
new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof XmlAttribute) {
visitor.visitXmlAttribute((XmlAttribute) element);
} else {
super.visitElement(element);
}
}
}.visitFile(xmlFile);
ProblemDescriptor[] results = holder.getResultsArray();
List<ProblemDescriptor> list = ContainerUtil.filter(results, myCondition);
Map<XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix, ProblemDescriptor> fixes = new LinkedHashMap<>();
for (ProblemDescriptor result : list) {
for (QuickFix fix : result.getFixes()) {
if (fix instanceof XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix) {
fixes.put((XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix) fix, result);
}
}
}
SmartPsiElementPointer<XmlTag> pointer = null;
for (Map.Entry<XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix, ProblemDescriptor> fix : fixes.entrySet()) {
pointer = fix.getKey().doFix(project, fix.getValue(), false);
myRemovedNameSpaces++;
}
if (pointer != null) {
XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix.reformatStartTag(project, pointer);
}
}
@Nullable
@Override
public String getUserNotificationInfo() {
return myRemovedNameSpaces > 0 ? "Removed " + myRemovedNameSpaces + " namespace" + (myRemovedNameSpaces > 1 ? "s" : "") : null;
}
};
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method registerInspectionKey.
private static void registerInspectionKey(MyDomElementsInspection inspection) {
final String shortName = inspection.getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
HighlightDisplayKey.register(shortName);
}
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method apply.
@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
if (state.isDirty()) {
return;
}
final Project project = file.getProject();
for (ProblemData problemData : state.getProblems()) {
final Issue issue = problemData.getIssue();
final String message = problemData.getMessage();
final TextRange range = problemData.getTextRange();
if (range.getStartOffset() == range.getEndOffset()) {
continue;
}
final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
if (pair == null) {
continue;
}
final AndroidLintInspectionBase inspection = pair.getFirst();
HighlightDisplayLevel displayLevel = pair.getSecond();
if (inspection != null) {
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key != null) {
final PsiElement startElement = file.findElementAt(range.getStartOffset());
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
if (problemData.getConfiguredSeverity() != null) {
HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
if (configuredLevel != null) {
displayLevel = configuredLevel;
}
}
final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
}
}
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
annotation.registerFix(intention);
}
String id = key.getID();
if (IntellijLintIssueRegistry.CUSTOM_ERROR == issue || IntellijLintIssueRegistry.CUSTOM_WARNING == issue) {
Issue original = IntellijLintClient.findCustomIssue(message);
if (original != null) {
id = original.getId();
}
}
annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
annotation.registerFix(new MyDisableInspectionFix(key));
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
for (SuppressQuickFix action : suppressActions) {
if (action.isAvailable(project, startElement)) {
ProblemHighlightType type = annotation.getHighlightType();
annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
}
}
}
}
}
}
}
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project kotlin by JetBrains.
the class AndroidLintUtil method getHighlighLevelAndInspection.
@Nullable
public static Pair<AndroidLintInspectionBase, HighlightDisplayLevel> getHighlighLevelAndInspection(@NotNull Project project, @NotNull Issue issue, @NotNull PsiElement context) {
final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
if (inspectionShortName == null) {
return null;
}
final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
if (key == null) {
return null;
}
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
if (!profile.isToolEnabled(key, context)) {
if (!issue.isEnabledByDefault()) {
// Lint will skip issues (and not report them) for issues that have been disabled,
// except for those issues that are explicitly enabled via Gradle. Therefore, if
// we get this far, lint has found this issue to be explicitly enabled, so we let
// that setting override a local enabled/disabled state in the IDE profile.
} else {
return null;
}
}
final AndroidLintInspectionBase inspection = (AndroidLintInspectionBase) profile.getUnwrappedTool(inspectionShortName, context);
if (inspection == null)
return null;
final HighlightDisplayLevel errorLevel = profile.getErrorLevel(key, context);
return Pair.create(inspection, errorLevel != null ? errorLevel : HighlightDisplayLevel.WARNING);
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.
the class HtmlMissingClosingTagInspectionTest method highlightTest.
protected void highlightTest(@Language("HTML") String code) {
final LocalInspectionTool inspection = getInspection();
myFixture.enableInspections(inspection);
final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
final Project project = myFixture.getProject();
final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile();
final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
}
myFixture.configureByText(HtmlFileType.INSTANCE, code);
myFixture.testHighlighting();
}
Aggregations