Search in sources :

Example 96 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredFunctionWithSelfTypeReference.

@Test
public void testInferredFunctionWithSelfTypeReference() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def Foo bar() { this } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals(inferredType, jvmOperation.getReturnType().getType());
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals(inferredType, xtendFunction.getReturnType().getType());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 97 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredJvmType.

@Test
public void testInferredJvmType() throws Exception {
    XtendFile xtendFile = file("class Foo { }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    assertEquals(associations.getInferredType(xtendClass), inferredType);
    assertEquals(xtendClass, associations.getXtendClass(inferredType));
    assertEquals(JvmVisibility.PUBLIC, inferredType.getVisibility());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 98 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testInferredFunctionWithReturnType_02.

@Test
public void testInferredFunctionWithReturnType_02() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<String> create result: newArrayList newList() {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType());
    assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 99 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class TestCaseCompiler method compile.

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);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmModelGenerator(org.eclipse.xtext.xbase.compiler.JvmModelGenerator) FileWriter(java.io.FileWriter) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) IGeneratorConfigProvider(org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider) IXtendJvmAssociations(org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations) File(java.io.File) XtendFile(org.eclipse.xtend.core.xtend.XtendFile)

Example 100 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.

the class DispatchHelperTest method testVisibility_00.

@Test
public void testVisibility_00() throws Exception {
    XtendClass superClazz = clazz("class Super {\n" + "  def private dispatch foo(Object x) {} \n" + "}");
    Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
    subResource.load(new StringInputStream("class Sub extends Super {\n" + "  def dispatch foo(String x) {}\n" + "  def dispatch foo(Number x) {}\n" + "}"), null);
    JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
    assertEquals(2, list.size());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15