geirm       2003/12/23 06:06:59

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTAddNode.java
  Log:
  added + as a string concatenation operator, and shuffled things around
  for speed as I assume that integer addition is what we'll have the
  majority of the time
  
  This is to finish off bug 17803
  
  Revision  Changes    Path
  1.9       +27 -17    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
  
  Index: ASTAddNode.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ASTAddNode.java   22 Oct 2001 03:53:24 -0000      1.8
  +++ ASTAddNode.java   23 Dec 2003 14:06:59 -0000      1.9
  @@ -3,7 +3,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -101,8 +101,8 @@
            *  get the two addends
            */
   
  -        Object left = jjtGetChild(0).value( context );
  -        Object right = jjtGetChild(1).value( context );
  +        Object left = jjtGetChild(0).value(context);
  +        Object right = jjtGetChild(1).value(context);
   
           /*
            *  if either is null, lets log and bail
  @@ -110,7 +110,7 @@
   
           if (left == null || right == null)
           {
  -            rsvc.error( ( left == null ? "Left" : "Right" ) 
  +            rsvc.error( ( left == null ? "Left" : "Right" )
                              + " side ("
                              + jjtGetChild( (left == null? 0 : 1) ).literal()
                              + ") of addition operation has null value."
  @@ -119,25 +119,35 @@
                              + ", column " + getColumn() + "]");
               return null;
           }
  -        
  +
           /*
  -         *  if not an Integer, not much we can do either
  +         * put the Integer test first, as that should happen most often
            */
   
  -        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        if (left instanceof Integer && right instanceof Integer)
           {
  -            rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  -                           + " side of addition operation is not a valid type. "
  -                           + "Currently only integers (1,2,3...) and Integer type 
is supported. "
  -                           + context.getCurrentTemplateName() + " [line " + 
getLine() 
  -                           + ", column " + getColumn() + "]");
  - 
  -            return null;
  +            return new Integer(((Integer) left).intValue() + ((Integer) 
right).intValue());
           }
   
  -        return new Integer( ( (Integer) left ).intValue() + (  (Integer) right 
).intValue() );
  -    }
  +        /*
  +         * shall we try for strings?
  +         */
  +        if (left instanceof String || right instanceof String)
  +        {
  +            return left.toString().concat(right.toString());
  +        }
  +
  +        /*
  +         *  if not an Integer or Strings, not much we can do right now
  +         */
  +        rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" )
  +                       + " side of addition operation is not a valid type. "
  +                       + "Currently only Strings, integers (1,2,3...) and Integer 
type are supported. "
  +                       + context.getCurrentTemplateName() + " [line " + getLine()
  +                       + ", column " + getColumn() + "]");
   
  +        return null;
  +    }
   }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to