use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method getProblemDescriptionProcessor.
@NotNull
private ProblemDescriptionsProcessor getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper, @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
return new ProblemDescriptionsProcessor() {
@Override
public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
for (CommonProblemDescriptor problemDescriptor : commonProblemDescriptors) {
if (!(problemDescriptor instanceof ProblemDescriptor)) {
continue;
}
ProblemGroup problemGroup = ((ProblemDescriptor) problemDescriptor).getProblemGroup();
InspectionToolWrapper targetWrapper = problemGroup == null ? toolWrapper : wrappersMap.get(problemGroup.getProblemName());
if (targetWrapper != null) {
// Else it's switched off
InspectionToolPresentation toolPresentation = getPresentation(targetWrapper);
toolPresentation.addProblemElement(refEntity, problemDescriptor);
}
}
}
};
}
use of com.intellij.codeInspection.reference.RefEntity 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.RefEntity 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.RefEntity in project intellij-community by JetBrains.
the class InitializationDependencyUtils method tabulateInitializationDependentClasses.
@SuppressWarnings({ "MethodWithMultipleLoops" })
private static void tabulateInitializationDependentClasses(RefElement element, Set<RefClass> dependents) {
final Collection<RefElement> references = element.getInReferences();
final RefJavaUtil refUtil = RefJavaUtil.getInstance();
for (RefElement reference : references) {
final RefClass refClass = refUtil.getTopLevelClass(reference);
if (refClass != null) {
dependents.add(refClass);
}
}
final List<RefEntity> children = element.getChildren();
for (RefEntity child : children) {
if (child instanceof RefElement) {
tabulateInitializationDependentClasses((RefElement) child, dependents);
}
}
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class PackageInMultipleModulesInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefPackage)) {
return null;
}
final List<RefEntity> children = refEntity.getChildren();
final Set<RefModule> modules = new HashSet<>();
for (RefEntity child : children) {
if (!(child instanceof RefClass)) {
continue;
}
final RefClass refClass = (RefClass) child;
final RefModule module = refClass.getModule();
modules.add(module);
}
if (modules.size() <= 1) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("package.in.multiple.modules.problem.descriptor", refEntity.getQualifiedName());
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Aggregations