本文整理汇总了Java中org.codehaus.groovy.ast.Parameter.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.getAnnotations方法的具体用法?Java Parameter.getAnnotations怎么用?Java Parameter.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.Parameter
的用法示例。
在下文中一共展示了Parameter.getAnnotations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inferClosureParameterTypes
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
/**
* This method is responsible for performing type inference on closure argument types whenever code like this is
* found: <code>foo.collect { it.toUpperCase() }</code>.
* In this case, the type checker tries to find if the <code>collect</code> method has its {@link Closure} argument
* annotated with {@link groovy.transform.stc.ClosureParams}. If yes, then additional type inference can be performed
* and the type of <code>it</code> may be inferred.
*
* @param receiver
* @param arguments
* @param expression a closure expression for which the argument types should be inferred
* @param param the parameter where to look for a {@link groovy.transform.stc.ClosureParams} annotation.
* @param selectedMethod the method accepting a closure
*/
protected void inferClosureParameterTypes(final ClassNode receiver, final Expression arguments, final ClosureExpression expression, final Parameter param, final MethodNode selectedMethod) {
List<AnnotationNode> annotations = param.getAnnotations(CLOSUREPARAMS_CLASSNODE);
if (annotations!=null && !annotations.isEmpty()) {
for (AnnotationNode annotation : annotations) {
Expression hintClass = annotation.getMember("value");
Expression options = annotation.getMember("options");
Expression resolverClass = annotation.getMember("conflictResolutionStrategy");
if (hintClass instanceof ClassExpression) {
doInferClosureParameterTypes(receiver, arguments, expression, selectedMethod, hintClass, resolverClass, options);
}
}
} else if (isSAMType(param.getOriginType())) {
// SAM coercion
inferSAMType(param, receiver, selectedMethod, InvocationWriter.makeArgumentList(arguments), expression);
}
}
示例2: visitParameterAnnotations
import org.codehaus.groovy.ast.Parameter; //导入方法依赖的package包/类
private void visitParameterAnnotations(Parameter parameter, int paramNumber, MethodVisitor mv) {
for (AnnotationNode an : parameter.getAnnotations()) {
// skip built-in properties
if (an.isBuiltIn()) continue;
if (an.hasSourceRetention()) continue;
final String annotationDescriptor = BytecodeHelper.getTypeDescription(an.getClassNode());
AnnotationVisitor av = mv.visitParameterAnnotation(paramNumber, annotationDescriptor, an.hasRuntimeRetention());
visitAnnotationAttributes(an, av);
av.visitEnd();
}
}