use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class InspectionTreeCellRenderer method getMainForegroundAttributes.
private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) {
SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES;
if (node instanceof RefElementNode) {
RefEntity refElement = ((RefElementNode) node).getElement();
if (refElement instanceof RefElement) {
refElement = ((RefElement) refElement).getContainingEntry();
if (((RefElement) refElement).isEntry() && ((RefElement) refElement).isPermanentEntry()) {
foreground = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.blue);
}
}
}
final FileStatus nodeStatus = node.getNodeStatus();
if (nodeStatus != FileStatus.NOT_CHANGED) {
foreground = new SimpleTextAttributes(foreground.getBgColor(), nodeStatus.getColor(), foreground.getWaveColor(), foreground.getStyle());
}
return foreground;
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class LocalDescriptorsUtil method addProblemDescriptors.
static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors, boolean filterSuppressed, @NotNull GlobalInspectionContext context, @Nullable LocalInspectionTool tool, @NotNull TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext, RefElement> getProblemElementFunction, @NotNull InspectionToolPresentation dpi) {
if (descriptors.isEmpty())
return;
Map<RefElement, List<ProblemDescriptor>> problems = new HashMap<>();
final RefManagerImpl refManager = (RefManagerImpl) context.getRefManager();
for (ProblemDescriptor descriptor : descriptors) {
final PsiElement element = descriptor.getPsiElement();
if (element == null)
continue;
if (filterSuppressed) {
String alternativeId;
String id;
if (refManager.isDeclarationsFound() && (context.isSuppressed(element, id = tool.getID()) || (alternativeId = tool.getAlternativeID()) != null && !alternativeId.equals(id) && context.isSuppressed(element, alternativeId))) {
continue;
}
if (SuppressionUtil.inspectionResultSuppressed(element, tool))
continue;
}
RefElement refElement = getProblemElementFunction.fun(tool, element, context);
List<ProblemDescriptor> elementProblems = problems.get(refElement);
if (elementProblems == null) {
elementProblems = new ArrayList<>();
problems.put(refElement, elementProblems);
}
elementProblems.add(descriptor);
}
for (Map.Entry<RefElement, List<ProblemDescriptor>> entry : problems.entrySet()) {
final List<ProblemDescriptor> problemDescriptors = entry.getValue();
RefElement refElement = entry.getKey();
CommonProblemDescriptor[] descriptions = problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]);
dpi.addProblemElement(refElement, filterSuppressed, descriptions);
}
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class QuickFixAction method getReadOnlyFiles.
private static Set<VirtualFile> getReadOnlyFiles(@NotNull RefEntity[] refElements) {
Set<VirtualFile> readOnlyFiles = new THashSet<>();
for (RefEntity refElement : refElements) {
PsiElement psiElement = refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
if (psiElement == null || psiElement.getContainingFile() == null)
continue;
readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile());
}
return readOnlyFiles;
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class InspectionEngine method runInspectionOnFile.
@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
toolWrapper.initialize(inspectionContext);
RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
refManager.inspectionReadActionStarted();
try {
if (toolWrapper instanceof LocalInspectionToolWrapper) {
return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
}
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
final List<ProblemDescriptor> descriptors = new ArrayList<>();
if (globalTool instanceof GlobalSimpleInspectionTool) {
GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {
@Nullable
@Override
public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
}
@Override
public void ignoreElement(@NotNull RefEntity refEntity) {
throw new RuntimeException();
}
@Override
public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
if (!(refEntity instanceof RefElement))
return;
PsiElement element = ((RefElement) refEntity).getElement();
convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
}
@Override
public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
throw new RuntimeException();
}
};
simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
return descriptors;
}
RefElement fileRef = refManager.getReference(file);
final AnalysisScope scope = new AnalysisScope(file);
assert fileRef != null;
fileRef.accept(new RefVisitor() {
@Override
public void visitElement(@NotNull RefEntity elem) {
CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
if (elemDescriptors != null) {
convertToProblemDescriptors(file, elemDescriptors, descriptors);
}
for (RefEntity child : elem.getChildren()) {
child.accept(this);
}
}
});
return descriptors;
}
} finally {
refManager.inspectionReadActionFinished();
toolWrapper.cleanup(file.getProject());
inspectionContext.cleanup();
}
return Collections.emptyList();
}
use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.
the class GlobalInspectionContextUtil method retrieveRefElement.
public static RefElement retrieveRefElement(@NotNull PsiElement element, @NotNull GlobalInspectionContext globalContext) {
PsiFile elementFile = element.getContainingFile();
RefElement refElement = globalContext.getRefManager().getReference(elementFile);
if (refElement == null) {
PsiElement context = InjectedLanguageManager.getInstance(elementFile.getProject()).getInjectionHost(elementFile);
if (context != null)
refElement = globalContext.getRefManager().getReference(context.getContainingFile());
}
return refElement;
}
Aggregations