org.eclipse.xtext.xbase.compiler.GeneratorConfig Java Examples

The following examples show how to use org.eclipse.xtext.xbase.compiler.GeneratorConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    appendable.openScope();
    this.assignThisAndSuper(appendable, it, config);
    ITreeAppendable _xtrycatchfinallyexpression = null;
    try {
      _xtrycatchfinallyexpression = this.generateBody(it, appendable, config);
    } finally {
      appendable.closeScope();
    }
    _xblockexpression = _xtrycatchfinallyexpression;
  }
  return _xblockexpression;
}
 
Example #2
Source File: CompilationTestHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Parses, validates and compiles the given source. Calls the given acceptor for each
 * resource which is generated from the source.
 *  
 * @param resourceSet - the {@link ResourceSet} to use
 * @param acceptor gets called once for each file generated in {@link IGenerator}
 */
public void compile(final ResourceSet resourceSet, IAcceptor<Result> acceptor) {
	try {
		List<Resource> resourcesToCheck = newArrayList(resourceSet.getResources());
		if (generatorConfigProvider instanceof GeneratorConfigProvider) {
			GeneratorConfigProvider configProvider = (GeneratorConfigProvider) generatorConfigProvider;
			GeneratorConfig config = generatorConfigProvider.get(null);
			config.setJavaSourceVersion(javaCompiler.getJavaVersion());
			GeneratorConfig existent = configProvider.install(resourceSet, config);
			if (existent != null) {
				existent.setJavaSourceVersion(javaCompiler.getJavaVersion());
				configProvider.install(resourceSet, existent);
			}
		}
		Result result = resultProvider.get();
		result.setJavaCompiler(javaCompiler);
		result.setCheckMode(getCheckMode());
		result.setResources(resourcesToCheck);
		result.setResourceSet(resourceSet);
		result.setOutputConfigurations(getOutputConfigurations());
		result.doGenerate();
		acceptor.accept(result);
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example #3
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateMember(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable tracedAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
    this.generateModifier(it, tracedAppendable, config);
    this._errorSafeExtensions.serializeSafely(it.getType(), "Object", tracedAppendable);
    tracedAppendable.append(" ");
    final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName()));
    this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name);
    this.generateInitialization(it, tracedAppendable, config);
    _xblockexpression = tracedAppendable.append(";");
  }
  return _xblockexpression;
}
 
Example #4
Source File: ConfiguredCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotationWithValueArray_02() {
  final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null);
  generatorConfig.setGenerateSyntheticSuppressWarnings(false);
  generatorConfig.setGenerateExpressions(true);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@SuppressWarnings(\'abc\', \'efg\')");
  _builder.newLine();
  _builder.append("class C {");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("@SuppressWarnings({ \"abc\", \"efg\" })");
  _builder_1.newLine();
  _builder_1.append("public class C {");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  this.assertCompilesTo(_builder, _builder_1);
}
 
Example #5
Source File: TestCaseCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void compile(String qualifiedName) throws IOException {
	ResourceSet set = injector.getInstance(ResourceSet.class);
	final String from = "src/" + qualifiedName.replace('.', '/') + ".xtend";
	final String to = "src-gen/" + qualifiedName.replace('.', '/') + ".java";

	Resource res = set.getResource(org.eclipse.emf.common.util.URI.createFileURI(from), true);
	EcoreUtil.resolveAll(res);
	if (!res.getErrors().isEmpty())
		throw new RuntimeException(res.getErrors().toString());
	final File file = new File(to);
	createFolders(file);
	FileWriter writer = new FileWriter(file);
	IXtendJvmAssociations associations = injector.getInstance(IXtendJvmAssociations.class);
	JvmModelGenerator generator = injector.getInstance(JvmModelGenerator.class);
	XtendFile xtendFile = (XtendFile)res.getContents().get(0);
	JvmGenericType inferredType = associations.getInferredType((XtendClass) xtendFile.getXtendTypes().get(0));
	GeneratorConfig config = injector.getInstance(IGeneratorConfigProvider.class).get(inferredType);
	CharSequence javaCode = generator.generateType(inferredType, config);
	writer.append(javaCode);
	writer.close();
	System.out.println("compiled " + from + " to " + to);
}
 
Example #6
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void generateParameter(final JvmFormalParameter it, final ITreeAppendable appendable, final boolean vararg, final GeneratorConfig config) {
  final ITreeAppendable tracedAppendable = appendable.trace(it);
  this.generateAnnotations(it.getAnnotations(), tracedAppendable, false, config);
  tracedAppendable.append("final ");
  if (vararg) {
    JvmTypeReference _parameterType = it.getParameterType();
    boolean _not = (!(_parameterType instanceof JvmGenericArrayTypeReference));
    if (_not) {
      tracedAppendable.append("/* Internal Error: Parameter was vararg but not an array type. */");
    } else {
      JvmTypeReference _parameterType_1 = it.getParameterType();
      this._errorSafeExtensions.serializeSafely(((JvmGenericArrayTypeReference) _parameterType_1).getComponentType(), "Object", tracedAppendable);
    }
    tracedAppendable.append("...");
  } else {
    this._errorSafeExtensions.serializeSafely(it.getParameterType(), "Object", tracedAppendable);
  }
  tracedAppendable.append(" ");
  final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName()));
  this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name);
}
 
Example #7
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public ITreeAppendable generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateMember((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateMember((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateMember((JvmField)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateMember((JvmDeclaredType)it, appendable, config);
  } else if (it != null) {
    return _generateMember(it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
 
Example #8
Source File: ConfiguredCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotationWithValueArray_01() {
  final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null);
  generatorConfig.setGenerateSyntheticSuppressWarnings(false);
  generatorConfig.setGenerateExpressions(true);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@SuppressWarnings(#[ \'abc\', \'efg\' ])");
  _builder.newLine();
  _builder.append("class C {");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("@SuppressWarnings({ \"abc\", \"efg\" })");
  _builder_1.newLine();
  _builder_1.append("public class C {");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  this.assertCompilesTo(_builder, _builder_1);
}
 
Example #9
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateModifier((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateModifier((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateModifier((JvmField)it, appendable, config);
  } else if (it instanceof JvmGenericType) {
    return _generateModifier((JvmGenericType)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateModifier((JvmDeclaredType)it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
 
Example #10
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void generateAnnotationMethod(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
  appendable.increaseIndentation().newLine();
  appendable.openScope();
  this.generateJavaDoc(it, appendable, config);
  final ITreeAppendable tracedAppendable = appendable.trace(it);
  this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
  this.generateModifier(it, tracedAppendable, config);
  this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable);
  tracedAppendable.append(" ");
  this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
  tracedAppendable.append("()");
  this.generateDefaultExpression(it, tracedAppendable, config);
  tracedAppendable.append(";");
  appendable.decreaseIndentation();
  appendable.closeScope();
}
 
Example #11
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void generateParameters(final JvmExecutable it, final ITreeAppendable appendable, final GeneratorConfig config) {
  boolean _isEmpty = it.getParameters().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    int _size = it.getParameters().size();
    int _minus = (_size - 1);
    IntegerRange _upTo = new IntegerRange(0, _minus);
    for (final Integer i : _upTo) {
      {
        int _size_1 = it.getParameters().size();
        final boolean last = (((i).intValue() + 1) == _size_1);
        final JvmFormalParameter p = it.getParameters().get((i).intValue());
        this.generateParameter(p, appendable, (last && it.isVarArgs()), config);
        if ((!last)) {
          appendable.append(", ");
        }
      }
    }
  }
}
 
Example #12
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateMember(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    appendable.openScope();
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable tracedAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
    this.generateModifier(it, tracedAppendable, config);
    this.generateTypeParameterDeclaration(it, tracedAppendable, config);
    this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
    tracedAppendable.append("(");
    this.generateParameters(it, tracedAppendable, config);
    tracedAppendable.append(")");
    this.generateThrowsClause(it, tracedAppendable, config);
    tracedAppendable.append(" ");
    this.generateExecutableBody(it, tracedAppendable, config);
    appendable.closeScope();
    _xblockexpression = appendable;
  }
  return _xblockexpression;
}
 
Example #13
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateModifier(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateVisibilityModifier(it, appendable);
    boolean _isStatic = it.isStatic();
    if (_isStatic) {
      appendable.append("static ");
    }
    boolean _isFinal = it.isFinal();
    if (_isFinal) {
      appendable.append("final ");
    }
    boolean _isTransient = it.isTransient();
    if (_isTransient) {
      appendable.append("transient ");
    }
    ITreeAppendable _xifexpression = null;
    boolean _isVolatile = it.isVolatile();
    if (_isVolatile) {
      _xifexpression = appendable.append("volatile ");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #14
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_05_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor5 _function = (String x, String... y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor5 a = _function;",
			"{var closures.IAcceptors.IAcceptor5 a = [x,y|]}",
			generatorConfig);
}
 
Example #15
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<Double> _function = (Double it_1) -> {
    String _switchResult = null;
    boolean _matched = false;
    boolean _isNaN = Double.isNaN((it_1).doubleValue());
    if (_isNaN) {
      _matched=true;
      _switchResult = "Double.NaN";
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.POSITIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.POSITIVE_INFINITY";
      }
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.NEGATIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.NEGATIVE_INFINITY";
      }
    }
    if (!_matched) {
      String _string = it_1.toString();
      _switchResult = (_string + "d");
    }
    appendable.append(_switchResult);
  };
  this._loopExtensions.<Double>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #16
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_04_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor4 _function = (String x, String[] y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor4 a = _function;",
			"{var closures.IAcceptors.IAcceptor4 a = [x,y|]}",
			generatorConfig);
}
 
Example #17
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_03_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor3 _function = (String... x) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor3 a = _function;",
			"{var closures.IAcceptors.IAcceptor3 a = [x|]}",
			generatorConfig);
}
 
Example #18
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_02_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor2 _function = (String[] x) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor2 a = _function;",
			"{var closures.IAcceptors.IAcceptor2 a = [x|]}",
			generatorConfig);
}
 
Example #19
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_01_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor _function = (String x) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor a = _function;",
			"{var closures.IAcceptors.IAcceptor a = [x|]}",
			generatorConfig);
}
 
Example #20
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_07_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor7 _function = (String[] x, String... y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor7 a = _function;",
			"{var closures.IAcceptors.IAcceptor7 a = [x,y|]}",
			generatorConfig);
}
 
Example #21
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmStringAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<String> _function = (String it_1) -> {
    String _doConvertToJavaString = this.doConvertToJavaString(it_1.toString());
    String _plus = ("\"" + _doConvertToJavaString);
    String _plus_1 = (_plus + "\"");
    appendable.append(_plus_1);
  };
  this._loopExtensions.<String>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #22
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmEnumAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_1) -> {
    appendable.append(it_1.getDeclaringType());
    appendable.append(".");
    appendable.append(this.makeJavaIdentifier(it_1.getSimpleName()));
  };
  this._loopExtensions.<JvmEnumerationLiteral>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #23
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_06_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor6 _function = (String[] x, String[] y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor6 a = _function;",
			"{var closures.IAcceptors.IAcceptor6 a = [x,y|]}",
			generatorConfig);
}
 
Example #24
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmFloatAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<Float> _function = (Float it_1) -> {
    String _switchResult = null;
    boolean _matched = false;
    boolean _isNaN = Float.isNaN((it_1).floatValue());
    if (_isNaN) {
      _matched=true;
      _switchResult = "Float.NaN";
    }
    if (!_matched) {
      if (Objects.equal(it_1, Float.POSITIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Float.POSITIVE_INFINITY";
      }
    }
    if (!_matched) {
      if (Objects.equal(it_1, Float.NEGATIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Float.NEGATIVE_INFINITY";
      }
    }
    if (!_matched) {
      String _string = it_1.toString();
      _switchResult = (_string + "f");
    }
    appendable.append(_switchResult);
  };
  this._loopExtensions.<Float>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #25
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable generateDocumentation(final String text, final List<INode> documentationNodes, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    final StringConcatenation doc = ((StringConcatenation) _builder);
    doc.newLine();
    doc.append(" * ");
    doc.append(text, " * ");
    doc.newLine();
    doc.append(" */");
    ITreeAppendable _xifexpression = null;
    boolean _isEmpty = documentationNodes.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      ITreeAppendable _xblockexpression_1 = null;
      {
        ITextRegionWithLineInformation documentationTrace = ITextRegionWithLineInformation.EMPTY_REGION;
        for (final INode node : documentationNodes) {
          documentationTrace = documentationTrace.merge(node.getTextRegionWithLineInformation());
        }
        LocationData _locationData = new LocationData(documentationTrace, null);
        appendable.trace(_locationData).append(doc.toString());
        _xblockexpression_1 = appendable.newLine();
      }
      _xifexpression = _xblockexpression_1;
    } else {
      _xifexpression = appendable.append(doc.toString()).newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #26
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getComplianceLevelArg() {
	JavaVersion javaVersion = JavaVersion.JAVA5;
	if (generatorConfigProvider != null) {
		GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
		javaVersion = generatorConfig.getJavaSourceVersion();
	}
	return javaVersion.getComplianceLevelArg();
}
 
Example #27
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the current generator config.
 *
 * @return the generator config.
 */
protected GeneratorConfig getGeneratorConfig() {
	if (this.currentGeneratorConfiguration == null) {
		this.currentGeneratorConfiguration = this.generatorConfigProvider.get(null);
	}
	return this.currentGeneratorConfiguration;
}
 
Example #28
Source File: AbstractOutputComparingCompilerTests.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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());
}
 
Example #29
Source File: GenerationContext.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the generator configuration.
 *
 * @return the configuration.
 */
public GeneratorConfig getGeneratorConfig() {
	if (this.generatorConfig == null) {
		this.generatorConfig = this.generatorConfigProvider.get(
				EcoreUtil.getRootContainer(this.contextObject));
	}
	return this.generatorConfig;
}
 
Example #30
Source File: ConfiguredCompilerTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGeneratedAnnotation_02() {
  final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null);
  generatorConfig.setGenerateSyntheticSuppressWarnings(false);
  generatorConfig.setGenerateGeneratedAnnotation(true);
  generatorConfig.setIncludeDateInGeneratedAnnotation(false);
  generatorConfig.setGeneratedAnnotationComment("Source: ${sourcefile}");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo");
  _builder.newLine();
  _builder.append("class Bar {");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("package foo;");
  _builder_1.newLine();
  _builder_1.newLine();
  {
    boolean _isJava11OrLater = AbstractXtendTestCase.isJava11OrLater();
    boolean _not = (!_isJava11OrLater);
    if (_not) {
      _builder_1.append("import javax.annotation.Generated;");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("@Generated(value = \"org.eclipse.xtend.core.compiler.XtendGenerator\", comments = \"Source: Bar.xtend\")");
      _builder_1.newLine();
    }
  }
  _builder_1.append("public class Bar {");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  this.assertCompilesTo(_builder, _builder_1);
}