@Test public void test_twoListParamsNoResult_03() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsNoResult, typeVar.getDeclarator()); }
@Test public void test_ParameterizedTypes_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodS = getMethodFromType(type, ParameterizedTypes.class, "methodS(S)"); JvmTypeReference listS = methodS.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends S>", listS.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listS; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends S", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, upperBound.getTypeReference().getType()); }
@Test public void test_ParameterizedTypes_03() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodT = getMethodFromType(type, ParameterizedTypes.class, "methodT(T)"); JvmTypeReference listS = methodT.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super T>", listS.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listS; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends java.lang.Object & super T", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound uperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", uperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); JvmTypeParameter t = type.getTypeParameters().get(1); assertSame(t, lowerBound.getTypeReference().getType()); }
@Test public void test_ParameterizedTypes_04() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodY = getMethodFromType(type, ParameterizedTypes.class, "methodY(Y)"); assertEquals(1, methodY.getParameters().size()); JvmType parameterType = methodY.getParameters().get(0).getParameterType().getType(); assertFalse(parameterType.eIsProxy()); assertEquals("Y", parameterType.getIdentifier()); assertTrue(parameterType instanceof JvmTypeParameter); assertSame(methodY, ((JvmTypeParameter) parameterType).getDeclarator()); JvmTypeParameter y = (JvmTypeParameter) parameterType; assertEquals(1, y.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) y.getConstraints().get(0); JvmTypeParameter t = type.getTypeParameters().get(1); assertSame(t, upperBound.getTypeReference().getType()); }
@Override /* @Nullable */ protected LightweightTypeReference getDeclaredUpperBound(JvmTypeParameter typeParameter, ConstraintVisitingInfo visiting) { if (!typeParameter.getConstraints().isEmpty() && ((DeclaredConstraintVisitingInfo)visiting).tryVisitDeclaredUpperBoundsOf(typeParameter)) { try { JvmTypeConstraint constraint = typeParameter.getConstraints().get(0); if (constraint instanceof JvmUpperBound) { LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference()); if (visiting.getCurrentDeclarator() != reference.getType()) { return reference.accept(this, visiting); } WildcardTypeReference result = getOwner().newWildcardTypeReference(); result.addUpperBound(getObjectReference()); return result; } } finally { ((DeclaredConstraintVisitingInfo)visiting).didVisitDeclaredUpperBoundsOf(typeParameter); } } return null; }
@Test public void test_ParameterizedTypes_Inner_Y_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterY = type.getTypeParameters().get(1); assertEquals("Y", typeParameterY.getIdentifier()); assertSame(type, typeParameterY.getDeclarator()); assertEquals(1, typeParameterY.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("X", typeArgument.getIdentifier()); JvmTypeParameter x = type.getTypeParameters().get(0); assertSame(x, typeArgument.getType()); }
@Test public void testPrepareComputation_08() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); iterableTypeReference.addTypeArgument(createTypeReference(typeParameter, state)); assertFalse(iterableTypeReference.isResolved()); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); // closure indicates Function1 but Iterable is Function0 - type is Function1 ClosureTypeComputer computer = new ClosureTypeComputer(closure("[]", getContextResourceSet()), expectation, state); computer.selectStrategy(); LightweightTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); }
@Test public void test_ParameterizedTypes_W_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterW = type.getTypeParameters().get(4); assertEquals("W", typeParameterW.getIdentifier()); assertSame(type, typeParameterW.getDeclarator()); assertEquals(2, typeParameterW.getConstraints().size()); JvmTypeConstraint secondTypeConstraint = typeParameterW.getConstraints().get(1); assertTrue(secondTypeConstraint instanceof JvmUpperBound); JvmUpperBound secondUpperBound = (JvmUpperBound) secondTypeConstraint; assertNotNull(secondUpperBound.getTypeReference()); assertFalse(secondUpperBound.getTypeReference().toString(), secondUpperBound.getTypeReference().eIsProxy()); assertEquals("java.io.Serializable", secondUpperBound.getTypeReference().getIdentifier()); }
protected void createUserData(EObject eObject, ImmutableMap.Builder<String, String> userData) { if (eObject instanceof JvmDeclaredType) { userData.put(SIGNATURE_HASH_KEY, hashProvider.getHash((JvmDeclaredType) eObject)); if (eObject.eContainer() != null) { userData.put(IS_NESTED_TYPE, Boolean.TRUE.toString()); } } if (eObject instanceof JvmGenericType) { JvmGenericType genericType = (JvmGenericType) eObject; if (genericType.isInterface()) userData.put(IS_INTERFACE, Boolean.TRUE.toString()); if (!genericType.getTypeParameters().isEmpty()) { String result = "<"; for (Iterator<JvmTypeParameter> iterator = genericType.getTypeParameters().iterator(); iterator.hasNext();) { JvmTypeParameter type = iterator.next(); result += type.getSimpleName(); if (iterator.hasNext()) { result += ","; } } result +=">"; userData.put(TYPE_PARAMETERS, result); } } }
@Check public void checkTypeParameterNotUsedInStaticContext(JvmTypeReference ref) { if(ref.getType() instanceof JvmTypeParameter) { JvmTypeParameter typeParameter = (JvmTypeParameter) ref.getType(); if (!(typeParameter.getDeclarator() instanceof JvmOperation) || !isTypeParameterOfClosureImpl(ref)) { EObject currentParent = logicalContainerProvider.getNearestLogicalContainer(ref); while(currentParent != null) { if(currentParent == typeParameter.eContainer()) return; else if(isStaticContext(currentParent)) error("Cannot make a static reference to the non-static type " + typeParameter.getName(), ref, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, STATIC_ACCESS_TO_INSTANCE_MEMBER); currentParent = currentParent.eContainer(); } } } }
/** * Returns the signature of the given type. If the type declares type parameters, the type * parameters are included but their bounds are omitted. That is, the type {@code X<T extends CharSequence>} * will be returned as {@code X<T>} * */ public StringBuilder appendTypeSignature(JvmType type, StringBuilder result) { result.append(type.getSimpleName()); if(type instanceof JvmTypeParameterDeclarator) { List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) type).getTypeParameters(); if (!typeParameters.isEmpty()) { result.append("<"); for(int i = 0, size = typeParameters.size(); i < size; i++) { if (i != 0) { result.append(", "); } result.append(typeParameters.get(i).getName()); } result.append(">"); } } return result; }
@Override /* @Nullable */ protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Set<JvmTypeParameter> visiting) { LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(type); if (boundTypeArgument != null) { LightweightTypeReference boundReference = boundTypeArgument.getTypeReference(); if (boundReference != null && reference != boundReference) { if (boundReference instanceof UnboundTypeReference) return boundReference.copyInto(getOwner()); JvmType boundType = boundReference.getType(); if (boundType != type) { if (visiting.add(type)) { try { LightweightTypeReference result = boundReference.accept(this, visiting); return result; } finally { visiting.remove(type); } } else { return reference; } } } } return null; }
protected void _computeTypes(XInstanceOfExpression object, ITypeComputationState state) { ITypeComputationState expressionState = state.withExpectation(state.getReferenceOwner().newReferenceToObject()); expressionState.computeTypes(object.getExpression()); JvmTypeReference type = object.getType(); if (type != null && type.getType() instanceof JvmTypeParameter) { LightweightTypeReference lightweightReference = state.getReferenceOwner().toLightweightTypeReference(type); LightweightTypeReference rawTypeRef = lightweightReference.getRawTypeReference(); state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_USE_OF_TYPE_PARAMETER, "Cannot perform instanceof check against type parameter "+lightweightReference.getHumanReadableName()+". Use its erasure "+rawTypeRef.getHumanReadableName()+" instead since further generic type information will be erased at runtime.", object.getType(), null, -1, new String[] { })); } LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state); state.acceptActualType(bool); }
public InstanceExtensionDescriptionWithImplicitFirstArgument( QualifiedName qualifiedName, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, int receiverConformanceFlags, XExpression firstArgument, LightweightTypeReference firstArgumentType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> firstArgumentTypeParameterMapping, int bucketId, boolean visible, boolean validStaticState) { super(qualifiedName, feature, receiver, receiverType, receiverTypeParameterMapping, receiverConformanceFlags, EcoreUtil.copy(firstArgument), firstArgumentType, firstArgumentTypeParameterMapping, ConformanceFlags.NONE, bucketId, visible, validStaticState); }
@Override /* @Nullable */ protected LightweightTypeReference getUnmappedSubstitute(ParameterizedTypeReference reference, JvmTypeParameter type, ConstraintVisitingInfo visiting) { if (!ignoreDeclaredTypeParameters) { if (isDeclaredTypeParameter(type)) { return reference; } } ConstraintAwareTypeArgumentCollector collector = new ConstraintAwareTypeArgumentCollector(getOwner()); LightweightTraversalData data = new LightweightTraversalData(); data.getTypeParameterMapping().putAll(getTypeParameterMapping()); reference.accept(collector, data); LightweightMergedBoundTypeArgument boundTypeArgument = data.getTypeParameterMapping().get(type); if (boundTypeArgument != null && boundTypeArgument.getTypeReference() != reference) { return boundTypeArgument.getTypeReference().accept(this, visiting); } if (boundTypeArgument != null) return boundTypeArgument.getTypeReference(); return null; }
@Test public void testPrepareComputation_12() throws Exception { JvmType comparatorType = getTypeForName(Comparator.class, state); // type with illegal type parameters JvmTypeParameter typeParameter = createTypeParameter("COMPARABLE", state); ParameterizedTypeReference comparatorTypeReference = state.getReferenceOwner().newParameterizedTypeReference(comparatorType); comparatorTypeReference.addTypeArgument(createTypeReference(typeParameter, state)); assertFalse(comparatorTypeReference.isResolved()); TypeExpectation expectation = new TypeExpectation(comparatorTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[x, y|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); LightweightTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.util.Comparator.compare(T,T)", computer.getOperation().getIdentifier()); assertEquals("Comparator<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("(Unbound[T], Unbound[T])=>int", closureType.getSimpleName()); }
@Test public void testHintsAfterPrepareComputation_01() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); UnboundTypeReference elementReference = (UnboundTypeReference) createTypeReference(typeParameter, state); iterableTypeReference.addTypeArgument(elementReference); assertTrue(state.getResolvedTypes().getHints(elementReference.getHandle()).isEmpty()); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); assertEquals(1, state.getResolvedTypes().getHints(elementReference.getHandle()).size()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); assertEquals(1, state.getResolvedTypes().getHints(closureTypeArgument.getHandle()).size()); }
@Test public void test_ParameterizedTypes_Inner_X_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterX = type.getTypeParameters().get(0); assertEquals("X", typeParameterX.getIdentifier()); assertSame(type, typeParameterX.getDeclarator()); assertEquals(1, typeParameterX.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterX.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("W", upperBound.getTypeReference().getIdentifier()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertTrue(upperBoundType instanceof JvmTypeParameter); JvmTypeParameter typeParameterW = (JvmTypeParameter) upperBoundType; assertSame(type.getDeclaringType(), typeParameterW.getDeclarator()); }
public boolean isLocalTypeParameter(EObject context, JvmTypeParameter parameter) { if (context == parameter.getDeclarator()) return true; if (context instanceof JvmOperation && ((JvmOperation) context).isStatic()) return false; if (context instanceof JvmDeclaredType && ((JvmDeclaredType) context).isStatic()) return false; JvmIdentifiableElement jvmElement = contextProvider.getNearestLogicalContainer(context); if (jvmElement != null) { return isLocalTypeParameter(jvmElement, parameter); } EObject container = context.eContainer(); if (container == null) { return false; } return isLocalTypeParameter(container, parameter); }
/** * Returns the unresolved string representation of the unresolved type parameters of the feature. The simple names of * the type bounds are used. The string representation includes the angle brackets. */ protected String getFeatureTypeParametersAsString(boolean showBounds) { List<JvmTypeParameter> typeParameters = getDeclaredTypeParameters(); if(!typeParameters.isEmpty()) { StringBuilder b = new StringBuilder(); b.append("<"); for(int i=0; i<typeParameters.size(); ++i) { JvmTypeParameter typeParameter = typeParameters.get(i); if(showBounds) b.append(getTypeParameterAsString(typeParameter)); else b.append(typeParameter.getSimpleName()); if(i < typeParameters.size()-1) b.append(", "); } b.append(">"); return b.toString(); } return ""; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case TypesPackage.JVM_GENERIC_TYPE__TYPE_PARAMETERS: getTypeParameters().clear(); getTypeParameters().addAll((Collection<? extends JvmTypeParameter>)newValue); return; case TypesPackage.JVM_GENERIC_TYPE__INTERFACE: setInterface((Boolean)newValue); return; case TypesPackage.JVM_GENERIC_TYPE__STRICT_FLOATING_POINT: setStrictFloatingPoint((Boolean)newValue); return; case TypesPackage.JVM_GENERIC_TYPE__ANONYMOUS: setAnonymous((Boolean)newValue); return; } super.eSet(featureID, newValue); }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmType type = (JvmType) description.getElementOrProxy(); String typeKind = ""; if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) { typeKind = "primitive type"; } else if (type instanceof JvmAnnotationType) { typeKind = "annotation type"; } else if (type instanceof JvmEnumerationType) { typeKind = "enum type"; } else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) { typeKind = "interface type"; } else if (type instanceof JvmTypeParameter) { typeKind = "type parameter"; } String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName()); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(), XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null); result.accept(diagnostic); return false; }
protected LightweightTypeReference substituteInArrayContext(final String componentType) { StringConcatenation _builder = new StringConcatenation(); _builder.append("Iterable<"); _builder.append(componentType); _builder.append(">"); final LightweightTypeReference typeReference = this.toTypeReference(_builder); final DeclaratorTypeArgumentCollector collector = new DeclaratorTypeArgumentCollector(); final Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping = collector.getTypeParameterMapping(typeReference); Assert.assertEquals(1, mapping.size()); final JvmTypeParameter typeParameter = IterableExtensions.<JvmTypeParameter>head(mapping.keySet()); final LightweightMergedBoundTypeArgument boundArgument = mapping.get(typeParameter); Assert.assertEquals(componentType, boundArgument.getTypeReference().getSimpleName()); final ITypeReferenceOwner owner = typeReference.getOwner(); final ArrayTypeReference originalArray = owner.newArrayTypeReference(owner.newParameterizedTypeReference(typeParameter)); Assert.assertEquals("T[]", originalArray.getSimpleName()); ITypeReferenceOwner _owner = typeReference.getOwner(); final LightweightTypeReference substitutedArray = new StandardTypeParameterSubstitutor(mapping, _owner).substitute(originalArray); return substitutedArray; }
protected boolean isResolvedTypeParameter(LightweightTypeReference typeReference, JvmTypeParameter typeParameter) { List<LightweightTypeReference> typeArguments = typeReference.getTypeArguments(); for(int i = 0, size = typeArguments.size(); i < size; i++) { LightweightTypeReference typeArgument = typeArguments.get(i); if (typeParameter.equals(typeArgument.getType()) || isResolvedTypeParameter(typeArgument, typeParameter)) { return true; } } LightweightTypeReference outer = typeReference.getOuter(); if (outer != null) { if (isResolvedTypeParameter(outer, typeParameter)) { return true; } } return false; }
protected JvmFormalParameter createFormalParameter(BinaryTypeSignature parameterType, String paramName, JvmMember container, Map<String, JvmTypeParameter> typeParameters) { JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter(); result.setName(paramName); result.setParameterType(proxies.createTypeReference(parameterType, typeParameters)); return result; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<JvmTypeParameter> getTypeParameters() { if (typeParameters == null) { typeParameters = new EObjectContainmentWithInverseEList<JvmTypeParameter>(JvmTypeParameter.class, this, TypesPackage.JVM_EXECUTABLE__TYPE_PARAMETERS, TypesPackage.JVM_TYPE_PARAMETER__DECLARATOR); } return typeParameters; }
@Test public void test_twoListParamsListResult_03() { JvmOperation twoListParamsListResult = getMethodFromParameterizedMethods( "twoListParamsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListParamsListResult.getReturnType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsListResult, typeVar.getDeclarator()); }
@Test public void test_arrayVariable_02() { JvmOperation arrayVariable = getMethodFromParameterizedMethods("arrayVariable(T[])"); JvmType paramType = arrayVariable.getParameters().get(0).getParameterType().getType(); assertEquals("T[]", paramType.getIdentifier()); assertTrue(paramType instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType; assertTrue(arrayType.getComponentType() instanceof JvmTypeParameter); }
@Test public void test_nestedArrayVariable_02() { JvmOperation nestedArrayVariable = getMethodFromParameterizedMethods("nestedArrayVariable(T[][])"); JvmType paramType = nestedArrayVariable.getParameters().get(0).getParameterType().getType(); assertTrue(paramType instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType; assertTrue(arrayType.getComponentType() instanceof JvmArrayType); arrayType = (JvmArrayType) arrayType.getComponentType(); assertTrue(arrayType.getComponentType() instanceof JvmTypeParameter); }
@Override protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ArrayTypeReference declaration) { JvmType type = reference.getType(); if (type instanceof JvmTypeParameter) { if (shouldProcess((JvmTypeParameter) type)) { JvmTypeParameter typeParameter = (JvmTypeParameter) type; processTypeParameter(typeParameter, declaration); } } else { LightweightTypeReference declarationAsList = declaration.tryConvertToListType(); outerVisit(declarationAsList, reference); } }
@Test public void test_ParameterizedTypes_V_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterV = type.getTypeParameters().get(3); assertEquals("V", typeParameterV.getIdentifier()); assertSame(type, typeParameterV.getDeclarator()); assertEquals(1, typeParameterV.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterV.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<java.util.List<? extends V>>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("java.util.List<? extends V>", typeArgument.getIdentifier()); JvmParameterizedTypeReference nestedListType = (JvmParameterizedTypeReference) typeArgument; assertEquals(1, nestedListType.getArguments().size()); JvmTypeReference nestedArgument = nestedListType.getArguments().get(0); assertTrue(nestedArgument instanceof JvmWildcardTypeReference); assertEquals(1, ((JvmWildcardTypeReference) nestedArgument).getConstraints().size()); JvmUpperBound nestedUpperBound = (JvmUpperBound) ((JvmWildcardTypeReference) nestedArgument).getConstraints() .get(0); assertSame(typeParameterV, nestedUpperBound.getTypeReference().getType()); }
protected void _format(final JvmTypeParameter ref, @Extension final IFormattableDocument document) { EList<JvmTypeConstraint> _constraints = ref.getConstraints(); for (final JvmTypeConstraint c : _constraints) { { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; document.<JvmTypeConstraint>prepend(c, _function); document.<JvmTypeConstraint>format(c); } } }
@Override protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> computeContextTypeParameterMapping() { if (typeArguments.isEmpty()) { return super.computeContextTypeParameterMapping(); } Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> result = Maps.newHashMap(super.computeContextTypeParameterMapping()); List<JvmTypeParameter> typeParameters = getDeclaration().getTypeParameters(); for(int i = 0; i < Math.min(typeParameters.size(), typeArguments.size()); i++) { result.put(typeParameters.get(i), new LightweightMergedBoundTypeArgument(typeArguments.get(i), VarianceInfo.INVARIANT)); } return result; }
protected BucketedEObjectDescription createExtensionDescription(QualifiedName name, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) { if (helper == null || !helper.isPossibleExtension(feature)) { return null; } return doCreateExtensionDescription(name, feature, receiver, receiverType, receiverTypeParameterMapping, bucket, validStaticState); }
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getReceiverTypeParameterMapping() { if (receiverTypeParameterMapping == null) { receiverTypeParameterMapping = Collections.emptyMap(); if (receiverType != null) { receiverTypeParameterMapping = new DeclaratorTypeArgumentCollector().getTypeParameterMapping(receiverType); } } return receiverTypeParameterMapping; }
protected String getUniqueIdentifier(JvmType type) { String typeIdentifier = type.getIdentifier(); if (type instanceof JvmTypeParameter) { JvmIdentifiableElement declarator = (JvmIdentifiableElement) ((JvmTypeParameter) type).getDeclarator(); // may happen in unit tests if (declarator != null) { typeIdentifier = typeIdentifier + ":" + declarator.getQualifiedName(); } else { typeIdentifier = typeIdentifier + ":"; } } return typeIdentifier; }
private void checkTypeParameterNotAllowedAsLiteral(EObject ctx, JvmType type, ITypeComputationState state) { if (type instanceof JvmTypeParameter) { state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_USE_OF_TYPE_PARAMETER, "Illegal class literal for the type parameter " + type.getSimpleName()+".", ctx, null, -1, new String[] { })); } }
@Override protected boolean shouldProcessInContextOf(JvmTypeParameter declaredTypeParameter, Set<JvmTypeParameter> boundParameters, Set<JvmTypeParameter> visited) { if (!shouldProcess(declaredTypeParameter)) { if (boundParameters.contains(declaredTypeParameter) && !visited.add(declaredTypeParameter)) return false; } return true; }