public static boolean isInferredAnnotation(@NotNull PsiAnnotation annotation) { return InferredAnnotationsManager.getInstance(annotation.getProject()).isInferredAnnotation(annotation); }
public static boolean isExternalAnnotation(@NotNull PsiAnnotation annotation) { return ExternalAnnotationsManager.getInstance(annotation.getProject()).isExternalAnnotation(annotation); }
@Nullable public static String getStringAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) { PsiAnnotationMemberValue attrValue = anno.findAttributeValue(attributeName); Object constValue = JavaPsiFacade.getInstance(anno.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue); return constValue instanceof String ? (String)constValue : null; } @Nullable
@Nullable public static Boolean getBooleanAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) { PsiAnnotationMemberValue attrValue = anno.findAttributeValue(attributeName); Object constValue = JavaPsiFacade.getInstance(anno.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue); return constValue instanceof Boolean ? (Boolean)constValue : null; }
@Override public Object invoke(Object proxy, Method method, Object[] args) { Class<?>[] paramTypes = method.getParameterTypes(); assert paramTypes.length == 0: Arrays.toString(paramTypes); String member = method.getName(); if (member.equals("toString")) { return toStringImpl(); } if (member.equals("annotationType")) { return type; } // Handle annotation member accessors PsiAnnotationMemberValue value = myAnnotation.findAttributeValue(member); if (value == null) { throw new IncompleteAnnotationException(type, member+". (Unable to find attribute in '"+myAnnotation.getText()+"')"); } Object result = JavaPsiFacade.getInstance(myAnnotation.getProject()).getConstantEvaluationHelper().computeConstantExpression(value); if (result == null) { throw new IncompleteAnnotationException(type, member+". (Unable to evaluate annotation value '"+value+"')"); } // todo arrays return result; }
PsiConstantEvaluationHelper evaluation = JavaPsiFacade.getInstance(psa_fields.getProject()) .getConstantEvaluationHelper();