use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class AbstractAssignabilityTest method isAssignableFrom.
public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def ");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue());
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("<");
String _value = lhsAndParams.getValue();
_builder.append(_value);
_builder.append("> ");
}
}
_builder.append("void method(");
String _fixup = this.fixup(lhsAndParams.getKey());
_builder.append(_fixup);
_builder.append(" lhs, ");
String _fixup_1 = this.fixup(rhs);
_builder.append(_fixup_1);
_builder.append(" rhs) {}");
final String signature = _builder.toString();
final XtendFunction function = this.function(signature.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
LightweightTypeReference _xifexpression = null;
String _key = lhsAndParams.getKey();
boolean _tripleNotEquals = (_key != null);
if (_tripleNotEquals) {
_xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
} else {
_xifexpression = this.getOwner().newAnyTypeReference();
}
final LightweightTypeReference lhsType = _xifexpression;
LightweightTypeReference _xifexpression_1 = null;
if ((rhs != null)) {
_xifexpression_1 = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
} else {
_xifexpression_1 = this.getOwner().newAnyTypeReference();
}
final LightweightTypeReference rhsType = _xifexpression_1;
String _simpleName = lhsType.getSimpleName();
String _plus = (_simpleName + " := ");
String _simpleName_1 = rhsType.getSimpleName();
String _plus_1 = (_plus + _simpleName_1);
Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(lhsType, rhsType)));
if (expectation) {
List<LightweightTypeReference> _allSuperTypes = lhsType.getAllSuperTypes();
for (final LightweightTypeReference superType : _allSuperTypes) {
if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(superType, rhsType)));
}
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class AbstractTestingTypeReferenceOwner method function.
@Override
protected XtendFunction function(final String string) throws Exception {
final XtendFunction result = super.function(string);
this.contextResourceSet = result.eResource().getResourceSet();
this.owner = this.createOwner();
return result;
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ActualTypeArgumentMergeTest method mappedBy.
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def ");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("<");
_builder.append(typeParameters);
_builder.append(">");
}
}
_builder.append(" void method(");
final Function1<String, CharSequence> _function = (String it) -> {
return it;
};
String _join = IterableExtensions.<String>join(((Iterable<String>) Conversions.doWrapArray(alternatingTypeReferences)), null, " p, ", " p", _function);
_builder.append(_join);
_builder.append(") {}");
final String signature = _builder.toString();
final XtendFunction function = this.function(signature.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
EList<JvmTypeParameter> _typeParameters = operation.getTypeParameters();
ITypeReferenceOwner _owner = this.getOwner();
final ActualTypeArgumentCollector collector = new ActualTypeArgumentCollector(_typeParameters, BoundTypeArgumentSource.INFERRED, _owner);
int _size = ((List<String>) Conversions.doWrapArray(alternatingTypeReferences)).size();
int _minus = (_size - 1);
IntegerRange _withStep = new IntegerRange(0, _minus).withStep(2);
for (final Integer i : _withStep) {
collector.populateTypeParameterMapping(this.toLightweightTypeReference(operation.getParameters().get((i).intValue()).getParameterType()), this.toLightweightTypeReference(operation.getParameters().get(((i).intValue() + 1)).getParameterType()));
}
return collector.getTypeParameterMapping();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class DispatchHelper method getDispatcherOperation.
/* @Nullable */
public JvmOperation getDispatcherOperation(JvmOperation dispatchCase) {
EObject sourceElement = associations.getPrimarySourceElement(dispatchCase);
if (sourceElement instanceof XtendFunction) {
XtendFunction function = (XtendFunction) sourceElement;
if (function.isDispatch()) {
Iterable<JvmOperation> operations = filter(associations.getJvmElements(sourceElement), JvmOperation.class);
for (JvmOperation operation : operations) {
if (Strings.equal(operation.getSimpleName(), function.getName())) {
return operation;
}
}
}
} else {
DispatchSignature signature = new DispatchSignature(dispatchCase.getSimpleName().substring(1), dispatchCase.getParameters().size());
JvmOperation result = getDispatcherOperation(dispatchCase.getDeclaringType(), signature);
return result;
}
return null;
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
for (JvmTypeReference intf : source.getExtends()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
transform(member, inferredJvmType, false);
}
}
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
Aggregations