下面列出了怎么用org.eclipse.emf.ecore.ETypeParameter的API类实例代码及写法,或者点击链接到github查看源代码。
public EGenericType getBoundGenericType(EGenericType genericType, EClass context) {
ETypeParameter typeParameter = genericType.getETypeParameter();
if (typeParameter != null) {
// the reference type is a type parameter
TypeBindingAcceptor typeBindingAcceptor = new TypeBindingAcceptor();
addTypeParameterBindingsRecursively(context, typeBindingAcceptor);
return typeBindingAcceptor.getBoundGenericType(typeParameter);
} else {
// the reference type is a generic type
if (genericType.getEClassifier() == null) {
throw new IllegalStateException("Either typeParameter or eRawType must be set in EGenericType "
+ genericType);
}
return genericType;
}
}
protected static void addTypeParameterBindingsRecursively(EClass context, TypeBindingAcceptor bindingAcceptor) {
for (EGenericType genericSuperType : context.getEGenericSuperTypes()) {
EClassifier rawSuperType = genericSuperType.getEClassifier();
EList<EGenericType> typeArguments = genericSuperType.getETypeArguments();
EList<ETypeParameter> typeParameters = rawSuperType.getETypeParameters();
if (typeArguments.size() != typeParameters.size()) {
throw new IllegalStateException(
"Number of typeArguments does not match number of typeParameters in EGenericType "
+ genericSuperType);
}
for (int i = 0; i < typeArguments.size(); ++i) {
bindingAcceptor.accept(typeParameters.get(i), typeArguments.get(i));
}
if (rawSuperType instanceof EClass) {
addTypeParameterBindingsRecursively((EClass) rawSuperType, bindingAcceptor);
}
}
}
public void accept(ETypeParameter typeParameter, EGenericType typeArgument) {
if(bindings==null) {
bindings = new HashMap<ETypeParameter, EGenericType>();
}
ETypeParameter replacedParameter = typeArgument.getETypeParameter();
if (replacedParameter != null) {
EGenericType existingBoundType = bindings.get(replacedParameter);
if (existingBoundType != null) {
bindings.remove(replacedParameter);
bindings.put(typeParameter, existingBoundType);
return;
}
} else {
if (typeArgument.getEClassifier() == null) {
throw new IllegalStateException("Either typeParameter or eClassifier must be set in ETypeArgument "
+ typeArgument);
}
}
bindings.put(typeParameter, typeArgument);
}
protected Object _transform(final EClass model) {
final Function1<ETypeParameter, Object> _function = (ETypeParameter e) -> {
return this.transform(e);
};
return ListExtensions.<ETypeParameter, Object>map(model.getETypeParameters(), _function);
}
public EGenericType getBoundGenericType(ETypeParameter typeParameter) {
if(bindings==null)
return null;
return bindings.get(typeParameter);
}
/**
* Complete the initialization of the package and its meta-model. This
* method is guarded to have no affect on any invocation but its first.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void initializePackageContents() {
if (isInitialized) return;
isInitialized = true;
// Initialize package
setName(eNAME);
setNsPrefix(eNS_PREFIX);
setNsURI(eNS_URI);
// Create type parameters
ETypeParameter aEClass_T = addETypeParameter(aEClass, "T");
ETypeParameter bEClass_U = addETypeParameter(bEClass, "U");
ETypeParameter bEClass_V = addETypeParameter(bEClass, "V");
ETypeParameter cEClass_W = addETypeParameter(cEClass, "W");
// Set bounds for type parameters
// Add supertypes to classes
EGenericType g1 = createEGenericType(this.getA());
EGenericType g2 = createEGenericType(bEClass_V);
g1.getETypeArguments().add(g2);
bEClass.getEGenericSuperTypes().add(g1);
g1 = createEGenericType(this.getB());
g2 = createEGenericType(cEClass_W);
g1.getETypeArguments().add(g2);
g2 = createEGenericType(this.getSomeType());
g1.getETypeArguments().add(g2);
cEClass.getEGenericSuperTypes().add(g1);
g1 = createEGenericType(this.getC());
g2 = createEGenericType(this.getOtherType());
g1.getETypeArguments().add(g2);
dEClass.getEGenericSuperTypes().add(g1);
// Initialize classes and features; add operations and parameters
initEClass(aEClass, org.eclipse.xtext.util.genericTest.A.class, "A", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
g1 = createEGenericType(aEClass_T);
initEReference(getA_SomeReference(), g1, null, "someReference", null, 0, 1, org.eclipse.xtext.util.genericTest.A.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getA_SomeReference1(), this.getSomeType(), null, "someReference1", null, 0, 1, org.eclipse.xtext.util.genericTest.A.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(bEClass, org.eclipse.xtext.util.genericTest.B.class, "B", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
g1 = createEGenericType(bEClass_U);
initEReference(getB_OtherReference(), g1, null, "otherReference", null, 0, 1, org.eclipse.xtext.util.genericTest.B.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
g1 = createEGenericType(this.getA());
g2 = createEGenericType(this.getOtherType());
g1.getETypeArguments().add(g2);
initEReference(getB_OtherReference1(), g1, null, "otherReference1", null, 0, 1, org.eclipse.xtext.util.genericTest.B.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(cEClass, org.eclipse.xtext.util.genericTest.C.class, "C", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEClass(dEClass, org.eclipse.xtext.util.genericTest.D.class, "D", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEClass(someTypeEClass, SomeType.class, "SomeType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEClass(otherTypeEClass, OtherType.class, "OtherType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
// Create resource
createResource(eNS_URI);
}
/**
* Complete the initialization of the package and its meta-model. This
* method is guarded to have no affect on any invocation but its first.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void initializePackageContents() {
if (isInitialized) return;
isInitialized = true;
// Initialize package
setName(eNAME);
setNsPrefix(eNS_PREFIX);
setNsURI(eNS_URI);
// Obtain other dependent packages
AnalysismodelPackage theAnalysismodelPackage = (AnalysismodelPackage)EPackage.Registry.INSTANCE.getEPackage(AnalysismodelPackage.eNS_URI);
// Create type parameters
ETypeParameter timeSeriesEClass_V = addETypeParameter(timeSeriesEClass, "V");
ETypeParameter timeSeriesEClass_U = addETypeParameter(timeSeriesEClass, "U");
ETypeParameter unitEClass_V = addETypeParameter(unitEClass, "V");
// Set bounds for type parameters
EGenericType g1 = createEGenericType(this.getValue());
timeSeriesEClass_V.getEBounds().add(g1);
g1 = createEGenericType(this.getUnit());
EGenericType g2 = createEGenericType(timeSeriesEClass_V);
g1.getETypeArguments().add(g2);
timeSeriesEClass_U.getEBounds().add(g1);
g1 = createEGenericType(this.getValue());
unitEClass_V.getEBounds().add(g1);
// Add supertypes to classes
intValueEClass.getESuperTypes().add(this.getValue());
longValueEClass.getESuperTypes().add(this.getValue());
floatValueEClass.getESuperTypes().add(this.getValue());
doubleValueEClass.getESuperTypes().add(this.getValue());
// Initialize classes, features, and operations; add parameters
initEClass(statisticsEClass, Statistics.class, "Statistics", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
g1 = createEGenericType(this.getTimeSeries());
g2 = createEGenericType();
g1.getETypeArguments().add(g2);
g2 = createEGenericType();
g1.getETypeArguments().add(g2);
initEReference(getStatistics_TimeSeries(), g1, null, "timeSeries", null, 0, -1, Statistics.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(timeSeriesEClass, TimeSeries.class, "TimeSeries", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getTimeSeries_Name(), ecorePackage.getEString(), "name", null, 0, 1, TimeSeries.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getTimeSeries_Unit(), ecorePackage.getEJavaObject(), "unit", null, 0, 1, TimeSeries.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
g1 = createEGenericType(timeSeriesEClass_V);
initEReference(getTimeSeries_Values(), g1, null, "values", null, 0, -1, TimeSeries.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(valueEClass, Value.class, "Value", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getValue_Timestamp(), theAnalysismodelPackage.getInstant(), "timestamp", null, 0, 1, Value.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(intValueEClass, IntValue.class, "IntValue", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getIntValue_Measurement(), ecorePackage.getEInt(), "measurement", null, 0, 1, IntValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(longValueEClass, LongValue.class, "LongValue", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getLongValue_Measurement(), ecorePackage.getELong(), "measurement", null, 0, 1, LongValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(floatValueEClass, FloatValue.class, "FloatValue", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getFloatValue_Measurement(), ecorePackage.getEFloat(), "measurement", null, 0, 1, FloatValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(doubleValueEClass, DoubleValue.class, "DoubleValue", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getDoubleValue_Measurement(), ecorePackage.getEDouble(), "measurement", null, 0, 1, DoubleValue.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(unitEClass, Unit.class, "Unit", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
// Initialize enums and add enum literals
initEEnum(predefinedUnitsEEnum, PredefinedUnits.class, "PredefinedUnits");
addEEnumLiteral(predefinedUnitsEEnum, PredefinedUnits.CPU_UTIL);
addEEnumLiteral(predefinedUnitsEEnum, PredefinedUnits.RESPONSE_TIME);
}