Java Code Examples for org.eclipse.xtext.xbase.XVariableDeclaration#getType()
The following examples show how to use
org.eclipse.xtext.xbase.XVariableDeclaration#getType() .
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: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected LightweightTypeReference appendVariableTypeAndName(XVariableDeclaration varDeclaration, ITreeAppendable appendable) { if (!varDeclaration.isWriteable()) { appendable.append("final "); } LightweightTypeReference type = null; if (varDeclaration.getType() != null) { serialize(varDeclaration.getType(), varDeclaration, appendable); type = getLightweightType((JvmIdentifiableElement) varDeclaration); } else { type = getLightweightType(varDeclaration.getRight()); if (type.isAny()) { type = getTypeForVariableDeclaration(varDeclaration.getRight()); } appendable.append(type); } appendable.append(" "); appendable.append(appendable.declareVariable(varDeclaration, makeJavaIdentifier(varDeclaration.getName()))); return type; }
Example 2
Source File: PyExpressionGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** 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 3
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Check public void checkVariableIsNotInferredAsVoid(XVariableDeclaration declaration) { if (declaration.getType() != null) return; LightweightTypeReference variableType = typeResolver.resolveTypes(declaration).getActualType((JvmIdentifiableElement) declaration); // TODO move to type resolver if (variableType != null && variableType.isPrimitiveVoid()) { error("void is an invalid type for the variable " + declaration.getName(), declaration, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, INVALID_USE_OF_TYPE); } }
Example 4
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Check public void checkVariableDeclaration(XVariableDeclaration declaration) { if (declaration.getRight() == null) { if (!declaration.isWriteable()) error("Value must be initialized", Literals.XVARIABLE_DECLARATION__WRITEABLE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_INITIALIZATION); if (declaration.getType() == null) error("Type cannot be derived", Literals.XVARIABLE_DECLARATION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_TYPE); } }
Example 5
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * @param assignment unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ protected Object _assignValueTo(XVariableDeclaration variable, XAbstractFeatureCall assignment, Object value, IEvaluationContext context, CancelIndicator indicator) { if (variable.getType() != null) { JvmTypeReference type = variable.getType(); Object coerced = coerceArgumentType(value, type); context.assignValue(QualifiedName.create(variable.getName()), coerced); } else { context.assignValue(QualifiedName.create(variable.getName()), value); } return value; }
Example 6
Source File: UIStringsTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testReferenceToString_3() throws Exception { XExpression expr = expression("{ var foo.String x }", false); assertNotNull(expr); XVariableDeclaration declaration = (XVariableDeclaration) (((XBlockExpression) expr).getExpressions().get(0)); JvmTypeReference reference = declaration.getType(); assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value")); }
Example 7
Source File: XsemanticsTypeSystemGen.java From xsemantics with Eclipse Public License 1.0 | 4 votes |
private JvmTypeReference _applyRuleXVariableDeclarationType_1(final RuleEnvironment G, final XVariableDeclaration e) throws RuleFailedException { JvmTypeReference _type = e.getType(); return _type; }