use of org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument in project xtext-xtend by eclipse.
the class MockTypeParameterSubstitutor method doVisitParameterizedTypeReference.
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(final ParameterizedTypeReference reference, final Set<JvmTypeParameter> visiting) {
final JvmType type = reference.getType();
if ((type instanceof JvmTypeParameter)) {
boolean _add = visiting.add(((JvmTypeParameter) type));
boolean _not = (!_add);
if (_not) {
return null;
}
try {
final LightweightMergedBoundTypeArgument mappedReference = this.getTypeParameterMapping().get(type);
if ((mappedReference != null)) {
return mappedReference.getTypeReference().<Set<JvmTypeParameter>, LightweightTypeReference>accept(this, visiting);
} else {
ITypeReferenceOwner _owner = this.getOwner();
Object _object = new Object();
final SimpleUnboundTypeReference result = new SimpleUnboundTypeReference(_owner, ((JvmTypeParameter) type), _object);
Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> _typeParameterMapping = this.getTypeParameterMapping();
LightweightMergedBoundTypeArgument _lightweightMergedBoundTypeArgument = new LightweightMergedBoundTypeArgument(result, VarianceInfo.INVARIANT);
_typeParameterMapping.put(((JvmTypeParameter) type), _lightweightMergedBoundTypeArgument);
return result;
}
} finally {
visiting.remove(type);
}
}
return super.doVisitParameterizedTypeReference(reference, visiting);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument in project xtext-xtend by eclipse.
the class ActualTypeArgumentMergeTest method merge.
public Pair<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument> merge(final Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mapping, final String typeParamName) {
final Set<JvmTypeParameter> allKeys = mapping.keySet();
for (final JvmTypeParameter key : allKeys) {
String _simpleName = key.getSimpleName();
boolean _equals = Objects.equal(_simpleName, typeParamName);
if (_equals) {
final List<LightweightBoundTypeArgument> mappingData = mapping.get(key);
LightweightMergedBoundTypeArgument _merge = this.merger.merge(mappingData, this.getOwner());
return Pair.<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument>of(mapping, _merge);
}
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("No mapping for ");
_builder.append(typeParamName);
_builder.append(" in ");
final Function1<JvmTypeParameter, String> _function = (JvmTypeParameter it) -> {
return it.getSimpleName();
};
Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function);
_builder.append(_map);
Assert.fail(_builder.toString());
return null;
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument in project xtext-eclipse by eclipse.
the class XbaseDeclarativeHoverSignatureProvider method _signature.
protected String _signature(XConstructorCall constructorCall, boolean typeAtEnd) {
if (typeAtEnd) {
throw new UnsupportedOperationException();
}
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(constructorCall);
LightweightTypeReference createdType = resolvedTypes.getActualType(constructorCall);
final List<LightweightTypeReference> typeArguments = resolvedTypes.getActualTypeArguments(constructorCall);
final int typeArgumentCount = createdType.getTypeArguments().size();
final int constructorTypeArgumentCount = typeArguments.size();
final JvmConstructor constructor = constructorCall.getConstructor();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, createdType) {
@Override
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> computeContextTypeParameterMapping() {
Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> result = super.computeContextTypeParameterMapping();
if (typeArgumentCount == constructorTypeArgumentCount)
return result;
List<JvmTypeParameter> constructorTypeParameters = getDeclaration().getTypeParameters();
for (int i = 0; i < constructorTypeParameters.size(); i++) {
result.put(constructorTypeParameters.get(i), new LightweightMergedBoundTypeArgument(typeArguments.get(i), VarianceInfo.INVARIANT));
}
return result;
}
};
StringBuilder result = new StringBuilder(250);
if (typeArgumentCount != constructorTypeArgumentCount) {
result.append("<");
for (int i = 0; i < constructorTypeArgumentCount - typeArgumentCount; i++) {
if (i != 0) {
result.append(", ");
}
result.append(typeArguments.get(i).getHumanReadableName());
}
result.append("> ");
}
result.append(constructor.getDeclaringType().getSimpleName());
if (typeArgumentCount != 0) {
result.append("<");
for (int i = constructorTypeArgumentCount - typeArgumentCount; i < constructorTypeArgumentCount; i++) {
if (i != constructorTypeArgumentCount - typeArgumentCount) {
result.append(", ");
}
result.append(typeArguments.get(i).getHumanReadableName());
}
result.append(">");
}
result.append('(');
List<LightweightTypeReference> parameterTypes = resolvedConstructor.getResolvedParameterTypes();
for (int i = 0; i < parameterTypes.size(); i++) {
if (i != 0) {
result.append(", ");
}
result.append(parameterTypes.get(i).getHumanReadableName());
result.append(' ').append(constructor.getParameters().get(i).getSimpleName());
}
result.append(')');
List<LightweightTypeReference> exceptions = resolvedConstructor.getResolvedExceptions();
if (!exceptions.isEmpty()) {
result.append(" throws ");
for (int i = 0; i < exceptions.size(); i++) {
if (i != 0) {
result.append(", ");
}
result.append(exceptions.get(i).getHumanReadableName());
}
}
return result.toString();
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument in project xtext-xtend by eclipse.
the class BoundTypeArgumentMergerTest method mergeSuccessive.
public LightweightMergedBoundTypeArgument mergeSuccessive(final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
try {
int _length = mergeUs.length;
boolean _greaterThan = (_length > 2);
Assert.assertTrue(_greaterThan);
StringConcatenation _builder = new StringConcatenation();
_builder.append("def void method(");
final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
return it.getFirst();
};
String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), 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);
final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
Object _object = new Object();
VarianceInfo _second = input.getSecond();
VarianceInfo _third = input.getThird();
LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _object, _second, _third);
mergable.add(_lightweightBoundTypeArgument);
};
IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
final Iterator<LightweightBoundTypeArgument> iterator = mergable.iterator();
LightweightBoundTypeArgument first = iterator.next();
LightweightBoundTypeArgument second = iterator.next();
LightweightMergedBoundTypeArgument merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
while (iterator.hasNext()) {
{
LightweightTypeReference _typeReference = merged.getTypeReference();
Object _object = new Object();
VarianceInfo _variance = merged.getVariance();
VarianceInfo _variance_1 = merged.getVariance();
LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_typeReference, null, _object, _variance, _variance_1);
first = _lightweightBoundTypeArgument;
second = iterator.next();
merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
}
}
return merged;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations