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


Java AnnotationUtil类代码示例

本文整理汇总了Java中com.intellij.codeInsight.AnnotationUtil的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtil类的具体用法?Java AnnotationUtil怎么用?Java AnnotationUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnnotationUtil类属于com.intellij.codeInsight包,在下文中一共展示了AnnotationUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: targetTypesForDefault

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@Nullable
private static Set<PsiAnnotation.TargetType> targetTypesForDefault(PsiAnnotation annotation) {
    PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
    PsiElement declaration = element == null ? null : element.resolve();

    if (!(declaration instanceof PsiClass)) {
        return Collections.emptySet();
    }

    PsiClass classDeclaration = (PsiClass) declaration;
    PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);

    if (tqDefault == null) {
        return Collections.emptySet();
    }

    return extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java

示例2: isNullabilityAnnotationForTypeQualifierDefault

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
private static boolean isNullabilityAnnotationForTypeQualifierDefault(PsiAnnotation annotation,
                                                                      boolean nullable,
                                                                      PsiAnnotation.TargetType[] targetTypes) {
    PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
    PsiElement declaration = element == null ? null : element.resolve();
    if (!(declaration instanceof PsiClass)) {
        return false;
    }

    String fqn = nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL;
    PsiClass classDeclaration = (PsiClass) declaration;
    if (!AnnotationUtil.isAnnotated(classDeclaration, fqn, false, true)) {
        return false;
    }

    PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
    if (tqDefault == null) {
        return false;
    }

    Set<PsiAnnotation.TargetType> required = extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
    return required != null
            && (required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(targetTypes)));
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:25,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java

