本文整理汇总了Java中org.codehaus.groovy.ast.AnnotationNode.getClassNode方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationNode.getClassNode方法的具体用法?Java AnnotationNode.getClassNode怎么用?Java AnnotationNode.getClassNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.AnnotationNode
的用法示例。
在下文中一共展示了AnnotationNode.getClassNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCircularReference
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public void checkCircularReference(ClassNode searchClass, ClassNode attrType, Expression startExp) {
if (!isValidAnnotationClass(attrType)) return;
if (!(startExp instanceof AnnotationConstantExpression)) {
addError("Found '" + startExp.getText() + "' when expecting an Annotation Constant", startExp);
return;
}
AnnotationConstantExpression ace = (AnnotationConstantExpression) startExp;
AnnotationNode annotationNode = (AnnotationNode) ace.getValue();
if (annotationNode.getClassNode().equals(searchClass)) {
addError("Circular reference discovered in " + searchClass.getName(), startExp);
return;
}
ClassNode cn = annotationNode.getClassNode();
for (MethodNode method : cn.getMethods()) {
if (method.getReturnType().equals(searchClass)) {
addError("Circular reference discovered in " + cn.getName(), startExp);
}
ReturnStatement code = (ReturnStatement) method.getCode();
if (code == null) continue;
checkCircularReference(searchClass, method.getReturnType(), code.getExpression());
}
}
示例2: visitOverride
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
private void visitOverride(AnnotatedNode node, AnnotationNode visited) {
ClassNode annotationClassNode = visited.getClassNode();
if (annotationClassNode.isResolved() && annotationClassNode.getName().equals("java.lang.Override")) {
if (node instanceof MethodNode && !Boolean.TRUE.equals(node.getNodeMetaData(Verifier.DEFAULT_PARAMETER_GENERATED))) {
boolean override = false;
MethodNode origMethod = (MethodNode) node;
ClassNode cNode = origMethod.getDeclaringClass();
if (origMethod.hasDefaultValue()) {
List<MethodNode> variants = cNode.getDeclaredMethods(origMethod.getName());
for (MethodNode m : variants) {
if (m.getAnnotations().contains(visited) && isOverrideMethod(m)) {
override = true;
break;
}
}
} else {
override = isOverrideMethod(origMethod);
}
if (!override) {
addError("Method '" + origMethod.getName() + "' from class '" + cNode.getName() + "' does not override " +
"method from its superclass or interfaces but is annotated with @Override.", visited);
}
}
}
}
示例3: visit
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void visit(final ASTNode[] nodes, final SourceUnit source) {
if (shouldSkip(nodes)) {
return; // skip
}
final AnnotationNode marker = (AnnotationNode) first(nodes);
final ClassNode type = marker.getClassNode();
final ClassNode reference = make(annotation);
final Boolean isAnnotationOk = A.UTIL.CLASS.isOrExtends(type, reference);
if (!isAnnotationOk) {
return;
}
final S annotated = (S) last(nodes);
this.sourceUnit = source;
doVisit(marker, annotated);
}
示例4: transformAnnotationConstantExpression
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
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;
}
示例5: visitAnnotations
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public void visitAnnotations(AnnotatedNode node) {
List<AnnotationNode> annotations = node.getAnnotations();
if (annotations.isEmpty()) return;
Map<String, AnnotationNode> tmpAnnotations = new HashMap<String, AnnotationNode>();
ClassNode annType;
for (AnnotationNode an : annotations) {
// skip built-in properties
if (an.isBuiltIn()) continue;
annType = an.getClassNode();
resolveOrFail(annType, ", unable to find class for annotation", an);
for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) {
Expression newValue = transform(member.getValue());
newValue = transformInlineConstants(newValue);
member.setValue(newValue);
checkAnnotationMemberValue(newValue);
}
if(annType.isResolved()) {
Class annTypeClass = annType.getTypeClass();
Retention retAnn = (Retention) annTypeClass.getAnnotation(Retention.class);
if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME)) {
AnnotationNode anyPrevAnnNode = tmpAnnotations.put(annTypeClass.getName(), an);
if(anyPrevAnnNode != null) {
addError("Cannot specify duplicate annotation on the same member : " + annType.getName(), an);
}
}
}
}
}
示例6: copy
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
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;
}
示例7: getTargetListFromAnnotations
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
private static List<AnnotationNode> getTargetListFromAnnotations(ClassNode alias) {
List<AnnotationNode> annotations = alias.getAnnotations();
if (annotations.size() < 2) {
return Collections.emptyList();
}
List<AnnotationNode> ret = new ArrayList<AnnotationNode>(annotations.size());
for (AnnotationNode an : annotations) {
ClassNode type = an.getClassNode();
if (type.getName().equals(AnnotationCollector.class.getName())) continue;
AnnotationNode toAdd = new AnnotationNode(type);
copyMembers(an, toAdd);
ret.add(toAdd);
}
return ret;
}
示例8: copyAnnotatedNodeAnnotations
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
/**
* Copies all <tt>candidateAnnotations</tt> with retention policy {@link java.lang.annotation.RetentionPolicy#RUNTIME}
* and {@link java.lang.annotation.RetentionPolicy#CLASS}.
* <p>
* Annotations with {@link org.codehaus.groovy.runtime.GeneratedClosure} members are not supported at present.
*/
public static void copyAnnotatedNodeAnnotations(final AnnotatedNode annotatedNode, final List<AnnotationNode> copied, List<AnnotationNode> notCopied) {
List<AnnotationNode> annotationList = annotatedNode.getAnnotations();
for (AnnotationNode annotation : annotationList) {
List<AnnotationNode> annotations = annotation.getClassNode().getAnnotations(AbstractASTTransformation.RETENTION_CLASSNODE);
if (annotations.isEmpty()) continue;
if (hasClosureMember(annotation)) {
notCopied.add(annotation);
continue;
}
AnnotationNode retentionPolicyAnnotation = annotations.get(0);
Expression valueExpression = retentionPolicyAnnotation.getMember("value");
if (!(valueExpression instanceof PropertyExpression)) continue;
PropertyExpression propertyExpression = (PropertyExpression) valueExpression;
boolean processAnnotation =
propertyExpression.getProperty() instanceof ConstantExpression &&
(
"RUNTIME".equals(((ConstantExpression) (propertyExpression.getProperty())).getValue()) ||
"CLASS".equals(((ConstantExpression) (propertyExpression.getProperty())).getValue())
);
if (processAnnotation) {
AnnotationNode newAnnotation = new AnnotationNode(annotation.getClassNode());
for (Map.Entry<String, Expression> member : annotation.getMembers().entrySet()) {
newAnnotation.addMember(member.getKey(), member.getValue());
}
newAnnotation.setSourcePosition(annotatedNode);
copied.add(newAnnotation);
}
}
}
示例9: visit
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public AnnotationNode visit(AnnotationNode node) {
this.annotation = node;
this.reportClass = node.getClassNode();
if (!isValidAnnotationClass(node.getClassNode())) {
addError("class " + node.getClassNode().getName() + " is not an annotation");
return node;
}
// check if values have been passed for all annotation attributes that don't have defaults
if (!checkIfMandatoryAnnotationValuesPassed(node)) {
return node;
}
// if enum constants have been used, check if they are all valid
if (!checkIfValidEnumConstsAreUsed(node)) {
return node;
}
Map<String, Expression> attributes = node.getMembers();
for (Map.Entry<String, Expression> entry : attributes.entrySet()) {
String attrName = entry.getKey();
Expression attrExpr = transformInlineConstants(entry.getValue());
entry.setValue(attrExpr);
ClassNode attrType = getAttributeType(node, attrName);
visitExpression(attrName, attrExpr, attrType);
}
VMPluginFactory.getPlugin().configureAnnotation(node);
return this.annotation;
}
示例10: checkIfMandatoryAnnotationValuesPassed
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
private boolean checkIfMandatoryAnnotationValuesPassed(AnnotationNode node) {
boolean ok = true;
Map attributes = node.getMembers();
ClassNode classNode = node.getClassNode();
for (MethodNode mn : classNode.getMethods()) {
String methodName = mn.getName();
// if the annotation attribute has a default, getCode() returns a ReturnStatement with the default value
if (mn.getCode() == null && !attributes.containsKey(methodName)) {
addError("No explicit/default value found for annotation attribute '" + methodName + "'", node);
ok = false;
}
}
return ok;
}
示例11: getAttributeType
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
private ClassNode getAttributeType(AnnotationNode node, String attrName) {
ClassNode classNode = node.getClassNode();
List methods = classNode.getMethods(attrName);
// if size is >1, then the method was overwritten or something, we ignore that
// if it is an error, we have to test it at another place. But size==0 is
// an error, because it means that no such attribute exists.
if (methods.isEmpty()) {
addError("'" + attrName + "'is not part of the annotation " + classNode, node);
return ClassHelper.OBJECT_TYPE;
}
MethodNode method = (MethodNode) methods.get(0);
return method.getReturnType();
}
示例12: checkForDuplicateAnnotations
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
private void checkForDuplicateAnnotations(AnnotatedNode node, Map<String, List<AnnotationNode>> runtimeAnnotations) {
for (Map.Entry<String, List<AnnotationNode>> next : runtimeAnnotations.entrySet()) {
if (next.getValue().size() > 1) {
ClassNode repeatable = null;
AnnotationNode repeatee = next.getValue().get(0);
List<AnnotationNode> repeateeAnnotations = repeatee.getClassNode().getAnnotations();
for (AnnotationNode anno : repeateeAnnotations) {
ClassNode annoClassNode = anno.getClassNode();
if (annoClassNode.getName().equals("java.lang.annotation.Repeatable")) {
Expression value = anno.getMember("value");
if (value instanceof ClassExpression) {
ClassExpression ce = (ClassExpression) value;
if (ce.getType() != null && ce.getType().isAnnotationDefinition()) {
repeatable = ce.getType();
break;
}
}
}
}
if (repeatable != null) {
AnnotationNode collector = new AnnotationNode(repeatable);
collector.setRuntimeRetention(true); // checked earlier
List<Expression> annos = new ArrayList<Expression>();
for (AnnotationNode an : next.getValue()) {
annos.add(new AnnotationConstantExpression(an));
}
collector.addMember("value", new ListExpression(annos));
node.addAnnotation(collector);
node.getAnnotations().removeAll(next.getValue());
}
}
}
}
示例13: configureAnnotation
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public void configureAnnotation(AnnotationNode node) {
ClassNode type = node.getClassNode();
List<AnnotationNode> annotations = type.getAnnotations();
for (AnnotationNode an : annotations) {
configureAnnotationFromDefinition(an, node);
}
configureAnnotationFromDefinition(node, node);
}
示例14: visit
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
final ClassNode declaringClass = parent.getDeclaringClass();
if (parent instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) parent;
ClassNode cNode = de.getDeclaringClass();
if (!cNode.isScript()) {
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
return;
}
candidate = de;
// GROOVY-4548: temp fix to stop CCE until proper support is added
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
return;
}
VariableExpression ve = de.getVariableExpression();
variableName = ve.getName();
// set owner null here, it will be updated by addField
final int modifiers = ve.getModifiers() | Modifier.VOLATILE | Modifier.PUBLIC;
fieldNode = new FieldNode(variableName, modifiers, ve.getType(), null, de.getRightExpression());
fieldNode.setSourcePosition(de);
fieldNode.addAnnotation(node);
fieldNode.setInitialValueExpression(new FieldExpression(fieldNode));
cNode.addField(fieldNode);
// GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
// GROOVY-6112 : also copy acceptable Groovy transforms
final List<AnnotationNode> annotations = de.getAnnotations();
for (AnnotationNode annotation : annotations) {
// GROOVY-6337 HACK: in case newly created field is @Lazy
if (annotation.getClassNode().equals(LAZY_TYPE)) {
PrivateAccessor.invokeStatic(LazyASTTransformation.class, "visitField", annotation, fieldNode);
// LazyASTTransformation.visitField(annotation, fieldNode);
}
// if(annotation.getClassNode().equals(MY_TYPE)) {
// final Map<String, Expression> members = annotation.getMembers();
// final Expression expr = members.remove("value");
// if(expr!=null) {
// final String exprValue = expr.getText();
// System.err.println("EXPR:" + exprValue);
// }
// }
final ClassNode annotationClassNode = annotation.getClassNode();
if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
fieldNode.addAnnotation(annotation);
}
}
super.visitClass(cNode);
// GROOVY-5207 So that Closures can see newly added fields
// (not super efficient for a very large class with many @Fields but we chose simplicity
// and understandability of this solution over more complex but efficient alternatives)
VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
scopeVisitor.visitClass(cNode);
}
}
示例15: visit
import org.codehaus.groovy.ast.AnnotationNode; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) parent;
ClassNode cNode = de.getDeclaringClass();
if (!cNode.isScript()) {
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
return;
}
candidate = de;
// GROOVY-4548: temp fix to stop CCE until proper support is added
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
return;
}
VariableExpression ve = de.getVariableExpression();
variableName = ve.getName();
// set owner null here, it will be updated by addField
fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression());
fieldNode.setSourcePosition(de);
cNode.addField(fieldNode);
// provide setter for CLI Builder purposes unless final
if (fieldNode.isFinal()) {
if (!de.getAnnotations(OPTION_TYPE).isEmpty()) {
addError("Can't have a final field also annotated with @" + OPTION_TYPE.getNameWithoutPackage(), de);
}
} else {
String setterName = "set" + MetaClassHelper.capitalize(variableName);
cNode.addMethod(setterName, ACC_PUBLIC | ACC_SYNTHETIC, ClassHelper.VOID_TYPE, params(param(ve.getType(), variableName)), ClassNode.EMPTY_ARRAY, block(
stmt(assignX(propX(varX("this"), variableName), varX(variableName)))
));
}
// GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
// GROOVY-6112 : also copy acceptable Groovy transforms
final List<AnnotationNode> annotations = de.getAnnotations();
for (AnnotationNode annotation : annotations) {
// GROOVY-6337 HACK: in case newly created field is @Lazy
if (annotation.getClassNode().equals(LAZY_TYPE)) {
LazyASTTransformation.visitField(this, annotation, fieldNode);
}
final ClassNode annotationClassNode = annotation.getClassNode();
if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
fieldNode.addAnnotation(annotation);
}
}
super.visitClass(cNode);
// GROOVY-5207 So that Closures can see newly added fields
// (not super efficient for a very large class with many @Fields but we chose simplicity
// and understandability of this solution over more complex but efficient alternatives)
VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
scopeVisitor.visitClass(cNode);
}
}