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


Java AnnotationUtil.isAnnotated方法代码示例

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


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

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

示例2: satisfiedBy

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiClass)) {
    return false;
  }
  final PsiClass aClass = (PsiClass)parent;
  if (!aClass.isInterface() || aClass.isAnnotationType()) {
    return false;
  }
  final PsiElement leftBrace = aClass.getLBrace();
  final int offsetInParent = element.getStartOffsetInParent();
  if (leftBrace == null ||
      offsetInParent >= leftBrace.getStartOffsetInParent()) {
    return false;
  }
  final SearchScope useScope = aClass.getUseScope();
  for (PsiClass inheritor :
    ClassInheritorsSearch.search(aClass, useScope, true)) {
    if (inheritor.isInterface()) {
      return false;
    }
  }
  return !AnnotationUtil.isAnnotated(aClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ConvertInterfaceToClassPredicate.java

示例3: isSetterNonNls

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static boolean isSetterNonNls(final Project project, final GlobalSearchScope searchScope,
                                      final String componentClassName, final String propertyName) {
  PsiClass componentClass = JavaPsiFacade.getInstance(project).findClass(componentClassName, searchScope);
  if (componentClass == null) {
    return false;
  }
  PsiMethod setter = PropertyUtil.findPropertySetter(componentClass, propertyName, false, true);
  if (setter != null) {
    PsiParameter[] parameters = setter.getParameterList().getParameters();
    if (parameters.length == 1 &&
        "java.lang.String".equals(parameters[0].getType().getCanonicalText()) &&
        AnnotationUtil.isAnnotated(parameters [0], AnnotationUtil.NON_NLS, false, true)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:I18nFormInspection.java

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

示例5: checkField

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
@Nullable
public ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
  PsiClass containingClass = field.getContainingClass();
  if (containingClass == null || isClassNonNls(containingClass)) {
    return null;
  }
  if (AnnotationUtil.isAnnotated(field, AnnotationUtil.NON_NLS, false, false)) {
    return null;
  }
  final PsiExpression initializer = field.getInitializer();
  if (initializer != null) return checkElement(initializer, manager, isOnTheFly);

  if (field instanceof PsiEnumConstant) {
    return checkElement(((PsiEnumConstant)field).getArgumentList(), manager, isOnTheFly);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:I18nInspection.java

示例6: buildVisitor

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public BaseInspectionVisitor buildVisitor() {
  return new BaseInspectionVisitor() {
    @Override
    public void visitField(PsiField field) {
      final boolean ruleAnnotated = REPORT_RULE_PROBLEMS && AnnotationUtil.isAnnotated(field, RULE_FQN, false);
      final boolean classRuleAnnotated = REPORT_CLASS_RULE_PROBLEMS && AnnotationUtil.isAnnotated(field, CLASS_RULE_FQN, false);
      if (ruleAnnotated || classRuleAnnotated) {
        String annotation = ruleAnnotated ? RULE_FQN : CLASS_RULE_FQN;
        String errorMessage = getPublicStaticErrorMessage(field, ruleAnnotated, classRuleAnnotated);
        if (errorMessage != null) {
          registerError(field.getNameIdentifier(), InspectionGadgetsBundle.message("junit.rule.problem.descriptor", annotation, errorMessage), "Make field " + errorMessage, annotation);
        }
        if (!InheritanceUtil.isInheritor(PsiUtil.resolveClassInClassTypeOnly(field.getType()), false, "org.junit.rules.TestRule")) {
          registerError(field.getNameIdentifier(), InspectionGadgetsBundle.message("junit.rule.type.problem.descriptor"));
        }
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JUnitRuleInspection.java

示例7: isUtilityMethod

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static boolean isUtilityMethod(@NotNull PsiMethod method, @NotNull PsiClass psiClass, @NotNull TestFramework framework) {
  if (method == framework.findSetUpMethod(psiClass) || method == framework.findTearDownMethod(psiClass)) {
    return true;
  }

  // JUnit3
  if (framework.getClass().getName().contains("JUnit3")) {
    return !method.getName().startsWith("test");
  }

  // JUnit4
  else if (framework.getClass().getName().contains("JUnit4")) {
    return !AnnotationUtil.isAnnotated(method, "org.junit.Test", false);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:TestDataGuessByExistingFilesUtil.java

示例8: visitClass

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  //don't call super, to prevent drilldown
  if (FileTypeUtils.isInServerPageFile(aClass.getContainingFile())) {
    return;
  }
  if (aClass.isInterface() || aClass.isEnum() || aClass.isAnnotationType()) {
    return;
  }
  if (aClass instanceof PsiTypeParameter) {
    return;
  }
  final PsiMethod[] constructors = aClass.getConstructors();
  if (constructors.length > 0) {
    return;
  }
  final PsiMethod[] methods = aClass.getMethods();
  if (methods.length > 0) {
    return;
  }
  final PsiField[] fields = aClass.getFields();
  if (fields.length > 0) {
    return;
  }
  final PsiClassInitializer[] initializers = aClass.getInitializers();
  if (initializers.length > 0) {
    return;
  }
  if (ignoreClassWithParameterization && isSuperParametrization(aClass)) {
    return;
  }
  if (AnnotationUtil.isAnnotated(aClass, ignorableAnnotations)) {
    return;
  }
  if (ignoreThrowables && InheritanceUtil.isInheritor(aClass, "java.lang.Throwable")) {
    return;
  }
  registerClassError(aClass, aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:EmptyClassInspectionBase.java

示例9: buildErrorString

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
@NotNull
protected String buildErrorString(Object... infos) {
  if (AnnotationUtil.isAnnotated((PsiMethod)infos[1], IGNORE, false)) {
    return InspectionGadgetsBundle.message("ignore.test.method.in.class.extending.junit3.testcase.problem.descriptor");
  }
  return InspectionGadgetsBundle.message("junit4.test.method.in.class.extending.junit3.testcase.problem.descriptor");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:JUnit4AnnotatedMethodInJUnit3TestCaseInspectionBase.java

示例10: isTestClass

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static boolean isTestClass(@NotNull PsiClass psiClass, boolean checkAbstract, boolean checkForTestCaseInheritance) {
  if (psiClass.getQualifiedName() == null) return false;
  final PsiClass topLevelClass = PsiTreeUtil.getTopmostParentOfType(psiClass, PsiClass.class);
  if (topLevelClass != null) {
    final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(topLevelClass, Collections.singleton(RUN_WITH));
    if (annotation != null) {
      final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
      if (attributeValue instanceof PsiClassObjectAccessExpression) {
        final String runnerName = ((PsiClassObjectAccessExpression)attributeValue).getOperand().getType().getCanonicalText();
        if (!(PARAMETERIZED_CLASS_NAME.equals(runnerName) || SUITE_CLASS_NAME.equals(runnerName))) {
          return true;
        }
      }
    }
  }
  if (!PsiClassUtil.isRunnableClass(psiClass, true, checkAbstract)) return false;
  if (checkForTestCaseInheritance && isTestCaseInheritor(psiClass)) return true;
  final PsiModifierList modifierList = psiClass.getModifierList();
  if (modifierList == null) return false;
  if (AnnotationUtil.isAnnotated(psiClass, RUN_WITH, true)) return true;

  for (final PsiMethod method : psiClass.getAllMethods()) {
    ProgressManager.checkCanceled();
    if (isSuiteMethod(method)) return true;
    if (isTestAnnotated(method)) return true;
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:JUnitUtil.java

示例11: isJUnit4TestClass

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static boolean isJUnit4TestClass(final PsiClass psiClass, boolean checkAbstract) {
  if (!PsiClassUtil.isRunnableClass(psiClass, true, checkAbstract)) return false;

  final PsiModifierList modifierList = psiClass.getModifierList();
  if (modifierList == null) return false;
  if (AnnotationUtil.isAnnotated(psiClass, RUN_WITH, true)) return true;
  for (final PsiMethod method : psiClass.getAllMethods()) {
    ProgressManager.checkCanceled();
    if (isTestAnnotated(method)) return true;
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:JUnitUtil.java

示例12: findSetUpMethod

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
@Override
protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) {
  for (PsiMethod each : clazz.getMethods()) {
    if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_ANNOTATION_NAME, false)) return each;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:JUnit4Framework.java

示例13: getTestMethod

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static PsiMethod getTestMethod(ConfigurationContext context) {
  PsiElement psi = context.getPsiLocation();
  if (psi instanceof PsiMethod
      && AnnotationUtil.isAnnotated((PsiMethod) psi, JUnitUtil.TEST_ANNOTATION, false)) {
    return (PsiMethod) psi;
  }
  List<PsiMethod> selectedMethods = TestMethodSelectionUtil.getSelectedMethods(context);
  return selectedMethods != null && selectedMethods.size() == 1 ? selectedMethods.get(0) : null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:10,代码来源:BlazeJavaAbstractTestCaseConfigurationProducer.java

示例14: checkClassMethods

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static void checkClassMethods(String methodName,
                                      PsiClass containingClass,
                                      Set<PsiMember> alreadyMarkedToBeChecked,
                                      Set<PsiMember> membersToCheckNow,
                                      Map<PsiClass, Map<PsiMethod, List<String>>> results) {
  final PsiMethod[] psiMethods = containingClass.findMethodsByName(methodName, true);
  for (PsiMethod method : psiMethods) {
    if (AnnotationUtil.isAnnotated(method, TestNGUtil.TEST_ANNOTATION_FQN, false) &&
        appendMember(method, alreadyMarkedToBeChecked, results)) {
      membersToCheckNow.add(method);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:TestNGTestObject.java

示例15: visitMethod

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  super.visitMethod(method);
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return;
  }
  if (method.getNameIdentifier() == null) {
    return;
  }
  final PsiMethod leastConcreteSuperMethod = getLeastConcreteSuperMethod(method);
  if (leastConcreteSuperMethod == null) {
    return;
  }
  final PsiClass objectClass = ClassUtils.findObjectClass(method);
  final PsiMethod[] superMethods = method.findSuperMethods(objectClass);
  if (superMethods.length > 0) {
    return;
  }
  if (ignoreEmptySuperMethods) {
    final PsiMethod superMethod = (PsiMethod)leastConcreteSuperMethod.getNavigationElement();
    if (MethodUtils.isTrivial(superMethod, true)) {
      return;
    }
  }
  if (onlyReportWhenAnnotated) {
    if (!AnnotationUtil.isAnnotated(leastConcreteSuperMethod, annotations)) {
      return;
    }
  }
  if (containsSuperCall(body, leastConcreteSuperMethod)) {
    return;
  }
  registerMethodError(method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:RefusedBequestInspectionBase.java


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