/** * Converts this type reference to a {@link JvmTypeReference} that can * be used in Java source code. */ public final JvmTypeReference toJavaCompliantTypeReference() { return toJavaCompliantTypeReference(IVisibilityHelper.ALL); }
protected JvmTypeReference toJavaCompliantTypeReference(LightweightTypeReference result, IFeatureScopeSession session) { return result.toJavaCompliantTypeReference(session); }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { return resolve().toJavaCompliantTypeReference(visibilityHelper); }
/** Remove the type parameters from the given type. * * <p><table> * <thead><tr><th>Referenced type</th><th>Input</th><th>Replied referenced type</th><th>Output</th></tr></thead> * <tbody> * <tr><td>Type with generic type parameter</td><td>{@code T<G>}</td><td>the type itself</td><td>{@code T}</td></tr> * <tr><td>Type without generic type parameter</td><td>{@code T}</td><td>the type itself</td><td>{@code T}</td></tr> * <tr><td>Type parameter without bound</td><td>{@code <S>}</td><td>{@code Object}</td><td>{@code Object}</td></tr> * <tr><td>Type parameter with lower bound</td><td>{@code <S super B>}</td><td>{@code Object}</td><td>{@code Object}</td></tr> * <tr><td>Type parameter with upper bound</td><td>{@code <S extends B>}</td><td>the bound type</td><td>{@code B}</td></tr> * </tbody> * </table> * * @param type the type. * @param context the context in which the reference is located. * @return the same type without the type parameters. */ protected JvmTypeReference skipTypeParameters(JvmTypeReference type, Notifier context) { final LightweightTypeReference ltr = Utils.toLightweightTypeReference(type, this.services); return ltr.getRawTypeReference().toJavaCompliantTypeReference(); }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { JvmGenericArrayTypeReference result = getTypesFactory().createJvmGenericArrayTypeReference(); result.setComponentType(component.toJavaCompliantTypeReference(visibilityHelper)); return result; }
public JvmTypeReference resolveMultiType(JvmTypeReference reference, EObject context) { ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context.eResource().getResourceSet()); return owner.toLightweightTypeReference(reference).toJavaCompliantTypeReference(); } }
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param type * the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} */ public JvmTypeReference typeRef(JvmType type, JvmTypeReference... typeArgs) { int typeParams = 0; if (type instanceof JvmGenericType) { typeParams = ((JvmGenericType) type).getTypeParameters().size(); } if (typeParams < typeArgs.length) { throw new IllegalArgumentException("The type "+type.getIdentifier()+" only declares "+typeParams+" type parameters. You passed "+typeArgs.length+"."); } LightweightTypeReference reference = typeReferenceOwner.toPlainTypeReference(type); for (JvmTypeReference jvmTypeReference : typeArgs) { ((ParameterizedTypeReference)reference).addTypeArgument(typeReferenceOwner.toLightweightTypeReference(jvmTypeReference)); } return reference.toJavaCompliantTypeReference(); }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (isTypeVisible(visibilityHelper)) { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toJavaCompliantTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toJavaCompliantTypeReference()); } return result; } else { return toJavaCompliantTypeReference(getSuperTypes(), visibilityHelper); } }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (isTypeVisible(visibilityHelper)) { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toJavaCompliantTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toJavaCompliantTypeReference()); } return result; } else { return toJavaCompliantTypeReference(getSuperTypes(), visibilityHelper); } }
public JvmTypeReference toJvmTypeReference(final TypeReference typeRef) { this.checkCanceled(); JvmTypeReference _switchResult = null; boolean _matched = false; if (typeRef instanceof TypeReferenceImpl) { _matched=true; _switchResult = ((TypeReferenceImpl)typeRef).getLightweightTypeReference().toJavaCompliantTypeReference(); } if (!_matched) { if (typeRef instanceof InferredTypeReferenceImpl) { _matched=true; _switchResult = EcoreUtil.<XComputedTypeReferenceImplCustom>copy(((InferredTypeReferenceImpl)typeRef).getDelegate()); } } return _switchResult; }
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ @SuppressWarnings("unchecked") protected Object _doEvaluate(XNumberLiteral literal, IEvaluationContext context, CancelIndicator indicator) { IResolvedTypes resolvedTypes = typeResolver.resolveTypes(literal); LightweightTypeReference expectedType = resolvedTypes.getExpectedType(literal); Class<? extends Number> type = numberLiterals.getJavaType(literal); if (expectedType != null && expectedType.isSubtypeOf(Number.class)) { try { Class<?> expectedClassType = getJavaType(expectedType.toJavaCompliantTypeReference().getType()); if (expectedClassType.isPrimitive()) { expectedClassType = ReflectionUtil.getObjectType(expectedClassType); } if (Number.class != expectedClassType && Number.class.isAssignableFrom(expectedClassType)) { type = (Class<? extends Number>) expectedClassType; } } catch (ClassNotFoundException e) { } } return numberLiterals.numberValue(literal, type); }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (isTypeVisible(visibilityHelper)) { JvmParameterizedTypeReference result = getTypesFactory().createJvmParameterizedTypeReference(); result.setType(type); if (typeArguments != null) { for(LightweightTypeReference typeArgument: typeArguments) { result.getArguments().add(typeArgument.toJavaCompliantTypeReference()); } } return result; } else { return toJavaCompliantTypeReference(getSuperTypes(), visibilityHelper); } }
@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; }
protected JvmTypeReference resolveSynonymType(JvmSynonymTypeReference reference, EObject context) { LightweightTypeReference lightweight = toLightweight(reference, context); LightweightTypeReference superType = lightweight.getOwner().getServices().getTypeConformanceComputer().getCommonSuperType(lightweight.getMultiTypeComponents(), lightweight.getOwner()); return superType.toJavaCompliantTypeReference(); }
/** Generate the given object. * * @param breakStatement the break statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ @SuppressWarnings("static-method") protected XExpression _generate(SarlBreakExpression breakStatement, IAppendable it, IExtraLanguageGeneratorContext context) { if (context.getExpectedExpressionType() == null) { it.append("break"); //$NON-NLS-1$ } else { it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return breakStatement; }
/** Generate the given object. * * @param continueStatement the continue statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ @SuppressWarnings("static-method") protected XExpression _generate(SarlContinueExpression continueStatement, IAppendable it, IExtraLanguageGeneratorContext context) { if (context.getExpectedExpressionType() == null) { it.append("continue"); //$NON-NLS-1$ } else { it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return continueStatement; }
@Override protected ITypeComputationResult createNoTypeResult() { JvmOperation operation = (JvmOperation) getMember(); LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession()); if (expectedType != null) { InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference()); } return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner()); } }
protected JvmTypeReference toJavaCompliantTypeReference(List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper) { LightweightTypeReference type = getServices().getTypeConformanceComputer().getCommonSuperType(types, getOwner()); if (type == null) { return getOwner().getServices().getTypeReferences().getTypeForName(Object.class, getOwner().getContextResourceSet()); } return type.toJavaCompliantTypeReference(visibilityHelper); }
@Override /* @Nullable */ protected LightweightTypeReference getExpectedType() { LightweightTypeReference expectedType = super.getExpectedType(); if (expectedType != null) { return expectedType; } if (dispatcher != null) { JvmOperation operation = (JvmOperation) getMember(); if (!InferredTypeIndicator.isInferred(dispatcher.getReturnType())) { LightweightTypeReference result = getResolvedTypes().getActualType(dispatcher); if (result != null) InferredTypeIndicator.resolveTo(operation.getReturnType(), result.toJavaCompliantTypeReference()); return result; } } return inheritedExpectedType; }
@Override /* @Nullable */ protected LightweightTypeReference getExpectedType() { JvmOperation operation = (JvmOperation) getMember(); LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession()); if (expectedType != null) { InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference()); return expectedType; } return getResolvedTypes().getExpectedTypeForAssociatedExpression(getMember(), getNonNullRootExpression()); }