Search in sources :

Example 1 with CommonProblemDescriptor

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;
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) SuppressIntentionAction(com.intellij.codeInspection.SuppressIntentionAction) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CommonProblemDescriptor

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();
    }
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) BatchQuickFix(com.intellij.codeInspection.BatchQuickFix) BatchQuickFix(com.intellij.codeInspection.BatchQuickFix) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefManager(com.intellij.codeInspection.reference.RefManager) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement)

Example 3 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor 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) };
}
Also used : RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor 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) };
}
Also used : RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CommonProblemDescriptor

use of com.intellij.codeInspection.CommonProblemDescriptor 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) };
}
Also used : RefClass(com.intellij.codeInspection.reference.RefClass) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiClass(com.intellij.psi.PsiClass) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)30 Nullable (org.jetbrains.annotations.Nullable)20 RefClass (com.intellij.codeInspection.reference.RefClass)13 RefEntity (com.intellij.codeInspection.reference.RefEntity)12 RefPackage (com.intellij.codeInspection.reference.RefPackage)9 PsiClass (com.intellij.psi.PsiClass)9 PsiElement (com.intellij.psi.PsiElement)7 HashSet (java.util.HashSet)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 RefModule (com.intellij.codeInspection.reference.RefModule)4 PsiIdentifier (com.intellij.psi.PsiIdentifier)4 NotNull (org.jetbrains.annotations.NotNull)4 QuickFix (com.intellij.codeInspection.QuickFix)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiField (com.intellij.psi.PsiField)2 PsiType (com.intellij.psi.PsiType)2 TreePath (javax.swing.tree.TreePath)2 BatchQuickFix (com.intellij.codeInspection.BatchQuickFix)1 ProblemDescriptorBase (com.intellij.codeInspection.ProblemDescriptorBase)1