use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForForXClosureVariable.
@Test
public void testSignatureForForXClosureVariable() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\t");
_builder.append("package testPackage");
_builder.newLine();
_builder.append("\t");
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("def zonk(){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("bar(s | s + \"42\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("def bar((String)=>String fun){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction xtendFunction = ((XtendFunction) _get);
XExpression _expression = xtendFunction.getExpression();
XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
XExpression _get_2 = ((XFeatureCall) _get_1).getFeatureCallArguments().get(0);
final XClosure closure = ((XClosure) _get_2);
final JvmFormalParameter param = closure.getDeclaredFormalParameters().get(0);
final String signature = this.signatureProvider.getSignature(param);
Assert.assertEquals("String s", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForForLoopVariable.
@Test
public void testSignatureForForLoopVariable() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("def bar(List<String> list){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("for(foo : list){");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendFunction xtendFunction = ((XtendFunction) _get);
XExpression _expression = xtendFunction.getExpression();
XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
final JvmFormalParameter param = ((XForLoopExpression) _get_1).getDeclaredParam();
final String signature = this.signatureProvider.getSignature(param);
Assert.assertEquals("String foo", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class TypeReferenceAssignabilityTest method isAssignableFrom.
@Override
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);
EObject _rootContainer = EcoreUtil.getRootContainer(function);
final XtendFile xtendFile = ((XtendFile) _rootContainer);
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
TypeReference _xifexpression = null;
String _key = lhsAndParams.getKey();
boolean _tripleNotEquals = (_key != null);
if (_tripleNotEquals) {
_xifexpression = it.toTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
} else {
_xifexpression = it.toTypeReference(this.getOwner().newAnyTypeReference());
}
final TypeReference lhsType = _xifexpression;
TypeReference _xifexpression_1 = null;
if ((rhs != null)) {
_xifexpression_1 = it.toTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
} else {
_xifexpression_1 = it.toTypeReference(this.getOwner().newAnyTypeReference());
}
final TypeReference 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(it, lhsType, rhsType)));
if (expectation) {
Iterable<? extends TypeReference> _declaredSuperTypes = lhsType.getDeclaredSuperTypes();
for (final TypeReference superType : _declaredSuperTypes) {
if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(it, superType, rhsType)));
}
}
}
};
this.asCompilationUnit(xtendFile, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class AbstractSuperTypesTest method assertSuperTypes.
public void assertSuperTypes(final Pair<String, String> type, final String... superTypes) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def ");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(type.getValue());
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("<");
String _value = type.getValue();
_builder.append(_value);
_builder.append("> ");
}
}
_builder.append("void method(");
String _key = type.getKey();
_builder.append(_key);
_builder.append(" type) {}");
final String signature = _builder.toString();
final XtendFunction function = this.function(signature.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final LightweightTypeReference subtype = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
final Function1<LightweightTypeReference, String> _function = (LightweightTypeReference it) -> {
return it.getSimpleName();
};
Assert.assertEquals(IterableExtensions.<String>toList(((Iterable<String>) Conversions.doWrapArray(superTypes))), IterableExtensions.<String>toList(IterableExtensions.<LightweightTypeReference, String>map(this.collectSuperTypes(subtype), _function)));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter 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);
}
}
Aggregations