Java Code Examples for org.eclipse.xtext.xbase.XVariableDeclaration#getRight()

The following examples show how to use org.eclipse.xtext.xbase.XVariableDeclaration#getRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Generate the given object.
 *
 * @param varDeclaration the variable declaration.
 * @param it the target for the generated content.
 * @param context the context.
 * @return the statement.
 */
protected XExpression _generate(XVariableDeclaration varDeclaration, IAppendable it, IExtraLanguageGeneratorContext context) {
	final String name = it.declareUniqueNameVariable(varDeclaration, varDeclaration.getName());
	it.append(name);
	it.append(" = "); //$NON-NLS-1$
	if (varDeclaration.getRight() != null) {
		generate(varDeclaration.getRight(), it, context);
	} else if (varDeclaration.getType() != null) {
		it.append(toDefaultValue(varDeclaration.getType()));
	} else {
		it.append("None"); //$NON-NLS-1$
	}
	if (context.getExpectedExpressionType() != null) {
		it.newLine();
		it.append("return ").append(name); //$NON-NLS-1$
	}
	return varDeclaration;
}
 
Example 2
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/** 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"));
}
 
Example 3
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testRecursiveClosure_02() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val (int)=>int fun = [ self.apply(it) ] }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XClosure closure = (XClosure) variable.getRight();
	XBlockExpression body = (XBlockExpression) closure.getExpression();
	XMemberFeatureCall member = (XMemberFeatureCall) body.getExpressions().get(0);
	XFeatureCall recursive = (XFeatureCall) member.getMemberCallTarget();
	assertEquals(Functions.Function1.class.getName(), recursive.getFeature().getQualifiedName('$'));
}
 
Example 4
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Ignore("TODO eager binding of type arguments to expectation")
@Test public void testStaticFeatureCall_26() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<CharSequence> iterable = testdata.MethodOverrides4.staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides3.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 5
Source File: BeforeLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testImplicitLambdaParameter() throws Exception {
	XBlockExpression block = (XBlockExpression) parseHelper.parse("{ val Comparable<String> c = [ length ] c.toString } ");
	BatchLinkableResource resource = (BatchLinkableResource) block.eResource();
	resource.resolveLazyCrossReferences(null);
	XVariableDeclaration assignment = (XVariableDeclaration) Iterables.getFirst(block.getExpressions(), null);
	XClosure lambda = (XClosure) assignment.getRight();
	JvmFormalParameter implicitParameter = Iterables.getFirst(lambda.getImplicitFormalParameters(), null);
	Assert.assertEquals("String", implicitParameter.getParameterType().getSimpleName());
	resource.update(0, 0, "");
	Assert.assertNull(implicitParameter.eResource());
}
 
Example 6
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/** Only the simple name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_1() throws Exception {
	XtendFile file1 = 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");
	assertNotNull(file1);
	XtendFile file2 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
	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());
	assertTrue(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
Example 7
Source File: XbaseExpectedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testTypeParamInference_09() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ var this = new testdata.ClosureClient() var Integer i = invoke1([e|null],'foo') }");
	XVariableDeclaration var = (XVariableDeclaration) block.getExpressions().get(1);
	XFeatureCall fc = (XFeatureCall) var.getRight();
	final XExpression closure = fc.getFeatureCallArguments().get(0);
	assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String, java.lang.Integer>", closure);
}
 
Example 8
Source File: XbaseExpectedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testTypeParamInference_04() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ var Integer i = new testdata.ClosureClient().invoke1([e|null],'foo') }");
	XVariableDeclaration var = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall fc = (XMemberFeatureCall) var.getRight();
	final XExpression closure = fc.getMemberCallArguments().get(0);
	assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String, java.lang.Integer>", closure);
}
 
Example 9
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Object _doEvaluate(XVariableDeclaration variableDecl, IEvaluationContext context, CancelIndicator indicator) {
	Object initialValue = null;
	if (variableDecl.getRight()!=null) {
		initialValue = internalEvaluate(variableDecl.getRight(), context, indicator);
	} else {
		if (services.getPrimitives().isPrimitive(variableDecl.getType())) {
			Primitive primitiveKind = services.getPrimitives().primitiveKind((JvmPrimitiveType) variableDecl.getType().getType());
			switch(primitiveKind) {
				case Boolean:
					initialValue = Boolean.FALSE; break;
				case Char:
					initialValue = Character.valueOf((char) 0); break;
				case Double:
					initialValue = Double.valueOf(0d); break;
				case Byte:
					initialValue = Byte.valueOf((byte) 0); break;
				case Float:
					initialValue = Float.valueOf(0f); break;
				case Int:
					initialValue = Integer.valueOf(0); break;
				case Long:
					initialValue = Long.valueOf(0L); break;
				case Short:
					initialValue = Short.valueOf((short) 0); break;
				case Void:
					throw new IllegalStateException("Void is not a valid variable type.");
				default:
					throw new IllegalStateException("Unknown primitive type " + primitiveKind);
			}
		}
	}
	context.newValue(QualifiedName.create(variableDecl.getName()), initialValue);
	return null;
}
 
Example 10
Source File: XbaseExpectedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testConstructorCall_01() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ var java.util.List<String> list = new java.util.ArrayList() }");
	XVariableDeclaration variableDeclaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall constructorCall = (XConstructorCall) variableDeclaration.getRight();
	assertExpected("java.util.List<java.lang.String>", constructorCall);
}
 
Example 11
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_30() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val boolean x = nested.NestedTypes.isInterface}");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("nested.NestedTypes.isInterface()", featureCall.getFeature().getIdentifier());
}
 
Example 12
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_29() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val int x = nested.NestedTypes.array }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("nested.NestedTypes$array", featureCall.getFeature().getIdentifier());
}
 
Example 13
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_07() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<java.io.Serializable> iterable = testdata::MethodOverrides4::staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 14
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_28() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<Object> iterable = testdata.MethodOverrides4.staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 15
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_09() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<Object> iterable = testdata::MethodOverrides4::staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 16
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_27() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<Object> iterable = testdata.MethodOverrides4.staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 17
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_16() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<java.io.Serializable> iterable = testdata.MethodOverrides4::staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 18
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_25() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<java.io.Serializable> iterable = testdata.MethodOverrides4.staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 19
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_18() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val Iterable<Object> iterable = testdata.MethodOverrides4::staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}
 
Example 20
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testStaticFeatureCall_24() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ val iterable = testdata.MethodOverrides4.staticM5(null) }");
	XVariableDeclaration variable = (XVariableDeclaration) block.getExpressions().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) variable.getRight();
	assertEquals("testdata.MethodOverrides4.staticM5(T)", featureCall.getFeature().getIdentifier());
}