Search in sources :

Example 21 with StandardTypeReferenceOwner

use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner in project xtext-xtend by eclipse.

the class DocumentRewriterTest method testInsertTypesImportsSorted.

@Test
public void testInsertTypesImportsSorted() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.io.Serializable");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo implements Serializable {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
        final DocumentRewriter.Section beforeFoo = it.newSection(model.indexOf("foo"), 0);
        final DocumentRewriter.Section beforeBar = it.newSection(model.indexOf("bar"), 0);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, r);
        final JvmTypeReference list = this.services.getTypeReferences().getTypeForName(List.class, r, this._typesFactory.createJvmWildcardTypeReference());
        beforeFoo.append(owner.toLightweightTypeReference(list));
        beforeBar.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(File.class, r)));
        beforeFoo.append(" ");
        beforeBar.append(" ");
    };
    String _rewrite = this.rewrite(model, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.io.File");
    _builder_1.newLine();
    _builder_1.append("import java.io.Serializable");
    _builder_1.newLine();
    _builder_1.append("import java.util.List");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo implements Serializable {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<?> foo() {}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def File bar() {}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.andExpect(_rewrite, _builder_1);
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) DocumentRewriter(org.eclipse.xtext.xbase.ui.document.DocumentRewriter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 22 with StandardTypeReferenceOwner

use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner in project xtext-xtend by eclipse.

the class DocumentRewriterTest method testInsertTypesWithOverlappingImports.

@Test
public void testInsertTypesWithOverlappingImports() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
        final DocumentRewriter.Section beforeFoo = it.newSection(model.indexOf("foo"), 0);
        final DocumentRewriter.Section beforeBar = it.newSection(model.indexOf("bar"), 0);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, r);
        beforeFoo.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(List.class, r, this.services.getTypeReferences().getTypeForName(String.class, r))));
        beforeBar.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(List.class, r, this.services.getTypeReferences().getTypeForName(File.class, r))));
        beforeFoo.append(" ");
        beforeBar.append(" ");
    };
    String _rewrite = this.rewrite(model, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.io.File");
    _builder_1.newLine();
    _builder_1.append("import java.util.List");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<String> foo() {}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<File> bar() {}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.andExpect(_rewrite, _builder_1);
}
Also used : DocumentRewriter(org.eclipse.xtext.xbase.ui.document.DocumentRewriter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) Test(org.junit.Test)

Aggregations

StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)22 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 ParameterizedTypeReference (org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 CommonTypeComputationServices (org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices)4 Injector (com.google.inject.Injector)3 List (java.util.List)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 XbaseStandaloneSetup (org.eclipse.xtext.xbase.XbaseStandaloneSetup)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2