kinman      2003/09/18 16:12:39

  Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
  Log:
  - When adjusting Java lines for tag handler codes that are generated in a body,
    make sure to include the CustomTag node itself.  This avoid strange Smap
    mappings in some cases.
  
  - Fix 22058: _jspx_push_body_count is not defined in a fragment, causing
    compilation errors when it is needed.  A _jspx_push_body_count is now
    defined in the Fragment_Helper class; its constructor and invokation
    adjusted accordingly.
  
  Revision  Changes    Path
  1.209     +35 -16    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
  retrieving revision 1.208
  retrieving revision 1.209
  diff -u -r1.208 -r1.209
  --- Generator.java    16 Sep 2003 17:46:43 -0000      1.208
  +++ Generator.java    18 Sep 2003 23:12:39 -0000      1.209
  @@ -1636,7 +1636,7 @@
                   // Set up new buffer for the method
                   outSave = out;
                   GenBuffer genBuffer =
  -                    new GenBuffer(n.implementsSimpleTag() ? null : n.getBody());
  +                    new GenBuffer(n.implementsSimpleTag() ? null : n);
                   methodsBuffered.add(genBuffer);
                   out = genBuffer.getOut();
   
  @@ -2957,11 +2957,17 @@
               isSimpleTagParent = true;
               boolean tmpIsFragment = isFragment;
               isFragment = true;
  +            String pushBodyCountVarSave = pushBodyCountVar;
  +            if (pushBodyCountVar != null) {
  +                // Use a fixed name for push body count, to simplify code gen
  +                pushBodyCountVar = "_jspx_push_body_count";
  +            }
               visitBody(n);
               out = outSave;
               parent = tmpParent;
               isSimpleTagParent = isSimpleTagParentSave;
               isFragment = tmpIsFragment;
  +            pushBodyCountVar = pushBodyCountVarSave;
               fragmentHelperClass.closeFragment(fragment, methodNesting);
               // XXX - Need to change pageContext to jspContext if
               // we're not in a place where pageContext is defined (e.g.
  @@ -2973,6 +2979,8 @@
                       + fragment.getId()
                       + ", pageContext, "
                       + tagHandlerVar
  +                    + ", "
  +                    + pushBodyCountVar
                       + ")");
           }
   
  @@ -3691,14 +3699,17 @@
        */
       private static class GenBuffer {
   
  -        private Node.Nodes body;
  +        private Node node;
           private java.io.CharArrayWriter charWriter;
           protected ServletWriter out;
   
  -        GenBuffer(Node.Nodes body) {
  -            this.body = body;
  -            if (body != null) {
  -                body.setGeneratedInBuffer(true);
  +        GenBuffer(Node n) {
  +            node = n;
  +            if (n != null) {
  +                Node.Nodes body = n.getBody();
  +                if (body != null) {
  +                    body.setGeneratedInBuffer(true);
  +                }
               }
               charWriter = new java.io.CharArrayWriter();
               out = new ServletWriter(new java.io.PrintWriter(charWriter));
  @@ -3720,9 +3731,10 @@
            */
           public void adjustJavaLines(final int offset) {
   
  -            if (body != null) {
  +            if (node != null) {
                   try {
  -                    body.visit(new Node.Visitor() {
  +                    node.accept(new Node.Visitor() {
  +
                           public void doVisit(Node n) {
                               if (n.getBeginJavaLine() > 0) {
                                   n.setBeginJavaLine(
  @@ -3735,7 +3747,11 @@
                               throws JasperException {
                               doVisit(n);
                               Node.Nodes body = n.getBody();
  -                            if (body != null && !body.isGeneratedInBuffer()) {
  +                            if (body != null &&
  +                                ((node == n) || !body.isGeneratedInBuffer())) {
  +                                // We want to adjust the Java lines only for
  +                                // top level Custom tags, unless its body is
  +                                // not generated in a buffer.
                                   body.visit(this);
                               }
                           }
  @@ -3755,9 +3771,9 @@
               private GenBuffer genBuffer;
               private int id;
   
  -            public Fragment(int id, Node.Nodes body) {
  +            public Fragment(int id, Node node) {
                   this.id = id;
  -                genBuffer = new GenBuffer(body);
  +                genBuffer = new GenBuffer(node);
               }
   
               public GenBuffer getGenBuffer() {
  @@ -3804,15 +3820,18 @@
               out.pushIndent();
               out.printil(
                   "private javax.servlet.jsp.tagext.JspTag _jspx_parent;");
  +            out.printil("private int[] _jspx_push_body_count;");
               out.println();
               out.printil(
                   "public "
                       + className
                       + "( int discriminator, JspContext jspContext, "
  -                    + "javax.servlet.jsp.tagext.JspTag _jspx_parent ) {");
  +                    + "javax.servlet.jsp.tagext.JspTag _jspx_parent, "
  +                    + "int[] _jspx_push_body_count ) {");
               out.pushIndent();
               out.printil("super( discriminator, jspContext, _jspx_parent );");
               out.printil("this._jspx_parent = _jspx_parent;");
  +            out.printil("this._jspx_push_body_count = _jspx_push_body_count;");
               out.popIndent();
               out.printil("}");
           }
  @@ -3822,7 +3841,7 @@
               String tagHandlerVar,
               int methodNesting)
               throws JasperException {
  -            Fragment result = new Fragment(fragments.size(), parent.getBody());
  +            Fragment result = new Fragment(fragments.size(), parent);
               fragments.add(result);
               this.used = true;
   
  
  
  

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

Reply via email to