Java 类org.eclipse.xtext.xbase.compiler.XbaseCompiler 实例源码

项目:xtext-extras    文件:EvaluationCompilerTest.java   
protected String compileToJavaCode(String xtendCode) {
    XExpression model = null;
    ITreeAppendable appendable = new FakeTreeAppendable();
    try {
        model = expression(xtendCode, true);
        XbaseCompiler compiler = compilerProvider.get();
        LightweightTypeReference objectRef = new StandardTypeReferenceOwner(services, model).newReferenceToObject();
        compiler.compile(model, appendable, objectRef);
    } catch (Exception e) {
        throw new RuntimeException("Xtend compilation failed", e);
    } finally {
        if (model != null)
            cache.clear(model.eResource());
    }
    return appendable.getContent();
}
项目:xtext-extras    文件:ConstantInlineExpansionTest.java   
protected String compileToJavaCode(String xtendCode) {
    XExpression model = null;
    ITreeAppendable appendable = new FakeTreeAppendable();
    try {
        model = expression(xtendCode, true);
        XbaseCompiler compiler = this.compilerProvider.get();
        LightweightTypeReference objectRef = new StandardTypeReferenceOwner(this.services, model).newReferenceToObject();
        compiler.compile(model, appendable, objectRef);
    } catch (Exception e) {
        throw new RuntimeException("Xtend compilation failed", e);
    } finally {
        if (model != null)
            this.cache.clear(model.eResource());
    }
    return appendable.getContent();
}
项目:xtext-extras    文件:CompilerTraceTest.java   
protected void assertTrace(final String javaCodeWithMarker, String xbaseCodeWithMarker) throws Exception {
    xbaseCodeWithMarker = " " + xbaseCodeWithMarker + " ";
    Matcher xbaseMatcher = p.matcher(xbaseCodeWithMarker);
    assertTrue(xbaseMatcher.matches());
    String xbaseGroup1 = xbaseMatcher.group(1);
    String xbaseGroup2 = xbaseMatcher.group(2);
    String xbaseGroup3 = xbaseMatcher.group(3);
    String actualCode = xbaseGroup1 + xbaseGroup2 + xbaseGroup3; 
    XExpression model = expression(actualCode,true);
    TreeAppendable appendable = new TreeAppendable(new ImportManager(true), converter, locationProvider, jvmModelAssociations, model, "  ", "\n");
    XbaseCompiler compiler = get(XbaseCompiler.class);
    LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model);
    if (returnType == null) {
        throw new IllegalStateException();
    }
    compiler.compile(model, appendable, returnType);
    String compiledJavaCode = appendable.getContent();
    Matcher javaMatcher = p.matcher(javaCodeWithMarker);
    assertTrue(javaMatcher.matches());
    String javaGroup1 = javaMatcher.group(1);
    String javaGroup2 = javaMatcher.group(2);
    String javaGroup3 = javaMatcher.group(3);
    String actualExpectation = javaGroup1 + javaGroup2 + javaGroup3;
    assertEquals(actualExpectation, compiledJavaCode);
    ITrace trace = new SimpleTrace(appendable.getTraceRegion());
    ILocationInResource location = trace.getBestAssociatedLocation(new TextRegion(javaGroup1.length(), javaGroup2.length()));
    if (location == null) {
        throw new IllegalStateException("location may not be null");
    }
    assertEquals(new TextRegion(xbaseGroup1.length(), xbaseGroup2.length()), location.getTextRegion());
}
项目:xtext-extras    文件:AbstractOutputComparingCompilerTests.java   
protected void assertCompilesTo(final CharSequence expectedJavaCode, final CharSequence xbaseCode,
        GeneratorConfig generatorConfig, boolean resolve) throws Exception {
    XExpression model = expression(xbaseCode.toString(), resolve);
    XbaseCompiler compiler = get(XbaseCompiler.class);
    FakeTreeAppendable tracing = createAppendable();
    tracing.setGeneratorConfig(generatorConfig);
    LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model);
    if (returnType == null) {
        throw new IllegalStateException();
    }
    compiler.compile(model, tracing, returnType);
    assertEquals(expectedJavaCode.toString().trim(), tracing.getContent().toString().trim());
}
项目:xtext-extras    文件:AbstractOutputComparingCompilerTests.java   
protected void assertCompilesToStatement(final CharSequence expectedJavaCode, final CharSequence xbaseCode) throws Exception {
    XExpression model = expression(xbaseCode.toString(),true);
    XbaseCompiler compiler = get(XbaseCompiler.class);
    ITreeAppendable tracing = createAppendable();
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, model);
    LightweightTypeReference voidRef = owner.newReferenceTo(Void.TYPE);
    compiler.compile(model, tracing, voidRef);
    assertEquals(expectedJavaCode, tracing.getContent());
}
项目:txtUML    文件:XtxtUMLRuntimeModule.java   
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
    return XtxtUMLCompiler.class;
}
项目:test-generation    文件:TestSpecRuntimeModule.java   
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
    return StrategyCompiler.class;
}
项目:dsl-devkit    文件:CheckRuntimeModule.java   
/**
 * Sets our own compiler.
 *
 * @return CheckCompiler.class
 */
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
  return CheckCompiler.class;
}