本文整理汇总了Java中org.codehaus.groovy.ast.AnnotationNode类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationNode类的具体用法?Java AnnotationNode怎么用?Java AnnotationNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationNode类属于org.codehaus.groovy.ast包,在下文中一共展示了AnnotationNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeBaseScriptTypeFromPackageOrImport
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的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: changeBaseScriptTypeFromDeclaration
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
Expression value = node.getMember("value");
if (value != null) {
addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
return;
}
ClassNode cNode = de.getDeclaringClass();
ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
de.setRightExpression(new VariableExpression("this"));
changeBaseScriptType(source, de, cNode, baseScriptType, node);
}
示例3: createGrabAnnotation
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private AnnotationNode createGrabAnnotation(String group, String module,
String version, String classifier, String type, boolean transitive) {
AnnotationNode annotationNode = new AnnotationNode(new ClassNode(Grab.class));
annotationNode.addMember("group", new ConstantExpression(group));
annotationNode.addMember("module", new ConstantExpression(module));
annotationNode.addMember("version", new ConstantExpression(version));
if (classifier != null) {
annotationNode.addMember("classifier", new ConstantExpression(classifier));
}
if (type != null) {
annotationNode.addMember("type", new ConstantExpression(type));
}
annotationNode.addMember("transitive", new ConstantExpression(transitive));
annotationNode.addMember("initClass", new ConstantExpression(false));
return annotationNode;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:DependencyCustomizer.java
示例4: applyGroupAndVersion
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private void applyGroupAndVersion(AnnotationNode annotation, String module) {
if (module != null) {
setMember(annotation, "module", module);
}
else {
Expression expression = annotation.getMembers().get("module");
module = (String) ((ConstantExpression) expression).getValue();
}
if (annotation.getMember("group") == null) {
setMember(annotation, "group", this.resolutionContext
.getArtifactCoordinatesResolver().getGroupId(module));
}
if (annotation.getMember("version") == null) {
setMember(annotation, "version", this.resolutionContext
.getArtifactCoordinatesResolver().getVersion(module));
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:ResolveDependencyCoordinatesTransformation.java
示例5: visitAnnotatedNode
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的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
示例6: assertGrabAnnotation
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private void assertGrabAnnotation(AnnotationNode annotationNode, String group,
String module, String version, String classifier, String type,
boolean transitive) {
assertThat(getMemberValue(annotationNode, "group")).isEqualTo(group);
assertThat(getMemberValue(annotationNode, "module")).isEqualTo(module);
if (type == null) {
assertThat(annotationNode.getMember("type")).isNull();
}
else {
assertThat(getMemberValue(annotationNode, "type")).isEqualTo(type);
}
if (classifier == null) {
assertThat(annotationNode.getMember("classifier")).isNull();
}
else {
assertThat(getMemberValue(annotationNode, "classifier"))
.isEqualTo(classifier);
}
assertThat(getMemberValue(annotationNode, "transitive")).isEqualTo(transitive);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:DependencyCustomizerTests.java
示例7: 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());
}
}
示例8: visit
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的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);
}
}
示例9: annotation
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
protected AnnotationNode annotation(AST annotationNode) {
annotationBeingDef = true;
AST node = annotationNode.getFirstChild();
String name = qualifiedName(node);
AnnotationNode annotatedNode = new AnnotationNode(ClassHelper.make(name));
configureAST(annotatedNode, annotationNode);
while (true) {
node = node.getNextSibling();
if (isType(ANNOTATION_MEMBER_VALUE_PAIR, node)) {
AST memberNode = node.getFirstChild();
String param = identifier(memberNode);
Expression expression = expression(memberNode.getNextSibling());
if (annotatedNode.getMember(param) != null) {
throw new ASTRuntimeException(memberNode, "Annotation member '" + param + "' has already been associated with a value");
}
annotatedNode.setMember(param, expression);
} else {
break;
}
}
annotationBeingDef = false;
return annotatedNode;
}
示例10: addTypeCheckingInfoAnnotation
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
protected void addTypeCheckingInfoAnnotation(final MethodNode node) {
// TypeChecked$TypeCheckingInfo can not be applied on constructors
if (node instanceof ConstructorNode) return;
// if a returned inferred type is available and no @TypeCheckingInfo is on node, then add an
// annotation to the method node
ClassNode rtype = getInferredReturnType(node);
if (rtype != null && node.getAnnotations(TYPECHECKING_INFO_NODE).isEmpty()) {
AnnotationNode anno = new AnnotationNode(TYPECHECKING_INFO_NODE);
anno.setMember("version", CURRENT_SIGNATURE_PROTOCOL);
SignatureCodec codec = SignatureCodecFactory.getCodec(CURRENT_SIGNATURE_PROTOCOL_VERSION, getTransformLoader());
String genericsSignature = codec.encode(rtype);
if (genericsSignature != null) {
ConstantExpression signature = new ConstantExpression(genericsSignature);
signature.setType(STRING_TYPE);
anno.setMember("inferredType", signature);
node.addAnnotation(anno);
}
}
}
示例11: deleteReplacement
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private static void deleteReplacement(boolean mergeParams, Map<Integer, List<AnnotationNode>> existingMap, List<AnnotationNode> replacements) {
Iterator<AnnotationNode> nodeIterator = replacements.iterator();
while (nodeIterator.hasNext()) {
boolean remove = false;
AnnotationNode replacement = nodeIterator.next();
for (Map.Entry<Integer, List<AnnotationNode>> entry : existingMap.entrySet()) {
for (AnnotationNode existing : entry.getValue()) {
if (replacement.getClassNode().getName().equals(existing.getClassNode().getName())) {
if (mergeParams) {
mergeParameters(existing, replacement);
}
remove = true;
}
}
}
if (remove) {
nodeIterator.remove();
}
}
}
示例12: serialize
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private Expression serialize(Expression e) {
if (e instanceof AnnotationConstantExpression) {
AnnotationConstantExpression ace = (AnnotationConstantExpression) e;
return serialize((AnnotationNode) ace.getValue());
} else if (e instanceof ListExpression) {
boolean annotationConstant = false;
ListExpression le = (ListExpression) e;
List<Expression> list = le.getExpressions();
List<Expression> newList = new ArrayList<Expression>(list.size());
for (Expression exp: list) {
annotationConstant = annotationConstant || exp instanceof AnnotationConstantExpression;
newList.add(serialize(exp));
}
ClassNode type = ClassHelper.OBJECT_TYPE;
if (annotationConstant) type = type.makeArray();
return new ArrayExpression(type, newList);
}
return e;
}
示例13: mergeCollectedAnnotations
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private static void mergeCollectedAnnotations(AnnotationCollectorMode mode, Map<Integer, List<AnnotationNode>> existing, List<AnnotationNode> replacements) {
switch(mode) {
case PREFER_COLLECTOR:
deleteExisting(false, existing, replacements);
break;
case PREFER_COLLECTOR_MERGED:
deleteExisting(true, existing, replacements);
break;
case PREFER_EXPLICIT:
deleteReplacement(false, existing, replacements);
break;
case PREFER_EXPLICIT_MERGED:
deleteReplacement(true, existing, replacements);
break;
default:
// nothing to do
}
}
示例14: createBuilderStrategy
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private BuilderStrategy createBuilderStrategy(AnnotationNode anno, GroovyClassLoader loader) {
ClassNode strategyClass = getMemberClassValue(anno, "builderStrategy", ClassHelper.make(DefaultStrategy.class));
if (strategyClass == null) {
addError("Couldn't determine builderStrategy class", anno);
return null;
}
String className = strategyClass.getName();
try {
Object instance = loader.loadClass(className).newInstance();
if (instance == null) {
addError("Can't load builderStrategy '" + className + "'", anno);
return null;
}
if (!BuilderStrategy.class.isAssignableFrom(instance.getClass())) {
addError("The builderStrategy class '" + strategyClass.getName() + "' on " + MY_TYPE_NAME + " is not a builderStrategy", anno);
return null;
}
return (BuilderStrategy) instance;
} catch (Exception e) {
addError("Can't load builderStrategy '" + className + "' " + e, anno);
return null;
}
}
示例15: setScriptURIOnDeclaration
import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private void setScriptURIOnDeclaration(final DeclarationExpression de, final AnnotationNode node) {
if (de.isMultipleAssignmentDeclaration()) {
addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
return;
}
if (!(de.getRightExpression() instanceof EmptyExpression)) {
addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
return;
}
URI uri = getSourceURI(node);
if (uri == null) {
addError("Unable to get the URI for the source of this script!", de);
} else {
// Set the RHS to '= URI.create("string for this URI")'.
// That may throw an IllegalArgumentExpression wrapping the URISyntaxException.
de.setRightExpression(getExpression(uri));
}
}