use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class DisjointPackageInspection method getRelatedClasses.
private static Set<RefClass> getRelatedClasses(RefPackage aPackage, RefClass classToProcess) {
final Set<RefClass> out = new HashSet<>();
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(classToProcess);
for (RefClass dependency : dependencies) {
if (packageContainsClass(aPackage, dependency)) {
out.add(dependency);
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(classToProcess);
for (RefClass dependent : dependents) {
if (packageContainsClass(aPackage, dependent)) {
out.add(dependent);
}
}
return out;
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class DisjointPackageInspection 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 RefPackage refPackage = (RefPackage) refEntity;
final List<RefEntity> children = refPackage.getChildren();
final Set<RefClass> childClasses = new HashSet<>();
for (RefEntity child : children) {
if (!(child instanceof RefClass)) {
continue;
}
final PsiClass psiClass = ((RefClass) child).getElement();
if (ClassUtils.isInnerClass(psiClass)) {
continue;
}
childClasses.add((RefClass) child);
}
if (childClasses.isEmpty()) {
return null;
}
final Set<Set<RefClass>> components = createComponents(refPackage, childClasses);
if (components.size() == 1) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("disjoint.package.problem.descriptor", refPackage.getQualifiedName(), Integer.valueOf(components.size()));
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class DisjointPackageInspection method createComponents.
private static Set<Set<RefClass>> createComponents(RefPackage aPackage, Set<RefClass> classes) {
final Set<RefClass> allClasses = new HashSet<>(classes);
final Set<Set<RefClass>> out = new HashSet<>();
while (!allClasses.isEmpty()) {
final RefClass seed = allClasses.iterator().next();
allClasses.remove(seed);
final Set<RefClass> currentComponent = new HashSet<>();
currentComponent.add(seed);
final List<RefClass> pendingClasses = new ArrayList<>();
pendingClasses.add(seed);
while (!pendingClasses.isEmpty()) {
final RefClass classToProcess = pendingClasses.remove(0);
final Set<RefClass> relatedClasses = getRelatedClasses(aPackage, classToProcess);
for (RefClass relatedClass : relatedClasses) {
if (!currentComponent.contains(relatedClass) && !pendingClasses.contains(relatedClass)) {
currentComponent.add(relatedClass);
pendingClasses.add(relatedClass);
allClasses.remove(relatedClass);
}
}
}
out.add(currentComponent);
}
return out;
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class ClassOnlyUsedInOneModuleInspection method checkElement.
@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final RefEntity owner = refClass.getOwner();
if (!(owner instanceof RefPackage)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
RefModule otherModule = null;
for (RefClass dependency : dependencies) {
final RefModule module = dependency.getModule();
if (refClass.getModule() == module) {
return null;
}
if (otherModule != module) {
if (otherModule == null) {
otherModule = module;
} else {
return null;
}
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
final RefModule module = dependent.getModule();
if (refClass.getModule() == module) {
return null;
}
if (otherModule != module) {
if (otherModule == null) {
otherModule = module;
} else {
return null;
}
}
}
if (otherModule == null) {
return null;
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
final String moduleName = otherModule.getName();
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.only.used.in.one.module.problem.descriptor", moduleName), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.codeInspection.reference.RefClass in project intellij-community by JetBrains.
the class ModuleWithTooFewClassesInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager inspectionManager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefModule)) {
return null;
}
final RefModule refModule = (RefModule) refEntity;
final List<RefEntity> children = refModule.getChildren();
int numClasses = 0;
for (RefEntity child : children) {
if (child instanceof RefClass) {
numClasses++;
}
}
if (numClasses >= limit || numClasses == 0) {
return null;
}
final Project project = globalInspectionContext.getProject();
final Module[] modules = ModuleManager.getInstance(project).getModules();
if (modules.length == 1) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("module.with.too.few.classes.problem.descriptor", refModule.getName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
Aggregations