Java Code Examples for org.eclipse.xtext.common.types.JvmUpperBound#setTypeReference()
The following examples show how to use
org.eclipse.xtext.common.types.JvmUpperBound#setTypeReference() .
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: XtendJvmModelInferrer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
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); } } }
Example 2
Source File: MutableJvmClassDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds); final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter(); param.setName(name); this.getDelegate().getTypeParameters().add(param); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); param.getConstraints().add(jvmUpperBound); } } TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param); return ((MutableTypeParameterDeclaration) _typeParameterDeclaration); }
Example 3
Source File: MutableJvmInterfaceDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds); final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter(); param.setName(name); this.getDelegate().getTypeParameters().add(param); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); param.getConstraints().add(jvmUpperBound); } } TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param); return ((MutableTypeParameterDeclaration) _typeParameterDeclaration); }
Example 4
Source File: JvmExecutableDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds); final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter(); param.setName(name); this.getDelegate().getTypeParameters().add(param); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); param.getConstraints().add(jvmUpperBound); } } TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param); return ((MutableTypeParameterDeclaration) _typeParameterDeclaration); }
Example 5
Source File: JvmTypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public JvmParameterizedTypeReferenceConstructor wildCardExtends(String qualifiedName) { JvmWildcardTypeReference argument = typesFactory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = typesFactory.createJvmUpperBound(); argument.getConstraints().add(upperBound); JvmParameterizedTypeReferenceConstructor constructor = new JvmParameterizedTypeReferenceConstructor(qualifiedName, typesFactory, typesProvider, this); upperBound.setTypeReference(constructor.getReference()); reference.getArguments().add(argument); return constructor; }
Example 6
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public JvmWildcardTypeReference wildCardExtends(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(clone); result.getConstraints().add(upperBound); return result; }
Example 7
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public JvmWildcardTypeReference wildCardSuper(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmLowerBound lowerBound = factory.createJvmLowerBound(); lowerBound.setTypeReference(clone); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(getTypeForName(Object.class, clone.getType())); result.getConstraints().add(lowerBound); result.getConstraints().add(upperBound); return result; }
Example 8
Source File: JvmTypeReferences.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public JvmParameterizedTypeReferenceConstructor wildCardExtends(String qualifiedName) { JvmWildcardTypeReference argument = typesFactory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = typesFactory.createJvmUpperBound(); argument.getConstraints().add(upperBound); JvmParameterizedTypeReferenceConstructor constructor = new JvmParameterizedTypeReferenceConstructor(qualifiedName, typesFactory, typesProvider, this); upperBound.setTypeReference(constructor.getReference()); reference.getArguments().add(argument); return constructor; }
Example 9
Source File: MutableJvmTypeParameterDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void setUpperBounds(final Iterable<? extends TypeReference> upperBounds) { this.checkMutable(); ConditionUtils.checkIterable(upperBounds, "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", ((TypeReference[])Conversions.unwrapArray(upperBounds, TypeReference.class))); this.getDelegate().getConstraints().clear(); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); this.getDelegate().getConstraints().add(jvmUpperBound); } } }
Example 10
Source File: TypeParameterBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
/** Add upper type bounds. * @param type the type. */ public void addUpperConstraint(String type) { final JvmUpperBound constraint = this.jvmTypesFactory.createJvmUpperBound(); constraint.setTypeReference(newTypeRef(this.context, type)); getJvmTypeParameter().getConstraints().add(constraint); }
Example 11
Source File: SARLJvmModelInferrer.java From sarl with Apache License 2.0 | 4 votes |
/** Initialize the SARL capacity context-aware wrapper. * * @param source the source. * @param inferredJvmType the JVM type. * @since 0.6 */ protected void appendCapacityContextAwareWrapper(SarlCapacity source, JvmGenericType inferredJvmType) { final JvmGenericType innerType = this.typesFactory.createJvmGenericType(); innerType.setInterface(false); innerType.setAbstract(false); innerType.setVisibility(JvmVisibility.PUBLIC); innerType.setStatic(true); innerType.setStrictFloatingPoint(false); innerType.setFinal(false); final String innerTypeName = Capacity.ContextAwareCapacityWrapper.class.getSimpleName(); innerType.setSimpleName(innerTypeName); inferredJvmType.getMembers().add(innerType); this.typeBuilder.setDocumentation(innerType, "@ExcludeFromApidoc"); //$NON-NLS-1$ final JvmTypeParameter typeParameter = this.typesFactory.createJvmTypeParameter(); typeParameter.setName("C"); //$NON-NLS-1$ final JvmUpperBound constraint = this.typesFactory.createJvmUpperBound(); constraint.setTypeReference(this._typeReferenceBuilder.typeRef(inferredJvmType)); typeParameter.getConstraints().add(constraint); innerType.getTypeParameters().add(typeParameter); final Iterator<JvmTypeReference> extendedTypeIterator = inferredJvmType.getExtendedInterfaces().iterator(); if (extendedTypeIterator.hasNext()) { final JvmTypeReference extendedType = extendedTypeIterator.next(); final JvmTypeReference superType = this._typeReferenceBuilder.typeRef( extendedType.getQualifiedName() + "$" + innerTypeName, //$NON-NLS-1$ this._typeReferenceBuilder.typeRef(typeParameter)); innerType.getSuperTypes().add(superType); } innerType.getSuperTypes().add(this._typeReferenceBuilder.typeRef(inferredJvmType)); final JvmConstructor constructor = this.typesFactory.createJvmConstructor(); constructor.setVisibility(JvmVisibility.PUBLIC); innerType.getMembers().add(constructor); final JvmFormalParameter parameter1 = this.typesFactory.createJvmFormalParameter(); parameter1.setName("capacity"); //$NON-NLS-1$ parameter1.setParameterType(this._typeReferenceBuilder.typeRef(typeParameter)); constructor.getParameters().add(parameter1); final JvmFormalParameter parameter2 = this.typesFactory.createJvmFormalParameter(); parameter2.setName("caller"); //$NON-NLS-1$ parameter2.setParameterType(this._typeReferenceBuilder.typeRef(AgentTrait.class)); constructor.getParameters().add(parameter2); setBody(constructor, it -> { it.append("super(capacity, caller);"); //$NON-NLS-1$ }); final Set<ActionPrototype> createdActions = new TreeSet<>(); for (final JvmGenericType sourceType : Iterables.concat( Collections.singletonList(inferredJvmType), Iterables.transform(Iterables.skip(inferredJvmType.getExtendedInterfaces(), 1), it -> { return (JvmGenericType) it.getType(); }))) { copyNonStaticPublicJvmOperations(sourceType, innerType, createdActions, (operation, it) -> { it.append("try {"); //$NON-NLS-1$ it.newLine(); it.append(" ensureCallerInLocalThread();"); //$NON-NLS-1$ it.newLine(); it.append(" "); //$NON-NLS-1$ if (operation.getReturnType() != null && !Objects.equal("void", operation.getReturnType().getIdentifier())) { //$NON-NLS-1$ it.append("return "); //$NON-NLS-1$ } it.append("this.capacity."); //$NON-NLS-1$ it.append(operation.getSimpleName()); it.append("("); //$NON-NLS-1$ boolean first = true; for (final JvmFormalParameter fparam : operation.getParameters()) { if (first) { first = false; } else { it.append(", "); //$NON-NLS-1$ } it.append(fparam.getName()); } it.append(");"); //$NON-NLS-1$ it.newLine(); it.append("} finally {"); //$NON-NLS-1$ it.newLine(); it.append(" resetCallerInLocalThread();"); //$NON-NLS-1$ it.newLine(); it.append("}"); //$NON-NLS-1$ }); } }