本文整理汇总了Java中org.codehaus.groovy.control.CompilePhase类的典型用法代码示例。如果您正苦于以下问题:Java CompilePhase类的具体用法?Java CompilePhase怎么用?Java CompilePhase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompilePhase类属于org.codehaus.groovy.control包,在下文中一共展示了CompilePhase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCalcCallers
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
@Test
public void testCalcCallers() {
String src = IO.readFile("src/main/java/yk/senjin/shaders/gshader/analysis/TestGroovyClass.groovy");
assertEquals("{foo=[foo1], foo1=[foo2]}", calcCallers(new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src)).toString());
src = IO.readFile("/home/yuri/1/public/senjin/src/main/java/yk/senjin/shaders/gshader/examples/blend/BlendF.groovy");
Probe probe = new Probe(new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src), p(MethodCallExpression.class, "getMethod", p("getText", "foo"))){{
skipMethods = hs("getMethodAsString", "getFirstStatement", "getVariableScope", "getDeclaringClass");
}};
SSearch.Node<State> node = probe.nextSolution(100000);
if (node != null) System.out.println("!" + node.state.stackTrace.toString("\n"));
src = IO.readFile("src/main/java/yk/senjin/shaders/gshader/analysis/TestGroovyClass2.groovy");
assertEquals("{foo=[foo1]}", calcCallers(new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src)).toString());
}
示例2: createParsingFailedException
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
private CompilationFailedException createParsingFailedException(Throwable t) {
if (t instanceof SyntaxException) {
this.collectSyntaxError((SyntaxException) t);
} else if (t instanceof GroovySyntaxError) {
GroovySyntaxError groovySyntaxError = (GroovySyntaxError) t;
this.collectSyntaxError(
new SyntaxException(
groovySyntaxError.getMessage(),
groovySyntaxError,
groovySyntaxError.getLine(),
groovySyntaxError.getColumn()));
} else if (t instanceof Exception) {
this.collectException((Exception) t);
}
return new CompilationFailedException(
CompilePhase.PARSING.getPhaseNumber(),
this.sourceUnit,
t);
}
示例3: postCompleteNode
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) {
if (node instanceof Map) {
Map map = (Map) node;
ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter(
map,
map.containsKey("superClass")?(Class)map.get("superClass"):CompilationCustomizer.class,
map.containsKey("interfaces")?(Class[])map.get("interfaces"):null,
this.getClass().getClassLoader(),
false,
null
);
Object phase = map.get("phase");
if (!(phase instanceof CompilePhase)) {
phase = CompilePhase.valueOf(phase.toString());
}
return adapter.proxy(map, phase);
}
return node;
}
示例4: verifyCompilePhase
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
private void verifyCompilePhase(AnnotationNode annotation, Class<?> klass) {
GroovyASTTransformation transformationClass = klass.getAnnotation(GroovyASTTransformation.class);
if (transformationClass != null) {
CompilePhase specifiedCompilePhase = transformationClass.phase();
if (specifiedCompilePhase.getPhaseNumber() < CompilePhase.SEMANTIC_ANALYSIS.getPhaseNumber()) {
source.getErrorCollector().addError(
new SimpleMessage(
annotation.getClassNode().getName() + " is defined to be run in compile phase " + specifiedCompilePhase + ". Local AST transformations must run in " + CompilePhase.SEMANTIC_ANALYSIS + " or later!",
source));
}
} else {
source.getErrorCollector().addError(
new SimpleMessage("AST transformation implementation classes must be annotated with " + GroovyASTTransformation.class.getName() + ". " + klass.getName() + " lacks this annotation.", source));
}
}
示例5: registerASTTransformations
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
private void registerASTTransformations(final ClassNode helper) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(
unit, compilationUnit.getTransformLoader()
);
collector.visitClass(helper);
// Perform an additional phase which has to be done *after* type checking
compilationUnit.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() {
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
if (classNode==helper) {
PostTypeCheckingExpressionReplacer replacer = new PostTypeCheckingExpressionReplacer(source);
replacer.visitClass(helper);
}
}
}, CompilePhase.INSTRUCTION_SELECTION.getPhaseNumber());
}
示例6: doVisit
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @since 0.2.0
*/
@Override
public void doVisit(final AnnotationNode annotationNode, final ClassNode annotatedNode) {
if(!A.UTIL.CLASS.isOrExtends(annotatedNode, AbstractLocalTransformation.class)) {
return;
}
final CompilePhase phase = extractCompilePhaseFrom(annotationNode);
TransformationUtils.addASTAnnotationsFromTo(annotatedNode, phase);
addClassConstructor(annotatedNode);
// tag::addCheckTo[]
A.UTIL.CHECK.addCheckTo(A.UTIL.CLASS.findMethodByName(annotatedNode, METHOD_DOVISIT));
// end::addCheckTo[]
A.UTIL.CLASS.removeAnnotation(annotatedNode, annotationNode);
}
示例7: transformClass
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void transformClass(final ClassNode annotated) {
final ClassNode superClass = annotated.getSuperClass();
if (superClass == null) {
return;
}
final ClassNode reference = A.NODES.clazz(AbstractGlobalTransformation.class).build();
final Boolean isGlobal = A.UTIL.CLASS.isOrExtendsUnsafe(annotated, reference);
if (!isGlobal) {
return;
}
final AnnotationNode annotation = A.UTIL.CLASS.getAnnotationFrom(annotated, TX_NAME);
final CompilePhase phase = extractCompilePhaseFromSafely(annotation);
TransformationUtils.addASTAnnotationsFromTo(annotated, phase);
A.UTIL.CLASS.removeAnnotation(annotated, annotation);
}
示例8: test1
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
@Test
public void test1() {
String src = IO.readFile("src/main/java/yk/senjin/shaders/gshader/analysis/BlendF.groovy");
List<ASTNode> nodes = new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src);
ClassNode classNode = (ClassNode) nodes.get(1);
for (MethodNode methodNode : classNode.getMethods()) {
System.out.println("looking at " + methodNode.getName());
getArgsModifiers(methodNode, null);
}
}
示例9: testAsserts
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
@Test
public void testAsserts() {
String src = IO.readFile("src/main/java/yk/senjin/shaders/gshader/analysis/BlendF.groovy");
assertEquals("(method main) field 'kSize' is rewritten, but it's forbidden in gglsl\n" +
"(method main) field 'direction' is used as inout arg, but it's forbidden in gglsl\n" +
"(method testFoo) parameter 'modified' is rewritten, but it's forbidden in gglsl (use explicity copyFrom)\n" +
"(method foo) parameter 'd' is used as return value, but it's forbidden in gglsl (use explicity copy)\n" +
"(method foo) field 'direction' is used as return value, but it's forbidden in gglsl",
gAsserts(new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src), hm("testFoo:0", hs("in", "inout"))).toString("\n"));
}
示例10: main
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
public static void main(String[] args) {
Object varWritePattern = stairs(
deeper(G_BODY_ACCESSORS),
p(BinaryExpression.class, "operation", p("text", "="), "leftExpression"),
p(VariableExpression.class, "variable", var("VAR_NAME")));
String src = IO.readFile("src/main/java/yk/senjin/shaders/gshader/analysis/HabraExample.groovy");
//parse kotlin file
Object node = new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, src);
//select method "foo"
for (YMap<String, Object> m : new Matcher().match(node, stairs(deeper(G_METHOD_ACCESSORS), var("method"), p(MethodNode.class, "name"), "foo"))) {
//getting methodNode object from select result
Object methodNode = m.get("method");
System.out.println("all variables are free:");
System.out.println(new Matcher().match(methodNode, G_FIELD_AS_ARG_PATTERN).toString("\n"));
System.out.println("\nfixed OBJ_NAME:");
System.out.println(new Matcher().match(methodNode, G_FIELD_AS_ARG_PATTERN, hm("OBJ_NAME", "vecB")).toString("\n"));
System.out.println("\nfixed ARG_INDEX:");
System.out.println(new Matcher().match(methodNode, G_FIELD_AS_ARG_PATTERN, hm("ARG_INDEX", 0)).toString("\n"));
}
System.out.println("\nsimple array\n");
Vec3f[] vv = new Vec3f[]{new Vec3f(0, 0, 0), new Vec3f(1, 1, 1)};
System.out.println(new Matcher().match(vv, i(p("x", var("X_VALUE")))));
System.out.println(new Matcher().match(vv, i(var("OBJ_INDEX"), p("x", var("X_VALUE")))));
}
示例11: MarkupTemplateEngine
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration tplConfig, final TemplateResolver resolver) {
compilerConfiguration = new CompilerConfiguration();
templateConfiguration = tplConfig;
compilerConfiguration.addCompilationCustomizers(new TemplateASTTransformer(tplConfig));
compilerConfiguration.addCompilationCustomizers(
new ASTTransformationCustomizer(Collections.singletonMap("extensions", "groovy.text.markup.MarkupTemplateTypeCheckingExtension"), CompileStatic.class));
if (templateConfiguration.isAutoNewLine()) {
compilerConfiguration.addCompilationCustomizers(
new CompilationCustomizer(CompilePhase.CONVERSION) {
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
new AutoNewLineTransformer(source).visitClass(classNode);
}
}
);
}
groovyClassLoader = AccessController.doPrivileged(new PrivilegedAction<TemplateGroovyClassLoader>() {
public TemplateGroovyClassLoader run() {
return new TemplateGroovyClassLoader(parentLoader, compilerConfiguration);
}
});
if (DEBUG_BYTECODE) {
compilerConfiguration.setBytecodePostprocessor(BytecodeDumper.STANDARD_ERR);
}
templateResolver = resolver == null ? new DefaultTemplateResolver() : resolver;
templateResolver.configure(groovyClassLoader, templateConfiguration);
}
示例12: execute
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
public long execute() throws Exception {
ClassLoader cl = new URLClassLoader(classpath, ClassLoader.getSystemClassLoader().getParent());
GroovyClassLoader gcl = new GroovyClassLoader(cl);
CompilationUnit cu = new CompilationUnit(new CompilerConfiguration(), null, gcl, new GroovyClassLoader(this.getClass().getClassLoader()));
for (File source : sources) {
cu.addSource(source);
}
long sd = System.nanoTime();
cu.compile(CompilePhase.CLASS_GENERATION.getPhaseNumber());
long dur = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sd);
return dur;
}
示例13: getTransformInstances
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
private Map<CompilePhase, Map<Class<? extends ASTTransformation>, Set<ASTNode>>> getTransformInstances() {
if(transformInstances == null){
transformInstances = new EnumMap<CompilePhase, Map<Class <? extends ASTTransformation>, Set<ASTNode>>>(CompilePhase.class);
for (CompilePhase phase : CompilePhase.values()) {
transformInstances.put(phase, new LinkedHashMap<Class <? extends ASTTransformation>, Set<ASTNode>>());
}
}
return transformInstances;
}
示例14: doParseClass
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
private Class doParseClass(GroovyCodeSource codeSource) {
validate(codeSource);
Class answer; // Was neither already loaded nor compiling, so compile and add to cache.
CompilationUnit unit = createCompilationUnit(config, codeSource.getCodeSource());
if (recompile!=null && recompile || recompile==null && config.getRecompileGroovySource()) {
unit.addFirstPhaseOperation(TimestampAdder.INSTANCE, CompilePhase.CLASS_GENERATION.getPhaseNumber());
}
SourceUnit su = null;
File file = codeSource.getFile();
if (file != null) {
su = unit.addSource(file);
} else {
URL url = codeSource.getURL();
if (url != null) {
su = unit.addSource(url);
} else {
su = unit.addSource(codeSource.getName(), codeSource.getScriptText());
}
}
ClassCollector collector = createCollector(unit, su);
unit.setClassgenCallback(collector);
int goalPhase = Phases.CLASS_GENERATION;
if (config != null && config.getTargetDirectory() != null) goalPhase = Phases.OUTPUT;
unit.compile(goalPhase);
answer = collector.generatedClass;
String mainClass = su.getAST().getMainClassName();
for (Object o : collector.getLoadedClasses()) {
Class clazz = (Class) o;
String clazzName = clazz.getName();
definePackageInternal(clazzName);
setClassCacheEntry(clazz);
if (clazzName.equals(mainClass)) answer = clazz;
}
return answer;
}
示例15: extractCompilePhaseFromSafely
import org.codehaus.groovy.control.CompilePhase; //导入依赖的package包/类
@SuppressWarnings("PMD.AvoidCatchingGenericException")
private CompilePhase extractCompilePhaseFromSafely(final AnnotationNode annotationNode) {
try {
return extractCompilePhaseFrom(annotationNode);
} catch(IllegalArgumentException iaex){
throw new GroovyBugError(PHASE_WRONG, iaex);
} catch(Exception ex) {
throw new GroovyBugError(PHASE_MISSING, ex);
}
}