You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/09/21 22:25:24 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor BaseVisitor.java

jvanzyl     00/09/21 13:25:23

  Modified:    src/java/org/apache/velocity/processor/javacc/visitor
                        BaseVisitor.java
  Log:
  - removing all code present that strictly belongs in a specific
    node type.
  
  Revision  Changes    Path
  1.3       +0 -143    jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/BaseVisitor.java
  
  Index: BaseVisitor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/BaseVisitor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseVisitor.java	2000/09/20 21:16:40	1.2
  +++ BaseVisitor.java	2000/09/21 20:25:23	1.3
  @@ -82,150 +82,7 @@
       {
           this.context = context;
       }
  -
  -    protected Object getReferenceValue(ASTReference node)
  -    {
  -        return getReferenceValue(node, 0);
  -    }
       
  -    // Put this in the base visitor.
  -    protected  Object getReferenceValue(ASTReference node, int tailChildrenToIgnore)
  -    {
  -        // The rootOfIntrospection is the object we will
  -        // retrieve from the Context. This is the base
  -        // object we will apply reflection to.
  -        
  -        String rootOfIntrospection = node.getFirstToken().image;
  -        Object result = getVariableValue(rootOfIntrospection);
  -        Object newResult;
  -        String method;
  -        String identifier;
  -        
  -        String signature = "";
  -        
  -        // How many child nodes do we have?
  -        int children = node.jjtGetNumChildren();
  -        
  -        for (int i = 0; i < children - tailChildrenToIgnore; i++)
  -        {
  -            Node n = node.jjtGetChild(i);
  -            
  -            // Change this to use polymorphism!
  -            
  -            switch(n.getType())
  -            {
  -                case ParserTreeConstants.JJTIDENTIFIER:
  -                    identifier = n.getFirstToken().image;
  -                    method = "get" + identifier;
  -
  -                    newResult = ClassUtils.invoke(result, method);
  -                    if (newResult == null)
  -                    {
  -                        method = "get";
  -                        Object[] args = { identifier };
  -                        Class[] ptypes = null;
  -                        
  -                        // Have to make sure class types are
  -                        // correct for a proper signature match.
  -                        
  -                        if (result instanceof Map)
  -                        {
  -                            // This can be created once.
  -                            ptypes = new Class[1];
  -                            ptypes[0] = new Object().getClass();
  -                            signature = signature + "Map.";
  -                        }                            
  -                        
  -                        result = ClassUtils.invoke(result, method, args, ptypes);
  -                    }
  -                    else
  -                    {
  -                        result = newResult;
  -                        signature = signature + "Property.";
  -                    }                        
  -                    
  -                    break;
  -            
  -                case ParserTreeConstants.JJTMETHOD:
  -
  -                    // node 1: method name
  -                    // The rest of the nodes are parameters
  -                    // to the method. They may be references
  -                    // or string literals. If they are
  -                    // references then we just use a little
  -                    // recursion.
  -
  -                    method = n.jjtGetChild(0).getFirstToken().image;
  -                    int parameters = n.jjtGetNumChildren() - 1;
  -                
  -                    Object[] params = new Object[parameters];
  -                
  -                    for (int j = 0; j < parameters; j++)
  -                    {
  -                        Node p = n.jjtGetChild(j + 1);
  -                    
  -                        // Again use polymorphism. Wait until
  -                        // the nodes settle down.
  -                        
  -                        switch(p.getType())
  -                        {
  -                            case ParserTreeConstants.JJTREFERENCE:
  -                                params[j] = getReferenceValue((ASTReference)p);
  -                                break;
  -                            
  -                            case ParserTreeConstants.JJTSTRINGLITERAL:
  -                                params[j] = getStringLiteralValue(p.getFirstToken().image);
  -                                break;
  -                        }
  -                    }                        
  -                
  -                result = ClassUtils.invoke(result, method, params);
  -                
  -                signature = signature + "Method.";
  -                
  -                break;                    
  -            }
  -        }
  -        
  -        if (tailChildrenToIgnore == 1)
  -            property = node.jjtGetChild(children - 1).getFirstToken().image;
  -
  -        //System.out.println("signature: " + signature);
  -        return result;
  -    }
  -
  -    // Put this in the base visitor.
  -    protected void setReferenceValue(ASTReference node, Object value)
  -    {
  -        Object result = getReferenceValue(node, 1);
  -        Object[] args = { value };
  -        ClassUtils.invoke(result, "set" + property, args);
  -    }
  -
  -    /**
  -     * Simply remove the quotes from a
  -     * string literal
  -     */
  -    protected  Object getStringLiteralValue(String s)
  -    {
  -        return s.substring(1, s.length() - 1);
  -    }
  -
  -    /**
  -     * Get the value of variable from the context
  -     */
  -    protected  Object getVariableValue(String variable)
  -    {
  -        if (context.containsKey(variable.substring(1)))
  -        {
  -            return context.get(variable.substring(1));
  -        }            
  -        else
  -        {
  -            return null;
  -        }            
  -    }
  -
       public Object visit(SimpleNode node, Object data)
       { 
           data = node.childrenAccept(this, data);