use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class NonOverridableTypesProviderTest method testInheritOuterTypeParam.
@Test
public void testInheritOuterTypeParam() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("import types.OuterClass");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo<MiddleClass, T> extends OuterClass<String> {");
_builder.newLine();
_builder.append("\t");
_builder.append("def <MiddleClass> foo() ");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar()");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendClass xtendClass = this.clazz(_builder.toString());
final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
this.assertTypeInScope("Foo", inferredType);
this.assertTypeInScope("MiddleClass", inferredType);
this.assertNotInScope("MiddleClass.InnerMostClass", inferredType);
this.assertTypeParameterInScope("T", inferredType);
this.assertNotInScope("OuterClass", inferredType);
final XtendMember method = xtendClass.getMembers().get(0);
final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
this.assertTypeInScope("Foo", operation);
this.assertTypeParameterInScope("MiddleClass", operation);
this.assertTypeParameterInScope("T", operation);
this.assertNotInScope("MiddleClass.InnerMostClass", operation);
this.assertNotInScope("OuterClass", operation);
final XtendMember method2 = xtendClass.getMembers().get(0);
final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
this.assertTypeInScope("Foo", operation2);
this.assertTypeParameterInScope("MiddleClass", operation2);
this.assertTypeParameterInScope("T", operation2);
this.assertNotInScope("MiddleClass.InnerMostClass", operation2);
this.assertNotInScope("OuterClass", operation2);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class JavaConverterTest method testStaticAccessCase.
@Test
public void testStaticAccessCase() throws Exception {
this.j2x.useRobustSyntax();
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class Test2 {");
_builder.newLine();
_builder.append("\t");
_builder.append("URI getURI(){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("int i = URI.FRAGMENT_FIRST_SEPARATOR;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("if(URI.FRAGMENT_FIRST_SEPARATOR==0) return null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return URI.createURI(\"myURI\")");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("static class URI {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("static int FRAGMENT_FIRST_SEPARATOR=0;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("static URI createURI(String str) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return (URI)null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
XtendClass xtendClazz = this.toValidXtendClass(_builder);
XtendFunction xtendMember = this.method(xtendClazz, 0);
Assert.assertEquals("getURI", xtendMember.getName());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class JavaConverterTest method testNonFinalMethodParameterCase_01.
@Test
public void testNonFinalMethodParameterCase_01() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class JavaToConvert {");
_builder.newLine();
_builder.append("\t");
_builder.append("public boolean visit(Object node, Object node2, int[] array, int[] array2, String... varArgs) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("node = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("node2 = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("array[0] = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("array2 = null");
_builder.newLine();
_builder.append("\t\t");
_builder.append("varArgs = null");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return true;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
XtendClass xtendClazz = this.toValidXtendClass(_builder);
XtendFunction xtendMember = this.method(xtendClazz, 0);
Assert.assertEquals(JvmVisibility.PUBLIC, xtendMember.getVisibility());
Assert.assertEquals("node_finalParam_", xtendMember.getParameters().get(0).getName());
Assert.assertEquals("node2_finalParam_", xtendMember.getParameters().get(1).getName());
Assert.assertEquals("array", xtendMember.getParameters().get(2).getName());
Assert.assertEquals("array2_finalParam_", xtendMember.getParameters().get(3).getName());
Assert.assertEquals("varArgs_finalParam_", xtendMember.getParameters().get(4).getName());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ValueConverterExceptionProducesErrorTest method assertLiteral.
private void assertLiteral(final String expectation, final Resource resource) {
EObject _head = IterableExtensions.<EObject>head(resource.getContents());
final XtendFile file = ((XtendFile) _head);
final XtendTypeDeclaration type = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(type.getMembers());
final XtendFunction method = ((XtendFunction) _head_1);
XExpression _expression = method.getExpression();
final RichString body = ((RichString) _expression);
XExpression _head_2 = IterableExtensions.<XExpression>head(body.getExpressions());
final RichStringLiteral singleElement = ((RichStringLiteral) _head_2);
Assert.assertEquals(expectation, singleElement.getValue());
}
use of org.eclipse.xtend.core.xtend.XtendFunction 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));
}
Aggregations