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


Java AnnotationUtil.findAnnotationInHierarchy方法代码示例

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


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

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

示例2: getParameterizedLocation

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static Location getParameterizedLocation(PsiClass psiClass,
                                                String paramSetName,
                                                String parameterizedClassName) {
  final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(psiClass, Collections.singleton(JUnitUtil.RUN_WITH));
  if (annotation != null) {
    final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
    if (attributeValue instanceof PsiClassObjectAccessExpression) {
      final PsiTypeElement operand = ((PsiClassObjectAccessExpression)attributeValue).getOperand();
      if (InheritanceUtil.isInheritor(operand.getType(), parameterizedClassName)) {
        return new PsiMemberParameterizedLocation(psiClass.getProject(), 
                                                  psiClass,
                                                  null,
                                                  paramSetName);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PsiMemberParameterizedLocation.java

示例3: getPresentableAnnoName

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@NotNull
private static String getPresentableAnnoName(@NotNull PsiModifierListOwner owner) {
  NullableNotNullManager manager = NullableNotNullManager.getInstance(owner.getProject());
  Set<String> names = ContainerUtil.newHashSet(manager.getNullables());
  names.addAll(manager.getNotNulls());

  PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(owner, names);
  if (annotation != null) return getPresentableAnnoName(annotation);
  
  String anno = manager.getNotNull(owner);
  return StringUtil.getShortName(anno != null ? anno : StringUtil.notNullize(manager.getNullable(owner), "???"));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:NullableStuffInspectionBase.java

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

示例5: isParamFlowAnnotated

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static Flow isParamFlowAnnotated(PsiMethod method, int paramIndex) {
  PsiParameter[] parameters = method.getParameterList().getParameters();
  if (parameters.length <= paramIndex) {
    if (parameters.length != 0 && parameters[parameters.length-1].isVarArgs()) {
      paramIndex = parameters.length-1;
    }
    else {
      return null;
    }
  }
  return AnnotationUtil.findAnnotationInHierarchy(parameters[paramIndex], Flow.class);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:SliceUtil.java

示例6: addLocalPermissions

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static PermissionHolder addLocalPermissions(PermissionHolder lookup, PsiCallExpression call) {
  // Accumulate @RequirePermissions available in the local context
  PsiMethod method = PsiTreeUtil.getParentOfType(call, PsiMethod.class);
  if (method == null) {
    return lookup;
  }
  PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(method, Collections.singleton(PERMISSION_ANNOTATION));
  if (annotation == null) {
    return lookup;
  }

  PermissionRequirement requirement = PermissionRequirement.create(null, LombokPsiParser.createResolvedAnnotation(annotation));
  return PermissionHolder.SetPermissionLookup.join(lookup, requirement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ResourceTypeInspection.java

示例7: getAnnotationsFromImpl

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
/**
 * The parameter <code>allowIndirect</code> determines if the method should look for indirect annotations, i.e.
 * annotations which have themselves been annotated by the supplied annotation name. Currently, this only allows
 * one level of indirection and returns an array of [base-annotation, indirect annotation]
 * <p/>
 * The <code>annotationName</code> parameter is a pair of the target annotation class' fully qualified name as a
 * String and as a Set. This is done for performance reasons because the Set is required by the
 * {@link com.intellij.codeInsight.AnnotationUtil} utility class and allows to avoid unnecessary object constructions.
 */

public static PsiAnnotation[] getAnnotationsFromImpl(PsiModifierListOwner owner,
                                                      Pair<String, ? extends Set<String>> annotationName,
                                                      boolean allowIndirect, boolean inHierarchy) {
  final PsiAnnotation directAnnotation = inHierarchy?
    AnnotationUtil.findAnnotationInHierarchy(owner, annotationName.second) :
    AnnotationUtil.findAnnotation(owner, annotationName.second);
  if (directAnnotation != null) {
    return new PsiAnnotation[]{directAnnotation};
  }
  if (allowIndirect) {
    final PsiAnnotation[] annotations = getAnnotations(owner, inHierarchy);
    for (PsiAnnotation annotation : annotations) {
      PsiJavaCodeReferenceElement nameReference = annotation.getNameReferenceElement();
      if (nameReference == null) continue;
      PsiElement resolved = nameReference.resolve();
      if (resolved instanceof PsiClass) {
        final PsiAnnotation psiAnnotation = AnnotationUtil.findAnnotationInHierarchy((PsiModifierListOwner)resolved, annotationName.second);
        if (psiAnnotation != null) {
          return new PsiAnnotation[]{psiAnnotation, annotation};
        }
      }
    }
  }
  return PsiAnnotation.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:AnnotationUtilEx.java

示例8: getTestDataBasePath

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
public static String getTestDataBasePath(@Nullable PsiClass psiClass) {
  if (psiClass == null) return null;

  final PsiAnnotation annotation =
    AnnotationUtil.findAnnotationInHierarchy(psiClass, Collections.singleton(TEST_DATA_PATH_ANNOTATION_QUALIFIED_NAME));
  if (annotation != null) {
    final PsiAnnotationMemberValue value = annotation.findAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME);
    if (value instanceof PsiExpression) {
      final Project project = value.getProject();
      final PsiConstantEvaluationHelper evaluationHelper = JavaPsiFacade.getInstance(project).getConstantEvaluationHelper();
      final Object constantValue = evaluationHelper.computeConstantExpression(value, false);
      if (constantValue instanceof String) {
        String path = (String) constantValue;
        if (path.contains(CONTENT_ROOT_VARIABLE)) {
          final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
          final VirtualFile file = psiClass.getContainingFile().getVirtualFile();
          if (file == null) {
            return null;
          }
          final VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
          if (contentRoot == null) return null;
          path = path.replace(CONTENT_ROOT_VARIABLE, contentRoot.getPath());
        }
        if (path.contains(PROJECT_ROOT_VARIABLE)) {
          final VirtualFile baseDir = project.getBaseDir();
          if (baseDir == null) {
            return null;
          }
          path = path.replace(PROJECT_ROOT_VARIABLE, baseDir.getPath());
        }
        return path;
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:TestDataLineMarkerProvider.java

示例9: getCapitalizationFromAnno

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public Nls.Capitalization getCapitalizationFromAnno(PsiModifierListOwner modifierListOwner) {
  PsiAnnotation nls = AnnotationUtil.findAnnotationInHierarchy(modifierListOwner, Collections.singleton(Nls.class.getName()));
  if (nls == null) return Nls.Capitalization.NotSpecified;
  PsiAnnotationMemberValue capitalization = nls.findAttributeValue("capitalization");
  Object cap = JavaPsiFacade.getInstance(modifierListOwner.getProject()).getConstantEvaluationHelper().computeConstantExpression(capitalization);
  return cap instanceof Nls.Capitalization ? (Nls.Capitalization)cap : Nls.Capitalization.NotSpecified;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:TitleCapitalizationInspection.java

示例10: getDefaultPropertyDescriptor

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private JavaFxPropertyElementDescriptor getDefaultPropertyDescriptor() {
  final PsiAnnotation defaultProperty = AnnotationUtil
    .findAnnotationInHierarchy(myPsiClass, Collections.singleton(JavaFxCommonClassNames.JAVAFX_BEANS_DEFAULT_PROPERTY));
  if (defaultProperty != null) {
    final PsiAnnotationMemberValue defaultPropertyAttributeValue = defaultProperty.findAttributeValue("value");
    if (defaultPropertyAttributeValue instanceof PsiLiteralExpression) {
      final Object value = ((PsiLiteralExpression)defaultPropertyAttributeValue).getValue();
      if (value instanceof String) {
        return new JavaFxPropertyElementDescriptor(myPsiClass, (String)value, false);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:JavaFxClassBackedElementDescriptor.java

示例11: getDefaultPropertyExpectedType

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static PsiType getDefaultPropertyExpectedType(PsiClass aClass) {
  final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(aClass, Collections.singleton(JavaFxCommonClassNames.JAVAFX_BEANS_DEFAULT_PROPERTY));
  if (annotation != null) {
    final PsiAnnotationMemberValue memberValue = annotation.findAttributeValue(null);
    if (memberValue != null) {
      final String propertyName = StringUtil.stripQuotesAroundValue(memberValue.getText());
      final PsiMethod getter = findPropertyGetter(propertyName, aClass);
      if (getter != null) {
        return getter.getReturnType();
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:JavaFxPsiUtil.java

示例12: getDefaultPropertyName

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
public static String getDefaultPropertyName(@Nullable PsiClass aClass) {
  if (aClass == null) {
    return null;
  }
  final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(aClass,
                                                                            Collections.singleton(JavaFxCommonClassNames.JAVAFX_BEANS_DEFAULT_PROPERTY));
  if (annotation != null) {
    final PsiAnnotationMemberValue memberValue = annotation.findAttributeValue(null);
    if (memberValue != null) {
      return StringUtil.stripQuotesAroundValue(memberValue.getText());
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:JavaFxPsiUtil.java

示例13: findContractAnnotation

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
@Nullable
public static PsiAnnotation findContractAnnotation(@NotNull PsiMethod method) {
  return AnnotationUtil.findAnnotationInHierarchy(method, Collections.singleton(ORG_JETBRAINS_ANNOTATIONS_CONTRACT));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:ControlFlowAnalyzer.java

示例14: isMethodFlowAnnotated

import com.intellij.codeInsight.AnnotationUtil; //导入方法依赖的package包/类
private static Flow isMethodFlowAnnotated(PsiMethod method) {
  if (method == null) return null;
  return AnnotationUtil.findAnnotationInHierarchy(method, Flow.class);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:SliceUtil.java


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