mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-intentions] Minor fixes for AddAnnotationModCommandAction (IDEA-369745)
GitOrigin-RevId: 709369c9b777866ada1961922b8e1cd3dc217d5a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c63b107f00
commit
7d57941ece
+14
-10
@@ -25,11 +25,11 @@ import java.util.List;
|
||||
* A common action to add an annotation into Java code (either in code or externally)
|
||||
*/
|
||||
public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiModifierListOwner> {
|
||||
private final String myAnnotation;
|
||||
private final String[] myAnnotationsToRemove;
|
||||
private final PsiNameValuePair[] myPairs;
|
||||
private final @NotNull String myAnnotation;
|
||||
private final @NotNull String @NotNull [] myAnnotationsToRemove;
|
||||
private final @NotNull PsiNameValuePair @NotNull [] myPairs;
|
||||
private final @IntentionName String myText;
|
||||
private final AnnotationPlace myAnnotationPlace;
|
||||
private final @NotNull AnnotationPlace myAnnotationPlace;
|
||||
private final boolean myExistsTypeUseTarget;
|
||||
private final boolean myHasApplicableAnnotations;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
/**
|
||||
* @param fqn annotation fully qualified name
|
||||
* @param modifierListOwner annotation owner to add an annotation to
|
||||
* @param values annotation attributes
|
||||
* @param values annotation attributes; must be non-physical PSI
|
||||
* @param annotationsToRemove fully qualified names of annotations to remove
|
||||
*/
|
||||
public AddAnnotationModCommandAction(@NotNull String fqn,
|
||||
@@ -60,7 +60,7 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
/**
|
||||
* @param fqn annotation fully qualified name
|
||||
* @param modifierListOwner annotation owner to add an annotation to
|
||||
* @param values annotation attributes
|
||||
* @param values annotation attributes; must be non-physical PSI
|
||||
* @param place place where to add an annotation
|
||||
* @param annotationsToRemove fully qualified names of annotations to remove
|
||||
*/
|
||||
@@ -89,7 +89,11 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
super(modifierListOwner);
|
||||
myText = text;
|
||||
myAnnotation = fqn;
|
||||
ObjectUtils.assertAllElementsNotNull(values);
|
||||
for (PsiNameValuePair value : values) {
|
||||
if (value.isPhysical()) {
|
||||
throw new IllegalArgumentException("Annotation attributes must be non-physical PSI");
|
||||
}
|
||||
}
|
||||
myPairs = values;
|
||||
ObjectUtils.assertAllElementsNotNull(annotationsToRemove);
|
||||
myAnnotationsToRemove = annotationsToRemove;
|
||||
@@ -161,7 +165,7 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
}
|
||||
|
||||
/**
|
||||
* Postprocess inserted (non-physical) annotation
|
||||
* Postprocess inserted (non-physical) annotation in the background read-action.
|
||||
*
|
||||
* @param annotation annotation
|
||||
* @param updater updater that could be used
|
||||
@@ -175,7 +179,7 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fix which will add default "Nullable" annotation to the given element.
|
||||
* Creates a fix which will add the default "Nullable" annotation to the given element.
|
||||
*
|
||||
* @param owner an element to add the annotation
|
||||
* @return newly created fix or null if adding nullability annotation is impossible for the specified element.
|
||||
@@ -186,7 +190,7 @@ public class AddAnnotationModCommandAction extends PsiBasedModCommandAction<PsiM
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fix which will add default "NotNull" annotation to the given element.
|
||||
* Creates a fix which will add the default "NotNull" annotation to the given element.
|
||||
*
|
||||
* @param owner an element to add the annotation
|
||||
* @return newly created fix or null if adding nullability annotation is impossible for the specified element.
|
||||
|
||||
+3
-3
@@ -34,11 +34,11 @@ import org.intellij.plugins.intelliLang.util.AnnotationUtilEx;
|
||||
import org.intellij.plugins.intelliLang.util.PsiUtilEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.codeInspection.options.OptPane.checkbox;
|
||||
import static com.intellij.codeInspection.options.OptPane.pane;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class LanguageMismatch extends LocalInspectionTool {
|
||||
public boolean CHECK_NON_ANNOTATED_REFERENCES = true;
|
||||
@@ -125,11 +125,11 @@ public class LanguageMismatch extends LocalInspectionTool {
|
||||
}
|
||||
// context implies language, but declaration isn't annotated
|
||||
final PsiAnnotation annotation = annotations[annotations.length - 1];
|
||||
String fqn = Objects.requireNonNull(annotation.getQualifiedName());
|
||||
String fqn = requireNonNull(annotation.getQualifiedName());
|
||||
ModCommandAction fix = null;
|
||||
PsiModifierListOwner owner = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_DECLARATION);
|
||||
if (owner != null && AddAnnotationPsiFix.isAvailable(owner, fqn)) {
|
||||
fix = new AddAnnotationModCommandAction(fqn, owner, annotation.getParameterList().getAttributes());
|
||||
fix = new AddAnnotationModCommandAction(fqn, owner, ((PsiAnnotation)annotation.copy()).getParameterList().getAttributes());
|
||||
}
|
||||
holder.problem(expression, IntelliLangBundle.message("inspection.language.problem.description", expected))
|
||||
.maybeFix(fix).register();
|
||||
|
||||
Reference in New Issue
Block a user