summaryrefslogtreecommitdiff
path: root/ridljar/com/sun
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2003-03-26 14:44:58 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2003-03-26 14:44:58 +0000
commit243a97038bdab8f2ec448df19c88ac2638035531 (patch)
tree7d3dfb01dc35d82225933ed2aae290b101a73039 /ridljar/com/sun
parent1fba74f4c5b460718e8307bf41ee6c7fbb0dac5d (diff)
MWS_SRX644: migrate branch mws_srx644 -> HEAD
Diffstat (limited to 'ridljar/com/sun')
-rw-r--r--ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java216
-rw-r--r--ridljar/com/sun/star/uno/Any.java17
-rw-r--r--ridljar/com/sun/star/uno/ITypeDescription.java79
-rw-r--r--ridljar/com/sun/star/uno/Type.java341
4 files changed, 382 insertions, 271 deletions
diff --git a/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java b/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java
index 68f146fd34d1..97757162b177 100644
--- a/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java
+++ b/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java
@@ -2,9 +2,9 @@
*
* $RCSfile: TypeDescription.java,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: jbu $ $Date: 2001-10-26 11:43:05 $
+ * last change: $Author: hr $ $Date: 2003-03-26 15:44:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,6 +63,7 @@ package com.sun.star.lib.uno.typedesc;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Hashtable;
import java.lang.reflect.Field;
@@ -97,7 +98,7 @@ import com.sun.star.lib.uno.typeinfo.TypeInfo;
* methods, which may be changed or moved in the furture, so please
* do not use these methods.
* <p>
- * @version $Revision: 1.13 $ $ $Date: 2001-10-26 11:43:05 $
+ * @version $Revision: 1.14 $ $ $Date: 2003-03-26 15:44:53 $
* @author Kay Ramme
* @since UDK2.0
*/
@@ -123,71 +124,75 @@ public class TypeDescription implements ITypeDescription {
public static final TypeDescription __type_TypeDescription = new TypeDescription(TypeClass.TYPE, "type", "[Lcom.sun.star.uno.Type;", Type.class); // TYPE
public static final TypeDescription __any_TypeDescription = new TypeDescription(TypeClass.ANY, "any", "[Ljava.lang.Object;", Object.class); // ANY
-
- static private final Hashtable __classToTypeDescription = new Hashtable();
- static private final Hashtable __typeNameToTypeDescription = new Hashtable();
- static private final Hashtable __typeClassToTypeName = new Hashtable();
-
- static private final Object[][] __typeClassToTypeDescription = new Object[][]{
- new Object[]{"java.lang.Void", "V", __void_TypeDescription}, // VOID
- new Object[]{"java.lang.Character", "C", __char_TypeDescription}, // CHAR
- new Object[]{"java.lang.Boolean", "Z", __boolean_TypeDescription}, // BOOLEAN
- new Object[]{"java.lang.Byte", "B", __byte_TypeDescription}, // BYTE
- new Object[]{"java.lang.Short", "S", __short_TypeDescription}, // SHORT
- new Object[]{"java.lang.Short", "S", __ushort_TypeDescription}, // UNSIGNED SHORT
- new Object[]{"java.lang.Integer", "I", __long_TypeDescription}, // LONG
- new Object[]{"java.lang.Integer", "I", __ulong_TypeDescription}, // UNSIGNED_LONG
- new Object[]{"java.lang.Long", "J", __hyper_TypeDescription}, // HYPER
- new Object[]{"java.lang.Long", "J", __uhyper_TypeDescription}, // UNSIGNED_HYPER
- new Object[]{"java.lang.Float", "F", __float_TypeDescription}, // FLOAT
- new Object[]{"java.lang.Double", "D", __double_TypeDescription}, // DOUBLE
- new Object[]{"java.lang.String", "Ljava.lang.String;", __string_TypeDescription}, // STRING
- new Object[]{"com.sun.star.uno.Type", "Lcom.sun.star.uno.Type;", __type_TypeDescription}, // TYPE
- new Object[]{"java.lang.Object", "Ljava.lang.Object;", __any_TypeDescription} // ANY
- };
-
+ static private final HashMap __typeNameToTypeDescription = new HashMap();
static {
- __typeNameToTypeDescription.put("boolean", __boolean_TypeDescription);
- __typeNameToTypeDescription.put("short", __short_TypeDescription);
- __typeNameToTypeDescription.put("unsigned short", __ushort_TypeDescription);
- __typeNameToTypeDescription.put("long", __long_TypeDescription);
- __typeNameToTypeDescription.put("unsigned long", __ulong_TypeDescription);
- __typeNameToTypeDescription.put("hyper", __hyper_TypeDescription);
- __typeNameToTypeDescription.put("unsigned hyper", __uhyper_TypeDescription);
- __typeNameToTypeDescription.put("float", __float_TypeDescription);
- __typeNameToTypeDescription.put("double", __double_TypeDescription);
- __typeNameToTypeDescription.put("char", __char_TypeDescription);
- __typeNameToTypeDescription.put("byte", __byte_TypeDescription);
- __typeNameToTypeDescription.put("string", __string_TypeDescription);
- __typeNameToTypeDescription.put("any", __any_TypeDescription);
- __typeNameToTypeDescription.put("void", __void_TypeDescription);
- __typeNameToTypeDescription.put("type", __type_TypeDescription);
-
- __classToTypeDescription.put(Void.class, __void_TypeDescription);
- __classToTypeDescription.put(void.class, __void_TypeDescription);
+ __typeNameToTypeDescription.put("void", __void_TypeDescription);
+ __typeNameToTypeDescription.put("boolean", __boolean_TypeDescription);
+ __typeNameToTypeDescription.put("char", __char_TypeDescription);
+ __typeNameToTypeDescription.put("byte", __byte_TypeDescription);
+ __typeNameToTypeDescription.put("short", __short_TypeDescription);
+ __typeNameToTypeDescription.put("unsigned short",
+ __ushort_TypeDescription);
+ __typeNameToTypeDescription.put("long", __long_TypeDescription);
+ __typeNameToTypeDescription.put("unsigned long",
+ __ulong_TypeDescription);
+ __typeNameToTypeDescription.put("hyper", __hyper_TypeDescription);
+ __typeNameToTypeDescription.put("unsigned hyper",
+ __uhyper_TypeDescription);
+ __typeNameToTypeDescription.put("float", __float_TypeDescription);
+ __typeNameToTypeDescription.put("double", __double_TypeDescription);
+ __typeNameToTypeDescription.put("string", __string_TypeDescription);
+ __typeNameToTypeDescription.put("type", __type_TypeDescription);
+ __typeNameToTypeDescription.put("any", __any_TypeDescription);
+ }
+
+ static private final HashMap __classToTypeDescription = new HashMap();
+ static {
+ __classToTypeDescription.put(void.class, __void_TypeDescription);
+ __classToTypeDescription.put(Void.class, __void_TypeDescription);
+ __classToTypeDescription.put(boolean.class, __boolean_TypeDescription);
+ __classToTypeDescription.put(Boolean.class, __boolean_TypeDescription);
+ __classToTypeDescription.put(char.class, __char_TypeDescription);
__classToTypeDescription.put(Character.class, __char_TypeDescription);
- __classToTypeDescription.put(char.class, __char_TypeDescription);
- __classToTypeDescription.put(Boolean.class, __boolean_TypeDescription);
- __classToTypeDescription.put(boolean.class, __boolean_TypeDescription);
- __classToTypeDescription.put(Byte.class, __byte_TypeDescription);
- __classToTypeDescription.put(byte.class, __byte_TypeDescription);
- __classToTypeDescription.put(Short.class, __short_TypeDescription);
- __classToTypeDescription.put(short.class, __short_TypeDescription);
- __classToTypeDescription.put(Integer.class, __long_TypeDescription);
- __classToTypeDescription.put(int.class, __long_TypeDescription);
- __classToTypeDescription.put(Long.class, __hyper_TypeDescription);
- __classToTypeDescription.put(long.class, __hyper_TypeDescription);
- __classToTypeDescription.put(Float.class, __float_TypeDescription);
- __classToTypeDescription.put(float.class, __float_TypeDescription);
- __classToTypeDescription.put(Double.class, __double_TypeDescription);
- __classToTypeDescription.put(double.class, __double_TypeDescription);
- __classToTypeDescription.put(String.class, __string_TypeDescription);
- __classToTypeDescription.put(Type.class, __type_TypeDescription);
- __classToTypeDescription.put(Any.class, __any_TypeDescription);
- __classToTypeDescription.put(Object.class, __any_TypeDescription);
- }
-
- static public boolean isTypeClassSimple(TypeClass typeClass) {
+ __classToTypeDescription.put(byte.class, __byte_TypeDescription);
+ __classToTypeDescription.put(Byte.class, __byte_TypeDescription);
+ __classToTypeDescription.put(short.class, __short_TypeDescription);
+ __classToTypeDescription.put(Short.class, __short_TypeDescription);
+ __classToTypeDescription.put(int.class, __long_TypeDescription);
+ __classToTypeDescription.put(Integer.class, __long_TypeDescription);
+ __classToTypeDescription.put(long.class, __hyper_TypeDescription);
+ __classToTypeDescription.put(Long.class, __hyper_TypeDescription);
+ __classToTypeDescription.put(float.class, __float_TypeDescription);
+ __classToTypeDescription.put(Float.class, __float_TypeDescription);
+ __classToTypeDescription.put(double.class, __double_TypeDescription);
+ __classToTypeDescription.put(Double.class, __double_TypeDescription);
+ __classToTypeDescription.put(String.class, __string_TypeDescription);
+ __classToTypeDescription.put(Type.class, __type_TypeDescription);
+ __classToTypeDescription.put(Object.class, __any_TypeDescription);
+ __classToTypeDescription.put(Any.class, __any_TypeDescription);
+ }
+
+ // must be sorted same as TypeClass:
+ private static final TypeDescription[] __typeClassToTypeDescription
+ = new TypeDescription[] {
+ __void_TypeDescription,
+ __char_TypeDescription,
+ __boolean_TypeDescription,
+ __byte_TypeDescription,
+ __short_TypeDescription,
+ __ushort_TypeDescription,
+ __long_TypeDescription,
+ __ulong_TypeDescription,
+ __hyper_TypeDescription,
+ __uhyper_TypeDescription,
+ __float_TypeDescription,
+ __double_TypeDescription,
+ __string_TypeDescription,
+ __type_TypeDescription,
+ __any_TypeDescription
+ };
+
+ public static boolean isTypeClassSimple(TypeClass typeClass) {
return typeClass.getValue() < __typeClassToTypeDescription.length;
}
@@ -424,6 +429,23 @@ public class TypeDescription implements ITypeDescription {
static private void addToCache(TypeDescription typeDescription) {
if(DEBUG_CACHE) System.err.println("addToCache:" + typeDescription.getTypeName());
+ // If typeDescription is a sequence type whose base component type is
+ // any of SHORT, UNSIGNED SHORT, LONG, UNSIGNED LONG, HYPER, UNSIGNED
+ // HYPER, ANY or com::sun::star::uno::XInterface, do not add it to the
+ // cache. Those UNO types have corresponding Java types that are not
+ // unique (e.g., both a sequence of SHORT and a sequence of UNSIGNED
+ // SHORT map to the Java type short[]), so using __typeCache_class to
+ // map from such a Java type to a type description could give a wrong
+ // result:
+ String n = typeDescription.getTypeName();
+ if (n.endsWith("[]short") || n.endsWith("[]unsigned short")
+ || n.endsWith("[]long") || n.endsWith("[]unsigned long")
+ || n.endsWith("[]hyper") || n.endsWith("[]unsigned hyper")
+ || n.endsWith("[]any")
+ || n.endsWith("[]com.sun.star.uno.XInterface")) {
+ return;
+ }
+
synchronized(__cacheEntrys) {
if(DEBUG_CACHE) listCache();
@@ -533,35 +555,30 @@ public class TypeDescription implements ITypeDescription {
return typeDescription;
}
- static public ITypeDescription getTypeDescription(Type type) throws ClassNotFoundException {
- ITypeDescription iTypeDescription = type.getTypeDescription();
-
- if(iTypeDescription == null) {
- if(type.getZClass() != null)
- iTypeDescription = getTypeDescription(type.getZClass());
-
- else if(type.getTypeClass() != null && type.getTypeClass() != TypeClass.UNKNOWN)
- iTypeDescription = getTypeDescription(type.getTypeClass());
-
- else if(type.getTypeName() != null)
- iTypeDescription = getTypeDescription(type.getTypeName());
-
- type.setTypeDescription(iTypeDescription);
+ public static ITypeDescription getTypeDescription(Type type)
+ throws ClassNotFoundException
+ {
+ ITypeDescription td = type.getTypeDescription();
+ if (td == null) {
+ if (type.getZClass() != null) {
+ td = getTypeDescription(type.getZClass());
+ } else {
+ td = getTypeDescription(type.getTypeClass());
+ if (td == null) {
+ td = getTypeDescription(type.getTypeName());
+ }
+ }
+ type.setTypeDescription(td);
}
-
- return iTypeDescription;
+ return td;
}
- static public TypeDescription getTypeDescription(TypeClass typeClass) {
- TypeDescription typeDescription = null;
-
- if(typeClass.getValue() < __typeClassToTypeDescription.length)
- typeDescription = (TypeDescription)__typeClassToTypeDescription[typeClass.getValue()][2];
-
- return typeDescription;
+ public static TypeDescription getTypeDescription(TypeClass typeClass) {
+ int n = typeClass.getValue();
+ return n < __typeClassToTypeDescription.length
+ ? __typeClassToTypeDescription[n] : null;
}
-
protected TypeClass _typeClass;
protected String _typeName;
protected String _arrayTypeName;
@@ -659,6 +676,8 @@ public class TypeDescription implements ITypeDescription {
_typeName = typeName;
_arrayTypeName = arrayTypeName;
_class = zClass;
+ // _componentType == null is ok, since only primitive TypeDescriptions
+ // are created with this constructor
}
private TypeDescription(Class zClass) {
@@ -887,19 +906,14 @@ public class TypeDescription implements ITypeDescription {
}
/**
- * Gets the component <code>TypeDescription</code> if
- * this is an array type.
- * <p>
- * @return the <code>TypeDescription</code>
+ * Gets the component <code>TypeDescription</code> if this is a sequence
+ * type.
+ *
+ * @return the component <code>TypeDescription</code>, or <code>null</code>
+ * if this is not a sequence type
*/
public ITypeDescription getComponentType() {
- ITypeDescription iTypeDescription = null;
-
- Class componentClass = getZClass().getComponentType();
- if(componentClass != null)
- iTypeDescription = getTypeDescription(componentClass);
-
- return iTypeDescription;
+ return _componentType;
}
/**
diff --git a/ridljar/com/sun/star/uno/Any.java b/ridljar/com/sun/star/uno/Any.java
index 1dddc264a7cf..3fca2cbfa51f 100644
--- a/ridljar/com/sun/star/uno/Any.java
+++ b/ridljar/com/sun/star/uno/Any.java
@@ -2,9 +2,9 @@
*
* $RCSfile: Any.java,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: jbu $ $Date: 2002-01-18 14:04:55 $
+ * last change: $Author: hr $ $Date: 2003-03-26 15:44:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -72,7 +72,7 @@ package com.sun.star.uno;
* an explicit interface type, so the remote counterpart doesn't need to invoke
* a queryInterface).
* <p>
- * @version $Revision: 1.4 $ $ $Date: 2002-01-18 14:04:55 $
+ * @version $Revision: 1.5 $ $ $Date: 2003-03-26 15:44:54 $
* @since UDK1.0
*/
public class Any {
@@ -90,6 +90,10 @@ public class Any {
*/
protected Object _object;
+ public static final Any VOID = new Any(new Type("void", TypeClass.VOID),
+ null);
+ // do not use Type.VOID here to avoid circular dependencies between
+ // static members of Any and Type
/**
* Constructs a new any.
@@ -129,6 +133,9 @@ public class Any {
public Object getObject() {
return _object;
}
-}
-
+ // @see java.lang.Object#toString
+ public String toString() {
+ return "Any[" + _type + ", " + _object + "]";
+ }
+}
diff --git a/ridljar/com/sun/star/uno/ITypeDescription.java b/ridljar/com/sun/star/uno/ITypeDescription.java
index 7788076df264..88250fb649ef 100644
--- a/ridljar/com/sun/star/uno/ITypeDescription.java
+++ b/ridljar/com/sun/star/uno/ITypeDescription.java
@@ -2,9 +2,9 @@
*
* $RCSfile: ITypeDescription.java,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: kr $ $Date: 2001-05-08 09:34:18 $
+ * last change: $Author: hr $ $Date: 2003-03-26 15:44:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -65,7 +65,7 @@ package com.sun.star.uno;
* The <code>ITypeDescription</code> allows to examine a type
* in detail (e.g. it is used for marshaling/unmarshaling).
* <p>
- * @version $Revision: 1.1 $ $ $Date: 2001-05-08 09:34:18 $
+ * @version $Revision: 1.2 $ $ $Date: 2003-03-26 15:44:54 $
* @author Kay Ramme
* @since UDK3.0
*/
@@ -139,16 +139,77 @@ public interface ITypeDescription {
ITypeDescription getComponentType();
/**
- * Gets the type name.
- * <p>
- * @return the type name.
+ * Gets the (UNO) type name.
+ *
+ * <p>The following table lists how UNO types map to type names:</p>
+ * <table>
+ * <thead>
+ * <tr><th>UNO type</th><th>type name</th></tr>
+ * </thead>
+ * <tbody>
+ * <tr><td>VOID</td><td><code>"void"</code></td></tr>
+ * <tr><td>BOOLEAN</td><td><code>"boolean"</code></td></tr>
+ * <tr><td>CHAR</td><td><code>"char"</code></td></tr>
+ * <tr><td>BYTE</td><td><code>"byte"</code></td></tr>
+ * <tr><td>SHORT</td><td><code>"short"</code></td></tr>
+ * <tr>
+ * <td>UNSIGNED SHORT</td><td><code>"unsigned short"</code></td>
+ * </tr>
+ * <tr><td>LONG</td><td><code>"long"</code></td></tr>
+ * <tr><td>UNSIGNED LONG</td><td><code>"unsigned long"</code></td></tr>
+ * <tr><td>HYPER</td><td></td><code>"hyper"</code></tr>
+ * <tr>
+ * <td>UNSIGNED HYPER</td><td></td><code>"unsigned hyper"</code>
+ * </tr>
+ * <tr><td>FLOAT</td><td></td><code>"float"</code></tr>
+ * <tr><td>DOUBLE</td><td></td><code>"double"</code></tr>
+ * <tr><td>STRING</td><td></td><code>"string"</code></tr>
+ * <tr><td>TYPE</td><td></td><code>"type"</code></tr>
+ * <tr><td>ANY</td><td></td><code>"any"</code></tr>
+ * <tr>
+ * <td>sequence type of base type <var>T</var></td>
+ * <td><code>"[]"</code> followed by type name for <var>T</var></td>
+ * </tr>
+ * <tr>
+ * <td>enum type named <var>N</var></td>
+ * <td><var>N</var> (see below)</td>
+ * </tr>
+ * <tr>
+ * <td>struct type named <var>N</var></td>
+ * <td><var>N</var> (see below)</td>
+ * </tr>
+ * <tr>
+ * <td>exception type named <var>N</var>
+ * </td><td><var>N</var> (see below)</td>
+ * </tr>
+ * <tr>
+ * <td>interface type named <var>N</var></td>
+ * <td><var>N</var> (see below)</td>
+ * </tr>
+ * <tbody>
+ * </table>
+ * <p>For a UNO type named <var>N</var>, consisting of a sequence of module
+ * names <var>M<sub>1</sub></var>, ..., <var>M<sub>n</sub></var> followed by
+ * a simple name <var>S</var>, the corresponding type name consists of the
+ * same sequence of module names and simple name, with <code>"."</code>
+ * seperating the individual elements.</p>
+ *
+ * @return the type name.
*/
String getTypeName();
/**
- * Gets the array type name.
- * <p>
- * @return the array type name.
+ * Gets the (Java) array type name.
+ *
+ * <p>The array type name is defined to be the Java class name (as returned
+ * by <code>Class.forName</code>) of the Java array class that corresponds
+ * to the UNO sequence type with this type (the UNO type represented by this
+ * <code>ITypeDescription</code> instance) as base type. For an
+ * <code>ITypeDescription</code> instance representing the UNO type VOID,
+ * the array type name is defined to be
+ * <code>"[Ljava.lang.Void;"</code>.</p>
+ *
+ * @return the array type name.
*/
String getArrayTypeName();
diff --git a/ridljar/com/sun/star/uno/Type.java b/ridljar/com/sun/star/uno/Type.java
index 7fd378ad1529..9e368500d15a 100644
--- a/ridljar/com/sun/star/uno/Type.java
+++ b/ridljar/com/sun/star/uno/Type.java
@@ -2,9 +2,9 @@
*
* $RCSfile: Type.java,v $
*
- * $Revision: 1.8 $
+ * $Revision: 1.9 $
*
- * last change: $Author: dbo $ $Date: 2002-10-30 11:10:41 $
+ * last change: $Author: hr $ $Date: 2003-03-26 15:44:55 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,28 +61,35 @@
package com.sun.star.uno;
-
-
-import java.util.Hashtable;
+import java.util.HashMap;
/**
- * The Type class represents the IDL builtin type <code>type</code>.
- * <p>
- * The IDL type is not directly mapped to <code>java.lang.Class</code>,
- * because it can be necessary to describe a type which is unknown
- * to the java runtime system, e.g. for delaying the need of a class,
- * so that it is possible to generate it on the fly.
- * <p>
- * @version $Revision: 1.8 $ $ $Date: 2002-10-30 11:10:41 $
- * @since UDK1.0
+ * Represents the UNO built-in type <code>TYPE</code>.
+ *
+ * <p>The UNO type is not directly mapped to <code>java.lang.Class</code> for at
+ * least two reasons. For one, some UNO types (like <code>UNSIGNED
+ * SHORT</code>) do not have a matching Java class. For another, it can be
+ * necessary to describe a type which is unknown to the Java runtime system
+ * (for example, for delaying the need of a class, so that it is possible to
+ * generate it on the fly.)</p>
+ *
+ * <p>A <code>Type</code> is uniquely determined by its type class (a
+ * <code>TypeClass</code>) and its type name (a <code>String</code>); these two
+ * will never be <code>null</code>. A <code>Type</code> may have an additional
+ * "z class" (a <code>java.lang.Class</code>), giving a Java class type that
+ * corresponds to the UNO type. Also, a <code>Type</code> can cache a type
+ * description (a <code>com.sun.star.uno.ITypeDescription</code>), which can be
+ * computed and set by <code>TypeDescription.getTypeDescription</code>.
+ *
+ * @since UDK1.0
*/
public class Type {
- /**
- * When set to true, enables various debugging output.
- */
- private static final boolean DEBUG = false;
+ // The following private static members and static initializer must come
+ // first in the class definition, so that the class can be initialized
+ // sucessfully:
- static private final String[] __typeClassToTypeName = new String[]{
+ // must be sorted same as TypeClass:
+ private static final String[] __typeClassToTypeName = new String[] {
"void",
"char",
"boolean",
@@ -100,67 +107,90 @@ public class Type {
"any"
};
- static private final Hashtable __javaClassToTypeName = new Hashtable();
+ private static final HashMap __javaClassToTypeName = new HashMap();
- static private final Hashtable __typeNameToTypeClass = new Hashtable();
+ private static final HashMap __typeNameToTypeClass = new HashMap();
static {
- for(int i = 0; i < __typeClassToTypeName.length; ++ i)
- __typeNameToTypeClass.put(__typeClassToTypeName[i], TypeClass.fromInt(i));
-
- __javaClassToTypeName.put(Void.class, "void");
- __javaClassToTypeName.put(void.class, "void");
+ for (int i = 0; i < __typeClassToTypeName.length; ++i) {
+ __typeNameToTypeClass.put(__typeClassToTypeName[i],
+ TypeClass.fromInt(i));
+ }
+ __javaClassToTypeName.put(Void.class, "void");
+ __javaClassToTypeName.put(void.class, "void");
__javaClassToTypeName.put(Character.class, "char");
__javaClassToTypeName.put(char.class, "char");
- __javaClassToTypeName.put(Boolean.class, "boolean");
- __javaClassToTypeName.put(boolean.class, "boolean");
- __javaClassToTypeName.put(Byte.class, "byte");
- __javaClassToTypeName.put(byte.class, "byte");
- __javaClassToTypeName.put(Short.class, "short");
- __javaClassToTypeName.put(short.class, "short");
- __javaClassToTypeName.put(Integer.class, "long");
- __javaClassToTypeName.put(int.class, "long");
- __javaClassToTypeName.put(Long.class, "hyper");
- __javaClassToTypeName.put(long.class, "hyper");
- __javaClassToTypeName.put(Float.class, "float");
- __javaClassToTypeName.put(float.class, "float");
- __javaClassToTypeName.put(Double.class, "double");
- __javaClassToTypeName.put(double.class, "double");
- __javaClassToTypeName.put(String.class, "string");
- __javaClassToTypeName.put(Type.class, "type");
- __javaClassToTypeName.put(Any.class, "any");
- __javaClassToTypeName.put(Object.class, "any");
+ __javaClassToTypeName.put(Boolean.class, "boolean");
+ __javaClassToTypeName.put(boolean.class, "boolean");
+ __javaClassToTypeName.put(Byte.class, "byte");
+ __javaClassToTypeName.put(byte.class, "byte");
+ __javaClassToTypeName.put(Short.class, "short");
+ __javaClassToTypeName.put(short.class, "short");
+ __javaClassToTypeName.put(Integer.class, "long");
+ __javaClassToTypeName.put(int.class, "long");
+ __javaClassToTypeName.put(Long.class, "hyper");
+ __javaClassToTypeName.put(long.class, "hyper");
+ __javaClassToTypeName.put(Float.class, "float");
+ __javaClassToTypeName.put(float.class, "float");
+ __javaClassToTypeName.put(Double.class, "double");
+ __javaClassToTypeName.put(double.class, "double");
+ __javaClassToTypeName.put(String.class, "string");
+ __javaClassToTypeName.put(Type.class, "type");
+ __javaClassToTypeName.put(Any.class, "any");
+ __javaClassToTypeName.put(Object.class, "any");
}
- static private boolean __isTypeClassPrimitive(TypeClass typeClass) {
- return typeClass.getValue() < 15;
- }
-
-
- protected String _typeName;
- protected Class _class;
- protected TypeClass _typeClass;
-
- protected ITypeDescription _iTypeDescription;
-
+ public static final Type VOID = new Type(void.class);
+ public static final Type CHAR = new Type(char.class);
+ public static final Type BOOLEAN = new Type(boolean.class);
+ public static final Type BYTE = new Type(byte.class);
+ public static final Type SHORT = new Type(short.class);
+ public static final Type UNSIGNED_SHORT = new Type(
+ "unsigned short", TypeClass.UNSIGNED_SHORT);
+ public static final Type LONG = new Type(int.class);
+ public static final Type UNSIGNED_LONG = new Type(
+ "unsigned long", TypeClass.UNSIGNED_LONG);
+ public static final Type HYPER = new Type(long.class);
+ public static final Type UNSIGNED_HYPER = new Type(
+ "unsigned hyper", TypeClass.UNSIGNED_HYPER);
+ public static final Type FLOAT = new Type(float.class);
+ public static final Type DOUBLE = new Type(double.class);
+ public static final Type STRING = new Type(String.class);
+ public static final Type TYPE = new Type(Type.class);
+ public static final Type ANY = new Type(Any.class);
/**
- * Constructs a new <code>Type</code> which defaults
- * to <code>void</code>
- * <p>
- * @since UDK3.0
+ * Constructs a new <code>Type</code> which defaults to <code>VOID</code>.
+ *
+ * @since UDK3.0
*/
public Type() {
this(void.class);
}
+ /**
+ * Constructs a new <code>Type</code> with the given type class and type
+ * name.
+ *
+ * @param typeName the type name. Must not be <code>null</code>.
+ * @param typeClass the type class. Must not be <code>null</code>, and must
+ * match the <code>typeName</code> (for example, it is illegal to
+ * combine a <code>typeName</code> of <code>"void"</code> with a
+ * <code>typeClass</code> of <code>BOOLEAN</code>).
+ */
+ public Type(String typeName, TypeClass typeClass) {
+ _typeClass = typeClass;
+ _typeName = typeName;
+ }
/**
- * Constructs a new <code>Type</code> with
- * the given <code>class</code>.
- * <p>
- * @since UDK3.0
- * @param zClass the java class of this type
+ * Constructs a new <code>Type</code> from the given
+ * <code>java.lang.Class</code>.
+ *
+ * @param zClass the Java class of this type. Must not be
+ * <code>null</code>.
+ *
+ * @since UDK3.0
*/
public Type(Class zClass) {
_class = zClass;
@@ -202,27 +232,37 @@ public class Type {
}
/**
- * Constructs a new <code>Type</code> with
- * the given type description.
- * <p>
- * @since UDK3.0
- * @param typeDescription a type description
+ * Constructs a new <code>Type</code> from the given type description.
+ *
+ * @param typeDescription a type description. Must not be
+ * <code>null</code>.
+ *
+ * @since UDK3.0
*/
- public Type(ITypeDescription iTypeDescription) {
- _typeName = iTypeDescription.getTypeName();
- _typeClass = iTypeDescription.getTypeClass();
- _iTypeDescription = iTypeDescription;
+ public Type(ITypeDescription typeDescription) {
+ _typeName = typeDescription.getTypeName();
+ _typeClass = typeDescription.getTypeClass();
+ _iTypeDescription = typeDescription;
}
/**
- * Constructs a new <code>Type</code> with
- * the given type name.
- * <p>
- * @since UDK3.0
- * @param typeName the name of this type. For simple types
- * (numbers,string,type,any), the typeclass is calculated,
- * for complex types (structs,interfaces), the
- * typeclass of this object is set to UNKNOWN
+ * Constructs a new <code>Type</code> with the given type name.
+ *
+ * <p>TODO: This constructor is dangerous, as it can create a
+ * <code>Type</code> with an <code>UNKNOWN</code> type class. It would be
+ * better if this constructor threw a <code>IllegalArgumentException</code>
+ * instead.</p>
+ *
+ * @param typeName the name of this type; must not be <code>null</code>.
+ * For simple types (<code>VOID</code>, <code>BOOLEAN</code>,
+ * <code>CHAR</code>, <code>BYTE</code>, <code>SHORT</code>,
+ * <code>UNSIGNED SHORT</code>, <code>LONG</code>, <code>UNSIGNED
+ * LONG</code>, <code>HYPER</code>, <code>UNSIGNED HYPER</code>,
+ * <code>FLOAT</code>, <code>DOUBLE</code>, <code>STRING</code>,
+ * <code>TYPE</code>, <code>ANY</code>), the type class is calculated;
+ * for other types, the type class is set to <code>UNKNOWN</code>.
+ *
+ * @since UDK3.0
*/
public Type(String typeName) {
_typeClass = (TypeClass)__typeNameToTypeClass.get(typeName);
@@ -233,26 +273,20 @@ public class Type {
_typeName = typeName;
}
- public Type( String type_name, TypeClass type_class )
- {
- _typeClass = type_class;
- _typeName = type_name;
- }
-
-
/**
- * Constructs a new <code>Type</code> with
- * the given <code>TypeClass</code>.
- * <p>
- * @since UDK3.0
- * @param typeClass the <code>TypeClass</code> of this type. Only typeclass for
- * simple types is allowed.
+ * Constructs a new <code>Type</code> with the given type class.
+ *
+ * @param typeClass the type class of this type; must not be
+ * <code>null</code>. Only type classes for simple types are allowed
+ * here.
+ *
+ * @throws IllegalArgumentException if the given <code>typeClass</code> is
+ * not simple (for example, a struct or an interface type). This
+ * constructor could not find out the type name in such a case.
*
- * @throws IllegalArgumentException when the typeClass is not simple (e.g.
- a struct or an interface. The Constructor cannot find out the
- name of the type in this case.
+ * @since UDK3.0
*/
- public Type(TypeClass typeClass) throws IllegalArgumentException {
+ public Type(TypeClass typeClass) {
if(__isTypeClassPrimitive(typeClass)) {
_typeClass = typeClass;
_typeName = __typeClassToTypeName[typeClass.getValue()];
@@ -262,93 +296,88 @@ public class Type {
}
/**
- * Gives the type description of this type.
- * <p>
- * @since UDK3.0
- * @return the type description
- */
- public ITypeDescription getTypeDescription() {
- return _iTypeDescription;
- }
-
- /**
- * Sets the type description for this type.
- * <p>
- * @since UDK3.0
- * @return the type description
+ * Gets the type class.
+ *
+ * @return the type class. Will never be <code>null</code>, but might be
+ * <code>UNKNOWN</code>.
+ *
+ * @since UDK1.0
*/
- public void setTypeDescription(ITypeDescription iTypeDescription) {
- _iTypeDescription = iTypeDescription;
+ public TypeClass getTypeClass() {
+ return _typeClass;
}
/**
* Gets the type name.
- * Returns <code>null</code> if this
- * type has not been constructed by name.
- * <p>
- * @since UDK1.0
- * @return the type name.
+ *
+ * @return the type name; will never be <code>null</code>
+ *
+ * @since UDK1.0
*/
public String getTypeName() {
return _typeName;
}
/**
- * Gets the java class.
- * Returns <code>null</code> if this
- * type has not been constructed by <code>Class</code>.
- * <p>
- * @since UDK1.0
- * @return the type name. Maybe null.
+ * Gets the Java class.
+ *
+ * <p>Returns <code>null</code> if this type has not been constructed by
+ * <code>Class</code>.</p>
+ *
+ * @return the type name; may be <code>null</code>
+ *
+ * @since UDK1.0
*/
public Class getZClass() {
return _class;
}
/**
- * Gets the typeClass.
- * Returns <code>null</code> if this
- * type has not been constructed by <code>TypeClass</code>.
- * <p>
- * @since UDK1.0
- * @return the type class. May be TypeClass.UNKNOWN.
+ * Gives the type description of this type.
+ *
+ * @return the type description; may be <code>null</code>
+ *
+ * @since UDK3.0
*/
- public TypeClass getTypeClass() {
- return _typeClass;
+ public ITypeDescription getTypeDescription() {
+ return _iTypeDescription;
}
/**
- * Compares two types.
- * <p>
- * @return true, if the given type and this type are equal
+ * Sets the type description for this type.
+ *
+ * @param typeDescription the type description
+ *
+ * @since UDK3.0
*/
- public boolean equals(Object object) {
- boolean result = false;
-
- Type type = (Type)object;
-
- if(type != null)
- result = _typeName.equals(type._typeName);
+ public void setTypeDescription(ITypeDescription typeDescription) {
+ _iTypeDescription = typeDescription;
+ }
- return result;
+ // @see java.lang.Object#equals
+ public boolean equals(Object obj) {
+ return this == obj
+ || (obj instanceof Type
+ && _typeName.equals(((Type) obj)._typeName));
}
- /**
- * Calculates the hash code.
- * <p>
- * @return the hash code
- */
+ // @see java.lang.Object#hashCode
public int hashCode() {
return _typeName.hashCode();
}
- /**
- * Constructs a descriptive <code>String</code> for the type.
- * <p>
- * @return a descriptive <code>String</code>
- */
+ // @see java.lang.Object#toString
public String toString() {
- return "Type<" + _typeName + ">";
+ return "Type[" + _typeName + "]";
}
-}
+ private static boolean __isTypeClassPrimitive(TypeClass typeClass) {
+ return typeClass.getValue() < __typeClassToTypeName.length;
+ }
+
+ protected TypeClass _typeClass; // TODO should be final
+ protected String _typeName; // TODO should be final
+ protected Class _class; // TODO should be final
+
+ protected ITypeDescription _iTypeDescription;
+}