本文整理汇总了Java中org.codehaus.groovy.ast.ClassNode.isScript方法的典型用法代码示例。如果您正苦于以下问题:Java ClassNode.isScript方法的具体用法?Java ClassNode.isScript怎么用?Java ClassNode.isScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.ClassNode
的用法示例。
在下文中一共展示了ClassNode.isScript方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.codehaus.groovy.ast.ClassNode; //导入方法依赖的package包/类
@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
for (ASTNode node : nodes) {
if (node instanceof ModuleNode) {
ModuleNode module = (ModuleNode) node;
for (ClassNode classNode : new ArrayList<ClassNode>(
module.getClasses())) {
if (classNode.isScript()) {
classNode.visitContents(new ClassVisitor(source, classNode));
}
}
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:GroovyBeansTransformation.java
示例2: changeBaseScriptType
import org.codehaus.groovy.ast.ClassNode; //导入方法依赖的package包/类
private void changeBaseScriptType(final SourceUnit source, final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType, final AnnotationNode node) {
if (!cNode.isScriptBody()) {
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
return;
}
if (!baseScriptType.isScript()) {
addError("Declared type " + baseScriptType + " does not extend groovy.lang.Script class!", parent);
return;
}
List<AnnotationNode> annotations = parent.getAnnotations(COMMAND_TYPE);
cNode.addAnnotations(annotations);
cNode.setSuperClass(baseScriptType);
// Method in base script that will contain the script body code.
MethodNode runScriptMethod = ClassHelper.findSAM(baseScriptType);
// If they want to use a name other than than "run", then make the change.
if (isCustomScriptBodyMethod(runScriptMethod)) {
MethodNode defaultMethod = cNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY);
// GROOVY-6706: Sometimes an NPE is thrown here.
// The reason is that our transform is getting called more than once sometimes.
if (defaultMethod != null) {
cNode.removeMethod(defaultMethod);
MethodNode methodNode = new MethodNode(runScriptMethod.getName(), runScriptMethod.getModifiers() & ~ACC_ABSTRACT
, runScriptMethod.getReturnType(), runScriptMethod.getParameters(), runScriptMethod.getExceptions()
, defaultMethod.getCode());
// The AST node metadata has the flag that indicates that this method is a script body.
// It may also be carrying data for other AST transforms.
methodNode.copyNodeMetaData(defaultMethod);
cNode.addMethod(methodNode);
}
}
// If the new script base class does not have a contextual constructor (g.l.Binding), then we won't either.
// We have to do things this way (and rely on just default constructors) because the logic that generates
// the constructors for our script class have already run.
if (cNode.getSuperClass().getDeclaredConstructor(CONTEXT_CTOR_PARAMETERS) == null) {
ConstructorNode orphanedConstructor = cNode.getDeclaredConstructor(CONTEXT_CTOR_PARAMETERS);
cNode.removeConstructor(orphanedConstructor);
}
}
示例3: visit
import org.codehaus.groovy.ast.ClassNode; //导入方法依赖的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);
}
}