use of org.eclipse.xtext.common.types.JvmConstructor 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.JvmConstructor in project xtext-xtend by eclipse.
the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_5.
@Test
public void testResolveAnonymousClassConstructorCall_5() throws Exception {
String model = "class Foo { val bar = new Bar() {} } class Bar { new(String x) {} }";
XtendFile file = file(model);
XtextResource resource = (XtextResource) file.eResource();
EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
assertTrue(constructor instanceof JvmConstructor);
assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
assertEquals(1, ((JvmConstructor) constructor).getParameters().size());
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_2.
@Test
public void testResolveAnonymousClassConstructorCall_2() throws Exception {
String model = "class Foo { val bar = new Bar() {} } class Bar { new(String x) {} new() {} }";
XtendFile file = file(model);
XtextResource resource = (XtextResource) file.eResource();
EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
assertTrue(constructor instanceof JvmConstructor);
assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class EObjectLocationTests method testFullLocationInFile.
@Test
public void testFullLocationInFile() throws Exception {
String model = "class Foo extends Object { def Foo foo() {this }}";
XtendClass clazz = clazz(model);
JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredType));
JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredConstructor));
XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
assertEquals(locationInFileProvider.getFullTextRegion(xtendFunction), locationInFileProvider.getFullTextRegion(inferredOperation));
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_1.
@Test
public void testResolveAnonymousClassConstructorCall_1() throws Exception {
String model = "class Foo { val bar = new Bar() {} } class Bar {}";
XtendFile file = file(model);
XtextResource resource = (XtextResource) file.eResource();
EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
assertTrue(constructor instanceof JvmConstructor);
assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
}
Aggregations