Java Code Examples for org.eclipse.xtext.common.types.JvmWildcardTypeReference#getConstraints()
The following examples show how to use
org.eclipse.xtext.common.types.JvmWildcardTypeReference#getConstraints() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmTypeReferencesValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Check public void checkNotMultipleBounds(JvmWildcardTypeReference typeRef) { List<JvmTypeConstraint> constraints = typeRef.getConstraints(); if (constraints.size() >= 2) { int upperBounds = 0; int lowerBounds = 0; for(int i = 0; i < constraints.size(); i++) { JvmTypeConstraint constraint = constraints.get(i); if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) { upperBounds++; if (upperBounds > 1) { error("Invalid type constraint. Cannot use multiple upper bounds in wildcards.", typeRef, TypesPackage.Literals.JVM_CONSTRAINT_OWNER__CONSTRAINTS, i, IssueCodes.INVALID_WILDCARD_CONSTRAINTS); return; } } else { lowerBounds++; if (lowerBounds > 1) { error("Invalid type constraint. Cannot use multiple lower bounds in wildcards.", typeRef, TypesPackage.Literals.JVM_CONSTRAINT_OWNER__CONSTRAINTS, i, IssueCodes.INVALID_WILDCARD_CONSTRAINTS); } } } } }
Example 2
Source File: XtypeFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _format(final JvmWildcardTypeReference ref, @Extension final IFormattableDocument document) { boolean _isEmpty = ref.getConstraints().isEmpty(); boolean _not = (!_isEmpty); if (_not) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; document.append(this.textRegionExtensions.regionFor(ref).keyword("?"), _function); } EList<JvmTypeConstraint> _constraints = ref.getConstraints(); for (final JvmTypeConstraint c : _constraints) { document.<JvmTypeConstraint>format(c); } }
Example 3
Source File: XbaseFormatter2.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _format(final JvmWildcardTypeReference ref, final FormattableDocument document) { boolean _isEmpty = ref.getConstraints().isEmpty(); boolean _not = (!_isEmpty); if (_not) { final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> { it.oneSpace(); }; Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _append = this._formattingDataFactory.append(this._nodeModelAccess.nodeForKeyword(ref, "?"), _function); document.operator_add(_append); } EList<JvmTypeConstraint> _constraints = ref.getConstraints(); for (final JvmTypeConstraint c : _constraints) { this.format(c, document); } }
Example 4
Source File: AbstractBuilder.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the type reference for the given name in the given context. */ public JvmParameterizedTypeReference newTypeRef(Notifier context, String typeName) { JvmTypeReference typeReference; try { typeReference = findType(context, typeName); getImportManager().addImportFor(typeReference.getType()); return (JvmParameterizedTypeReference) typeReference; } catch (TypeNotPresentException exception) { } final JvmParameterizedTypeReference pref = ExpressionBuilderImpl.parseType(context, typeName, this); final JvmTypeReference baseType = findType(context, pref.getType().getIdentifier()); final int len = pref.getArguments().size(); final JvmTypeReference[] args = new JvmTypeReference[len]; for (int i = 0; i < len; ++i) { final JvmTypeReference original = pref.getArguments().get(i); if (original instanceof JvmAnyTypeReference) { args[i] = EcoreUtil.copy(original); } else if (original instanceof JvmWildcardTypeReference) { final JvmWildcardTypeReference wc = EcoreUtil.copy((JvmWildcardTypeReference) original); for (final JvmTypeConstraint c : wc.getConstraints()) { c.setTypeReference(newTypeRef(context, c.getTypeReference().getIdentifier())); } args[i] = wc; } else { args[i] = newTypeRef(context, original.getIdentifier()); } } final TypeReferences typeRefs = getTypeReferences(); return typeRefs.createTypeRef(baseType.getType(), args); }