本文整理了Java中org.codehaus.groovy.ast.AnnotationNode.getClassNode()
方法的一些代码示例,展示了AnnotationNode.getClassNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationNode.getClassNode()
方法的具体详情如下:
包路径:org.codehaus.groovy.ast.AnnotationNode
类名称:AnnotationNode
方法名:getClassNode
暂无
代码示例来源:origin: org.codehaus.groovy/groovy
public List<AnnotationNode> getAnnotations(ClassNode type) {
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(annotations.size());
for (AnnotationNode node: annotations) {
if (type.equals(node.getClassNode())) ret.add(node);
}
return ret;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static List<AnnotationNode> filterAnnotations(List<AnnotationNode> annotations) {
List<AnnotationNode> result = new ArrayList<AnnotationNode>(annotations.size());
for (AnnotationNode annotation : annotations) {
if (!OVERRIDE_CLASSNODE.equals(annotation.getClassNode())) {
result.add(annotation);
}
}
return result;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static boolean acceptableTransform(AnnotationNode annotation) {
// TODO also check for phase after sourceUnit.getPhase()? but will be ignored anyway?
// TODO we should only copy those annotations with FIELD_TARGET but haven't visited annotations
// and gathered target info at this phase, so we can't do this:
// return annotation.isTargetAllowed(AnnotationNode.FIELD_TARGET);
// instead just don't copy ourselves for now
return !annotation.getClassNode().equals(MY_TYPE);
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static List<AnnotationNode> filterAnnotations(List<AnnotationNode> annotations) {
List<AnnotationNode> result = new ArrayList<AnnotationNode>(annotations.size());
for (AnnotationNode annotation : annotations) {
if (!OVERRIDE_CLASSNODE.equals(annotation.getClassNode())) {
result.add(annotation);
}
}
return result;
}
代码示例来源:origin: spockframework/spock
public static AnnotationNode getAnnotation(ASTNode node, Class<?> annotationType) {
if (!(node instanceof AnnotatedNode)) return null;
AnnotatedNode annotated = (AnnotatedNode)node;
@SuppressWarnings("unchecked")
List<AnnotationNode> annotations = annotated.getAnnotations();
for (AnnotationNode a : annotations)
if (a.getClassNode().getName().equals(annotationType.getName())) return a;
return null;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void printAnnotation(PrintWriter out, AnnotationNode annotation) {
out.print("@" + annotation.getClassNode().getName().replace('$', '.') + "(");
boolean first = true;
Map<String, Expression> members = annotation.getMembers();
for (Map.Entry<String, Expression> entry : members.entrySet()) {
String key = entry.getKey();
if (first) first = false;
else out.print(", ");
out.print(key + "=" + getAnnotationValue(entry.getValue()).replace('$', '.'));
}
out.print(") ");
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static List<AnnotationNode> copy(List<AnnotationNode> orig, AnnotationNode aliasAnnotationUsage) {
if (orig.isEmpty()) return orig;
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(orig.size());
for (AnnotationNode an : orig) {
AnnotationNode newAn = new AnnotationNode(an.getClassNode());
copyMembers(an, newAn);
newAn.setSourcePosition(aliasAnnotationUsage);
ret.add(newAn);
}
return ret;
}
代码示例来源:origin: org.codehaus.groovy/groovy
protected Expression transformAnnotationConstantExpression(AnnotationConstantExpression ace) {
AnnotationNode an = (AnnotationNode) ace.getValue();
ClassNode type = an.getClassNode();
resolveOrFail(type, ", unable to find class for annotation", an);
for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) {
member.setValue(transform(member.getValue()));
}
return ace;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void verifyClass(AnnotationNode annotation, Class klass) {
if (!ASTTransformation.class.isAssignableFrom(klass)) {
source.getErrorCollector().addError(new SimpleMessage("Not an ASTTransformation: " +
klass.getName() + " declared by " + annotation.getClassNode().getName(), source));
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof ClassNode) {
processClass((ClassNode) parent, node);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static boolean hasImmutableAnnotation(ClassNode type) {
List<AnnotationNode> annotations = type.getAnnotations();
for (AnnotationNode next : annotations) {
String name = next.getClassNode().getName();
if (matchingMarkerName(name)) return true;
}
return false;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static List<AnnotationNode> getStoredTargetList(AnnotationNode aliasAnnotationUsage, SourceUnit source) {
ClassNode alias = aliasAnnotationUsage.getClassNode().redirect();
List<AnnotationNode> ret = getMeta(alias);
return copy(ret, aliasAnnotationUsage);
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public void visitAnnotations(AnnotatedNode node) {
super.visitAnnotations(node);
for (AnnotationNode an : node.getAnnotations()) {
addToCache(an.getClassNode());
}
}
@Override
代码示例来源:origin: spockframework/spock
private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr) {
ClassNode targetType = methodCallExpr.getObjectExpression().getType();
String methodName = methodCallExpr.getMethodAsString();
List<MethodNode> methods = targetType.getMethods(methodName);
for (MethodNode method : methods) {
for (AnnotationNode annotation : method.getAnnotations()) {
if (annotation.getClassNode().getName().equals(ConditionBlock.class.getName())) return true;
}
}
return false;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private Expression serialize(AnnotationNode an) {
MapExpression map = new MapExpression();
for (String key : an.getMembers().keySet()) {
map.addMapEntryExpression(new ConstantExpression(key), serialize(an.getMember(key)));
}
List<Expression> l = new ArrayList<Expression>(2);
l.add(new ClassExpression(an.getClassNode()));
l.add(map);
return new ArrayExpression(ClassHelper.OBJECT_TYPE, l);
}
}
代码示例来源:origin: spockframework/spock
@Override
@SuppressWarnings("unchecked")
public void visitAnnotations(AnnotatedNode node) {
for (AnnotationNode an : node.getAnnotations()) {
ClassNode cn = an.getClassNode();
// this comparison should be good enough, and also works in phase conversion
if (cn.getNameWithoutPackage().equals(Inspect.class.getSimpleName())) {
ConstantExpression name = (ConstantExpression)an.getMember("value");
if (name == null || !(name.getValue() instanceof String))
throw new AstInspectorException("@Inspect must have a String argument");
addNode(markedNodes, (String)name.getValue(), node);
break;
}
}
super.visitAnnotations(node);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void configureAnnotation(AnnotationNode node) {
ClassNode type = node.getClassNode();
VMPlugin plugin = VMPluginFactory.getPlugin();
List<AnnotationNode> annotations = type.getAnnotations();
for (AnnotationNode an : annotations) {
plugin.configureAnnotationNodeFromDefinition(an, node);
}
plugin.configureAnnotationNodeFromDefinition(node, node);
}
代码示例来源:origin: org.codehaus.groovy/groovy
private Class loadTransformClass(String transformClass, AnnotationNode annotation) {
try {
return transformLoader.loadClass(transformClass, false, true, false);
} catch (ClassNotFoundException e) {
source.getErrorCollector().addErrorAndContinue(
new SimpleMessage(
"Could not find class for Transformation Processor " + transformClass
+ " declared by " + annotation.getClassNode().getName(),
source));
}
return null;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private AnnotationVisitor getAnnotationVisitor(AnnotatedNode targetNode, AnnotationNode an, Object visitor) {
final String annotationDescriptor = BytecodeHelper.getTypeDescription(an.getClassNode());
if (targetNode instanceof MethodNode) {
return ((MethodVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention());
} else if (targetNode instanceof FieldNode) {
return ((FieldVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention());
} else if (targetNode instanceof ClassNode) {
return ((ClassVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention());
}
throwException("Cannot create an AnnotationVisitor. Please report Groovy bug");
return null;
}
代码示例来源:origin: org.codehaus.groovy/groovy
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();
}
}
内容来源于网络,如有侵权,请联系作者删除!