Adding quasigeneric qualifications to Collection-typed return values and parameters in JMI-generated interfaces.
PLEASE REVIEW
1.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/mapping/GenericMapper.java Mon Nov 22 21:52:59 2004 +0000
1.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/mapping/GenericMapper.java Mon Nov 22 21:56:39 2004 +0000
1.3 @@ -7,9 +7,10 @@
1.4 * http://www.sun.com/
1.5 *
1.6 * The Original Code is NetBeans. The Initial Developer of the Original
1.7 - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
1.8 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
1.9 * Microsystems, Inc. All Rights Reserved.
1.10 */
1.11 +
1.12 package org.netbeans.lib.jmi.mapping;
1.13
1.14 import org.netbeans.lib.jmi.util.TagProvider;
1.15 @@ -22,7 +23,6 @@
1.16 * Generates java interfaces for specified meta objects or whole meta model.
1.17 *
1.18 * @author Dusan Balek, Martin Matula
1.19 - * @version 0.1
1.20 */
1.21 public abstract class GenericMapper {
1.22 protected static String PACKAGE_POSTFIX = "Package"; //NOI18N
1.23 @@ -149,37 +149,54 @@
1.24
1.25 return attrType;
1.26 }
1.27 +
1.28 + protected static final int GENERIC_STYLE_NONE = 0;
1.29 + protected static final int GENERIC_STYLE_FAKE = 1;
1.30 + protected static final int GENERIC_STYLE_REAL = 2;
1.31
1.32 - // returns correct type name for attribute (depending on the multiplicity type)
1.33 - protected String getTypeName(Attribute attr) {
1.34 - MultiplicityType mp = attr.getMultiplicity();
1.35 -
1.36 + // returns correct type name for attribute or reference or parameter (depending on the multiplicity type)
1.37 + protected String getTypeName(StructuralFeature f) {
1.38 + return getTypeName(f, GENERIC_STYLE_NONE);
1.39 + }
1.40 + protected String getTypeName(StructuralFeature f, int genericStyle) {
1.41 + return getTypeName(f, f.getMultiplicity(), genericStyle);
1.42 + }
1.43 + protected String getTypeName(Parameter p) {
1.44 + return getTypeName(p, GENERIC_STYLE_NONE);
1.45 + }
1.46 + protected String getTypeName(Parameter p, int genericStyle) {
1.47 + return getTypeName(p, p.getMultiplicity(), genericStyle);
1.48 + }
1.49 + private String getTypeName(TypedElement te, MultiplicityType mp, int genericStyle) {
1.50 + String n = getTypeName(getAttrType(te));
1.51 + if (n == null || n.equals("null")) { // NOI18N
1.52 + throw new IllegalStateException("No type name for " + te); // NOI18N
1.53 + }
1.54 if (mp.getUpper() > 1 || mp.getUpper() == -1) {
1.55 - return (mp.isOrdered() ? DT_ORDERED : DT_MULTIVALUED);
1.56 + String rawname = mp.isOrdered() ? DT_ORDERED : DT_MULTIVALUED;
1.57 + switch (genericStyle) {
1.58 + case GENERIC_STYLE_NONE:
1.59 + return rawname;
1.60 + case GENERIC_STYLE_FAKE:
1.61 + return rawname + "/*<" + n + ">*/"; // NOI18N
1.62 + case GENERIC_STYLE_REAL:
1.63 + return rawname + "<" + n + ">"; // NOI18N
1.64 + default:
1.65 + throw new IllegalArgumentException("Bad genericStyle: " + genericStyle); // NOI18N
1.66 + }
1.67 } else if (mp.getLower() < 1) {
1.68 - return getTypeName(getAttrType(attr));
1.69 + return n;
1.70 } else {
1.71 - return getTypeName2(attr);
1.72 + return getPrimitiveName(n);
1.73 }
1.74 }
1.75
1.76 + //protected String getCollectionTypeName(String rawname, )
1.77 +
1.78 protected String getTypeName2(TypedElement te) {
1.79 return getPrimitiveName(getTypeName(getAttrType(te)));
1.80 }
1.81
1.82 - // returns correct type name for parameter (depending on the multiplicity type)
1.83 - protected String getTypeName(Parameter prm) {
1.84 - MultiplicityType mp = prm.getMultiplicity();
1.85 -
1.86 - if (mp.getUpper() > 1 || mp.getUpper() == -1) {
1.87 - return (mp.isOrdered() ? DT_ORDERED : DT_MULTIVALUED);
1.88 - } else if (mp.getLower() < 1) {
1.89 - return getTypeName(getAttrType(prm));
1.90 - } else {
1.91 - return getTypeName2(prm);
1.92 - }
1.93 - }
1.94 -
1.95 // resolves datatype name
1.96 protected String getTypeName(Classifier type) {
1.97 String result = (String) typeNameCache.get(type);
2.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/mapping/JavaMapper.java Mon Nov 22 21:52:59 2004 +0000
2.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/mapping/JavaMapper.java Mon Nov 22 21:56:39 2004 +0000
2.3 @@ -7,9 +7,10 @@
2.4 * http://www.sun.com/
2.5 *
2.6 * The Original Code is NetBeans. The Initial Developer of the Original
2.7 - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
2.8 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
2.9 * Microsystems, Inc. All Rights Reserved.
2.10 */
2.11 +
2.12 package org.netbeans.lib.jmi.mapping;
2.13
2.14 import org.netbeans.api.mdr.JMIStreamFactory;
2.15 @@ -27,7 +28,6 @@
2.16 * Generates java interfaces for specified meta objects or whole meta model.
2.17 *
2.18 * @author Martin Matula, Dusan Balek
2.19 - * @version 0.1
2.20 */
2.21 public class JavaMapper extends GenericMapper {
2.22
2.23 @@ -41,8 +41,8 @@
2.24 private static final String DOC_ATTR_SETTER = "Sets the value of {0} attribute. See '{'@link #{1}'}' for description on the attribute."; //NOI18N
2.25 private static final String DOC_ATTR_SETTER_PARAM = "New value to be set."; //NOI18N
2.26 // getter (multi-value)
2.27 - private static final String DOC_ATTR_GETTER_RETURN_ORDERED = "Value of {0} attribute."; //NOI18N
2.28 - private static final String DOC_ATTR_GETTER_RETURN_MULTI = "Value of {0} attribute."; //NOI18N
2.29 + private static final String DOC_ATTR_GETTER_RETURN_ORDERED = "Value of {0} attribute. Element type: '{'@link {1}'}'"; //NOI18N
2.30 + private static final String DOC_ATTR_GETTER_RETURN_MULTI = "Value of {0} attribute. Element type: '{'@link {1}'}'"; //NOI18N
2.31
2.32 // association template
2.33 private static final String DOC_ASSOC_PROXY = "{0} association proxy interface."; //NOI18N
2.34 @@ -77,8 +77,8 @@
2.35 private static final String DOC_REFERENCE_SETTER = "Sets the value of reference {0}. See '{'@link #{1}'}' for description on the reference."; //NOI18N
2.36 private static final String DOC_REFERENCE_SETTER_PARAM = "New value to be set."; //NOI18N
2.37 // getter (multi-value)
2.38 - private static final String DOC_REFERENCE_GETTER_RETURN_ORDERED = "Value of reference {0}."; //NOI18N
2.39 - private static final String DOC_REFERENCE_GETTER_RETURN_MULTI = "Value of reference {0}."; //NOI18N
2.40 + private static final String DOC_REFERENCE_GETTER_RETURN_ORDERED = "Value of reference {0}. Element type: '{'@link {1}'}'"; //NOI18N
2.41 + private static final String DOC_REFERENCE_GETTER_RETURN_MULTI = "Value of reference {0}. Element type: '{'@link {1}'}'"; //NOI18N
2.42
2.43 // class proxy template
2.44 private static final String DOC_CLASS_PROXY = "{0} class proxy interface."; //NOI18N
2.45 @@ -149,7 +149,7 @@
2.46 private static final String DOC_STRUCT_GETTER_RETURN = "Value of {1} field."; //NOI18N
2.47
2.48 // warning - for every file
2.49 - private static final String DOC_WARNING = "<p/><i><b>Note:</b> This type should not be subclassed or implemented by clients. It is generated from a MOF metamodel and automatically implemented by MDR (see <a href=\"http://mdr.netbeans.org\">mdr.netbeans.org</a>)</i>"; // NOI18N
2.50 + private static final String DOC_WARNING = "<p><em><strong>Note:</strong> This type should not be subclassed or implemented by clients. It is generated from a MOF metamodel and automatically implemented by MDR (see <a href=\"http://mdr.netbeans.org/\">mdr.netbeans.org</a>).</em></p>"; // NOI18N
2.51
2.52 // ..........................................................................
2.53
2.54 @@ -348,7 +348,7 @@
2.55 Attribute attr = (Attribute) objAttribute;
2.56 String attrName = firstUpper(tagProvider.getSubstName(attr));
2.57 Classifier attrType = getAttrType(attr);
2.58 - String attrTypeName = getTypeName(attrType);
2.59 + String attrTypeName = getTypeName(attr, GENERIC_STYLE_FAKE);
2.60
2.61 if (attr.getMultiplicity().getUpper() == 1) {
2.62 // getter
2.63 @@ -384,9 +384,10 @@
2.64 // getter
2.65 boolean ordered = attr.getMultiplicity().isOrdered();
2.66 methodJavaDoc(attr, true, DOC_ATTR_GETTER,
2.67 - (ordered ? DOC_ATTR_GETTER_RETURN_ORDERED : DOC_ATTR_GETTER_RETURN_MULTI), null, null, null
2.68 + (ordered ? DOC_ATTR_GETTER_RETURN_ORDERED : DOC_ATTR_GETTER_RETURN_MULTI), null, null,
2.69 + new String[] {getTypeName(attrType)}
2.70 );
2.71 - interfaceMethod((ordered ? DT_ORDERED : DT_MULTIVALUED), "get" + attrName, null, null); //NOI18N
2.72 + interfaceMethod(attrTypeName, "get" + attrName, null, null); //NOI18N
2.73 }
2.74 }
2.75
2.76 @@ -407,10 +408,10 @@
2.77 if (element instanceof Parameter) {
2.78 param = (Parameter) element;
2.79 if (param.getDirection().equals(DirectionKindEnum.RETURN_DIR)) {
2.80 - operType = getTypeName(param);
2.81 + operType = getTypeName(param, GENERIC_STYLE_FAKE);
2.82 returnParam = param;
2.83 } else {
2.84 - parameters.add(getTypeName(param));
2.85 + parameters.add(getTypeName(param, GENERIC_STYLE_FAKE));
2.86 String name = tagProvider.getSubstName(param) + (param.getDirection().equals(DirectionKindEnum.IN_DIR) ? "" : "[]"); //NOI18N
2.87 parameters.add(name);
2.88
2.89 @@ -477,9 +478,9 @@
2.90 methodJavaDoc (
2.91 ref, true, DOC_REFERENCE_GETTER,
2.92 isOrdered ? DOC_REFERENCE_GETTER_RETURN_ORDERED : DOC_REFERENCE_GETTER_RETURN_MULTI,
2.93 - null, null, null
2.94 + null, null, new String[] {refType}
2.95 );
2.96 - interfaceMethod((isOrdered ? DT_ORDERED : DT_MULTIVALUED), "get" + refName, null, null); //NOI18N
2.97 + interfaceMethod(getTypeName(ref, GENERIC_STYLE_FAKE), "get" + refName, null, null); //NOI18N
2.98 }
2.99 }
2.100
2.101 @@ -509,6 +510,7 @@
2.102 objClass, false, DOC_CLASS_PROXY_CREATE2, DOC_CLASS_PROXY_CREATE_RETURN,
2.103 paramsNames, paramsObjects, null
2.104 );
2.105 + // XXX note element type in @param for Javadoc of create* methods: e.g. in javamodel, see TypeParameterClass.createTypeParameter
2.106 interfaceMethod(tagProvider.getSubstName(objClass), "create" + name, params, null); //NOI18N
2.107 }
2.108 }
2.109 @@ -626,7 +628,7 @@
2.110 clsAttributes.add(feature);
2.111 } else {
2.112 if (!((Attribute) feature).isDerived()) {
2.113 - allAttributes.add(getTypeName((Attribute) feature));
2.114 + allAttributes.add(getTypeName((Attribute) feature, GENERIC_STYLE_FAKE));
2.115 allAttributes.add(tagProvider.getSubstName(feature));
2.116 allAttributesObjects.add(feature);
2.117 }
2.118 @@ -679,6 +681,7 @@
2.119 single ? DOC_ASSOC_GET_END1_RETURN_SINGLE : (ordered ? DOC_ASSOC_GET_END1_RETURN_ORDERED : DOC_ASSOC_GET_END1_RETURN_MULTI),
2.120 new String [] {end2Name}, new Object [] {DOC_ASSOC_GET_END2_PARAM}, null
2.121 );
2.122 + // XXX genericize:
2.123 interfaceMethod(single ? end1Class : (ordered ? DT_ORDERED : DT_MULTIVALUED),
2.124 "get" + firstUpper(end1Name), new String[] {end2Class, end2Name}, null); //NOI18N
2.125 }
2.126 @@ -693,6 +696,7 @@
2.127 single ? DOC_ASSOC_GET_END1_RETURN_SINGLE : (ordered ? DOC_ASSOC_GET_END1_RETURN_ORDERED : DOC_ASSOC_GET_END1_RETURN_MULTI),
2.128 new String [] {end1Name}, new Object [] {DOC_ASSOC_GET_END1_PARAM}, null
2.129 );
2.130 + // XXX genericize:
2.131 interfaceMethod(single ? end2Class : (ordered ? DT_ORDERED : DT_MULTIVALUED),
2.132 "get" + firstUpper(end2Name), new String[] {end1Class, end1Name}, null); //NOI18N
2.133 }
2.134 @@ -826,7 +830,7 @@
2.135 if (element instanceof Parameter) {
2.136 param = (Parameter) element;
2.137 paramsObjects.add (param);
2.138 - params.add(getTypeName(param));
2.139 + params.add(getTypeName(param, GENERIC_STYLE_FAKE));
2.140 paramName = firstLower(tagProvider.getSubstName(param));
2.141 paramsNames.add (paramName);
2.142 params.add(removeUnderscores(paramName));
2.143 @@ -955,6 +959,7 @@
2.144 objEnumeration, false, DOC_ENUM_REFTYPENAME, DOC_ENUM_REFTYPENAME_RETURN,
2.145 null, null, null
2.146 );
2.147 + // XXX genericize
2.148 generate("public java.util.List refTypeName() {"); //NOI18N
2.149 indent();
2.150 generate("return typeName;"); //NOI18N