本文整理汇总了Java中org.codehaus.groovy.ast.AnnotatedNode.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedNode.getAnnotations方法的具体用法?Java AnnotatedNode.getAnnotations怎么用?Java AnnotatedNode.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.AnnotatedNode
的用法示例。
在下文中一共展示了AnnotatedNode.getAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSkipMode
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
public boolean isSkipMode(final AnnotatedNode node) {
if (node == null) return false;
for (ClassNode tca : getTypeCheckingAnnotations()) {
List<AnnotationNode> annotations = node.getAnnotations(tca);
if (annotations != null) {
for (AnnotationNode annotation : annotations) {
Expression value = annotation.getMember("value");
if (value != null) {
if (value instanceof ConstantExpression) {
ConstantExpression ce = (ConstantExpression) value;
if (TypeCheckingMode.SKIP.toString().equals(ce.getValue().toString())) return true;
} else if (value instanceof PropertyExpression) {
PropertyExpression pe = (PropertyExpression) value;
if (TypeCheckingMode.SKIP.toString().equals(pe.getPropertyAsString())) return true;
}
}
}
}
}
if (node instanceof MethodNode) {
return isSkipMode(node.getDeclaringClass());
}
if (isSkippedInnerClass(node)) return true;
return false;
}
示例2: disableGrabResolvers
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
private void disableGrabResolvers(List<? extends AnnotatedNode> nodes) {
for (AnnotatedNode classNode : nodes) {
List<AnnotationNode> annotations = classNode.getAnnotations();
for (AnnotationNode node : new ArrayList<AnnotationNode>(annotations)) {
if (node.getClassNode().getNameWithoutPackage()
.equals("GrabResolver")) {
node.setMember("initClass", new ConstantExpression(false));
}
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:ArchiveCommand.java
示例3: hasAtLeastOneAnnotation
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
/**
* Determine if an {@link AnnotatedNode} has one or more of the specified annotations.
* N.B. the annotation type names are not normally fully qualified.
* @param node the node to examine
* @param annotations the annotations to look for
* @return {@code true} if at least one of the annotations is found, otherwise
* {@code false}
*/
public static boolean hasAtLeastOneAnnotation(AnnotatedNode node,
String... annotations) {
for (AnnotationNode annotationNode : node.getAnnotations()) {
for (String annotation : annotations) {
if (PatternMatchUtils.simpleMatch(annotation,
annotationNode.getClassNode().getName())) {
return true;
}
}
}
return false;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:AstUtils.java
示例4: getAnnotation
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
private AnnotationNode getAnnotation(AnnotatedNode annotated) {
List<AnnotationNode> annotations = annotated.getAnnotations(BOM);
if (!annotations.isEmpty()) {
return annotations.get(0);
}
AnnotationNode annotation = new AnnotationNode(BOM);
annotated.addAnnotation(annotation);
return annotation;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:GenericBomAstTransformation.java
示例5: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的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: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
/**
* Adds the annotation to the internal target list if a match is found.
*
* @param node the node to be processed
*/
public void visitAnnotations(AnnotatedNode node) {
super.visitAnnotations(node);
for (AnnotationNode annotation : node.getAnnotations()) {
if (transforms.containsKey(annotation)) {
targetNodes.add(new ASTNode[]{annotation, node});
}
}
}
示例7: isEnabled
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
private boolean isEnabled(final AnnotatedNode node) {
if (node == null) return false;
List<AnnotationNode> annotations = node.getAnnotations(MY_TYPE);
if (annotations != null) {
// any explicit false for enabled disables functionality
// this allows, for example, configscript to set all
// classes to true and one class to be explicitly disabled
for (AnnotationNode anno : annotations) {
// abort if explicit false found
if (memberHasValue(anno, "enabled", false)) return false;
}
}
return true;
}
示例8: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
boolean legacyMode = LEGACY_TYPE_NAME.equals(node.getClassNode().getName());
if (!MY_TYPE.equals(node.getClassNode()) && !legacyMode) return;
Expression value = node.getMember("value");
if (parent instanceof ClassNode) {
List<groovy.transform.PackageScopeTarget> targets;
if (value == null) targets = Collections.singletonList(legacyMode ? PackageScopeTarget.FIELDS : PackageScopeTarget.CLASS);
else targets = determineTargets(value);
visitClassNode((ClassNode) parent, targets);
parent.getAnnotations();
} else {
if (value != null) {
addError("Error during " + MY_TYPE_NAME
+ " processing: " + TARGET_CLASS_NAME + " only allowed at class level.", parent);
return;
}
if (parent instanceof MethodNode) {
visitMethodNode((MethodNode) parent);
} else if (parent instanceof FieldNode) {
visitFieldNode((FieldNode) parent);
}
}
}
示例9: copyAnnotatedNodeAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的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);
}
}
}
示例10: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
private void visitAnnotations(AnnotatedNode targetNode, AnnotatedNode sourceNode, Object visitor) {
for (AnnotationNode an : sourceNode.getAnnotations()) {
// skip built-in properties
if (an.isBuiltIn()) continue;
if (an.hasSourceRetention()) continue;
AnnotationVisitor av = getAnnotationVisitor(targetNode, an, visitor);
visitAnnotationAttributes(an, av);
av.visitEnd();
}
}
示例11: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
protected void visitAnnotations(AnnotatedNode node, int target) {
if (node.getAnnotations().isEmpty()) {
return;
}
this.currentClass.setAnnotated(true);
if (!isAnnotationCompatible()) {
addError("Annotations are not supported in the current runtime. " + JVM_ERROR_MESSAGE, node);
return;
}
Map<String, List<AnnotationNode>> runtimeAnnotations = new LinkedHashMap<String, List<AnnotationNode>>();
for (AnnotationNode unvisited : node.getAnnotations()) {
AnnotationNode visited = visitAnnotation(unvisited);
String name = visited.getClassNode().getName();
if (visited.hasRuntimeRetention()) {
List<AnnotationNode> seen = runtimeAnnotations.get(name);
if (seen == null) {
seen = new ArrayList<AnnotationNode>();
}
seen.add(visited);
runtimeAnnotations.put(name, seen);
}
boolean isTargetAnnotation = name.equals("java.lang.annotation.Target");
// Check if the annotation target is correct, unless it's the target annotating an annotation definition
// defining on which target elements the annotation applies
if (!isTargetAnnotation && !visited.isTargetAllowed(target)) {
addError("Annotation @" + name + " is not allowed on element "
+ AnnotationNode.targetToName(target), visited);
}
visitDeprecation(node, visited);
visitOverride(node, visited);
}
checkForDuplicateAnnotations(node, runtimeAnnotations);
}
示例12: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
public void visitAnnotations(AnnotatedNode node) {
List<AnnotationNode> annotations = node.getAnnotations();
if (annotations.isEmpty()) return;
for (AnnotationNode an : annotations) {
// skip built-in properties
if (an.isBuiltIn()) continue;
for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) {
Expression annMemberValue = member.getValue();
annMemberValue.visit(this);
}
}
}
示例13: visitAnnotations
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
@Override
public void visitAnnotations(AnnotatedNode node) {
super.visitAnnotations(node);
for (AnnotationNode an : node.getAnnotations()) {
addToCache(an.getClassNode());
}
}
示例14: hasBindableAnnotation
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
/**
* Convenience method to see if an annotated node is {@code @Bindable}.
*
* @param node the node to check
* @return true if the node is bindable
*/
public static boolean hasBindableAnnotation(AnnotatedNode node) {
for (AnnotationNode annotation : node.getAnnotations()) {
if (boundClassNode.equals(annotation.getClassNode())) {
return true;
}
}
return false;
}
示例15: hasVetoableAnnotation
import org.codehaus.groovy.ast.AnnotatedNode; //导入方法依赖的package包/类
/**
* Convenience method to see if an annotated node is {@code @Vetoable}.
*
* @param node the node to check
* @return true if the node is constrained
*/
public static boolean hasVetoableAnnotation(AnnotatedNode node) {
for (AnnotationNode annotation : node.getAnnotations()) {
if (constrainedClassNode.equals(annotation.getClassNode())) {
return true;
}
}
return false;
}