@Test public void test_twoListWildcardsListResult_03() { JvmOperation twoListWildcardsListResult = getMethodFromParameterizedMethods( "twoListWildcardsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListWildcardsListResult.getReturnType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
@Test public void test_ParameterizedTypes_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodZ = getMethodFromType(type, ParameterizedTypes.class, "methodZ(java.util.List)"); assertEquals(1, methodZ.getParameters().size()); assertEquals(1, methodZ.getTypeParameters().size()); assertEquals("Z", methodZ.getTypeParameters().get(0).getIdentifier()); JvmTypeReference listZ = methodZ.getReturnType(); assertFalse(listZ.toString(), listZ.getType().eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super Z>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; 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 Z", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); assertEquals("Z", lowerBound.getTypeReference().getIdentifier()); JvmTypeParameter z = methodZ.getTypeParameters().get(0); assertSame(z, lowerBound.getTypeReference().getType()); }
@Test public void test_ParameterizedTypes_W_01() { 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 firstTypeConstraint = typeParameterW.getConstraints().get(0); assertTrue(firstTypeConstraint instanceof JvmUpperBound); JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint; assertNotNull(firstUpperBound.getTypeReference()); assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy()); assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound .getTypeReference(); assertEquals(1, comparableType.getArguments().size()); JvmTypeReference typeArgument = comparableType.getArguments().get(0); assertEquals("S", typeArgument.getIdentifier()); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
private void setSuperTypes(String name, BinarySuperTypeSignature signature, String superName, String[] interfaces) { InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>) result.getSuperTypes(); if (signature != null) { List<BinaryGenericTypeSignature> superTypeSignatures = signature.getSuperTypes(); if (result.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) result).isInterface()) { if (superTypeSignatures.size() > 1) { superTypeSignatures = superTypeSignatures.subList(1, superTypeSignatures.size()); } } for (int i = 0; i < superTypeSignatures.size(); i++) { superTypes.addUnique(proxies.createTypeReference(superTypeSignatures.get(i), typeParameters)); } } else { if (superName != null && result.eClass() != TypesPackage.Literals.JVM_ANNOTATION_TYPE) { superTypes.addUnique(proxies.createTypeReference(BinarySignatures.createObjectTypeSignature(superName), typeParameters)); } setInterfaces(interfaces, typeParameters, superTypes); if (superTypes.isEmpty() && !Proxies.JAVA_LANG_OBJECT.equals(name)) { superTypes.addUnique(proxies.createObjectTypeReference()); } } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setTypeReference(JvmTypeReference newTypeReference) { if (newTypeReference != typeReference) { NotificationChain msgs = null; if (typeReference != null) msgs = ((InternalEObject)typeReference).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_TYPE_CONSTRAINT__TYPE_REFERENCE, null, msgs); if (newTypeReference != null) msgs = ((InternalEObject)newTypeReference).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_TYPE_CONSTRAINT__TYPE_REFERENCE, null, msgs); msgs = basicSetTypeReference(newTypeReference, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.JVM_TYPE_CONSTRAINT__TYPE_REFERENCE, newTypeReference, newTypeReference)); }
@Test public void test_ParameterizedTypes_Inner_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_01()"); JvmTypeReference listT = methodV.getReturnType(); assertEquals("java.util.List<? extends V>[]", listT.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listT) .getComponentType(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends V", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter v = type.getTypeParameters().get(3); assertSame(v, upperBound.getTypeReference().getType()); }
@Test public void test_ParameterizedTypes_Inner_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_02()"); JvmTypeReference listV = methodV.getReturnType(); assertEquals("java.util.List<? extends V[]>", listV.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listV; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends V[]", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertTrue(upperBoundType instanceof JvmArrayType); assertTrue(((JvmArrayType) upperBoundType).getComponentType() instanceof JvmTypeParameter); JvmTypeParameter v = type.getTypeParameters().get(3); assertSame(v, ((JvmArrayType) upperBoundType).getComponentType()); }
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) { ResourceSet rs = EcoreUtil2.getResourceSet(rawType); JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference(); if (rs != null) { EObject javaLangObject = rs.getEObject(javaLangObjectURI, true); if (javaLangObject instanceof JvmType) { JvmType objectDeclaration = (JvmType) javaLangObject; refToObject.setType(objectDeclaration); return refToObject; } } JvmGenericType proxy = typesFactory.createJvmGenericType(); ((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI); refToObject.setType(proxy); return refToObject; }
@Override public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) { if (obj instanceof JvmTypeParameter) return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName(); if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter) return fallback.getFragment(obj); if (obj instanceof JvmIdentifiableElement) { if (obj instanceof JvmArrayType) { if (obj.eContainer() instanceof JvmGenericArrayTypeReference) return fallback.getFragment(obj); if (obj.eContainer() instanceof JvmIdentifiableElement) { return getFragment(obj.eContainer(), fallback) + "[]"; } } return ((JvmIdentifiableElement) obj).getIdentifier(); } return fallback.getFragment(obj); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setType(JvmTypeReference newType) { if (newType != type) { NotificationChain msgs = null; if (type != null) msgs = ((InternalEObject)type).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CheckPackage.FORMAL_PARAMETER__TYPE, null, msgs); if (newType != null) msgs = ((InternalEObject)newType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CheckPackage.FORMAL_PARAMETER__TYPE, null, msgs); msgs = basicSetType(newType, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, CheckPackage.FORMAL_PARAMETER__TYPE, newType, newType)); }
@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()); }
@Override public JvmTypeReference doVisitCompoundTypeReference(JvmCompoundTypeReference reference, Resource resource) { JvmCompoundTypeReference result = null; List<JvmTypeReference> components = reference.getReferences(); int recent = -1; for (int i = 0; i < components.size(); i++) { JvmTypeReference component = components.get(i); JvmTypeReference rawType = visit(component, resource); if (rawType != null && component != rawType) { if (result == null) { result = (JvmCompoundTypeReference) EcoreUtil.create(reference.eClass()); } for (int j = recent + 1; j < i; j++) { result.getReferences().add(components.get(j)); } result.getReferences().add(rawType); recent = i; } } if (result != null) return result; return reference; }
@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(); } } } }
/** * Creates a setter method for the given properties name with the standard implementation assigning the passed * parameter to a similarly named field. * * Example: <code> * public void setFoo(String foo) { * this.foo = foo; * } * </code> * * @return a setter method for a JavaBeans property with the given name, <code>null</code> if sourceElement or name are <code>null</code>. */ /* @Nullable */ public JvmOperation toSetter(/* @Nullable */ final EObject sourceElement, /* @Nullable */ final String propertyName, /* @Nullable */ final String fieldName, /* @Nullable */ JvmTypeReference typeRef) { if(sourceElement == null || propertyName == null || fieldName == null) return null; JvmOperation result = typesFactory.createJvmOperation(); result.setVisibility(JvmVisibility.PUBLIC); result.setReturnType(references.getTypeForName(Void.TYPE,sourceElement)); result.setSimpleName("set" + Strings.toFirstUpper(propertyName)); result.getParameters().add(toParameter(sourceElement, propertyName, typeRef)); setBody(result, new Procedures.Procedure1<ITreeAppendable>() { @Override public void apply(/* @Nullable */ ITreeAppendable p) { if(p != null) { p = p.trace(sourceElement); p.append("this."); p.append(javaKeywords.isJavaKeyword(fieldName) ? fieldName+"_" : fieldName); p.append(" = "); p.append(javaKeywords.isJavaKeyword(propertyName) ? propertyName+"_" : propertyName); p.append(";"); } } }); return associate(sourceElement, result); }
@Test public void test_ParameterizedTypes_Inner_Z_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterZ = type.getTypeParameters().get(2); assertEquals("Z", typeParameterZ.getIdentifier()); assertSame(type, typeParameterZ.getDeclarator()); assertEquals(1, typeParameterZ.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterZ.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<W>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("W", typeArgument.getIdentifier()); JvmTypeParameter w = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(4); assertSame(w, typeArgument.getType()); }
protected JvmTypeReference createComputedTypeReference( Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmMember member, /* @Nullable */ InferredTypeIndicator indicator, boolean returnType) { XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); if (indicator == null || indicator.getExpression() == null) result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, returnType)); else result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, indicator.getExpression(), returnType)); // TODO do we need a lightweight computed type reference? // resolvedTypes.setType(member, result); return result; }
@Override protected List<IEObjectDescription> getAllLocalElements() { List<IEObjectDescription> result = super.getAllLocalElements(); if (getSession().isInstanceContext() && !isExplicitStaticFeatureCall()) { ITypeReferenceOwner owner = getReceiverType().getOwner(); QualifiedThisOrSuperDescription thisDescription = new QualifiedThisOrSuperDescription(THIS, owner.newParameterizedTypeReference(getTypeLiteral()), getBucket().getId(), true, getReceiver()); addToList(thisDescription, result); JvmType receiverRawType = getTypeLiteral(); if (receiverRawType instanceof JvmDeclaredType) { JvmType referencedType = receiverRawType; // If the receiver type is an interface, 'super' always refers to that interface if (!(receiverRawType instanceof JvmGenericType && ((JvmGenericType) receiverRawType).isInterface())) { JvmTypeReference superType = ((JvmDeclaredType) receiverRawType).getExtendedClass(); if (superType != null) { referencedType = superType.getType(); } } QualifiedThisOrSuperDescription superDescription = new QualifiedThisOrSuperDescription(SUPER, owner.newParameterizedTypeReference(referencedType), getBucket().getId(), true, getReceiver()); addToList(superDescription, result); } } return result; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setType(JvmTypeReference newType) { if (newType != type) { NotificationChain msgs = null; if (type != null) msgs = ((InternalEObject)type).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_FIELD__TYPE, null, msgs); if (newType != null) msgs = ((InternalEObject)newType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_FIELD__TYPE, null, msgs); msgs = basicSetType(newType, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.JVM_FIELD__TYPE, newType, newType)); }
@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()); }
@Override /* @Nullable */ protected JvmTypeReference doGetTypeReference(XComputedTypeReferenceImplCustom context) { try { resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type", typeResolver.getSourceElement(member), null, -1, null)); return TypesFactory.eINSTANCE.createJvmAnyTypeReference(); } finally { context.unsetTypeProviderWithoutNotification(); } }
protected void _infer(final Model m, final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) { final XBlockExpression e = m.getBlock(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmTypeReference> _exceptions = it_1.getExceptions(); JvmTypeReference _typeRef = this._typeReferenceBuilder.typeRef(Throwable.class); this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef); this._jvmTypesBuilder.setBody(it_1, e); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(e, "myMethod", this._jvmTypesBuilder.inferredType(), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); }; acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(e, this.name(e.eResource())), _function); }
/** * Creates a clone of the given {@link JvmTypeReference} without resolving any proxies. * The clone will be associated with the original element by means of {@link JvmModelAssociator associations}. * * @param typeRef the type reference to be cloned. * @return a clone of typeRef, <code>null</code> if typeRef is <code>null</code> or a {@link JvmUnknownTypeReference} * if there is a problem with the typeRef. */ /* @Nullable */ public JvmTypeReference cloneWithProxies(/* @Nullable */ JvmTypeReference typeRef) { if(typeRef == null) return null; if (typeRef instanceof JvmParameterizedTypeReference && !typeRef.eIsProxy() && !typeRef.eIsSet(TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE)) { JvmUnknownTypeReference unknownTypeReference = typesFactory.createJvmUnknownTypeReference(); return unknownTypeReference; } return cloneAndAssociate(typeRef); }
protected boolean hasUnhandledException(List<LightweightTypeReference> thrownExceptions, Collection<JvmTypeReference> declaredExceptions) { for(LightweightTypeReference thrownException: thrownExceptions) { if (!thrownException.isSubtypeOf(RuntimeException.class) && !thrownException.isSubtypeOf(Error.class)) { if (isUnhandledException(thrownException, declaredExceptions)) { return true; } } } return false; }
@Override public JvmTypeReference toTypeReference() { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toTypeReference()); } return result; }
@Test public void test_twoListWildcardsNoResult_02() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); assertNotNull(paramType); assertEquals("java.util.List<? extends java.lang.Object>", paramType.getIdentifier()); assertTrue(paramType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
@Test public void test_arrayWildcard_02() { JvmOperation arrayWildcard = getMethodFromParameterizedMethods("arrayWildcard(java.util.List[])"); JvmTypeReference paramType = arrayWildcard.getParameters().get(0).getParameterType(); assertEquals("java.util.List<? extends java.lang.Object>[]", paramType.getIdentifier()); assertTrue(paramType.getType() instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType.getType(); assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType); assertTrue(paramType instanceof JvmGenericArrayTypeReference); assertTrue( ((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference); }
protected IFeatureScopeSession addExtensionFieldsToMemberSession( ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmDeclaredType type, JvmIdentifiableElement thisFeature, Set<String> seenNames, Set<JvmType> seenTypes) { if (seenTypes.add(type)) { Iterable<JvmField> fields = type.getDeclaredFields(); // collect local fields first, to populate the set of names Map<XExpression, LightweightTypeReference> extensionProviders = null; for(JvmField field: fields) { if (featureScopeSession.isVisible(field) && seenNames.add(field.getSimpleName()) && isExtensionProvider(field)) { if (extensionProviders == null) { extensionProviders = Maps2.newLinkedHashMapWithExpectedSize(3); } XAbstractFeatureCall extensionProvider = createExtensionProvider(thisFeature, field); LightweightTypeReference fieldType = resolvedTypes.getActualType(field); extensionProviders.put(extensionProvider, fieldType); } } // traverse the type hierarchy to create the feature scope sessions JvmTypeReference superType = getExtendedClass(type); IFeatureScopeSession result = featureScopeSession; if (superType != null) { result = addExtensionFieldsToMemberSession(resolvedTypes, featureScopeSession, (JvmDeclaredType) superType.getType(), thisFeature, seenNames, seenTypes); } if (extensionProviders != null) { result = result.addToExtensionScope(extensionProviders); } return result; } return featureScopeSession; }
@Test public void test_arrayParameterized_02() { JvmOperation arrayParameterized = getMethodFromParameterizedMethods("arrayParameterized(java.util.List[])"); JvmTypeReference paramType = arrayParameterized.getParameters().get(0).getParameterType(); assertEquals("java.util.List<T>[]", paramType.getIdentifier()); assertTrue(paramType.getType() instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType.getType(); assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType); assertTrue(paramType instanceof JvmGenericArrayTypeReference); assertTrue( ((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference); }
@Test public void testDefaultTypeAnnotationValue_01() throws Exception { JvmTypeAnnotationValue value = (JvmTypeAnnotationValue) getDefaultAnnotationValue("charSequenceClass"); assertEquals(1, value.getValues().size()); JvmTypeReference typeReference = value.getValues().get(0); assertEquals(String.class.getName(), typeReference.getIdentifier()); }
@Override public List<LightweightTypeReference> getResolvedTypeParameterConstraints(int idx) throws IndexOutOfBoundsException { JvmTypeParameter typeParameter = getResolvedTypeParameters().get(idx); List<JvmTypeConstraint> constraints = typeParameter.getConstraints(); List<JvmTypeReference> constraintReferences = Lists.newArrayListWithCapacity(constraints.size()); for(JvmTypeConstraint constraint: constraints) { constraintReferences.add(constraint.getTypeReference()); } List<LightweightTypeReference> result = getResolvedReferences(constraintReferences); return result; }
protected void acceptType(JvmTypeReference ref) { if (ref instanceof XFunctionTypeRef || ref instanceof JvmWildcardTypeReference || ref instanceof JvmGenericArrayTypeReference || (ref.eContainer() instanceof XFunctionTypeRef && ref.eContainmentFeature() == JVM_SPECIALIZED_TYPE_REFERENCE__EQUIVALENT) || NodeModelUtils.findActualNodeFor(ref) == null) return; else acceptPreferredType(ref); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetType(JvmTypeReference newType, NotificationChain msgs) { JvmTypeReference oldType = type; type = newType; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CheckPackage.FORMAL_PARAMETER__TYPE, oldType, newType); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; }
protected void setInterfaces(String[] interfaces, Map<String, JvmTypeParameter> typeParameters, InternalEList<JvmTypeReference> result) { if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { String interfaceName = interfaces[i]; result.addUnique(proxies.createTypeReference(BinarySignatures.createObjectTypeSignature(interfaceName), typeParameters)); } } }
@Test public void test_ParameterizedTypes_inner_return_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes.class, "plainInner(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes$Inner)"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals("ParameterizedTypes<S, T, U, V, W>$Inner<W, List<W>, List<W>>", returnType.getSimpleName()); }
private JvmTypeReference newObjectReference() { JvmType objectType = typesFactory.createJvmGenericType(); String objectClassName = Object.class.getName(); ((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName)); JvmParameterizedTypeReference result = typesFactory.createJvmParameterizedTypeReference(); result.setType(objectType); return result; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case TypesPackage.JVM_FORMAL_PARAMETER__NAME: setName((String)newValue); return; case TypesPackage.JVM_FORMAL_PARAMETER__PARAMETER_TYPE: setParameterType((JvmTypeReference)newValue); return; } super.eSet(featureID, newValue); }
@Test public void testRawIterable_01() { String typeName = RawIterable.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmTypeReference> superTypes = type.getSuperTypes(); JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1); assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier()); assertTrue(iterableSuperType.getArguments().isEmpty()); }
@Test public void testBug427098() { String typeName = Bug427098.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmAnnotationReference annotationReference = type.getAnnotations().get(0); JvmTypeAnnotationValue annotationValue = getClassArrayAnnotationValue(annotationReference); assertEquals("classArray", annotationValue.getOperation().getSimpleName()); List<JvmTypeReference> typeReferences = annotationValue.getValues(); assertEquals(5, typeReferences.size()); assertTypeReference("int", typeReferences, 0); assertTypeReference("void", typeReferences, 1); assertTypeReference("double[][][]", typeReferences, 2); assertTypeReference("CharSequence[]", typeReferences, 3); assertTypeReference("Iterable", typeReferences, 4); }
protected String getFeatureParameterTypesAsString(JvmExecutable executable) { ITypeReferenceOwner referenceOwner = getState().getReferenceOwner(); List<JvmFormalParameter> parameters = executable.getParameters(); StringBuilder b = new StringBuilder(); b.append("("); for(int i=0; i<parameters.size(); ++i) { JvmTypeReference parameterType = parameters.get(i).getParameterType(); LightweightTypeReference typeReference = referenceOwner.toLightweightTypeReference(parameterType); b.append(typeReference.getHumanReadableName()); if(i < parameters.size()-1) b.append(", "); } b.append(")"); return b.toString(); }