use of org.eclipse.xtext.xbase.XVariableDeclaration in project xtext-xtend by eclipse.
the class ParserTest method testRichStringFOR_03.
@Test
public void testRichStringFOR_03() throws Exception {
XtendFunction function = function("def withForLoop(String it) '''�it��val it = 1..10��FOR i: it SEPARATOR it��ENDFOR�'''");
final RichString richString = (RichString) function.getExpression();
assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
assertTrue(richString.getExpressions().get(1) instanceof XFeatureCall);
JvmOperation operation = associations.getDirectlyInferredOperation(function);
assertSame(operation.getParameters().get(0), ((XAbstractFeatureCall) richString.getExpressions().get(1)).getFeature());
assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
assertTrue(richString.getExpressions().get(3) instanceof XVariableDeclaration);
assertTrue(richString.getExpressions().get(4) instanceof RichStringLiteral);
assertTrue(richString.getExpressions().get(5) instanceof RichStringForLoop);
final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(5);
assertTrue(rsFor.getForExpression() instanceof XFeatureCall);
assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getForExpression()).getFeature());
assertEquals("i", rsFor.getDeclaredParam().getName());
assertTrue(rsFor.getSeparator() instanceof XFeatureCall);
assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getSeparator()).getFeature());
}
use of org.eclipse.xtext.xbase.XVariableDeclaration in project xtext-xtend by eclipse.
the class UIStringsTest method testReferenceToString_0.
/**
* Only the simple name of the type is specified.
* The JvmTypeReference is not a proxy.
*/
@Test
public void testReferenceToString_0() throws Exception {
XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + " def test() {\n" + " val x = new List<ClassC>\n" + " }\n" + "}\n");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
XConstructorCall cons = (XConstructorCall) declaration.getRight();
JvmTypeReference reference = cons.getTypeArguments().get(0);
assertNotNull(reference);
assertNotNull(reference.getType());
assertFalse(reference.getType().eIsProxy());
assertNotNull(reference.eResource());
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
use of org.eclipse.xtext.xbase.XVariableDeclaration in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest_02.
@Test
public void testSignatureForAnonymousClassLocalVarTypeTest_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val r = new Runnable { override run() {} def void m() {} }");
_builder.newLine();
_builder.append("\t\t");
_builder.append("r");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XVariableDeclaration variable = ((XVariableDeclaration) _head);
final String signature = this.signatureProvider.getSignature(variable);
Assert.assertEquals("new Runnable(){} r", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XVariableDeclaration in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest_03.
@Test
public void testSignatureForAnonymousClassLocalVarTypeTest_03() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val r = newArrayList(new Runnable { override run() {} })");
_builder.newLine();
_builder.append("\t\t");
_builder.append("r");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XVariableDeclaration variable = ((XVariableDeclaration) _head);
final String signature = this.signatureProvider.getSignature(variable);
Assert.assertEquals("ArrayList<new Runnable(){}> r", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XVariableDeclaration in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest.
@Test
public void testSignatureForAnonymousClassLocalVarTypeTest() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.newLine();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def m() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val r = new Runnable { override run() {} }");
_builder.newLine();
_builder.append("\t\t");
_builder.append("r");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XVariableDeclaration variable = ((XVariableDeclaration) _head);
final String signature = this.signatureProvider.getSignature(variable);
Assert.assertEquals("new Runnable(){} r", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations