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 };
}
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);
}
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);
}
};
}
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);
}
}
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);
}
};
}
Aggregations