use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendOverrideFunction.
public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
methodBuilder.setOverrideFlag(true);
methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
if (_isSynchronized) {
methodBuilder.setSynchronizedFlag(true);
}
boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
newTypeParam.setName(typeParam.getName());
final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
upperBound.setTypeReference(it.toJavaCompliantTypeReference());
EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
_constraints.add(upperBound);
};
overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
typeParameters.add(newTypeParam);
};
IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
methodBuilder.setTypeParameters(typeParameters);
}
boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
boolean _not_1 = (!_isAbstract);
if (_not_1) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("super.");
{
List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
boolean _hasElements = false;
for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
if (!_hasElements) {
_hasElements = true;
_builder.append("<");
} else {
_builder.appendImmediate(", ", "");
}
String _simpleName = typeParam.getSimpleName();
_builder.append(_simpleName);
}
if (_hasElements) {
_builder.append(">");
}
}
String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
_builder.append(_simpleName_1);
_builder.append("(");
final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
return it.getSimpleName();
};
String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
_builder.append(_join);
_builder.append(")");
final String body = _builder.toString();
final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
if (superTypeRef != null) {
superTypeRef.apply(it);
}
it.append(body);
};
methodBuilder.setBodyGenerator(_function_2);
}
boolean _isValid = methodBuilder.isValid();
if (_isValid) {
methodBuilder.build(appendable);
}
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class XtendFormatter method _format.
protected void _format(final XtendConstructor func, @Extension final IFormattableDocument format) {
this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterConstructorAnnotations);
this.formatModifiers(func, format);
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.append(this.textRegionExtensions.regionFor(func).keyword("new"), _function);
boolean _isEmpty = func.getTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function_1);
EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
for (final JvmTypeParameter arg : _typeParameters) {
{
format.<JvmTypeParameter>format(arg);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_2), _function_3);
}
}
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.surround(this.textRegionExtensions.regionFor(func).keyword(">"), _function_2);
}
final ISemanticRegion open = this.textRegionExtensions.regionFor(func).keyword("(");
final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
this.formatCommaSeparatedList(func.getParameters(), open, close, format);
format.<XExpression>format(func.getExpression());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class XtendFormatter method formatTypeParameters.
protected ISemanticRegion formatTypeParameters(final XtendMember member, final List<? extends JvmTypeParameter> typeParameters, @Extension final IFormattableDocument format) {
ISemanticRegion _xifexpression = null;
boolean _isEmpty = typeParameters.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
ISemanticRegion _xblockexpression = null;
{
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.surround(this.textRegionExtensions.regionFor(member).keyword("<"), _function);
for (final JvmTypeParameter arg : typeParameters) {
{
format.<JvmTypeParameter>format(arg);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
}
}
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
_xblockexpression = format.prepend(this.textRegionExtensions.regionFor(member).keyword(">"), _function_1);
}
_xifexpression = _xblockexpression;
}
return _xifexpression;
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method fixTypeParameters.
protected void fixTypeParameters(JvmTypeParameterDeclarator target) {
for (JvmTypeParameter typeParameter : target.getTypeParameters()) {
boolean upperBoundSeen = false;
for (JvmTypeConstraint constraint : typeParameter.getConstraints()) {
if (constraint instanceof JvmUpperBound) {
upperBoundSeen = true;
break;
}
}
if (!upperBoundSeen) {
JvmUpperBound upperBound = typesFactory.createJvmUpperBound();
upperBound.setTypeReference(typeReferences.getTypeForName(Object.class, target));
typeParameter.getConstraints().add(upperBound);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class AbstractCodeBuilder method appendTypeParameters.
protected ISourceAppender appendTypeParameters(final ISourceAppender appendable, final List<JvmTypeParameter> typeParameters) {
ISourceAppender _xblockexpression = null;
{
final Iterator<JvmTypeParameter> iterator = typeParameters.iterator();
boolean _hasNext = iterator.hasNext();
if (_hasNext) {
appendable.append("<");
do {
{
final JvmTypeParameter typeParameter = iterator.next();
appendable.append(typeParameter.getName());
final Function1<JvmUpperBound, Boolean> _function = (JvmUpperBound it) -> {
String _identifier = it.getTypeReference().getIdentifier();
return Boolean.valueOf((!Objects.equal(_identifier, "java.lang.Object")));
};
final Iterable<JvmUpperBound> upperBounds = IterableExtensions.<JvmUpperBound>filter(Iterables.<JvmUpperBound>filter(typeParameter.getConstraints(), JvmUpperBound.class), _function);
boolean _isEmpty = IterableExtensions.isEmpty(upperBounds);
boolean _not = (!_isEmpty);
if (_not) {
appendable.append(" extends ");
boolean isFirst = true;
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, this.context);
for (final JvmUpperBound upperBound : upperBounds) {
{
if ((!isFirst)) {
appendable.append(" & ");
}
isFirst = false;
this.appendType(appendable, owner.toLightweightTypeReference(upperBound.getTypeReference()), "Object");
}
}
}
boolean _hasNext_1 = iterator.hasNext();
if (_hasNext_1) {
appendable.append(",");
}
}
} while (iterator.hasNext());
appendable.append("> ");
}
_xblockexpression = appendable;
}
return _xblockexpression;
}
Aggregations