• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AnnotationNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.codehaus.groovy.ast.AnnotationNode的典型用法代码示例。如果您正苦于以下问题:Java AnnotationNode类的具体用法?Java AnnotationNode怎么用?Java AnnotationNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AnnotationNode类属于org.codehaus.groovy.ast包,在下文中一共展示了AnnotationNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
        }
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:20,代码来源:PicocliScriptASTTransformation.java


示例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);
}
 
开发者ID:remkop,项目名称:picocli,代码行数:23,代码来源:PicocliScriptASTTransformation.java


示例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());
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:AnnotationVisitor.java


示例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);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:ExternalizeMethodsASTTransformation.java


示例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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:AntlrParserPlugin.java


示例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);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:StaticTypeCheckingVisitor.java


示例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();
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ASTTransformationCollectorCodeVisitor.java


示例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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:AnnotationCollectorTransform.java


示例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
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:ASTTransformationCollectorCodeVisitor.java


示例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;
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:BuilderASTTransformation.java


示例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));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:SourceURIASTTransformation.java


示例16: getKnownImmutables

import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private List<String> getKnownImmutables(AnnotationNode node) {
    final List<String> immutables = new ArrayList<String>();

    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLES);
    if (expression == null) return immutables;

    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable property names via \"" + MEMBER_KNOWN_IMMUTABLES + "\"", node);
        return immutables;
    }

    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ConstantExpression) {
            immutables.add((String) ((ConstantExpression) listItemExpression).getValue());
        }
    }

    return immutables;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ImmutableASTTransformation.java


示例17: processClass

import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private void processClass(ClassNode cNode, AnnotationNode node) {
    if (cNode.isInterface()) {
        addError("Error processing interface '" + cNode.getName() +
                "'. " + MY_TYPE_NAME + " only allowed for classes.", cNode);
        return;
    }
    boolean copyConstructorAnnotations = memberHasValue(node, "constructorAnnotations", true);
    boolean copyParameterAnnotations = memberHasValue(node, "parameterAnnotations", true);
    ClassNode sNode = cNode.getSuperClass();
    List<AnnotationNode> superAnnotations = sNode.getAnnotations(MY_TYPE);
    if (superAnnotations.size() == 1) {
        // We need @InheritConstructors from parent classes processed first
        // so force that order here. The transformation is benign on an already
        // processed node so processing twice in any order won't matter bar
        // a very small time penalty.
        processClass(sNode, node);
    }
    for (ConstructorNode cn : sNode.getDeclaredConstructors()) {
        addConstructorUnlessAlreadyExisting(cNode, cn, copyConstructorAnnotations, copyParameterAnnotations);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:InheritConstructorsASTTransformation.java


示例18: getKnownImmutableClasses

import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
private List<String> getKnownImmutableClasses(AnnotationNode node) {
    final List<String> immutableClasses = new ArrayList<String>();

    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLE_CLASSES);
    if (expression == null) return immutableClasses;

    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable classes via \"" + MEMBER_KNOWN_IMMUTABLE_CLASSES + "\"", node);
        return immutableClasses;
    }

    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ClassExpression) {
            immutableClasses.add(listItemExpression.getType().getName());
        }
    }

    return immutableClasses;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ImmutableASTTransformation.java


示例19: getEnumMemberValue

import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends Enum> T getEnumMemberValue(AnnotationNode node, String name, Class<T> type, T defaultValue) {
    if (node == null) return defaultValue;

    final PropertyExpression member = (PropertyExpression) node.getMember(name);
    if (member == null)
        return defaultValue;

    if (!type.equals(member.getObjectExpression().getType().getTypeClass()))
        return defaultValue;

    try {
        String value = member.getPropertyAsString();
        Method fromString = type.getMethod("valueOf", String.class);
        return (T) fromString.invoke(null, value);
    } catch (Exception e) {
        return defaultValue;
    }
}
 
开发者ID:klum-dsl,项目名称:klum-ast,代码行数:20,代码来源:DSLASTTransformation.java


示例20: inferClosureParameterTypes

import org.codehaus.groovy.ast.AnnotationNode; //导入依赖的package包/类
/**
 * This method is responsible for performing type inference on closure argument types whenever code like this is
 * found: <code>foo.collect { it.toUpperCase() }</code>.
 * In this case, the type checker tries to find if the <code>collect</code> method has its {@link Closure} argument
 * annotated with {@link groovy.transform.stc.ClosureParams}. If yes, then additional type inference can be performed
 * and the type of <code>it</code> may be inferred.
 *
 * @param receiver
 * @param arguments
 * @param expression a closure expression for which the argument types should be inferred
 * @param param the parameter where to look for a {@link groovy.transform.stc.ClosureParams} annotation.
 * @param selectedMethod the method accepting a closure
 */
protected void inferClosureParameterTypes(final ClassNode receiver, final Expression arguments, final ClosureExpression expression, final Parameter param, final MethodNode selectedMethod) {
    List<AnnotationNode> annotations = param.getAnnotations(CLOSUREPARAMS_CLASSNODE);
    if (annotations!=null && !annotations.isEmpty()) {
        for (AnnotationNode annotation : annotations) {
            Expression hintClass = annotation.getMember("value");
            Expression options = annotation.getMember("options");
            Expression resolverClass = annotation.getMember("conflictResolutionStrategy");
            if (hintClass instanceof ClassExpression) {
                doInferClosureParameterTypes(receiver, arguments, expression, selectedMethod, hintClass, resolverClass, options);
            }
        }
    } else if (isSAMType(param.getOriginType())) {
        // SAM coercion
        inferSAMType(param, receiver, selectedMethod, InvocationWriter.makeArgumentList(arguments), expression);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:StaticTypeCheckingVisitor.java



注:本文中的org.codehaus.groovy.ast.AnnotationNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Executor类代码示例发布时间:2022-05-21
下一篇:
Java DnsDiscovery类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap