Search in sources :

Example 1 with GeneratorConfig

use of org.eclipse.xtext.xbase.compiler.GeneratorConfig in project xtext-eclipse by eclipse.

the class EclipseGeneratorConfigProvider method get.

@Override
public GeneratorConfig get(EObject context) {
    GeneratorConfig result = new GeneratorConfig();
    IProject project = null;
    if (context.eResource() != null) {
        Pair<IStorage, IProject> pair = Iterables.getFirst(storage2UriMapper.getStorages(context.eResource().getURI()), null);
        if (pair != null) {
            project = pair.getSecond();
        }
    }
    xbaseBuilderPreferenceAccess.loadBuilderPreferences(result, project);
    return result;
}
Also used : GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject)

Example 2 with GeneratorConfig

use of org.eclipse.xtext.xbase.compiler.GeneratorConfig in project xtext-xtend by eclipse.

the class ConfiguredCompilerTest method testGeneratedAnnotation_01.

@Test
public void testGeneratedAnnotation_01() {
    final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null);
    generatorConfig.setGenerateSyntheticSuppressWarnings(false);
    generatorConfig.setGenerateGeneratedAnnotation(true);
    generatorConfig.setIncludeDateInGeneratedAnnotation(false);
    generatorConfig.setGeneratedAnnotationComment("");
    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 = JavaRuntimeVersion.isJava11OrLater();
        boolean _not = (!_isJava11OrLater);
        if (_not) {
            _builder_1.append("import javax.annotation.Generated;");
            _builder_1.newLine();
            _builder_1.newLine();
            _builder_1.append("@Generated(\"org.eclipse.xtend.core.compiler.XtendGenerator\")");
            _builder_1.newLine();
        }
    }
    _builder_1.append("public class Bar {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) Test(org.junit.Test)

Example 3 with GeneratorConfig

use of org.eclipse.xtext.xbase.compiler.GeneratorConfig in project xtext-xtend by eclipse.

the class ConfiguredCompilerTest method testAnnotationWithValueArray_01.

@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);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) Test(org.junit.Test)

Example 4 with GeneratorConfig

use of org.eclipse.xtext.xbase.compiler.GeneratorConfig in project xtext-xtend by eclipse.

the class ConfiguredCompilerTest method compileWithConfiguration.

@Test
public void compileWithConfiguration() {
    final GeneratorConfig generatorConfig = this.generatorConfigProvider.get(null);
    generatorConfig.setGenerateSyntheticSuppressWarnings(false);
    generatorConfig.setGenerateExpressions(false);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* javadoc");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("class Bar {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(){");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("1 + 1");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package foo;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("/**");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("* javadoc");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("*/");
    _builder_1.newLine();
    _builder_1.append("public class Bar {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public int foo() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("throw new UnsupportedOperationException(\"foo is not implemented\");");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) Test(org.junit.Test)

Example 5 with GeneratorConfig

use of org.eclipse.xtext.xbase.compiler.GeneratorConfig in project xtext-xtend by eclipse.

the class ConfiguredCompilerTest method testAnnotationWithValueArray_02.

@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);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) Test(org.junit.Test)

Aggregations

GeneratorConfig (org.eclipse.xtext.xbase.compiler.GeneratorConfig)19 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 Test (org.junit.Test)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 IGeneratorConfigProvider (org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IStorage (org.eclipse.core.resources.IStorage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IXtendJvmAssociations (org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations)1 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 XtendInterface (org.eclipse.xtend.core.xtend.XtendInterface)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 Check (org.eclipse.xtext.validation.Check)1