You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ki...@apache.org on 2003/04/16 20:05:41 UTC

cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Mark.java SmapUtil.java

kinman      2003/04/16 11:05:41

  Modified:    jasper2/src/share/org/apache/jasper/compiler Mark.java
                        SmapUtil.java
  Log:
  - Rewrite the Smap production to use a Node.Visitor for node traversal.
    This facilitates generating better smap inf, based on the node type.
  - Start line and column number in the JSP page with 1 instead of 0, to
    match expectation for most users.
  
  Revision  Changes    Path
  1.4       +8 -6      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Mark.java
  
  Index: Mark.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Mark.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Mark.java	13 Dec 2002 21:13:25 -0000	1.3
  +++ Mark.java	16 Apr 2003 18:05:41 -0000	1.4
  @@ -123,7 +123,9 @@
       {
   	this.reader = reader;
   	this.stream = inStream;
  -	this.cursor = this.line = this.col = 0;
  +	this.cursor = 0;
  +	this.line = 1;
  +	this.col = 1;
   	this.fileid = fileid;
   	this.fileName = name;
   	this.baseDir = inBaseDir;
  @@ -180,8 +182,8 @@
   
   	// set new variables
   	cursor = 0;
  -	line = 0;
  -	col = 0;
  +	line = 1;
  +	col = 1;
   	fileid = inFileid;
   	fileName = name;
   	baseDir = inBaseDir;
  
  
  
  1.8       +141 -25   jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java
  
  Index: SmapUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SmapUtil.java	19 Nov 2002 03:27:44 -0000	1.7
  +++ SmapUtil.java	16 Apr 2003 18:05:41 -0000	1.8
  @@ -61,6 +61,7 @@
   import java.util.*;
   import org.apache.jasper.JspCompilationContext;
   import org.apache.jasper.compiler.Node;
  +import org.apache.jasper.JasperException;
   
   /**
    * Contains static utilities for generating SMAP data based on the
  @@ -109,7 +110,7 @@
   	String smapPath = inputSmapPath(ctxt.getRealPath(ctxt.getJspFile()));
           File inputSmap = new File(smapPath);
           if (inputSmap.exists()) {
  -        byte[] embeddedSmap = null;
  +            byte[] embeddedSmap = null;
   	    byte[] subSmap = SDEInstaller.readWhole(inputSmap);
   	    String subSmapString = new String(subSmap, SMAP_ENCODING);
   	    g.addSmap(subSmapString, "JSP");
  @@ -472,32 +473,147 @@
               }
           }
       }
  +
       public static void evaluateNodes(Node.Nodes nodes, SmapStratum s) {
  -        if( nodes != null && nodes.size()>0) {
  -            int numChildNodes = nodes.size();
  -            for( int i = 0; i < numChildNodes; i++ ) {
  -                Node n = nodes.getNode( i );
  -		if (!n.isDummy()) {
  -		    Mark mark = n.getStart();
  -
  -		    if (verbose) {
  -			System.out.println("Mark(start): line=" +
  -					   mark.getLineNumber() +
  -					   " col="+mark.getColumnNumber() +
  -					   "Node: begLine=" +
  -					   n.getBeginJavaLine() +
  -					   " endLine="+n.getEndJavaLine());
  -		    }
  -		    String unqualifiedName = unqualify(mark.getFile());
  -		    s.addFile(unqualifiedName);
  -		    s.addLineData(mark.getLineNumber(),
  -				  unqualifiedName,
  -				  1,
  -				  n.getBeginJavaLine(),
  -				  n.getEndJavaLine() - n.getBeginJavaLine());
  -		}
  -		evaluateNodes(nodes.getNode(i).getBody(), s);
  +        try {
  +            nodes.visit(new SmapGenVisitor(s));
  +        } catch (JasperException ex) {
  +	}
  +    }
  +
  +    static class SmapGenVisitor extends Node.Visitor {
  +
  +        private SmapStratum smap;
  +
  +        SmapGenVisitor(SmapStratum s) {
  +            this.smap = s;
  +        }
  +
  +        public void visit(Node.Declaration n) throws JasperException {
  +            doSmapText(n);
  +        }
  +
  +        public void visit(Node.Expression n) throws JasperException {
  +            doSmapText(n);
  +        }
  +
  +        public void visit(Node.Scriptlet n) throws JasperException {
  +            doSmapText(n);
  +        }
  +
  +        public void visit(Node.IncludeAction n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.ForwardAction n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.GetProperty n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.SetProperty n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.UseBean n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.PlugIn n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.CustomTag n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.UninterpretedTag n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.JspElement n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.JspText n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +        public void visit(Node.NamedAttribute n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.JspBody n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.InvokeAction n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.DoBodyAction n) throws JasperException {
  +            doSmap(n);
  +            visitBody(n);
  +        }
  +
  +        public void visit(Node.TemplateText n) throws JasperException {
  +            // Skip smap there the text is all noise
  +            String text = n.getText();
  +            int i = 0;
  +            while (i < text.length()) {
  +                if (text.charAt(i) > ' ')
  +                    break;
  +                i++;
               }
  +            if (i < text.length()) {
  +                doSmap(n);
  +            }
  +        }
  +
  +        private void doSmap(Node n, int inLineCount, int outIncrement) {
  +            Mark mark = n.getStart();
  +	    if (mark == null) {
  +                 return;
  +            }
  +
  +            String unqualifiedName = unqualify(mark.getFile());
  +            smap.addFile(unqualifiedName);
  +            smap.addLineData(mark.getLineNumber(),
  +                          unqualifiedName,
  +                          inLineCount,
  +                          n.getBeginJavaLine(),
  +                          outIncrement);
  +        }
  +
  +        private void doSmap(Node n) {
  +            doSmap(n, 1, n.getEndJavaLine() - n.getBeginJavaLine());
  +        }
  +
  +        private void doSmapText(Node n) {
  +            String text = n.getText();
  +            int index = 0;
  +            int lineCount = 1;
  +            // count lines inside text
  +            while ((index = text.indexOf('\n', index)) > -1 ) {
  +                lineCount++;
  +                index++;
  +            }
  +
  +            doSmap(n, lineCount, 1);
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org