use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_03.
@Test
public void testAnonymousClass_03() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def <T> foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Iterable<T>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
this.typeResolver.resolveTypes(operation.eResource());
Assert.assertEquals(1, operation.getLocalClasses().size());
final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
Assert.assertTrue(anonymous.isFinal());
Assert.assertFalse(anonymous.isStatic());
Assert.assertTrue(anonymous.isLocal());
Assert.assertTrue(anonymous.isAnonymous());
Assert.assertEquals(0, anonymous.getTypeParameters().size());
Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
Assert.assertEquals(2, anonymous.getSuperTypes().size());
Assert.assertEquals("java.lang.Iterable<T>", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
Assert.assertEquals(2, anonymous.getMembers().size());
final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
Assert.assertTrue((constructor instanceof JvmConstructor));
Assert.assertEquals(0, ((JvmConstructor) constructor).getTypeParameters().size());
final JvmMember overriding = IterableExtensions.<JvmMember>head(anonymous.getMembers());
Assert.assertTrue((overriding instanceof JvmOperation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class JvmModelTests method testJvmTypeParameter_07.
@Test
public void testJvmTypeParameter_07() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T> String foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
final JvmOperation member = IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(clazz.getMembers(), JvmOperation.class));
EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
String _plus = ("" + _typeParameters);
Assert.assertEquals(_plus, 1, member.getTypeParameters().size());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
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);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_02.
@Test
public void testIgnoreVoidInParameterTypeInferrence_02() throws Exception {
XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Number n, Void v) {null}" + " def dispatch foo(Void ignore, Object o) {null}" + "}");
JvmGenericType type = associations.getInferredType(clazz);
JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
assertEquals("java.lang.Number", firstParameter.getParameterType().getIdentifier());
JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
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());
}
Aggregations