use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class CommonSuperTypeTest method isSuperTypeOf.
public Object isSuperTypeOf(final Pair<String, String> superTypeAndParam, final String... types) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def ");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(superTypeAndParam.getValue());
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("<");
String _value = superTypeAndParam.getValue();
_builder.append(_value);
_builder.append("> ");
}
}
_builder.append("void method(");
{
boolean _hasElements = false;
for (final String type : types) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "");
}
String _fixup = this.fixup(type);
_builder.append(_fixup);
_builder.append(" t");
}
}
_builder.append(") {}");
final String signature = _builder.toString();
final XtendFunction function = this.function(signature.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final Function1<JvmFormalParameter, LightweightTypeReference> _function = (JvmFormalParameter it) -> {
return this.toLightweightTypeReference(it.getParameterType());
};
List<LightweightTypeReference> _map = ListExtensions.<JvmFormalParameter, LightweightTypeReference>map(operation.getParameters(), _function);
final ArrayList<LightweightTypeReference> typeReferences = new ArrayList<LightweightTypeReference>(_map);
final TypeConformanceComputer conformanceComputer = this.getServices().getTypeConformanceComputer();
LightweightTypeReference computedSuperType = conformanceComputer.getCommonSuperType(typeReferences, this.getOwner());
String _simpleName = null;
if (computedSuperType != null) {
_simpleName = computedSuperType.getSimpleName();
}
Assert.assertEquals(superTypeAndParam.getKey(), _simpleName);
computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(IterableExtensions.<LightweightTypeReference>toList(Iterables.<LightweightTypeReference>concat(typeReferences, typeReferences)), this.getOwner());
String _simpleName_1 = null;
if (computedSuperType != null) {
_simpleName_1 = computedSuperType.getSimpleName();
}
Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_1);
computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(ListExtensions.<LightweightTypeReference>reverseView(typeReferences), this.getOwner());
String _simpleName_2 = null;
if (computedSuperType != null) {
_simpleName_2 = computedSuperType.getSimpleName();
}
Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_2);
boolean _isPrimitiveOrVoid = this.isPrimitiveOrVoid(computedSuperType);
boolean _not_1 = (!_isPrimitiveOrVoid);
if (_not_1) {
List<AnyTypeReference> _newImmutableList = CollectionLiterals.<AnyTypeReference>newImmutableList(this.getOwner().newAnyTypeReference(), this.getOwner().newAnyTypeReference());
computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(IterableExtensions.<LightweightTypeReference>toList(Iterables.<LightweightTypeReference>concat(typeReferences, _newImmutableList)), this.getOwner());
String _simpleName_3 = null;
if (computedSuperType != null) {
_simpleName_3 = computedSuperType.getSimpleName();
}
Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_3);
}
if ((computedSuperType != null)) {
final Procedure1<LightweightTypeReference> _function_1 = (LightweightTypeReference superType) -> {
final Consumer<LightweightTypeReference> _function_2 = (LightweightTypeReference it) -> {
LightweightTypeReference _commonSuperType = conformanceComputer.getCommonSuperType(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(it, superType)), superType.getOwner());
String _simpleName_4 = null;
if (_commonSuperType != null) {
_simpleName_4 = _commonSuperType.getSimpleName();
}
Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_4);
};
typeReferences.forEach(_function_2);
};
ObjectExtensions.<LightweightTypeReference>operator_doubleArrow(computedSuperType, _function_1);
}
if ((computedSuperType != null)) {
for (final LightweightTypeReference subType : typeReferences) {
Assert.assertTrue(computedSuperType.isAssignableFrom(subType));
}
}
return computedSuperType;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class DeferredTypeParameterHintCollectorTest method in.
public Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> in(final String typeParameters, final String expectedType, final String actualType) {
final JvmOperation operation = this.operation(typeParameters, expectedType, actualType);
ITypeReferenceOwner _owner = this.getOwner();
final DeferredTypeParameterHintCollector collector = new DeferredTypeParameterHintCollector(_owner);
final DefaultReentrantTypeResolver resolver = this.resolverProvider.get();
resolver.initializeFrom(EcoreUtil.getRootContainer(operation));
ITypeReferenceOwner _owner_1 = this.getOwner();
PublicResolvedTypes _publicResolvedTypes = new PublicResolvedTypes(resolver);
final MockTypeParameterSubstitutor substitutor = new MockTypeParameterSubstitutor(_owner_1, _publicResolvedTypes);
final LightweightTypeReference hasUnbounds = substitutor.substitute(this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()));
final LightweightTypeReference isActual = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
collector.processPairedReferences(hasUnbounds, isActual);
return substitutor.getTypeParameterMapping();
}
use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-xtend by eclipse.
the class Oven method fireproof.
public void fireproof(final String input) throws Exception {
try {
final EObject file = this._parseHelper.parse(input);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
Assert.assertNotNull(resolvedTypes);
if ((file != null)) {
Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
for (final EObject content : _iterable) {
boolean _matched = false;
if (content instanceof XAbstractFeatureCall) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
boolean _tripleNotEquals = (_implicitReceiver != null);
if (_tripleNotEquals) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
}
XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
if (_tripleNotEquals_1) {
this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof XClosure) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
};
((XClosure) content).getImplicitFormalParameters().forEach(_function);
}
}
if (!_matched) {
if (content instanceof XExpression) {
_matched = true;
this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
}
}
if (!_matched) {
if (content instanceof JvmIdentifiableElement) {
_matched = true;
this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
}
}
}
}
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
String _message = e.getMessage();
final ComparisonFailure error = new ComparisonFailure(_message, input, "");
error.setStackTrace(e.getStackTrace());
throw error;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
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 ErrorTest method testErrorModel_019.
@Test
public void testErrorModel_019() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package x");
_builder.newLine();
_builder.append("import bug396879.*");
_builder.newLine();
_builder.append("class Z {");
_builder.newLine();
_builder.append(" \t");
_builder.append("def addListeners(BooleanProperty prop) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val ChangeListenerBoolean> listener = [ p, oldValue, newValue | ]\t\tprop.addListener(listener)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration z = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _get = z.getMembers().get(1);
final XtendField field = ((XtendField) _get);
XExpression _initialValue = field.getInitialValue();
final XClosure closure = ((XClosure) _initialValue);
final JvmFormalParameter param = IterableExtensions.<JvmFormalParameter>head(closure.getDeclaredFormalParameters());
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(param);
Assert.assertNotNull(resolvedTypes.getActualType(param));
}
Aggregations