use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class ClassWithTooManyTransitiveDependenciesInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final PsiClass aClass = refClass.getElement();
if (ClassUtils.isInnerClass(aClass)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateTransitiveDependenciesForClass(refClass);
final int numDependencies = dependencies.size();
if (numDependencies <= limit) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("class.with.too.many.transitive.dependencies.problem.descriptor", refEntity.getName(), numDependencies, limit);
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class ClassWithTooManyTransitiveDependentsInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final PsiClass aClass = refClass.getElement();
if (ClassUtils.isInnerClass(aClass)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateTransitiveDependentsForClass(refClass);
final int numDependents = dependencies.size();
if (numDependents <= limit) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("class.with.too.many.transitive.dependents.problem.descriptor", refEntity.getName(), numDependents, limit);
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class CyclicClassDependencyInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
if (refClass.isAnonymous() || refClass.isLocalClass() || refClass.isSyntheticJSP()) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateTransitiveDependenciesForClass(refClass);
final Set<RefClass> dependents = DependencyUtils.calculateTransitiveDependentsForClass(refClass);
final Set<RefClass> mutualDependents = new HashSet<>(dependencies);
mutualDependents.retainAll(dependents);
final int numMutualDependents = mutualDependents.size();
if (numMutualDependents == 0) {
return null;
}
final String errorString;
if (numMutualDependents == 1) {
final RefClass[] classes = mutualDependents.toArray(new RefClass[1]);
errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.1.problem.descriptor", refEntity.getName(), classes[0].getExternalName());
} else if (numMutualDependents == 2) {
final RefClass[] classes = mutualDependents.toArray(new RefClass[2]);
Arrays.sort(classes, RefEntityAlphabeticalComparator.getInstance());
errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.2.problem.descriptor", refEntity.getName(), classes[0].getExternalName(), classes[1].getExternalName());
} else {
errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.problem.descriptor", refEntity.getName(), Integer.valueOf(numMutualDependents));
}
final PsiClass aClass = refClass.getElement();
if (aClass == null) {
return null;
}
final PsiElement anchor = aClass.getNameIdentifier();
if (anchor == null)
return null;
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(anchor, errorString, (LocalQuickFix) null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class CyclicClassInitializationInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final PsiClass aClass = refClass.getElement();
if (aClass.getContainingClass() != null) {
return null;
}
final Set<RefClass> dependencies = InitializationDependencyUtils.calculateTransitiveInitializationDependentsForClass(refClass);
final Set<RefClass> dependents = InitializationDependencyUtils.calculateTransitiveInitializationDependenciesForClass(refClass);
final Set<RefClass> mutualDependents = new HashSet<>(dependencies);
mutualDependents.retainAll(dependents);
final int numMutualDependents = mutualDependents.size();
if (numMutualDependents == 0) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("cyclic.class.initialization.problem.descriptor", refEntity.getName(), numMutualDependents);
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class InitializationDependencyUtils method tabulateInitializationTransitiveDependentClasses.
private static void tabulateInitializationTransitiveDependentClasses(RefClass refClass, Set<RefClass> newDependents) {
final LinkedList<RefClass> pendingClasses = new LinkedList<>();
final Set<RefClass> processedClasses = new HashSet<>();
pendingClasses.addLast(refClass);
while (!pendingClasses.isEmpty()) {
final RefClass classToProcess = pendingClasses.removeFirst();
newDependents.add(classToProcess);
processedClasses.add(classToProcess);
final Set<RefClass> dependents = calculateInitializationDependentsForClass(classToProcess);
for (RefClass dependent : dependents) {
if (!pendingClasses.contains(dependent) && !processedClasses.contains(dependent)) {
pendingClasses.addLast(dependent);
}
}
}
newDependents.remove(refClass);
}
Aggregations