use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class ReplacingAppendableTest method insertListField.
protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
final int cursorPosition = model.indexOf('|');
String actualModel = model.replace("|", " ");
final XtendFile file = testHelper.xtendFile("Foo", actualModel);
final XtextDocument document = documentProvider.get();
document.set(actualModel);
XtextResource xtextResource = (XtextResource) file.eResource();
document.setInput(xtextResource);
final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
a.append(typeRef);
a.append(" ").append(fieldName);
a.commitChanges();
}
});
return document;
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class ConstructorBuilderTest method testXtendExceptions.
@Test
public void testXtendExceptions() {
AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
it.setContext(this.getXtendClass());
LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getXtendClass());
LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getXtendClass());
it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
};
AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("new() throws Exception, RuntimeException {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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.xbase.typesystem.references.LightweightTypeReference 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);
}
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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