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) };
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class PackageWithTooFewClassesInspection 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();
int numClasses = 0;
boolean subpackage = false;
for (RefEntity child : children) {
if (child instanceof RefClass) {
numClasses++;
} else if (child instanceof RefPackage) {
subpackage = true;
}
}
if (numClasses >= limit || (numClasses == 0 && subpackage)) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("package.with.too.few.classes.problem.descriptor", refEntity.getQualifiedName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class PackageWithTooManyClassesInspection 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();
int numClasses = 0;
for (RefEntity child : children) {
if (child instanceof RefClass) {
numClasses++;
}
}
if (numClasses <= limit) {
return null;
}
final String errorString = InspectionGadgetsBundle.message("package.with.too.many.classes.problem.descriptor", refEntity.getQualifiedName(), Integer.valueOf(numClasses), Integer.valueOf(limit));
return new CommonProblemDescriptor[] { inspectionManager.createProblemDescriptor(errorString) };
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class ClassUnconnectedToPackageInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalInspectionContext) {
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);
for (RefClass dependency : dependencies) {
if (inSamePackage(refClass, dependency)) {
return null;
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
if (inSamePackage(refClass, dependent)) {
return null;
}
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.unconnected.to.package.problem.descriptor"), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
Aggregations