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 ModelExtensionsTest method testXtendFunction.
@Test
public void testXtendFunction() throws Exception {
XtendFile file = file("package foo class Bar { def int foo() {1}}");
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
assertEquals("foo", xtendFunction.getName());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XtendFormatter method formatBody.
protected ISemanticRegion formatBody(final XtendTypeDeclaration type, @Extension final IFormattableDocument format) {
ISemanticRegion _xblockexpression = null;
{
final ISemanticRegion open = this.textRegionExtensions.regionFor(type).keyword("{");
final ISemanticRegion close = this.textRegionExtensions.regionFor(type).keyword("}");
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.indent();
};
format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function);
format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
ISemanticRegion _xifexpression = null;
boolean _isEmpty = type.getMembers().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
int _size = type.getMembers().size();
int _minus = (_size - 1);
IntegerRange _upTo = new IntegerRange(0, _minus);
for (final Integer i : _upTo) {
{
final XtendMember current = type.getMembers().get((i).intValue());
format.<XtendMember>format(current);
int _size_1 = type.getMembers().size();
int _minus_1 = (_size_1 - 1);
boolean _lessThan = ((i).intValue() < _minus_1);
if (_lessThan) {
final XtendMember next = type.getMembers().get(((i).intValue() + 1));
if (((current instanceof XtendField) && (next instanceof XtendField))) {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFields);
} else {
if (((current instanceof XtendFunction) && (next instanceof XtendFunction))) {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenMethods);
} else {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFieldsAndMethods);
}
}
} else {
final XtendMember member = type.getMembers().get((i).intValue());
format.<XtendMember>append(member, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
}
}
}
} else {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
_xifexpression = format.append(open, _function_1);
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XAnnotationExtensions method getAnnotatedTarget.
public XtendAnnotationTarget getAnnotatedTarget(final XAnnotation annotation) {
XtendAnnotationTarget _switchResult = null;
EObject _eContainer = annotation.eContainer();
final EObject container = _eContainer;
boolean _matched = false;
if (container instanceof XtendAnnotationType) {
_matched = true;
}
if (!_matched) {
if (container instanceof XtendClass) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendInterface) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnum) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendField) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendFunction) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendConstructor) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnumLiteral) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendParameter) {
_matched = true;
}
}
if (_matched) {
_switchResult = ((XtendAnnotationTarget) container);
}
if (!_matched) {
if (container instanceof XtendAnnotationTarget) {
_matched = true;
XtendAnnotationTarget _xblockexpression = null;
{
final EObject containerContainer = ((XtendAnnotationTarget) container).eContainer();
XtendAnnotationTarget _xifexpression = null;
if ((containerContainer instanceof XtendAnnotationTarget)) {
_xifexpression = ((XtendAnnotationTarget) containerContainer);
} else {
_xifexpression = ((XtendAnnotationTarget) container);
}
_xblockexpression = _xifexpression;
}
_switchResult = _xblockexpression;
}
}
if (!_matched) {
if (container instanceof XAnnotation) {
_matched = true;
_switchResult = this.getAnnotatedTarget(((XAnnotation) container));
}
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
Aggregations