use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method ignoreElement.
public void ignoreElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
final RefElement refElement = getRefManager().getReference(element);
final Tools tools = getTools().get(tool.getShortName());
if (tools != null) {
for (ScopeToolState state : tools.getTools()) {
InspectionToolWrapper toolWrapper = state.getTool();
ignoreElementRecursively(toolWrapper, refElement);
}
}
}
use of com.intellij.codeInspection.reference.RefElement 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.RefElement 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.RefElement 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;
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class QuickFixAction method getSelectedElements.
@NotNull
private static RefEntity[] getSelectedElements(InspectionResultsView view) {
if (view == null)
return new RefElement[0];
List<RefEntity> selection = new ArrayList<>(Arrays.asList(view.getTree().getSelectedElements()));
PsiDocumentManager.getInstance(view.getProject()).commitAllDocuments();
Collections.sort(selection, (o1, o2) -> {
if (o1 instanceof RefElement && o2 instanceof RefElement) {
RefElement r1 = (RefElement) o1;
RefElement r2 = (RefElement) o2;
final PsiElement element1 = r1.getElement();
final PsiElement element2 = r2.getElement();
final PsiFile containingFile1 = element1.getContainingFile();
final PsiFile containingFile2 = element2.getContainingFile();
if (containingFile1 == containingFile2) {
int i1 = element1.getTextOffset();
int i2 = element2.getTextOffset();
if (i1 < i2) {
return 1;
}
if (i1 > i2) {
return -1;
}
return 0;
}
return containingFile1.getName().compareTo(containingFile2.getName());
}
if (o1 instanceof RefElement) {
return 1;
}
if (o2 instanceof RefElement) {
return -1;
}
return o1.getName().compareTo(o2.getName());
});
return selection.toArray(new RefEntity[selection.size()]);
}
Aggregations