use of com.intellij.codeInspection.ProblemDescriptor in project qi4j-sdk by Qi4j.
the class StructureAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.
@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation structureAnnotation, @NotNull InspectionManager manager) {
StructureAnnotationDeclarationValidationResult annotationCheck = validateStructureAnnotationDeclaration(psiVariable);
switch(annotationCheck) {
case invalidInjectionType:
String message = message("injections.structure.annotation.declared.correctly.error.invalid.injection.type", psiVariable.getType().getCanonicalText());
AbstractFix removeStructureAnnotationFix = createRemoveAnnotationFix(structureAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(structureAnnotation, message, removeStructureAnnotationFix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
return null;
}
use of com.intellij.codeInspection.ProblemDescriptor in project qi4j-sdk by Qi4j.
the class MixinsAnnotationDeclaredOnMixinType method checkClass.
@Override
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
PsiAnnotation mixinsAnnotation = getMixinsAnnotation(psiClass);
if (mixinsAnnotation == null) {
return null;
}
if (psiClass.isInterface()) {
return null;
}
String message = message("mixins.annotation.declared.on.mixin.type.error.declared.on.class");
RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix(mixinsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(mixinsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
use of com.intellij.codeInspection.ProblemDescriptor in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class PyRemoveParameterQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement parameter = descriptor.getPsiElement();
assert parameter instanceof PyParameter;
final PyFunction function = PsiTreeUtil.getParentOfType(parameter, PyFunction.class);
if (function != null) {
final PyResolveContext resolveContext = PyResolveContext.noImplicits();
StreamEx.of(PyRefactoringUtil.findUsages(function, false)).map(UsageInfo::getElement).nonNull().map(PsiElement::getParent).select(PyCallExpression.class).flatMap(callExpression -> callExpression.multiMapArguments(resolveContext).stream()).flatMap(mapping -> mapping.getMappedParameters().entrySet().stream()).filter(entry -> entry.getValue() == parameter).forEach(entry -> entry.getKey().delete());
final PyStringLiteralExpression docStringExpression = function.getDocStringExpression();
final String parameterName = ((PyParameter) parameter).getName();
if (docStringExpression != null && parameterName != null) {
PyDocstringGenerator.forDocStringOwner(function).withoutParam(parameterName).buildAndInsert();
}
}
parameter.delete();
}
use of com.intellij.codeInspection.ProblemDescriptor in project intellij-community by JetBrains.
the class HardwiredNamespacePrefix method createVisitor.
protected Visitor createVisitor(final InspectionManager manager, final boolean isOnTheFly) {
return new Visitor(manager, isOnTheFly) {
protected void checkExpression(XPathExpression expression) {
if (!(expression instanceof XPathBinaryExpression)) {
return;
}
final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
if (expr.getOperator() == XPathTokenTypes.EQ) {
final XPathExpression lop = expr.getLOperand();
final XPathExpression rop = expr.getROperand();
if (isNameComparison(lop, rop)) {
assert rop != null;
final ProblemDescriptor p = manager.createProblemDescriptor(rop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
addProblem(p);
} else if (isNameComparison(rop, lop)) {
assert lop != null;
final ProblemDescriptor p = manager.createProblemDescriptor(lop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
addProblem(p);
} else if (isNameFunctionCall(lop)) {
// TODO
} else if (isNameFunctionCall(rop)) {
// TODO
}
}
}
};
}
Aggregations