/** * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that * can be created under this object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { super.collectNewChildDescriptors(newChildDescriptors, object); EGenericType eGenericType = (EGenericType) object; if (eGenericType.eContainmentFeature() == EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS && eGenericType.getEClassifier() == null && eGenericType.getETypeParameter() == null) { newChildDescriptors.add( createChildParameter( EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND, EcoreFactory.eINSTANCE.createEGenericType())); newChildDescriptors.add( createChildParameter( EcorePackage.Literals.EGENERIC_TYPE__ELOWER_BOUND, EcoreFactory.eINSTANCE.createEGenericType())); } if (eGenericType.getEClassifier() != null && !eGenericType.getEClassifier().getETypeParameters().isEmpty()) { newChildDescriptors.add( createChildParameter( EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS, EcoreFactory.eINSTANCE.createEGenericType())); } }
protected Type resolveWildcardType(@NonNull EGenericType eGenericType) { assert eGenericType.getETypeArguments().isEmpty(); assert eGenericType.getEClassifier() == null; EClassifier eClassifier = eGenericType.getERawType(); assert eClassifier == EcorePackage.Literals.EJAVA_OBJECT; /* WildcardTypeRefCS csTypeRef = BaseCSFactory.eINSTANCE.createWildcardTypeRefCS(); setOriginalMapping(csTypeRef, eObject); // csTypeRef.setExtends(doSwitchAll(eGenericType.getExtends())); // csTypeRef.setSuper(doSwitchAll(eGenericType.getSuper())); return csTypeRef; */ return metamodelManager.createWildcardType(null, null); // FIXME bounds /* org.eclipse.ocl.pivot.Class pivotElement = PivotFactory.eINSTANCE.createClass(); String name = PivotConstants.WILDCARD_NAME; EStructuralFeature eFeature = eGenericType.eContainmentFeature(); if ((eFeature != null) && eFeature.isMany()) { EObject eContainer = eGenericType.eContainer(); List<?> list = (List<?>)eContainer.eGet(eGenericType.eContainingFeature()); int index = list.indexOf(eGenericType); if (index != 0) { name += index; } } pivotElement.setName(name); return pivotElement; */ }
protected Type resolveType( @NonNull Map<String, Type> resolvedSpecializations, @NonNull EGenericType eGenericType) { Type pivotType = getCreated(Type.class, eGenericType); if (pivotType != null) { return pivotType; } EClassifier eClassifier = eGenericType.getEClassifier(); ETypeParameter eTypeParameter = eGenericType.getETypeParameter(); List<EGenericType> eTypeArguments = eGenericType.getETypeArguments(); if (eTypeParameter != null) { pivotType = resolveTypeParameter(eGenericType); } else if (eClassifier == null) { pivotType = resolveWildcardType(eGenericType); } else if (!eTypeArguments.isEmpty()) { String ecoreMoniker = Ecore2Moniker.toString(eGenericType); pivotType = resolvedSpecializations.get(ecoreMoniker); if (pivotType == null) { pivotType = resolveGenericType(resolvedSpecializations, eGenericType); resolvedSpecializations.put(ecoreMoniker, pivotType); } } else if (eClassifier instanceof EDataType) { assert eGenericType.getETypeArguments().isEmpty(); pivotType = resolveDataType((EDataType) eClassifier); } else { assert eGenericType.getETypeArguments().isEmpty(); pivotType = resolveSimpleType(eClassifier); } if (pivotType != null) { newCreateMap.put(eGenericType, pivotType); } return pivotType; }
protected void handleEGenericType( EGenericType genericType, Set<EPackage> visitedPackages, Set<Object> visited) { if (genericType != null && visited.add(genericType)) { handleEClassifier(genericType.getEClassifier(), visitedPackages, visited); handleEClassifier(genericType.getERawType(), visitedPackages, visited); handleEGenericType(genericType.getELowerBound(), visitedPackages, visited); handleEGenericType(genericType.getEUpperBound(), visitedPackages, visited); handleEGenericTypes(genericType.getETypeArguments(), visitedPackages, visited); handleETypeParameter(genericType.getETypeParameter(), visitedPackages, visited); } }
protected Type resolveTypeParameter(@NonNull EGenericType eGenericType) { EClassifier eClassifier = eGenericType.getEClassifier(); ETypeParameter eTypeParameter = eGenericType.getETypeParameter(); List<EGenericType> eTypeArguments = eGenericType.getETypeArguments(); assert eClassifier == null; assert eTypeArguments.isEmpty(); Type pivotType = null; if (eTypeParameter != null) { pivotType = getCreated(Type.class, eTypeParameter); } return pivotType; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override protected EStructuralFeature getChildFeature(Object object, Object child) { EGenericType eGenericType = (EGenericType) object; if (child instanceof EObject) { EObject eObject = (EObject) child; if (eObject.eContainer() == eGenericType) { // If it's really a contained child, return the feature for it. // return eObject.eContainingFeature(); } } if (eGenericType.getEClassifier() != null) { // You can only add type arguments if there are type parameters not yet used up. // return eGenericType.getETypeArguments().size() < eGenericType.getEClassifier().getETypeParameters().size() ? EcorePackage.Literals.EGENERIC_TYPE__ETYPE_ARGUMENTS : null; } else if (eGenericType.getETypeParameter() != null) { // You cannot add any children for a type parameter. // return null; } else if (eGenericType.eContainer() instanceof EGenericType) { // Only if you are contained by a generic type can you have bounds, // and only if there is no classifier or type parameter // and in that case the lower bound is returned only if that's the one that's set. // return eGenericType.getELowerBound() != null ? EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND : EcorePackage.Literals.EGENERIC_TYPE__EUPPER_BOUND; } else { // Otherwise you can't make it a child. // return null; } }
static String getText(EGenericType eGenericType) { ETypeParameter eTypeParameter = eGenericType.getETypeParameter(); if (eTypeParameter != null) { String name = eTypeParameter.getName(); return name == null ? "null" : name; } else { EClassifier eClassifier = eGenericType.getEClassifier(); if (eClassifier != null) { List<EGenericType> eTypeArguments = eGenericType.getETypeArguments(); if (eTypeArguments.isEmpty()) { String name = eClassifier.getName(); return name == null ? "null" : name; } else { StringBuilder result = new StringBuilder(); result.append(eClassifier.getName()); result.append('<'); for (Iterator<EGenericType> i = eTypeArguments.iterator(); ; ) { result.append(getText(i.next())); if (i.hasNext()) { result.append(", "); } else { break; } } result.append('>'); return result.toString(); } } else { EGenericType eUpperBound = eGenericType.getEUpperBound(); if (eUpperBound != null) { return "? extends " + getText(eUpperBound); } else { EGenericType eLowerBound = eGenericType.getELowerBound(); if (eLowerBound != null) { return "? super " + getText(eLowerBound); } else { return "?"; } } } } }
protected Type resolveGenericType( @NonNull Map<String, Type> resolvedSpecializations, @NonNull EGenericType eGenericType) { List<EGenericType> eTypeArguments = eGenericType.getETypeArguments(); assert !eGenericType.getETypeArguments().isEmpty(); EClassifier eClassifier = eGenericType.getEClassifier(); List<ETypeParameter> eTypeParameters = eClassifier.getETypeParameters(); assert eTypeParameters.size() == eTypeArguments.size(); Type unspecializedPivotType = getASType(eClassifier); if (unspecializedPivotType == null) { return null; } List<@NonNull Type> templateArguments = new ArrayList<@NonNull Type>(); for (EGenericType eTypeArgument : eTypeArguments) { if (eTypeArgument != null) { Type typeArgument = resolveType(resolvedSpecializations, eTypeArgument); if (typeArgument != null) { templateArguments.add(typeArgument); } } } org.eclipse.ocl.pivot.Class unspecializedPivotClass = unspecializedPivotType.isClass(); assert unspecializedPivotClass != null; // FIXME return metamodelManager.getLibraryType(unspecializedPivotClass, templateArguments); }