use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class OfflineDescriptorResolveResult method createDescriptor.
@Nullable
private static CommonProblemDescriptor createDescriptor(@Nullable RefEntity element, @NotNull OfflineProblemDescriptor offlineDescriptor, @NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionToolPresentation presentation) {
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
final LocalInspectionToolWrapper localTool = ((GlobalInspectionToolWrapper) toolWrapper).getSharedLocalInspectionToolWrapper();
if (localTool != null) {
final CommonProblemDescriptor descriptor = createDescriptor(element, offlineDescriptor, localTool, presentation);
if (descriptor != null) {
return descriptor;
}
}
return createRerunGlobalToolDescriptor((GlobalInspectionToolWrapper) toolWrapper, element);
}
if (!(toolWrapper instanceof LocalInspectionToolWrapper))
return null;
final InspectionManager inspectionManager = InspectionManager.getInstance(presentation.getContext().getProject());
final OfflineProblemDescriptor offlineProblemDescriptor = offlineDescriptor;
if (element instanceof RefElement) {
final PsiElement psiElement = ((RefElement) element).getElement();
if (psiElement != null) {
ProblemDescriptor descriptor = ProgressManager.getInstance().runProcess(() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, (LocalInspectionToolWrapper) toolWrapper), new DaemonProgressIndicator());
if (descriptor != null)
return descriptor;
}
return null;
}
final List<String> hints = offlineProblemDescriptor.getHints();
CommonProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), (QuickFix) null);
final QuickFix[] quickFixes = getFixes(descriptor, hints, presentation);
if (quickFixes != null) {
descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), quickFixes);
}
return descriptor;
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class SuppressActionSequentialTask method suppress.
private void suppress(@NotNull final PsiElement element, @Nullable final CommonProblemDescriptor descriptor, @NotNull final SuppressIntentionAction action, @NotNull final RefEntity refEntity, InspectionToolWrapper wrapper, @NotNull final SuppressableInspectionTreeNode node) {
if (action instanceof SuppressIntentionActionFromFix && !(descriptor instanceof ProblemDescriptor)) {
LOG.info("local suppression fix for specific problem descriptor: " + wrapper.getTool().getClass().getName());
}
final Project project = element.getProject();
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project).commitAllDocuments();
try {
PsiElement container = null;
if (action instanceof SuppressIntentionActionFromFix) {
container = ((SuppressIntentionActionFromFix) action).getContainer(element);
}
if (container == null) {
container = element;
}
if (action.isAvailable(project, null, element)) {
action.invoke(project, null, element);
}
final Set<GlobalInspectionContextImpl> globalInspectionContexts = ((InspectionManagerEx) InspectionManager.getInstance(element.getProject())).getRunningContexts();
for (GlobalInspectionContextImpl context : globalInspectionContexts) {
context.ignoreElement(wrapper.getTool(), container);
if (descriptor != null) {
context.getPresentation(wrapper).ignoreCurrentElementProblem(refEntity, descriptor);
}
}
final RefElement containerRef = refEntity.getRefManager().getReference(container);
final Set<Object> suppressedNodes = myContext.getView().getSuppressedNodes(wrapper.getShortName());
if (containerRef != null) {
Queue<RefEntity> toIgnoreInView = new Queue<>(1);
toIgnoreInView.addLast(containerRef);
while (!toIgnoreInView.isEmpty()) {
final RefEntity entity = toIgnoreInView.pullFirst();
if (node instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
if (descriptors != null) {
Collections.addAll(suppressedNodes, descriptors);
}
} else {
suppressedNodes.add(entity);
}
final List<RefEntity> children = entity.getChildren();
for (RefEntity child : children) {
toIgnoreInView.addLast(child);
}
}
}
if (node instanceof ProblemDescriptionNode) {
suppressedNodes.add(descriptor);
}
} catch (IncorrectOperationException e1) {
LOG.error(e1);
}
});
node.removeSuppressActionFromAvailable(mySuppressAction);
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class InspectionResultsView method initOccurenceNavigator.
private OccurenceNavigatorSupport initOccurenceNavigator() {
return new OccurenceNavigatorSupport(myTree) {
@Override
@Nullable
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
if (node instanceof InspectionTreeNode && ((InspectionTreeNode) node).isExcluded(myExcludedInspectionTreeNodesManager)) {
return null;
}
if (node instanceof RefElementNode) {
final RefElementNode refNode = (RefElementNode) node;
if (refNode.hasDescriptorsUnder())
return null;
final RefEntity element = refNode.getElement();
if (element == null || !element.isValid())
return null;
final CommonProblemDescriptor problem = refNode.getDescriptor();
if (problem != null) {
return navigate(problem);
}
if (element instanceof RefElement) {
return getOpenFileDescriptor((RefElement) element);
}
} else if (node instanceof ProblemDescriptionNode) {
boolean isValid;
if (((ProblemDescriptionNode) node).isValid()) {
if (((ProblemDescriptionNode) node).isQuickFixAppliedFromView()) {
isValid = ((ProblemDescriptionNode) node).calculateIsValid();
} else {
isValid = true;
}
} else {
isValid = false;
}
return isValid ? navigate(((ProblemDescriptionNode) node).getDescriptor()) : InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) node);
}
return null;
}
@Nullable
private Navigatable navigate(final CommonProblemDescriptor descriptor) {
return getSelectedNavigatable(descriptor);
}
@Override
public String getNextOccurenceActionName() {
return InspectionsBundle.message("inspection.action.go.next");
}
@Override
public String getPreviousOccurenceActionName() {
return InspectionsBundle.message("inspection.actiongo.prev");
}
};
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class InspectionResultsViewComparator method compareEntities.
private static int compareEntities(final RefEntity entity1, final RefEntity entity2) {
if (entity1 instanceof RefElement && entity2 instanceof RefElement) {
final SmartPsiElementPointer p1 = ((RefElement) entity1).getPointer();
final SmartPsiElementPointer p2 = ((RefElement) entity2).getPointer();
if (p1 != null && p2 != null) {
final VirtualFile file1 = p1.getVirtualFile();
final VirtualFile file2 = p2.getVirtualFile();
if (file1 != null && Comparing.equal(file1, file2) && file1.isValid()) {
final int positionComparing = PsiUtilCore.compareElementsByPosition(((RefElement) entity1).getElement(), ((RefElement) entity2).getElement());
if (positionComparing != 0) {
return positionComparing;
}
}
}
}
if (entity1 instanceof RefFile && entity2 instanceof RefFile) {
final VirtualFile file1 = ((RefFile) entity1).getPointer().getVirtualFile();
final VirtualFile file2 = ((RefFile) entity2).getPointer().getVirtualFile();
if (file1 != null && file2 != null) {
if (file1.equals(file2))
return 0;
final int cmp = compareEntitiesByName(entity1, entity2);
if (cmp != 0)
return cmp;
return file1.hashCode() - file2.hashCode();
}
}
if (entity1 != null && entity2 != null) {
return compareEntitiesByName(entity1, entity2);
}
if (entity1 != null)
return -1;
return entity2 != null ? 1 : 0;
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class InspectionResultsViewUtil method getNavigatableForInvalidNode.
@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
RefEntity element = node.getElement();
while (element != null && !element.isValid()) {
element = element.getOwner();
}
if (!(element instanceof RefElement))
return null;
PsiElement containingElement = ((RefElement) element).getElement();
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid())
return null;
final int lineNumber = node.getLineNumber();
if (lineNumber != -1) {
final PsiFile containingFile = containingElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null && document.getLineCount() > lineNumber) {
return new OpenFileDescriptor(containingElement.getProject(), file, lineNumber, 0);
}
}
}
return (Navigatable) containingElement;
}
Aggregations