示例3: addSuppressAnnotation

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
public static void addSuppressAnnotation(@NotNull Project project,
                                         final PsiElement container,
                                         final PsiModifierListOwner modifierOwner,
                                         @NotNull String id) throws IncorrectOperationException {
  PsiAnnotation annotation = AnnotationUtil.findAnnotation(modifierOwner, SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
  final PsiAnnotation newAnnotation = createNewAnnotation(project, container, annotation, id);
  if (newAnnotation != null) {
    if (annotation != null && annotation.isPhysical()) {
      annotation.replace(newAnnotation);
    }
    else {
      final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes();
      new AddAnnotationPsiFix(SUPPRESS_INSPECTIONS_ANNOTATION_NAME, modifierOwner, attributes).applyFix();
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JavaSuppressionUtil.java

示例4: buildVisitor

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new JavaElementVisitor() {
    final String annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getPatternAnnotationClass();

    @Override
    public void visitAnnotation(PsiAnnotation annotation) {
      final String name = annotation.getQualifiedName();
      if (annotationName.equals(name)) {
        checkAnnotation(annotation, holder);
      }
      else if (name != null) {
        final PsiClass psiClass = JavaPsiFacade.getInstance(annotation.getProject()).findClass(name, annotation.getResolveScope());
        if (psiClass != null && AnnotationUtil.isAnnotated(psiClass, annotationName, false, false)) {
          checkAnnotation(annotation, holder);
        }
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PatternAnnotationNotApplicable.java

示例5: 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

示例6: buildVisitor

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new JavaElementVisitor() {
    final String annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getLanguageAnnotationClass();

    @Override
    public void visitAnnotation(PsiAnnotation annotation) {
      final String name = annotation.getQualifiedName();
      if (annotationName.equals(name)) {
        checkAnnotation(annotation, holder);
      }
      else if (name != null) {
        final PsiClass psiClass = JavaPsiFacade.getInstance(annotation.getProject()).findClass(name, annotation.getResolveScope());
        if (psiClass != null && AnnotationUtil.isAnnotated(psiClass, annotationName, false, false)) {
          checkAnnotation(annotation, holder);
        }
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:InjectionNotApplicable.java

示例7: findGuardForMember

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@Nullable
static String findGuardForMember(PsiMember member) {
  final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, GUARDED_BY);
  if (annotation != null) {
    return getGuardValue(annotation);
  }
  if (member instanceof PsiCompiledElement) {
    member = (PsiMember)member.getNavigationElement();
    if (member == null || member instanceof PsiCompiledElement) {
      return null; // can't analyze compiled code
    }
  }
  final GuardedTagVisitor visitor = new GuardedTagVisitor();
  member.accept(visitor);
  return visitor.getGuardString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JCiPUtil.java

示例8: hasRuntimeAnnotations

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
private static boolean hasRuntimeAnnotations(PsiMethod method) {
  PsiAnnotation[] annotations = method.getModifierList().getAnnotations();
  for (PsiAnnotation annotation : annotations) {
    PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
    PsiElement target = ref != null ? ref.resolve() : null;
    if (target instanceof PsiClass) {
      final PsiAnnotation retentionAnno = AnnotationUtil.findAnnotation((PsiClass)target, Retention.class.getName());
      if (retentionAnno != null) {
        PsiAnnotationMemberValue value = retentionAnno.findAttributeValue("value");
        if (value instanceof PsiReferenceExpression) {
          final PsiElement resolved = ((PsiReferenceExpression)value).resolve();
          if (resolved instanceof PsiField && RetentionPolicy.RUNTIME.name().equals(((PsiField)resolved).getName())) {
            final PsiClass containingClass = ((PsiField)resolved).getContainingClass();
            if (containingClass != null && RetentionPolicy.class.getName().equals(containingClass.getQualifiedName())) {
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AnonymousCanBeLambdaInspection.java

示例9: visitClass

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@Override
public void visitClass(PsiClass aClass) {
  super.visitClass(aClass);
  if (!aClass.isInterface() || AnnotationUtil.isAnnotated(aClass, "java.lang.FunctionalInterface", false)) {
    return;
  }
  if (LambdaHighlightingUtil.checkInterfaceFunctional(aClass) != null) {
    return;
  }
  final List<HierarchicalMethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass);
  if (candidates == null || candidates.size() != 1) {
    return;
  }
  final MethodSignature signature = candidates.get(0);
  if (signature.getTypeParameters().length > 0) {
    return;
  }
  registerClassError(aClass, aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:InterfaceMayBeAnnotatedFunctionalInspection.java

示例10: isAvailable

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project,
                           @NotNull PsiFile file,
                           @NotNull PsiElement startElement,
                           @NotNull PsiElement endElement) {
  if (!super.isAvailable(project, file, startElement, endElement)) {
    return false;
  }
  PsiModifierListOwner owner = getContainer(file, startElement.getTextRange().getStartOffset());
  if (owner == null || AnnotationUtil.isAnnotated(owner, getAnnotationsToRemove()[0], false, false)) {
    return false;
  }
  if (owner instanceof PsiMethod) {
    PsiType returnType = ((PsiMethod)owner).getReturnType();

    return returnType != null && !(returnType instanceof PsiPrimitiveType);
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:AddNullableNotNullAnnotationFix.java

示例11: isTestAnnotated

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
public static boolean isTestAnnotated(final PsiMethod method) {
  if (AnnotationUtil.isAnnotated(method, TEST_ANNOTATION, false) || JUnitRecognizer.willBeAnnotatedAfterCompilation(method)) {
    final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(method.getContainingClass(), Collections.singleton(RUN_WITH));
    if (annotation != null) {
      final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
      for (PsiNameValuePair attribute : attributes) {
        final PsiAnnotationMemberValue value = attribute.getValue();
        if (value instanceof PsiClassObjectAccessExpression ) {
          final PsiTypeElement typeElement = ((PsiClassObjectAccessExpression)value).getOperand();
          if (typeElement.getType().getCanonicalText().equals(PARAMETERIZED_CLASS_NAME)) {
            return false;
          }
        }
      }
    }
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:JUnitUtil.java

示例12: appendModifierList

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
private static void appendModifierList(@NotNull StringBuilder buffer, @NotNull PsiModifierListOwner owner) {
  int lastSize = buffer.length();
  Set<String> shownAnnotations = ContainerUtil.newHashSet();
  for (PsiAnnotation annotation : AnnotationUtil.getAllAnnotations(owner, false, null, !DumbService.isDumb(owner.getProject()))) {
    final PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
    if (element != null) {
      final PsiElement resolved = element.resolve();
      if (resolved instanceof PsiClass && !JavaDocInfoGenerator.isDocumentedAnnotationType(resolved)) {
        continue;
      }

      String referenceName = element.getReferenceName();
      if (shownAnnotations.add(referenceName) || JavaDocInfoGenerator.isRepeatableAnnotationType(resolved)) {
        if (lastSize != buffer.length()) buffer.append(" ");
        buffer.append("@").append(referenceName);
      }
    }
  }
  if (lastSize != buffer.length()) buffer.append(" ");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MethodParameterInfoHandler.java

示例13: isReturnedFromNonNlsMethod

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
private static boolean isReturnedFromNonNlsMethod(final PsiLiteralExpression expression, final Set<PsiModifierListOwner> nonNlsTargets) {
  PsiElement parent = expression.getParent();
  PsiMethod method;
  if (parent instanceof PsiNameValuePair) {
    method = AnnotationUtil.getAnnotationMethod((PsiNameValuePair)parent);
  }
  else {
    final PsiElement returnStmt = PsiTreeUtil.getParentOfType(expression, PsiReturnStatement.class, PsiMethodCallExpression.class);
    if (!(returnStmt instanceof PsiReturnStatement)) {
      return false;
    }
    method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
  }
  if (method == null) return false;

  if (AnnotationUtil.isAnnotated(method, AnnotationUtil.NON_NLS, true, false)) {
    return true;
  }
  nonNlsTargets.add(method);
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:I18nInspection.java

示例14: setModifiers

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
public static void setModifiers(PsiField field, Settings settings) {
  if (!settings.isIntroduceEnumConstant()) {
    if (settings.isDeclareStatic()) {
      PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true);
    }
    if (settings.isDeclareFinal()) {
      PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true);
    }
    if (settings.isAnnotateAsNonNls()) {
      PsiAnnotation annotation = JavaPsiFacade.getInstance(field.getProject()).getElementFactory()
        .createAnnotationFromText("@" + AnnotationUtil.NON_NLS, field);
      final PsiModifierList modifierList = field.getModifierList();
      LOG.assertTrue(modifierList != null);
      modifierList.addAfter(annotation, null);
    }
  }
  JavaCodeStyleManager.getInstance(field.getProject()).shortenClassReferences(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:BaseExpressionToFieldHandler.java

示例15: registerReferenceProviders

import com.intellij.codeInsight.AnnotationUtil; //导入依赖的package包/类
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {

    final JavaClassListReferenceProvider classListProvider = new JavaClassListReferenceProvider();
    registrar.registerReferenceProvider(xmlAttributeValue(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);

    final PsiReferenceProvider filePathReferenceProvider = new FilePathReferenceProvider();
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) context;
        final Map<String, Object> annotationParams = new HashMap<String, Object>();
        annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
        return !JavaI18nUtil.mustBePropertyKey(context.getProject(), literalExpression, annotationParams);
      }

      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    })), filePathReferenceProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiDocToken.class),
                                        CommentsReferenceContributor.COMMENTS_REFERENCE_PROVIDER_TYPE.getProvider());
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaReferenceContributor.java


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