use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class AbstractAssignabilityTest method testIsAssignable.
public boolean testIsAssignable(final LightweightTypeReference lhs, final LightweightTypeReference rhs) {
Assert.assertTrue(this.doIsAssignable(lhs, lhs));
Assert.assertTrue(this.doIsAssignable(lhs, this.toLightweightTypeReference(lhs.toTypeReference())));
Assert.assertTrue(this.doIsAssignable(rhs, this.toLightweightTypeReference(rhs.toTypeReference())));
final boolean result = this.doIsAssignable(lhs, rhs);
boolean _isPrimitiveVoid = rhs.isPrimitiveVoid();
boolean _not = (!_isPrimitiveVoid);
if (_not) {
final WildcardTypeReference wcRhs = this.getOwner().newWildcardTypeReference();
wcRhs.addUpperBound(rhs.getWrapperTypeIfPrimitive());
Assert.assertEquals(Boolean.valueOf(result), Boolean.valueOf(this.doIsAssignable(lhs, wcRhs)));
final CompoundTypeReference compoundRhs = this.getOwner().newCompoundTypeReference(true);
compoundRhs.addComponent(rhs);
final JvmType object = rhs.getOwner().getServices().getTypeReferences().findDeclaredType(Object.class, rhs.getOwner().getContextResourceSet());
compoundRhs.addComponent(rhs.getOwner().newParameterizedTypeReference(object));
String _plus = (lhs + " := ");
String _string = compoundRhs.toString();
String _plus_1 = (_plus + _string);
Assert.assertEquals(_plus_1, Boolean.valueOf(result), Boolean.valueOf(this.doIsAssignable(lhs, compoundRhs)));
}
return result;
}
use of org.eclipse.xtext.common.types.JvmType 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.JvmType in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method getJavaType.
protected Class<?> getJavaType(final JvmType type, final ClassFinder classFinder) throws ClassNotFoundException {
if ((type instanceof JvmArrayType)) {
JvmType t = type;
String dimensions = "";
while ((t instanceof JvmArrayType)) {
{
dimensions = (dimensions + "[]");
t = ((JvmArrayType) t).getComponentType();
}
}
final Class<?> componentClass = this.getJavaType(t, classFinder);
String _name = componentClass.getName();
String _plus = (_name + dimensions);
return classFinder.forName(_plus);
}
String _identifier = type.getIdentifier();
boolean _equals = Objects.equal(_identifier, "java.lang.Class");
if (_equals) {
return JvmTypeReference.class;
}
if ((type instanceof JvmEnumerationType)) {
return JvmEnumerationLiteral.class;
}
if ((type instanceof JvmAnnotationType)) {
return XAnnotation.class;
}
return classFinder.forName(type.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XAnnotationExtensions method getProcessorType.
public JvmType getProcessorType(final JvmAnnotationType it) {
final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> {
JvmAnnotationType _annotation = it_1.getAnnotation();
String _identifier = null;
if (_annotation != null) {
_identifier = _annotation.getIdentifier();
}
String _name = Active.class.getName();
return Boolean.valueOf(Objects.equal(_identifier, _name));
};
final JvmAnnotationReference activeAnnotation = IterableExtensions.<JvmAnnotationReference>findFirst(it.getAnnotations(), _function);
final Function1<JvmAnnotationValue, Boolean> _function_1 = (JvmAnnotationValue it_1) -> {
return Boolean.valueOf(((it_1.getOperation() == null) || Objects.equal(it_1.getOperation().getSimpleName(), "value")));
};
final JvmAnnotationValue annoVal = IterableExtensions.<JvmAnnotationValue>findFirst(activeAnnotation.getValues(), _function_1);
boolean _matched = false;
if (annoVal instanceof JvmTypeAnnotationValue) {
_matched = true;
JvmTypeReference _head = IterableExtensions.<JvmTypeReference>head(((JvmTypeAnnotationValue) annoVal).getValues());
JvmType _type = null;
if (_head != null) {
_type = _head.getType();
}
return _type;
}
if (!_matched) {
if (annoVal instanceof JvmCustomAnnotationValue) {
_matched = true;
EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) annoVal).getValues());
JvmOperation _operation = ((JvmCustomAnnotationValue) annoVal).getOperation();
JvmTypeReference _returnType = null;
if (_operation != null) {
_returnType = _operation.getReturnType();
}
final Object type = this.constantExpressionsInterpreter.evaluate(((XExpression) _head), _returnType);
if ((type instanceof JvmTypeReference)) {
return ((JvmTypeReference) type).getType();
}
}
}
return null;
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class AnnotationReferenceBuildContextImpl method throwNotApplicable.
protected void throwNotApplicable(final JvmAnnotationValue it, final String valueType) {
JvmTypeReference _returnType = it.getOperation().getReturnType();
JvmType _type = null;
if (_returnType != null) {
_type = _returnType.getType();
}
String _isNotApplicableMessage = ConditionUtils.isNotApplicableMessage(valueType, this.getAnnotationValueTypeName(_type));
throw new IllegalArgumentException(_isNotApplicableMessage);
}
Aggregations