本文整理汇总了Java中org.codehaus.groovy.ast.AnnotatedNode类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedNode类的具体用法?Java AnnotatedNode怎么用?Java AnnotatedNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedNode类属于org.codehaus.groovy.ast包,在下文中一共展示了AnnotatedNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeBaseScriptTypeFromPackageOrImport
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
Expression value = node.getMember("value");
ClassNode scriptType;
if (value == null) {
scriptType = BASE_SCRIPT_TYPE;
} else {
if (!(value instanceof ClassExpression)) {
addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
return;
}
scriptType = value.getType();
}
List<ClassNode> classes = source.getAST().getClasses();
for (ClassNode classNode : classes) {
if (classNode.isScriptBody()) {
changeBaseScriptType(source, parent, classNode, scriptType, node);
}
}
}
示例2: visitAnnotatedNode
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
private void visitAnnotatedNode(AnnotatedNode annotatedNode,
List<AnnotationNode> annotatedNodes) {
if (annotatedNode != null) {
Iterator<AnnotationNode> annotationNodes = annotatedNode.getAnnotations()
.iterator();
while (annotationNodes.hasNext()) {
AnnotationNode annotationNode = annotationNodes.next();
if (this.interestingAnnotationNames
.contains(annotationNode.getClassNode().getName())) {
annotatedNodes.add(annotationNode);
if (this.removeAnnotations) {
annotationNodes.remove();
}
}
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:AnnotatedNodeASTTransformation.java
示例3: visitAnnotatedNode
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
private void visitAnnotatedNode(AnnotatedNode annotatedNode) {
if (annotatedNode != null) {
Iterator<AnnotationNode> annotationNodes = annotatedNode.getAnnotations()
.iterator();
while (annotationNodes.hasNext()) {
AnnotationNode annotationNode = annotationNodes.next();
if (this.interestingAnnotationNames
.contains(annotationNode.getClassNode().getName())) {
this.annotationNodes.add(annotationNode);
if (this.removeAnnotations) {
annotationNodes.remove();
}
}
}
}
}
示例4: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
/**
* Implementation method of the alias annotation processor. This method will
* get the list of annotations we aliased from the collector and adds it to
* aliasAnnotationUsage. The method will also map all members from
* aliasAnnotationUsage to the aliased nodes. Should a member stay unmapped,
* we will ad an error. Further processing of those members is done by the
* annotations.
*
* @param collector reference to the annotation with {@link AnnotationCollector}
* @param aliasAnnotationUsage reference to the place of usage of the alias
* @param aliasAnnotated reference to the node that has been annotated by the alias
* @param source source unit for error reporting
* @return list of the new AnnotationNodes
*/
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) {
List<AnnotationNode> ret = getTargetAnnotationList(collector, aliasAnnotationUsage, source);
Set<String> unusedNames = new HashSet<String>(aliasAnnotationUsage.getMembers().keySet());
for (AnnotationNode an: ret) {
for (String name : aliasAnnotationUsage.getMembers().keySet()) {
if (an.getClassNode().hasMethod(name, Parameter.EMPTY_ARRAY)) {
unusedNames.remove(name);
an.setMember(name, aliasAnnotationUsage.getMember(name));
}
}
}
if (!unusedNames.isEmpty()) {
String message = "Annotation collector got unmapped names "+unusedNames.toString()+".";
addError(message, aliasAnnotationUsage, source);
}
return ret;
}
示例5: 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];
if (!MY_TYPE.equals(node.getClassNode())) return;
String value = getMemberStringValue(node, "value");
if (parent instanceof MethodNode) {
MethodNode mNode = (MethodNode) parent;
if (mNode.isAbstract()) {
addError("Error during " + MY_TYPE_NAME + " processing: annotation not allowed on abstract method '" + mNode.getName() + "'", mNode);
return;
}
ClassNode cNode = mNode.getDeclaringClass();
String lockExpr = determineLock(value, cNode, mNode);
if (lockExpr == null) return;
Statement origCode = mNode.getCode();
Statement newCode = new SynchronizedStatement(varX(lockExpr), origCode);
mNode.setCode(newCode);
}
}
示例6: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(anno.getClassNode())) return;
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!hasNoargConstructor(cNode)) {
addError(MY_TYPE_NAME + ": An Externalizable class requires a no-arg constructor but none found", cNode);
}
if (!implementsExternalizable(cNode)) {
addError(MY_TYPE_NAME + ": An Externalizable class must implement the Externalizable interface", cNode);
}
boolean includeFields = memberHasValue(anno, "includeFields", true);
boolean checkPropertyTypes = memberHasValue(anno, "checkPropertyTypes", true);
List<String> excludes = getMemberStringList(anno, "excludes");
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return;
List<FieldNode> list = getInstancePropertyFields(cNode);
if (includeFields) {
list.addAll(getInstanceNonPropertyFields(cNode));
}
checkProps(list, excludes, checkPropertyTypes);
}
}
示例7: 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;
}
示例8: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!Traits.TRAIT_CLASSNODE.equals(anno.getClassNode())) return;
unit = source;
init(nodes, source);
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!checkNotInterface(cNode, Traits.TRAIT_TYPE_NAME)) return;
checkNoConstructor(cNode);
checkExtendsClause(cNode);
generateMethodsWithDefaultArgs(cNode);
replaceExtendsByImplements(cNode);
ClassNode helperClassNode = createHelperClass(cNode);
resolveHelperClassIfNecessary(helperClassNode);
}
}
示例9: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(anno.getClassNode())) return;
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!checkNotInterface(cNode, MY_TYPE_NAME)) return;
cNode.addInterface(EXTERNALIZABLE_TYPE);
boolean includeFields = memberHasValue(anno, "includeFields", true);
List<String> excludes = getMemberStringList(anno, "excludes");
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return;
List<FieldNode> list = getInstancePropertyFields(cNode);
if (includeFields) {
list.addAll(getInstanceNonPropertyFields(cNode));
}
createWriteExternal(cNode, excludes, list);
createReadExternal(cNode, excludes, list);
}
}
示例10: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(anno.getClassNode())) return;
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!checkNotInterface(cNode, MY_TYPE_NAME)) return;
ClassNode exception = getMemberClassValue(anno, "exception");
if (exception != null && Undefined.isUndefinedException(exception)) {
exception = null;
}
String message = getMemberStringValue(anno, "message");
Expression code = anno.getMember("code");
if (code != null && !(code instanceof ClosureExpression)) {
addError("Expected closure value for annotation parameter 'code'. Found " + code, cNode);
return;
}
createMethods(cNode, exception, message, (ClosureExpression) code);
if (code != null) {
anno.setMember("code", new ClosureExpression(new Parameter[0], EmptyStatement.INSTANCE));
}
}
}
示例11: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
this.source = source;
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
internalError("Expecting [AnnotationNode, AnnotatedClass] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode())) {
internalError("Transformation called from wrong annotation: " + node.getClassNode().getName());
}
boolean autoFlag = determineAutoFlag(node.getMember("auto"));
Expression value = node.getMember("value");
if (parent instanceof ClassNode) {
newifyClass((ClassNode) parent, autoFlag, determineClasses(value, false));
} else if (parent instanceof MethodNode || parent instanceof FieldNode) {
newifyMethodOrField(parent, autoFlag, determineClasses(value, false));
} else if (parent instanceof DeclarationExpression) {
newifyDeclaration((DeclarationExpression) parent, autoFlag, determineClasses(value, true));
}
}
示例12: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(anno.getClassNode())) return;
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!checkNotInterface(cNode, MY_TYPE_NAME)) return;
boolean callSuper = memberHasValue(anno, "callSuper", true);
boolean cacheHashCode = memberHasValue(anno, "cache", true);
boolean useCanEqual = !memberHasValue(anno, "useCanEqual", false);
if (callSuper && cNode.getSuperClass().getName().equals("java.lang.Object")) {
addError("Error during " + MY_TYPE_NAME + " processing: callSuper=true but '" + cNode.getName() + "' has no super class.", anno);
}
boolean includeFields = memberHasValue(anno, "includeFields", true);
List<String> excludes = getMemberStringList(anno, "excludes");
List<String> includes = getMemberStringList(anno, "includes");
final boolean allNames = memberHasValue(anno, "allNames", true);
if (!checkIncludeExcludeUndefinedAware(anno, excludes, includes, MY_TYPE_NAME)) return;
if (!checkPropertyList(cNode, includes, "includes", anno, MY_TYPE_NAME, includeFields)) return;
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return;
createHashCode(cNode, cacheHashCode, includeFields, callSuper, excludes, includes, allNames);
createEquals(cNode, includeFields, callSuper, useCanEqual, excludes, includes, allNames);
}
}
示例13: visitOverride
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的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);
}
}
}
}
示例14: visit
import org.codehaus.groovy.ast.AnnotatedNode; //导入依赖的package包/类
/**
* Handles the bulk of the processing, mostly delegating to other methods.
*
* @param nodes the AST nodes
* @param source the source unit for the nodes
*/
public void visit(ASTNode[] nodes, SourceUnit source) {
if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
}
AnnotationNode node = (AnnotationNode) nodes[0];
if (nodes[1] instanceof ClassNode) {
addListenerToClass(source, (ClassNode) nodes[1]);
} else {
if ((((FieldNode)nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException("@groovy.beans.Vetoable cannot annotate a final property.",
node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source));
}
addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
}
}
示例15: 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];
if (!MY_TYPE.equals(node.getClassNode())) return;
if (parent instanceof DeclarationExpression) {
changeBaseScriptTypeFromDeclaration(source, (DeclarationExpression) parent, node);
} else if (parent instanceof ImportNode || parent instanceof PackageNode) {
changeBaseScriptTypeFromPackageOrImport(source, parent, node);
} else if (parent instanceof ClassNode) {
changeBaseScriptTypeFromClass(source, (ClassNode) parent, node);
}
}