本文整理汇总了Java中com.intellij.codeInsight.AnnotationUtil.isAnnotatingApplicable方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtil.isAnnotatingApplicable方法的具体用法?Java AnnotationUtil.isAnnotatingApplicable怎么用?Java AnnotationUtil.isAnnotatingApplicable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.AnnotationUtil
的用法示例。
在下文中一共展示了AnnotationUtil.isAnnotatingApplicable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNonStandardAnnotations
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static boolean checkNonStandardAnnotations(PsiField field,
Annotated annotated,
NullableNotNullManager manager, String anno, @NotNull ProblemsHolder holder) {
if (!AnnotationUtil.isAnnotatingApplicable(field, anno)) {
final PsiAnnotation notNull = AnnotationUtil.findAnnotation(field, manager.getNotNulls());
final PsiAnnotation nullable = AnnotationUtil.findAnnotation(field, manager.getNullables());
final PsiAnnotation annotation;
String message = "Not \'";
if (annotated.isDeclaredNullable) {
message += nullable.getQualifiedName();
annotation = nullable;
} else {
message += notNull.getQualifiedName();
annotation = notNull;
}
message += "\' but \'" + anno + "\' would be used for code generation.";
final PsiJavaCodeReferenceElement annotationNameReferenceElement = annotation.getNameReferenceElement();
holder.registerProblem(annotationNameReferenceElement != null && annotationNameReferenceElement.isPhysical() ? annotationNameReferenceElement : field.getNameIdentifier(),
message,
ProblemHighlightType.WEAK_WARNING,
new ChangeNullableDefaultsFix(notNull, nullable, manager));
return false;
}
return true;
}
示例2: buildFix
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
final PsiElement elt = (PsiElement)infos[0];
if (!AnnotationUtil.isAnnotatingApplicable(elt)) {
return null;
}
if (PsiTreeUtil.getParentOfType(elt, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiLambdaExpression) {
return null;
}
final NullableNotNullManager manager = NullableNotNullManager.getInstance(elt.getProject());
return new DelegatingFix(new AnnotateMethodFix(
manager.getDefaultNullable(),
ArrayUtil.toStringArray(manager.getNotNulls())){
@Override
public int shouldAnnotateBaseMethod(PsiMethod method, PsiMethod superMethod, Project project) {
return ReturnNullInspectionBase.this.shouldAnnotateBaseMethod(method, superMethod);
}
});
}
示例3: reportNullableArgumentsPassedToNonAnnotated
import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private void reportNullableArgumentsPassedToNonAnnotated(DataFlowInstructionVisitor visitor, ProblemsHolder holder, Set<PsiElement> reportedAnchors) {
for (PsiElement expr : visitor.getProblems(NullabilityProblem.passingNullableArgumentToNonAnnotatedParameter)) {
if (reportedAnchors.contains(expr)) continue;
final String text = isNullLiteralExpression(expr)
? "Passing <code>null</code> argument to non annotated parameter"
: "Argument <code>#ref</code> #loc might be null but passed to non annotated parameter";
LocalQuickFix[] fixes = createNPEFixes((PsiExpression)expr, (PsiExpression)expr, holder.isOnTheFly());
final PsiElement parent = expr.getParent();
if (parent instanceof PsiExpressionList) {
final int idx = ArrayUtilRt.find(((PsiExpressionList)parent).getExpressions(), expr);
if (idx > -1) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiCallExpression) {
final PsiMethod psiMethod = ((PsiCallExpression)gParent).resolveMethod();
if (psiMethod != null && psiMethod.getManager().isInProject(psiMethod) && AnnotationUtil.isAnnotatingApplicable(psiMethod)) {
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
if (idx < parameters.length) {
final AddNullableAnnotationFix addNullableAnnotationFix = new AddNullableAnnotationFix(parameters[idx]);
fixes = fixes == null ? new LocalQuickFix[]{addNullableAnnotationFix} : ArrayUtil.append(fixes, addNullableAnnotationFix);
holder.registerProblem(expr, text, fixes);
reportedAnchors.add(expr);
}
}
}
}
}
}
}