xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santiag...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util ObjectType.java StringType.java Type.java
Date Fri, 17 Oct 2003 17:15:15 GMT
santiagopg    2003/10/17 10:15:15

  Modified:    java/src/org/apache/xalan/xsltc/compiler CastCall.java
                        CastExpr.java FunctionCall.java
               java/src/org/apache/xalan/xsltc/compiler/util
                        ObjectType.java StringType.java Type.java
  Log:
  Allow conversion between types 'string' and 'object[java.lang.String]'.
  Conversion is trivial as instances of both types have the same runtime
  representation. This was needed in order to write expressions such
  as,
  
      string:new(xsltc:cast('java.lang.String', $object))
  
  where 'object' is a param bound to a value of type 'java.lang.String'.
  
  Revision  Changes    Path
  1.2       +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastCall.java
  
  Index: CastCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastCall.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CastCall.java	7 Oct 2003 15:44:22 -0000	1.1
  +++ CastCall.java	17 Oct 2003 17:15:15 -0000	1.2
  @@ -108,7 +108,7 @@
   	Expression exp = argument(0);
           if (exp instanceof LiteralExpr) {
               _className = ((LiteralExpr) exp).getValue();
  -            _type = new ObjectType(_className);
  +            _type = Type.newObjectType(_className);
           }
           else {
   	    throw new TypeCheckError(new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
  
  
  
  1.19      +3 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java
  
  Index: CastExpr.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CastExpr.java	1 Apr 2003 21:08:59 -0000	1.18
  +++ CastExpr.java	17 Oct 2003 17:15:15 -0000	1.19
  @@ -116,6 +116,7 @@
   	InternalTypeMap.put(Type.String, Type.Real);
   	InternalTypeMap.put(Type.String, Type.Reference);
           InternalTypeMap.put(Type.String, Type.Object);
  +        InternalTypeMap.put(Type.String, Type.ObjectString);
   
   	InternalTypeMap.put(Type.NodeSet, Type.NodeSet);
   	InternalTypeMap.put(Type.NodeSet, Type.Boolean);
  @@ -152,6 +153,7 @@
   	InternalTypeMap.put(Type.Reference, Type.Object);
   
   	InternalTypeMap.put(Type.Object, Type.String);
  +	InternalTypeMap.put(Type.ObjectString, Type.String);
   
   	InternalTypeMap.put(Type.Void, Type.String);
       }
  
  
  
  1.32      +4 -6      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java
  
  Index: FunctionCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- FunctionCall.java	14 Aug 2003 16:27:43 -0000	1.31
  +++ FunctionCall.java	17 Oct 2003 17:15:15 -0000	1.32
  @@ -512,10 +512,8 @@
   	        _isExtConstructor = true;
   		bestConstrDistance = currConstrDistance;
   		
  -		if (_clazz != null)
  -	          _type = new ObjectType(_clazz);
  -		else
  -		  _type = new ObjectType(_className);
  +                _type = (_clazz != null) ? Type.newObjectType(_clazz)
  +                    : Type.newObjectType(_className);
   	    }
   	}
   
  @@ -651,7 +649,7 @@
   		
   		  _type = (Type) _java2Internal.get(extType);
   		  if (_type == null) {
  -		      _type = new ObjectType(extType);
  +		      _type = Type.newObjectType(extType);
   		  }		
   
   		  // Use this method if all parameters & return type match
  
  
  
  1.7       +4 -9      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ObjectType.java
  
  Index: ObjectType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ObjectType.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ObjectType.java	14 Aug 2003 16:27:44 -0000	1.6
  +++ ObjectType.java	17 Oct 2003 17:15:15 -0000	1.7
  @@ -77,21 +77,16 @@
   import org.apache.xml.utils.ObjectFactory;
   
   public final class ObjectType extends Type {
  -
  +    
       private String _javaClassName = "java.lang.Object";
       private Class  _clazz = java.lang.Object.class;
   
       /**
  -     * Used to represent an 'any' type.
  -     */
  -    protected ObjectType() {}
  -
  -    /**
        * Used to represent a Java Class type such is required to support 
        * non-static java functions. 
        * @param javaClassName name of the class such as 'com.foo.Processor'
        */
  -    public ObjectType(String javaClassName) {
  +    protected ObjectType(String javaClassName) {
   	_javaClassName = javaClassName;
   
   	try {
  @@ -103,7 +98,7 @@
   	}
       }
       
  -    public ObjectType(Class clazz) {
  +    protected ObjectType(Class clazz) {
           _clazz = clazz;
           _javaClassName = clazz.getName();	
       }
  
  
  
  1.10      +4 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/StringType.java
  
  Index: StringType.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/StringType.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StringType.java	30 Jan 2003 18:46:09 -0000	1.9
  +++ StringType.java	17 Oct 2003 17:15:15 -0000	1.10
  @@ -119,6 +119,9 @@
   	else if (type == Type.Reference) {
   	    translateTo(classGen, methodGen, (ReferenceType) type);
   	}
  +        else if (type == Type.ObjectString) {
  +            // NOP -> same representation
  +        }
   	else {
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
   					toString(), type.toString());
  
  
  
  1.14      +36 -2     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Type.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Type.java	30 Jan 2003 18:46:09 -0000	1.13
  +++ Type.java	17 Oct 2003 17:15:15 -0000	1.14
  @@ -79,7 +79,9 @@
       public static final Type ResultTree = new ResultTreeType();
       public static final Type Reference  = new ReferenceType();
       public static final Type Void       = new VoidType();
  -    public static final Type Object     = new ObjectType();
  +    
  +    public static final Type Object       = new ObjectType(java.lang.Object.class);
  +    public static final Type ObjectString = new ObjectType(java.lang.String.class);
   
       public static final Type Node       = new NodeType(NodeTest.ANODE);
       public static final Type Root       = new NodeType(NodeTest.ROOT);
  @@ -89,6 +91,38 @@
       public static final Type Comment    = new NodeType(NodeTest.COMMENT);
       public static final Type Processing_Instruction = new NodeType(NodeTest.PI);
   
  +    /**
  +     * Factory method to instantiate object types. Returns a pre-defined
  +     * instance for "java.lang.Object" and "java.lang.String".
  +     */
  +    public static Type newObjectType(String javaClassName) {
  +        if (javaClassName == "java.lang.Object") {
  +            return Type.Object;
  +        }
  +        else if (javaClassName == "java.lang.String") {
  +            return Type.ObjectString;
  +        }
  +        else {
  +            return new ObjectType(javaClassName);
  +        }
  +    }
  +    
  +   /**
  +     * Factory method to instantiate object types. Returns a pre-defined
  +     * instance for java.lang.Object.class and java.lang.String.class.
  +     */
  +    public static Type newObjectType(Class clazz) {
  +        if (clazz == java.lang.Object.class) {
  +            return Type.Object;
  +        }
  +        else if (clazz == java.lang.String.class) {
  +            return Type.ObjectString;
  +        }
  +        else {
  +            return new ObjectType(clazz);
  +        }
  +    }
  +    
       /**
        * Returns a string representation of this type.	
        */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message