本文整理汇总了Java中org.codehaus.groovy.ast.ClassNode类的典型用法代码示例。如果您正苦于以下问题:Java ClassNode类的具体用法?Java ClassNode怎么用?Java ClassNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassNode类属于org.codehaus.groovy.ast包,在下文中一共展示了ClassNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileToDir
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public void compileToDir(ScriptSource source, ClassLoader classLoader, File classesDir, File metadataDir, CompileOperation<?> extractingTransformer,
Class<? extends Script> scriptBaseClass, Action<? super ClassNode> verifier) {
Timer clock = Timers.startTimer();
GFileUtils.deleteDirectory(classesDir);
GFileUtils.mkdirs(classesDir);
CompilerConfiguration configuration = createBaseCompilerConfiguration(scriptBaseClass);
configuration.setTargetDirectory(classesDir);
try {
compileScript(source, classLoader, configuration, metadataDir, extractingTransformer, verifier);
} catch (GradleException e) {
GFileUtils.deleteDirectory(classesDir);
GFileUtils.deleteDirectory(metadataDir);
throw e;
}
logger.debug("Timing: Writing script to cache at {} took: {}", classesDir.getAbsolutePath(), clock.getElapsed());
}
示例2: changeBaseScriptTypeFromPackageOrImport
import org.codehaus.groovy.ast.ClassNode; //导入依赖的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);
}
}
}
示例3: changeBaseScriptTypeFromDeclaration
import org.codehaus.groovy.ast.ClassNode; //导入依赖的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);
}
示例4: createGrabAnnotation
import org.codehaus.groovy.ast.ClassNode; //导入依赖的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
示例5: transformationOfAnnotationOnLocalVariable
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Test
public void transformationOfAnnotationOnLocalVariable() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
DeclarationExpression declarationExpression = new DeclarationExpression(
new VariableExpression("test"), null, new ConstantExpression("test"));
declarationExpression.addAnnotation(this.grabAnnotation);
BlockStatement code = new BlockStatement(
Arrays.asList((Statement) new ExpressionStatement(declarationExpression)),
new VariableScope());
MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
new Parameter[0], new ClassNode[0], code);
classNode.addMethod(methodNode);
assertGrabAnnotationHasBeenTransformed();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ResolveDependencyCoordinatesTransformationTests.java
示例6: eval
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public Object eval(String script, ScriptContext ctx) throws ScriptException {
COMPILE_OPTIONS.remove();
Map<String, ClassNode> variableTypes = new HashMap<>();
for (Map.Entry<String, Object> entry : ctx.getBindings(ScriptContext.ENGINE_SCOPE).entrySet()) {
variableTypes.put(entry.getKey(),
ClassHelper.make(entry.getValue().getClass()));
}
variableTypes.put("execution", ClassHelper.make(clazz));
Map<String, Object> options = new HashMap<>();
options.put(VAR_TYPES, variableTypes);
COMPILE_OPTIONS.set(options);
Object ret = super.eval(script, ctx);
return ret;
}
示例7: call
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)
throws CompilationFailedException {
ImportCustomizer importCustomizer = new SmartImportCustomizer(source, context,
classNode);
ClassNode mainClassNode = MainClass.get(source.getAST().getClasses());
// Additional auto configuration
for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) {
if (autoConfiguration.matches(classNode)) {
if (GroovyCompiler.this.configuration.isGuessImports()) {
autoConfiguration.applyImports(importCustomizer);
importCustomizer.call(source, context, classNode);
}
if (classNode.equals(mainClassNode)) {
autoConfiguration.applyToMainClass(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
autoConfiguration.apply(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
}
importCustomizer.call(source, context, classNode);
}
示例8: getScriptClass
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
public static ClassNode getScriptClass(SourceUnit source) {
if (source.getAST().getStatementBlock().getStatements().isEmpty() && source.getAST().getMethods().isEmpty()) {
// There is no script class when there are no statements or methods declared in the script
return null;
}
return source.getAST().getClasses().get(0);
}
示例9: getGeneratedClosureImplMethod
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
public static MethodNode getGeneratedClosureImplMethod(ClassNode classNode) {
if (!classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)) {
throw new IllegalArgumentException("expecting generated closure class node");
}
List<MethodNode> doCallMethods = classNode.getDeclaredMethods("doCall");
return doCallMethods.get(0);
}
示例10: execute
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public void execute(ClassNode node) {
if (node.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)) {
RulesVisitor.visitGeneratedClosure(node);
RuleVisitor.visitGeneratedClosure(node);
}
}
示例11: compile
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public <T extends Script, M> CompiledScript<T, M> compile(ScriptSource source, ClassLoader classLoader, ClassLoaderId classLoaderId, CompileOperation<M> operation, Class<T> scriptBaseClass, Action<? super ClassNode> verifier) {
ScriptCacheKey key = new ScriptCacheKey(source.getClassName(), classLoader, operation.getId());
CompiledScript<T, M> compiledScript = Cast.uncheckedCast(cachedCompiledScripts.get(key));
if (compiledScript == null) {
compiledScript = cache.getOrCompile(source, classLoader, classLoaderId, operation, scriptBaseClass, verifier, scriptClassCompiler);
cachedCompiledScripts.put(key, compiledScript);
}
return compiledScript;
}
示例12: CustomCompilationUnit
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
public CustomCompilationUnit(CompilerConfiguration compilerConfiguration, CodeSource codeSource, final Action<? super ClassNode> customVerifier, GroovyClassLoader groovyClassLoader) {
super(compilerConfiguration, codeSource, groovyClassLoader);
this.verifier = new Verifier() {
public void visitClass(ClassNode node) {
customVerifier.execute(node);
super.visitClass(node);
}
};
this.resolveVisitor = new GradleResolveVisitor(this, defaultImportPackages, simpleNameToFQN);
}
示例13: CompileToCrossBuildCacheAction
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
public <T extends Script> CompileToCrossBuildCacheAction(ScriptSource source, ClassLoader classLoader, CompileOperation<?> transformer,
Action<? super ClassNode> verifier, Class<T> scriptBaseClass) {
this.source = source;
this.classLoader = classLoader;
this.transformer = transformer;
this.verifier = verifier;
this.scriptBaseClass = scriptBaseClass;
}
示例14: RemapBuildScriptsAction
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
public RemapBuildScriptsAction(RemappingScriptSource remapped, String classpathHash, String sourceHash, String dslId, ClassLoader classLoader, CompileOperation<M> operation, Action<? super ClassNode> verifier, Class<T> scriptBaseClass) {
this.classpathHash = classpathHash;
this.sourceHash = sourceHash;
this.dslId = dslId;
this.remapped = remapped;
this.source = remapped.getSource();
this.classLoader = classLoader;
this.operation = operation;
this.verifier = verifier;
this.scriptBaseClass = scriptBaseClass;
}
示例15: call
import org.codehaus.groovy.ast.ClassNode; //导入依赖的package包/类
@Override
public void call(SourceUnit source) throws CompilationFailedException {
ClassNode scriptClass = AstUtils.getScriptClass(source);
if (scriptClass == null) {
return;
}
for (MethodNode methodNode : scriptClass.getMethods()) {
if (methodNode.getName().equals("main")) {
AstUtils.removeMethod(scriptClass, methodNode);
break;
}
}
}