use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class AssignmentFeatureCallArgumentsTest method toArguments.
protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def void m(");
_builder.append(type);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(expression, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
final String functionString = _builder.toString();
final XtendFunction function = this.function(functionString);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions());
JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters());
JvmTypeReference _parameterType = null;
if (_head != null) {
_parameterType = _head.getParameterType();
}
final JvmTypeReference declaredType = _parameterType;
if ((declaredType != null)) {
LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType);
return new AssignmentFeatureCallArguments(value, _lightweightTypeReference);
} else {
return new AssignmentFeatureCallArguments(value, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_02.
@Test
public void testAnonymousClass_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_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(JvmVisibility.DEFAULT, anonymous.getVisibility());
Assert.assertEquals(2, anonymous.getSuperTypes().size());
Assert.assertEquals("java.lang.Runnable", 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).getParameters().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.JvmTypeReference in project xtext-xtend by eclipse.
the class JvmModelTests method testClassImplicitSuperType.
@Test
public void testClassImplicitSuperType() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmGenericType inferred = this._iXtendJvmAssociations.getInferredType(this.clazz(_builder.toString()));
Assert.assertEquals(1, inferred.getSuperTypes().size());
Assert.assertEquals("java.lang.Object", IterableExtensions.<JvmTypeReference>head(inferred.getSuperTypes()).getIdentifier());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method _internalEvaluate.
protected Object _internalEvaluate(final XFeatureCall it, final Context ctx) {
Object _eGet = it.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, this.isResolveProxies(it));
final EObject feature = ((EObject) _eGet);
boolean _eIsProxy = feature.eIsProxy();
boolean _not = (!_eIsProxy);
if (_not) {
Object _switchResult = null;
boolean _matched = false;
if (feature instanceof JvmEnumerationLiteral) {
_matched = true;
_switchResult = feature;
}
if (!_matched) {
if (feature instanceof JvmField) {
_matched = true;
_switchResult = this.evaluateField(it, ((JvmField) feature), ctx);
}
}
if (!_matched) {
if (feature instanceof JvmType) {
_matched = true;
_switchResult = this.toTypeReference(((JvmType) feature), 0);
}
}
return _switchResult;
}
final String featureName = it.getConcreteSyntaxFeatureName();
JvmType _switchResult_1 = null;
JvmTypeReference _expectedType = ctx.getExpectedType();
final JvmTypeReference it_1 = _expectedType;
boolean _matched_1 = false;
if (it_1 instanceof XComputedTypeReferenceImplCustom) {
boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) it_1).isEquivalentComputed();
if (_isEquivalentComputed) {
_matched_1 = true;
_switchResult_1 = ((XComputedTypeReferenceImplCustom) it_1).getType();
}
}
if (!_matched_1) {
if (it_1 instanceof XComputedTypeReference) {
_matched_1 = true;
}
if (!_matched_1) {
if ((it_1 == null)) {
_matched_1 = true;
}
}
if (_matched_1) {
_switchResult_1 = null;
}
}
if (!_matched_1) {
_switchResult_1 = it_1.getType();
}
final JvmType expectedRawType = _switchResult_1;
Map<String, JvmIdentifiableElement> _xifexpression = null;
boolean _isEnumExpectationInAnnotationValue = this.isEnumExpectationInAnnotationValue(it, expectedRawType);
if (_isEnumExpectationInAnnotationValue) {
HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
{
JvmEnumerationType _switchResult_2 = null;
boolean _matched_2 = false;
if (expectedRawType instanceof JvmEnumerationType) {
_matched_2 = true;
_switchResult_2 = ((JvmEnumerationType) expectedRawType);
}
if (!_matched_2) {
if (expectedRawType instanceof JvmArrayType) {
_matched_2 = true;
JvmComponentType _componentType = ((JvmArrayType) expectedRawType).getComponentType();
_switchResult_2 = ((JvmEnumerationType) _componentType);
}
}
final JvmEnumerationType enumType = _switchResult_2;
Map<String, JvmIdentifiableElement> _visibleFeatures = ctx.getVisibleFeatures();
final HashMap<String, JvmIdentifiableElement> copy = new HashMap<String, JvmIdentifiableElement>(_visibleFeatures);
final Consumer<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_2) -> {
copy.put(it_2.getSimpleName(), it_2);
};
enumType.getLiterals().forEach(_function);
_xblockexpression = copy;
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = ctx.getVisibleFeatures();
}
final Map<String, JvmIdentifiableElement> visibleFeatures = _xifexpression;
boolean _containsKey = visibleFeatures.containsKey(featureName);
if (_containsKey) {
Object _switchResult_2 = null;
JvmIdentifiableElement _get = visibleFeatures.get(featureName);
final JvmIdentifiableElement visibleFeature = _get;
boolean _matched_2 = false;
if (visibleFeature instanceof JvmEnumerationLiteral) {
_matched_2 = true;
JvmEnumerationLiteral _xblockexpression_1 = null;
{
this.resolveFeature(it, visibleFeature);
_xblockexpression_1 = ((JvmEnumerationLiteral) visibleFeature);
}
_switchResult_2 = _xblockexpression_1;
}
if (!_matched_2) {
if (visibleFeature instanceof JvmField) {
_matched_2 = true;
Object _xblockexpression_1 = null;
{
this.resolveFeature(it, visibleFeature);
_xblockexpression_1 = this.evaluateField(it, ((JvmField) visibleFeature), ctx);
}
_switchResult_2 = _xblockexpression_1;
}
}
return _switchResult_2;
}
final JvmType type = this.findTypeByName(it, featureName);
if ((type != null)) {
this.resolveType(it, type);
return this.toTypeReference(type, 0);
}
throw new UnresolvableFeatureException(("Couldn\'t resolve feature " + featureName), it);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method evaluateField.
protected Object evaluateField(final XAbstractFeatureCall call, final JvmField field, final Context context) {
if ((field.isSetConstant() || (field.eResource() instanceof TypeResource))) {
boolean _isConstant = field.isConstant();
if (_isConstant) {
return field.getConstantValue();
} else {
String _simpleName = field.getDeclaringType().getSimpleName();
String _plus = ("Field " + _simpleName);
String _plus_1 = (_plus + ".");
String _simpleName_1 = field.getSimpleName();
String _plus_2 = (_plus_1 + _simpleName_1);
String _plus_3 = (_plus_2 + " is not a constant");
throw new ConstantExpressionEvaluationException(_plus_3);
}
}
final XExpression expression = this.containerProvider.getAssociatedExpression(field);
boolean _contains = context.getAlreadyEvaluating().contains(expression);
if (_contains) {
throw new ConstantExpressionEvaluationException("Endless recursive evaluation detected.");
}
try {
final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
JvmTypeReference _type = field.getType();
ClassFinder _classFinder = context.getClassFinder();
Set<XExpression> _alreadyEvaluating = context.getAlreadyEvaluating();
final Context ctx = new Context(_type, _classFinder, visibleFeatures, _alreadyEvaluating);
return this.evaluate(expression, ctx);
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
throw new StackedConstantExpressionEvaluationException(call, field, e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
Aggregations