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 findVisibleFeatures.
/**
* looks up the static final fields which are accessible in unqualified form for the given expression.
* That essentially includes static imports and the fields declared in the containing types
*/
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
{
Resource _eResource = expression.eResource();
final Resource res = _eResource;
boolean _matched = false;
if (res instanceof StorageAwareResource) {
boolean _isLoadedFromStorage = ((StorageAwareResource) res).isLoadedFromStorage();
if (_isLoadedFromStorage) {
_matched = true;
return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
}
}
JvmDeclaredType _switchResult_1 = null;
JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
final JvmIdentifiableElement cont = _nearestLogicalContainer;
boolean _matched_1 = false;
if (cont instanceof JvmGenericType) {
_matched_1 = true;
_switchResult_1 = ((JvmGenericType) cont);
}
if (!_matched_1) {
if (cont instanceof JvmMember) {
_matched_1 = true;
_switchResult_1 = ((JvmMember) cont).getDeclaringType();
}
}
final JvmDeclaredType container = _switchResult_1;
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
Resource _eResource_1 = expression.eResource();
final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
if ((section != null)) {
EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
for (final XImportDeclaration imp : _importDeclarations) {
boolean _isStatic = imp.isStatic();
if (_isStatic) {
final String importedTypeName = imp.getImportedTypeName();
if ((importedTypeName != null)) {
final JvmType type = this.findTypeByName(imp, importedTypeName);
boolean _matched_2 = false;
if (type instanceof JvmGenericType) {
_matched_2 = true;
this.collectAllVisibleFields(((JvmDeclaredType) type), result);
}
if (!_matched_2) {
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType) type).getLiterals();
for (final JvmEnumerationLiteral feature : _literals) {
result.put(feature.getSimpleName(), feature);
}
}
}
}
}
}
}
this.collectAllVisibleFields(container, result);
return result;
};
_xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method _internalEvaluate.
protected Object _internalEvaluate(final XMemberFeatureCall 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();
try {
final Object receiver = this.evaluate(it.getMemberCallTarget(), ctx);
boolean _matched_1 = false;
if (receiver instanceof JvmTypeReference) {
_matched_1 = true;
JvmType _type = ((JvmTypeReference) receiver).getType();
final JvmType type = _type;
boolean _matched_2 = false;
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
final Function1<JvmEnumerationLiteral, Boolean> _function = (JvmEnumerationLiteral it_1) -> {
String _simpleName = it_1.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, featureName));
};
final JvmEnumerationLiteral enumValue = IterableExtensions.<JvmEnumerationLiteral>findFirst(((JvmEnumerationType) type).getLiterals(), _function);
if ((enumValue == null)) {
String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
String _plus = ((("Couldn\'t find enum value " + featureName) + " on enum ") + _simpleName);
throw new ConstantExpressionEvaluationException(_plus, it);
}
this.resolveFeature(it, enumValue);
return enumValue;
}
if (!_matched_2) {
if (type instanceof JvmGenericType) {
_matched_2 = true;
final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
String _simpleName = it_1.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, featureName));
};
final JvmField field = IterableExtensions.<JvmField>findFirst(Iterables.<JvmField>filter(((JvmGenericType) type).getAllFeatures(), JvmField.class), _function);
if ((field == null)) {
String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
String _plus = ((("Couldn\'t find field " + featureName) + " on type ") + _simpleName);
throw new ConstantExpressionEvaluationException(_plus, it);
}
this.resolveFeature(it, field);
return this.evaluateField(it, field, ctx);
}
}
}
throw new UnresolvableFeatureException(((("Unresolvable feature " + featureName) + " on ") + receiver), it);
} catch (final Throwable _t) {
if (_t instanceof UnresolvableFeatureException) {
final String typeName = this.getFullName(it);
final JvmType type = this.findTypeByName(it, typeName);
if ((type != null)) {
this.resolveType(it, type);
return this.toTypeReference(type, 0);
} else {
throw new UnresolvableFeatureException(("Unresolvable type " + typeName), it);
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class AnnotationReferenceBuildContextImpl method findOperation.
protected JvmOperation findOperation(final String name, final boolean mustBeArray) {
final JvmOperation result = this.findOperation(name);
JvmTypeReference _returnType = result.getReturnType();
JvmType _type = null;
if (_returnType != null) {
_type = _returnType.getType();
}
final JvmType returnType = _type;
boolean _and = false;
if (!mustBeArray) {
_and = false;
} else {
EClass _eClass = null;
if (returnType != null) {
_eClass = returnType.eClass();
}
boolean _notEquals = (!Objects.equal(_eClass, TypesPackage.Literals.JVM_ARRAY_TYPE));
_and = _notEquals;
}
if (_and) {
throw new IllegalArgumentException("Cannot assign array value to simple annotation property");
}
return result;
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class AbstractScope method getElements.
@Override
public final Iterable<IEObjectDescription> getElements(EObject object) {
if (!(object instanceof JvmType) || object.eIsProxy()) {
throw new IllegalArgumentException(String.valueOf(object));
}
List<IEObjectDescription> result = Lists.newLinkedList();
doGetElements((JvmType) object, result);
Iterator<IEObjectDescription> iterator = result.iterator();
while (iterator.hasNext()) {
IEObjectDescription description = iterator.next();
IEObjectDescription lookUp = getSingleElement(description.getName());
if (lookUp == null || lookUp.getEObjectOrProxy() != object) {
iterator.remove();
}
}
return result;
}
Aggregations