use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.
the class SuppressableInspectionTreeNode method getOnlyAvailableSuppressActions.
@NotNull
private Set<SuppressIntentionAction> getOnlyAvailableSuppressActions(@NotNull Project project) {
final Set<SuppressIntentionAction> actions = getSuppressActions();
if (actions.isEmpty()) {
return Collections.emptySet();
}
final Pair<PsiElement, CommonProblemDescriptor> suppress = getSuppressContent();
final PsiElement suppressElement = suppress.getFirst();
if (suppressElement == null) {
return actions;
}
Set<SuppressIntentionAction> availableActions = null;
for (SuppressIntentionAction action : actions) {
if (action.isAvailable(project, null, suppressElement)) {
if (availableActions == null) {
availableActions = ContainerUtil.newConcurrentSet(TObjectHashingStrategy.IDENTITY);
}
availableActions.add(action);
}
}
return availableActions == null ? Collections.emptySet() : availableActions;
}
use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.
the class LocalQuickFixWrapper method applyFix.
@Override
protected void applyFix(@NotNull final Project project, @NotNull final GlobalInspectionContextImpl context, @NotNull final CommonProblemDescriptor[] descriptors, @NotNull final Set<PsiElement> ignoredElements) {
if (myFix instanceof BatchQuickFix) {
final List<PsiElement> collectedElementsToIgnore = new ArrayList<>();
final Runnable refreshViews = () -> {
DaemonCodeAnalyzer.getInstance(project).restart();
for (CommonProblemDescriptor descriptor : descriptors) {
ignore(ignoredElements, descriptor, getWorkingQuickFix(descriptor.getFixes()), context);
}
final RefManager refManager = context.getRefManager();
final RefElement[] refElements = new RefElement[collectedElementsToIgnore.size()];
for (int i = 0, collectedElementsToIgnoreSize = collectedElementsToIgnore.size(); i < collectedElementsToIgnoreSize; i++) {
refElements[i] = refManager.getReference(collectedElementsToIgnore.get(i));
}
removeElements(refElements, project, myToolWrapper);
};
((BatchQuickFix) myFix).applyFix(project, descriptors, collectedElementsToIgnore, refreshViews);
return;
}
boolean restart = false;
for (CommonProblemDescriptor descriptor : descriptors) {
if (descriptor == null)
continue;
final QuickFix[] fixes = descriptor.getFixes();
if (fixes != null) {
final QuickFix fix = getWorkingQuickFix(fixes);
if (fix != null) {
//CCE here means QuickFix was incorrectly inherited, is there a way to signal (plugin) it is wrong?
fix.applyFix(project, descriptor);
restart = true;
ignore(ignoredElements, descriptor, fix, context);
}
}
}
if (restart) {
DaemonCodeAnalyzer.getInstance(project).restart();
}
}
use of com.intellij.codeInspection.CommonProblemDescriptor in project intellij-community by JetBrains.
the class ClassOnlyUsedInOnePackageInspection 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);
RefPackage otherPackage = null;
for (RefClass dependency : dependencies) {
final RefPackage refPackage = RefJavaUtil.getPackage(dependency);
if (owner == refPackage) {
return null;
}
if (otherPackage != refPackage) {
if (otherPackage == null) {
otherPackage = refPackage;
} else {
return null;
}
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
final RefPackage refPackage = RefJavaUtil.getPackage(dependent);
if (owner == refPackage) {
return null;
}
if (otherPackage != refPackage) {
if (otherPackage == null) {
otherPackage = refPackage;
} else {
return null;
}
}
}
if (otherPackage == null) {
return null;
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
final String packageName = otherPackage.getName();
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.only.used.in.one.package.problem.descriptor", packageName), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.codeInspection.CommonProblemDescriptor 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.CommonProblemDescriptor 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) };
}
Aggregations