Search in sources :

Example 16 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.

the class InspectionDescriptionNotFoundInspection method checkClass.

@Override
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final Project project = psiClass.getProject();
    final PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
    if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(psiClass))
        return null;
    final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INSPECTION_PROFILE_ENTRY, psiClass.getResolveScope());
    if (base == null || !psiClass.isInheritor(base, true) || isPathMethodsAreOverridden(psiClass))
        return null;
    final InspectionDescriptionInfo info = InspectionDescriptionInfo.create(module, psiClass);
    if (!info.isValid() || info.hasDescriptionFile())
        return null;
    final PsiElement problemElement = getProblemElement(psiClass, info.getShortNameMethod());
    final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(problemElement == null ? nameIdentifier : problemElement, "Inspection does not have a description", isOnTheFly, new LocalQuickFix[] { new CreateHtmlDescriptionFix(info.getFilename(), module, DescriptionType.INSPECTION) }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] { problemDescriptor };
}
Also used : Project(com.intellij.openapi.project.Project) CreateHtmlDescriptionFix(org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) Module(com.intellij.openapi.module.Module)

Example 17 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.

the class BaseInspectionVisitor method registerErrorAtRange.

protected final void registerErrorAtRange(@NotNull PsiElement startLocation, @NotNull PsiElement endLocation, Object... infos) {
    if (startLocation.getTextLength() == 0 && startLocation == endLocation) {
        return;
    }
    final LocalQuickFix[] fixes = createAndInitFixes(infos);
    final String description = inspection.buildErrorString(infos);
    final ProblemDescriptor problemDescriptor = holder.getManager().createProblemDescriptor(startLocation, endLocation, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly, fixes);
    holder.registerProblem(problemDescriptor);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix)

Example 18 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.

the class ChangeToMethodInspection method getFix.

@Nullable
protected GroovyFix getFix(@NotNull Transformation<?> transformation) {
    return new GroovyFix() {

        @Nls
        @NotNull
        @Override
        public String getFamilyName() {
            return message("replace.with.method.fix", transformation.getMethod());
        }

        @Override
        protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
            PsiElement call = descriptor.getPsiElement().getParent();
            if (!(call instanceof GrExpression))
                return;
            if (!transformation.couldApplyRow((GrExpression) call))
                return;
            transformation.applyRow((GrExpression) call);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) GroovyFix(org.jetbrains.plugins.groovy.codeInspection.GroovyFix) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.

the class GrAccessibilityChecker method registerFixes.

private void registerFixes(GrReferenceElement ref, GroovyResolveResult result, HighlightInfo info) {
    PsiElement element = result.getElement();
    assert element != null;
    ProblemDescriptor descriptor = InspectionManager.getInstance(ref.getProject()).createProblemDescriptor(element, element, "", HighlightInfo.convertSeverityToProblemHighlight(info.getSeverity()), true, LocalQuickFix.EMPTY_ARRAY);
    for (GroovyFix fix : buildFixes(ref, result)) {
        QuickFixAction.registerQuickFixAction(info, new LocalQuickFixAsIntentionAdapter(fix, descriptor), myDisplayKey);
    }
}
Also used : GroovyFix(org.jetbrains.plugins.groovy.codeInspection.GroovyFix) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFixAsIntentionAdapter(com.intellij.codeInspection.LocalQuickFixAsIntentionAdapter)

Example 20 with ProblemDescriptor

use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.

the class ChangeToOperatorInspection method getFix.

@Nullable
protected GroovyFix getFix(@NotNull Transformation transformation, @NotNull String methodName) {
    return new GroovyFix() {

        @Nls
        @NotNull
        @Override
        public String getFamilyName() {
            return message("replace.with.operator.fix", methodName);
        }

        @Override
        protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
            PsiElement call = descriptor.getPsiElement().getParent();
            if (call == null)
                return;
            call = call.getParent();
            if (!(call instanceof GrMethodCall))
                return;
            GrMethodCall methodCall = (GrMethodCall) call;
            GrExpression invokedExpression = methodCall.getInvokedExpression();
            if (!(invokedExpression instanceof GrReferenceExpression))
                return;
            Options options = getOptions();
            if (!transformation.couldApply(methodCall, options))
                return;
            transformation.apply(methodCall, options);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) GroovyFix(org.jetbrains.plugins.groovy.codeInspection.GroovyFix) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)40 Project (com.intellij.openapi.project.Project)15 NotNull (org.jetbrains.annotations.NotNull)13 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)11 PsiElement (com.intellij.psi.PsiElement)10 Nullable (org.jetbrains.annotations.Nullable)8 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)5 PsiAnnotation (com.intellij.psi.PsiAnnotation)5 LinkedList (java.util.LinkedList)5 InspectionManager (com.intellij.codeInspection.InspectionManager)4 PsiFile (com.intellij.psi.PsiFile)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 QuickFix (com.intellij.codeInspection.QuickFix)3 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)3 PsiClass (com.intellij.psi.PsiClass)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 GroovyFix (org.jetbrains.plugins.groovy.codeInspection.GroovyFix)3 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 ASTNode (com.intellij.lang.ASTNode)2 Editor (com.intellij.openapi.editor.Editor)2