use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class ProblemDescriptionNode method calculatePresentableName.
@NotNull
@Override
protected String calculatePresentableName() {
CommonProblemDescriptor descriptor = getDescriptor();
if (descriptor == null)
return "";
PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null;
return XmlStringUtil.stripHtml(ProblemDescriptorUtil.renderDescriptionMessage(descriptor, element, TRIM_AT_TREE_END));
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class SuppressableInspectionTreeNode method getSuppressContent.
@NotNull
public final Pair<PsiElement, CommonProblemDescriptor> getSuppressContent() {
RefEntity refElement = getElement();
CommonProblemDescriptor descriptor = getDescriptor();
PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
return Pair.create(element, descriptor);
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class InspectionResultsViewComparator method compare.
@Override
public int compare(InspectionTreeNode node1, InspectionTreeNode node2) {
if (node1 instanceof InspectionSeverityGroupNode && node2 instanceof InspectionSeverityGroupNode) {
final InspectionSeverityGroupNode groupNode1 = (InspectionSeverityGroupNode) node1;
final InspectionSeverityGroupNode groupNode2 = (InspectionSeverityGroupNode) node2;
return -SeverityRegistrar.getSeverityRegistrar(groupNode1.getProject()).compare(groupNode1.getSeverityLevel().getSeverity(), groupNode2.getSeverityLevel().getSeverity());
}
if (node1 instanceof InspectionSeverityGroupNode)
return -1;
if (node2 instanceof InspectionSeverityGroupNode)
return 1;
if (node1 instanceof InspectionGroupNode && node2 instanceof InspectionGroupNode) {
return ((InspectionGroupNode) node1).getGroupTitle().compareToIgnoreCase(((InspectionGroupNode) node2).getGroupTitle());
}
if (node1 instanceof InspectionGroupNode)
return -1;
if (node2 instanceof InspectionGroupNode)
return 1;
if (node1 instanceof InspectionNode && node2 instanceof InspectionNode)
return InspectionsConfigTreeComparator.getDisplayTextToSort(node1.toString()).compareToIgnoreCase(InspectionsConfigTreeComparator.getDisplayTextToSort(node2.toString()));
if (node1 instanceof InspectionNode)
return -1;
if (node2 instanceof InspectionNode)
return 1;
if (node1 instanceof InspectionModuleNode && node2 instanceof InspectionModuleNode) {
return Comparing.compare(node1.toString(), node2.toString());
}
if (node1 instanceof InspectionModuleNode)
return -1;
if (node2 instanceof InspectionModuleNode)
return 1;
if (node1 instanceof InspectionPackageNode && node2 instanceof InspectionPackageNode) {
return ((InspectionPackageNode) node1).getPackageName().compareToIgnoreCase(((InspectionPackageNode) node2).getPackageName());
}
if (node1 instanceof InspectionPackageNode)
return -1;
if (node2 instanceof InspectionPackageNode)
return 1;
if (node1 instanceof RefElementNode && node2 instanceof RefElementNode) {
//sort by filename and inside file by start offset
return compareEntities(((RefElementNode) node1).getElement(), ((RefElementNode) node2).getElement());
}
if (node1 instanceof ProblemDescriptionNode && node2 instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor descriptor1 = ((ProblemDescriptionNode) node1).getDescriptor();
final CommonProblemDescriptor descriptor2 = ((ProblemDescriptionNode) node2).getDescriptor();
if (descriptor1 instanceof ProblemDescriptor && descriptor2 instanceof ProblemDescriptor) {
int diff = ((ProblemDescriptor) descriptor1).getLineNumber() - ((ProblemDescriptor) descriptor2).getLineNumber();
if (diff != 0) {
return diff;
}
diff = ((ProblemDescriptor) descriptor1).getHighlightType().compareTo(((ProblemDescriptor) descriptor2).getHighlightType());
if (diff != 0) {
return diff;
}
diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor) descriptor1).getStartElement(), ((ProblemDescriptor) descriptor2).getStartElement());
if (diff != 0) {
return diff;
}
diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor) descriptor2).getEndElement(), ((ProblemDescriptor) descriptor1).getEndElement());
if (diff != 0)
return diff;
final TextRange range1 = ((ProblemDescriptor) descriptor1).getTextRangeInElement();
final TextRange range2 = ((ProblemDescriptor) descriptor2).getTextRangeInElement();
if (range1 != null && range2 != null) {
diff = range1.getStartOffset() - range2.getStartOffset();
if (diff != 0)
return diff;
diff = range1.getEndOffset() - range2.getEndOffset();
if (diff != 0)
return diff;
}
}
if (descriptor1 != null && descriptor2 != null) {
return descriptor1.getDescriptionTemplate().compareToIgnoreCase(descriptor2.getDescriptionTemplate());
}
if (descriptor1 == null)
return descriptor2 == null ? 0 : -1;
return 1;
}
if (node1 instanceof RefElementNode && node2 instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode) node2).getDescriptor();
if (descriptor instanceof ProblemDescriptor) {
return compareEntity(((RefElementNode) node1).getElement(), ((ProblemDescriptor) descriptor).getPsiElement());
}
return compareEntities(((RefElementNode) node1).getElement(), ((ProblemDescriptionNode) node2).getElement());
}
if (node2 instanceof RefElementNode && node1 instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode) node1).getDescriptor();
if (descriptor instanceof ProblemDescriptor) {
return -compareEntity(((RefElementNode) node2).getElement(), ((ProblemDescriptor) descriptor).getPsiElement());
}
return -compareEntities(((RefElementNode) node2).getElement(), ((ProblemDescriptionNode) node1).getElement());
}
if (node1 instanceof InspectionRootNode && node2 instanceof InspectionRootNode) {
//TODO Dmitry Batkovich: optimization, because only one root node is existed
return 0;
}
LOG.error("node1: " + node1 + ", node2: " + node2);
return 0;
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class LocalQuickFixWrapper method ignore.
private void ignore(@NotNull Collection<PsiElement> ignoredElements, @NotNull CommonProblemDescriptor descriptor, @Nullable QuickFix fix, @NotNull GlobalInspectionContextImpl context) {
if (fix != null) {
InspectionToolPresentation presentation = context.getPresentation(myToolWrapper);
presentation.ignoreProblem(descriptor, fix);
}
if (descriptor instanceof ProblemDescriptor) {
PsiElement element = ((ProblemDescriptor) descriptor).getPsiElement();
if (element != null) {
ignoredElements.add(element);
}
}
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class PerformFixesModalTask method iteration.
@Override
public boolean iteration() {
final CommonProblemDescriptor descriptor = myDescriptors[myCount++];
ProgressIndicator indicator = myTask.getIndicator();
if (indicator != null) {
indicator.setFraction((double) myCount / myDescriptors.length);
String presentableText = "usages";
if (descriptor instanceof ProblemDescriptor) {
final PsiElement psiElement = ((ProblemDescriptor) descriptor).getPsiElement();
if (psiElement != null) {
presentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement);
}
}
indicator.setText("Processing " + presentableText);
}
final boolean[] runInReadAction = { false };
final QuickFix[] fixes = descriptor.getFixes();
if (fixes != null) {
for (QuickFix fix : fixes) {
if (!fix.startInWriteAction()) {
runInReadAction[0] = true;
} else {
runInReadAction[0] = false;
break;
}
}
}
ApplicationManager.getApplication().runWriteAction(() -> {
myDocumentManager.commitAllDocuments();
if (!runInReadAction[0]) {
applyFix(myProject, descriptor);
}
});
if (runInReadAction[0]) {
applyFix(myProject, descriptor);
}
return isDone();
}
Aggregations