use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionRVContentProvider method addNodeToParent.
@NotNull
protected static RefElementNode addNodeToParent(@NotNull RefEntityContainer container, @NotNull InspectionToolPresentation presentation, final InspectionTreeNode parentNode) {
final RefElementNode nodeToBeAdded = container.createNode(presentation);
final Ref<Boolean> firstLevel = new Ref<>(true);
RefElementNode prevNode = null;
final Ref<RefElementNode> result = new Ref<>();
while (true) {
final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(presentation);
final RefEntityContainer finalContainer = container;
final RefElementNode finalPrevNode = prevNode;
TreeUtil.traverseDepth(parentNode, node -> {
if (node instanceof RefElementNode) {
final RefElementNode refElementNode = (RefElementNode) node;
final RefEntity userObject = finalContainer.getRefEntity();
final RefEntity object = refElementNode.getElement();
if (userObject != null && object != null && (userObject.getClass().equals(object.getClass())) && finalContainer.areEqual(object, userObject)) {
if (firstLevel.get()) {
result.set(refElementNode);
return false;
} else {
refElementNode.insertByOrder(finalPrevNode, false);
result.set(nodeToBeAdded);
return false;
}
}
}
return true;
});
if (!result.isNull())
return result.get();
if (!firstLevel.get()) {
currentNode.insertByOrder(prevNode, false);
}
final RefEntityContainer owner = container.getOwner();
if (owner == null) {
parentNode.insertByOrder(currentNode, false);
return nodeToBeAdded;
}
container = owner;
prevNode = currentNode;
firstLevel.set(false);
}
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionRVContentProviderImpl method appendDescriptor.
@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode pNode, final boolean canPackageRepeat) {
final RefEntity refElement = container.getRefEntity();
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>) container).getDescriptors();
if (problems != null) {
final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
for (CommonProblemDescriptor problem : problems) {
assert problem != null;
elemNode.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
elemNode.setProblem(elemNode.getChildCount() == 1 ? problems[0] : null);
}
} else {
if (canPackageRepeat && pNode instanceof InspectionPackageNode) {
final Set<RefEntity> currentElements = presentation.getContent().get(((InspectionPackageNode) pNode).getPackageName());
if (currentElements != null) {
final Set<RefEntity> currentEntities = new HashSet<>(currentElements);
if (RefUtil.contains(refElement, currentEntities))
return;
}
}
addNodeToParent(container, presentation, pNode);
}
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionRVContentProviderImpl method checkReportedProblems.
@Override
public boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper) {
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
presentation.updateContent();
final SearchScope searchScope = context.getCurrentScope().toSearchScope();
if (searchScope instanceof LocalSearchScope) {
final Map<String, Set<RefEntity>> contents = presentation.getContent();
final Map<RefEntity, CommonProblemDescriptor[]> problemElements = presentation.getProblemElements();
for (Set<RefEntity> entities : contents.values()) {
for (Iterator<RefEntity> iterator = entities.iterator(); iterator.hasNext(); ) {
RefEntity entity = iterator.next();
if (entity instanceof RefElement) {
final PsiElement element = ((RefElement) entity).getElement();
if (element != null) {
final TextRange range = element.getTextRange();
if (range != null && ((LocalSearchScope) searchScope).containsRange(element.getContainingFile(), range)) {
continue;
}
}
}
problemElements.remove(entity);
iterator.remove();
}
}
}
return presentation.hasReportedProblems();
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionResultsView method collectPsiElements.
@NotNull
private PsiElement[] collectPsiElements() {
RefEntity[] refElements = myTree.getSelectedElements();
List<PsiElement> psiElements = new ArrayList<>();
for (RefEntity refElement : refElements) {
PsiElement psiElement = refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
if (psiElement != null && psiElement.isValid()) {
psiElements.add(psiElement);
}
}
return PsiUtilCore.toPsiElementArray(psiElements);
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionResultsView method getData.
@Override
public Object getData(String dataId) {
if (PlatformDataKeys.HELP_ID.is(dataId))
return HELP_ID;
if (DATA_KEY.is(dataId))
return this;
if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId))
return myExclusionHandler;
if (myTree == null)
return null;
TreePath[] paths = myTree.getSelectionPaths();
if (paths == null || paths.length == 0)
return null;
if (paths.length > 1) {
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
return collectPsiElements();
}
return null;
}
TreePath path = paths[0];
InspectionTreeNode selectedNode = (InspectionTreeNode) path.getLastPathComponent();
if (!CommonDataKeys.NAVIGATABLE.is(dataId) && !CommonDataKeys.PSI_ELEMENT.is(dataId)) {
return null;
}
if (selectedNode instanceof RefElementNode) {
final RefElementNode refElementNode = (RefElementNode) selectedNode;
RefEntity refElement = refElementNode.getElement();
if (refElement == null)
return null;
final RefEntity item = refElement.getRefManager().getRefinedElement(refElement);
if (!item.isValid())
return null;
PsiElement psiElement = item instanceof RefElement ? ((RefElement) item).getElement() : null;
if (psiElement == null)
return null;
final CommonProblemDescriptor problem = refElementNode.getDescriptor();
if (problem instanceof ProblemDescriptor) {
PsiElement elementFromDescriptor = ((ProblemDescriptor) problem).getPsiElement();
if (elementFromDescriptor == null && CommonDataKeys.NAVIGATABLE.is(dataId)) {
final InspectionTreeNode node = (InspectionTreeNode) refElementNode.getChildAt(0);
if (node.isValid()) {
return InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) node);
}
} else {
psiElement = elementFromDescriptor;
}
}
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
return getSelectedNavigatable(problem, psiElement);
} else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
return psiElement != null && psiElement.isValid() ? psiElement : null;
}
} else if (selectedNode instanceof ProblemDescriptionNode && CommonDataKeys.NAVIGATABLE.is(dataId)) {
Navigatable navigatable = getSelectedNavigatable(((ProblemDescriptionNode) selectedNode).getDescriptor());
return navigatable == null ? InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) selectedNode) : navigatable;
}
return null;
}
Aggregations