use of com.intellij.codeInspection.LocalQuickFix in project qi4j-sdk by Qi4j.
the class InvocationAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.
@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation invocationAnnotation, @NotNull InspectionManager manager) {
LocalQuickFix fix = null;
String message = null;
String variableTypeQualifiedName = psiVariable.getType().getCanonicalText();
InvocationAnnotationDeclarationValidationResult validationResult = isValidInvocationAnnotationDeclaration(psiVariable);
switch(validationResult) {
case invalidTypeIsInjectedViaStructureAnnotation:
if (getStructureAnnotation(psiVariable) == null) {
fix = new ReplaceWithStructureAnnotation(message("injections.invocation.annotation.declared.correctly.fix.replace.with.structure.annotation"), invocationAnnotation);
}
message = message("injections.invocation.annotation.declared.correctly.error.type.is.injected.by.structure", variableTypeQualifiedName);
break;
case invalidType:
message = message("injections.invocation.annotation.declared.correctly.error.type.is.not.injectable", variableTypeQualifiedName);
break;
}
// If it's not an error, return null
if (message == null) {
return null;
}
// If Fix not defined, by default we remove it.
if (fix == null) {
fix = createRemoveAnnotationFix(invocationAnnotation);
}
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(invocationAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
use of com.intellij.codeInspection.LocalQuickFix in project qi4j-sdk by Qi4j.
the class ServiceAnnotationDeclaredCorrectlyInspection method verifyAnnotationDeclaredCorrectly.
@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly(@NotNull PsiVariable psiVariable, @NotNull PsiAnnotation serviceAnnotation, @NotNull InspectionManager manager) {
ServiceAnnotationDeclarationValidationResult annotationCheck = isValidServiceAnnotationDeclaration(psiVariable);
String message = null;
LocalQuickFix fix = null;
switch(annotationCheck) {
case invalidTypeIsInjectedViaStructureAnnotation:
if (getStructureAnnotation(psiVariable) == null) {
fix = new ReplaceWithStructureAnnotation(message("injections.service.annotation.declared.correctly.fix.replace.with.structure.annotation"), serviceAnnotation);
}
message = message("injections.service.annotation.declared.correctly.error.type.is.injected.by.structure", psiVariable.getType().getCanonicalText());
break;
}
// If it's not an error, return null
if (message == null) {
return null;
}
// Default behavior to remove @Service annotation
if (fix == null) {
fix = createRemoveAnnotationFix(serviceAnnotation);
}
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(serviceAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class PyTestCase method findQuickFixByClassInIntentions.
/**
* Searches for quickfix itetion by its class
*
* @param clazz quick fix class
* @param <T> quick fix class
* @return quick fix or null if nothing found
*/
@Nullable
public <T extends LocalQuickFix> T findQuickFixByClassInIntentions(@NotNull final Class<T> clazz) {
for (final IntentionAction action : myFixture.getAvailableIntentions()) {
if ((action instanceof QuickFixWrapper)) {
final QuickFixWrapper quickFixWrapper = (QuickFixWrapper) action;
final LocalQuickFix fix = quickFixWrapper.getFix();
if (clazz.isInstance(fix)) {
@SuppressWarnings("unchecked") final T result = (T) fix;
return result;
}
}
}
return null;
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class SpellingPopupActionGroup method extractActions.
private static void extractActions(List<HighlightInfo.IntentionActionDescriptor> descriptors, Map<Anchor, List<AnAction>> actions) {
for (HighlightInfo.IntentionActionDescriptor actionDescriptor : descriptors) {
IntentionAction action = actionDescriptor.getAction();
if (action instanceof QuickFixWrapper) {
QuickFixWrapper wrapper = (QuickFixWrapper) action;
LocalQuickFix localQuickFix = wrapper.getFix();
if (localQuickFix instanceof SpellCheckerQuickFix) {
SpellCheckerQuickFix spellCheckerQuickFix = (SpellCheckerQuickFix) localQuickFix;
Anchor anchor = spellCheckerQuickFix.getPopupActionAnchor();
SpellCheckerIntentionAction popupAction = new SpellCheckerIntentionAction(action);
List<AnAction> list = actions.get(anchor);
if (list != null) {
list.add(popupAction);
}
}
}
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class HtmlUnknownBooleanAttributeInspectionBase method checkAttribute.
@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (attribute.getValueElement() == null) {
final XmlTag tag = attribute.getParent();
if (tag instanceof HtmlTag) {
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
return;
}
XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) {
String name = attribute.getName();
if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
final boolean html5 = HtmlUtil.isHtml5Context(tag);
LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[] { new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionAction(name) } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) };
String error = null;
if (html5) {
if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor) attributeDescriptor).getValueDeclaration(attribute, "") == null) {
error = XmlErrorMessages.message("wrong.value", "attribute");
}
} else {
error = XmlErrorMessages.message("attribute.is.not.boolean", attribute.getName());
}
if (error != null) {
registerProblemOnAttributeName(attribute, error, holder, quickFixes);
}
}
}
}
}
}
Aggregations