public JvmWildcardTypeReference wildCardExtends(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(clone); result.getConstraints().add(upperBound); return result; }
public JvmWildcardTypeReference wildCardExtends(JvmTypeReference clone) { JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference(); JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(clone); result.getConstraints().add(upperBound); return result; }
/** 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); }
protected JvmTypeParameter createTypeParameter(TypeVariable<?> variable, JvmMember container) { JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter(); result.setName(variable.getName()); Type[] bounds = variable.getBounds(); if (bounds.length != 0) { InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints(); for (Type bound : variable.getBounds()) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(createTypeReference(bound)); constraints.addUnique(upperBound); } } return result; }
protected JvmTypeParameter createTypeParameter(TypeVariable<?> variable, JvmMember container) { JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter(); result.setName(variable.getName()); Type[] bounds = variable.getBounds(); if (bounds.length != 0) { InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints(); for (Type bound : variable.getBounds()) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(createTypeReference(bound)); constraints.addUnique(upperBound); } } return result; }
public JvmTypeReference getCommonParameterSuperType(final List<JvmTypeReference> types, List<JvmTypeReference> initiallyRequested) { Function<JvmTypeReference, String> getCanonicalName = new Function<JvmTypeReference, String>() { public String apply(JvmTypeReference from) { return from.getIdentifier(); } }; Set<String> allNames = Sets.newHashSet(Iterables.transform(types, getCanonicalName)); if (allNames.size() == 1) return types.get(0); if (types.size() == initiallyRequested.size()) { Set<String> initiallyRequestedNames = Sets.newHashSet(Iterables.transform(initiallyRequested, getCanonicalName)); if (initiallyRequestedNames.equals(allNames)) { // recursion - return object wildcard JvmTypeReference objectTypeReference = typeReferences.getTypeForName(Object.class, types.get(0).getType()); return typeReferences.wildCardExtends(objectTypeReference); } } JvmTypeReference superType = getCommonSuperType(types); if (superType instanceof JvmWildcardTypeReference) return superType; JvmWildcardTypeReference wildcardTypeReference = factory.createJvmWildcardTypeReference(); if (superType != null) { JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(EcoreUtil2.clone(superType)); wildcardTypeReference.getConstraints().add(upperBound); } return wildcardTypeReference; }
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); } } }
.getConstraints(); for (int j = 0; j < bounds.size(); j++) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(proxies.createTypeReference(bounds.get(j), result)); constraints.addUnique(upperBound);
.getConstraints(); for (int j = 0; j < bounds.size(); j++) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(createTypeReference(bounds.get(j), result)); constraints.addUnique(upperBound);
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; }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper helper) { TypesFactory typesFactory = getTypesFactory(); JvmWildcardTypeReference result = typesFactory.createJvmWildcardTypeReference(); if (upperBounds != null && !upperBounds.isEmpty()) { List<LightweightTypeReference> nonInterfaceTypes = getNonInterfaceTypes(upperBounds); JvmTypeReference upperBound = toJavaCompliantTypeReference(nonInterfaceTypes != null ? nonInterfaceTypes: upperBounds, helper); JvmUpperBound constraint = typesFactory.createJvmUpperBound(); constraint.setTypeReference(upperBound); result.getConstraints().add(constraint); } if (lowerBound != null) { JvmLowerBound constraint = typesFactory.createJvmLowerBound(); constraint.setTypeReference(lowerBound.toJavaCompliantTypeReference()); result.getConstraints().add(constraint); } return result; }
@Override public JvmTypeReference toTypeReference() { TypesFactory typesFactory = getTypesFactory(); JvmWildcardTypeReference result = typesFactory.createJvmWildcardTypeReference(); if (upperBounds != null && !upperBounds.isEmpty()) { for(LightweightTypeReference typeArgument: upperBounds) { JvmUpperBound constraint = typesFactory.createJvmUpperBound(); constraint.setTypeReference(typeArgument.getWrapperTypeIfPrimitive().toTypeReference()); result.getConstraints().add(constraint); } } if (lowerBound != null) { JvmLowerBound constraint = typesFactory.createJvmLowerBound(); constraint.setTypeReference(lowerBound.getWrapperTypeIfPrimitive().toTypeReference()); result.getConstraints().add(constraint); } return result; }
@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); } } }
private JvmOperation genMethodForGuiceModuleWithWildcard(final EObject element, final String methodName, final JvmTypeReference typeRefToBind, final boolean shouldOverride, final IAcceptor<JvmExecutable> acceptor) { JvmOperation _xblockexpression = null; { final JvmWildcardTypeReference wildCard = this._typesFactory.createJvmWildcardTypeReference(); final JvmUpperBound upperBound = this._typesFactory.createJvmUpperBound(); upperBound.setTypeReference(this._jvmTypesBuilder.cloneWithProxies(typeRefToBind)); EList<JvmTypeConstraint> _constraints = wildCard.getConstraints(); this._jvmTypesBuilder.<JvmUpperBound>operator_add(_constraints, upperBound); _xblockexpression = this.genMethodForGuiceModule(element, methodName, this._typeReferenceBuilder.typeRef(Class.class, wildCard), shouldOverride, acceptor); } return _xblockexpression; }
protected JvmTypeReference createTypeArgument(Type actualTypeArgument) { if (actualTypeArgument instanceof WildcardType) { WildcardType wildcardType = (WildcardType) actualTypeArgument; JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference(); InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints(); Type[] upperBounds = wildcardType.getUpperBounds(); if (upperBounds.length != 0) { for (Type boundType : upperBounds) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); JvmTypeReference upperBoundType = createTypeReference(boundType); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(upperBoundType); constraints.addUnique(upperBound); } } Type[] lowerBounds = wildcardType.getLowerBounds(); if (lowerBounds.length != 0) { for (Type boundType : lowerBounds) { JvmLowerBound lowerBound = TypesFactory.eINSTANCE.createJvmLowerBound(); JvmTypeReference lowerBoundType = createTypeReference(boundType); ((JvmTypeConstraintImplCustom) lowerBound).internalSetTypeReference(lowerBoundType); constraints.addUnique(lowerBound); } } return result; } else { JvmTypeReference result = createTypeReference(actualTypeArgument); return result; } }
protected JvmTypeReference createTypeArgument(Type actualTypeArgument) { if (actualTypeArgument instanceof WildcardType) { WildcardType wildcardType = (WildcardType) actualTypeArgument; JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference(); InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints(); Type[] upperBounds = wildcardType.getUpperBounds(); if (upperBounds.length != 0) { for (Type boundType : upperBounds) { JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); JvmTypeReference upperBoundType = createTypeReference(boundType); ((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(upperBoundType); constraints.addUnique(upperBound); } } Type[] lowerBounds = wildcardType.getLowerBounds(); if (lowerBounds.length != 0) { for (Type boundType : lowerBounds) { JvmLowerBound lowerBound = TypesFactory.eINSTANCE.createJvmLowerBound(); JvmTypeReference lowerBoundType = createTypeReference(boundType); ((JvmTypeConstraintImplCustom) lowerBound).internalSetTypeReference(lowerBoundType); constraints.addUnique(lowerBound); } } return result; } else { JvmTypeReference result = createTypeReference(actualTypeArgument); return result; } }
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); }
@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); } }
@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); } }
public JvmTypeReference createTypeArgument(BinaryTypeArgumentSignature actualTypeArgument, Map<String, JvmTypeParameter> typeParameters) { if (actualTypeArgument.isWildcard()) { JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference(); InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints(); BinaryGenericTypeSignature upperBound = actualTypeArgument.getUpperBound(); if (upperBound != null) { JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); JvmTypeReference upperBoundType = createTypeReference(upperBound, typeParameters); ((JvmTypeConstraintImplCustom) jvmUpperBound).internalSetTypeReference(upperBoundType); constraints.addUnique(jvmUpperBound); } else { JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); // TODO this might be bogus due to constrained type information on the declarator ((JvmTypeConstraintImplCustom) jvmUpperBound).internalSetTypeReference(createObjectTypeReference()); constraints.addUnique(jvmUpperBound); } BinaryGenericTypeSignature lowerBound = actualTypeArgument.getLowerBound(); if (lowerBound != null) { JvmLowerBound jvmLowerBound = TypesFactory.eINSTANCE.createJvmLowerBound(); JvmTypeReference boundType = createTypeReference(lowerBound, typeParameters); ((JvmTypeConstraintImplCustom) jvmLowerBound).internalSetTypeReference(boundType); constraints.addUnique(jvmLowerBound); } return result; } else { return createTypeReference(actualTypeArgument, typeParameters); } }