当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationUtil.isAnnotatingApplicable方法代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:NullableStuffInspectionBase.java

示例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);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ReturnNullInspectionBase.java

示例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);
            }
          }
        }
      }
    }

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:DataFlowInspectionBase.java


注:本文中的com.intellij.codeInsight.AnnotationUtil.isAnnotatingApplicable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。