You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by st...@apache.org on 2004/01/07 16:19:38 UTC

cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava JavaWriter.java JavaTestCaseWriter.java JavaStubWriter.java JavaSkelWriter.java JavaServiceImplWriter.java JavaServiceIfaceWriter.java JavaInterfaceWriter.java JavaBeanWriter.java

stevel      2004/01/07 07:19:38

  Modified:    java/src/org/apache/axis/wsdl/toJava JavaWriter.java
                        JavaTestCaseWriter.java JavaStubWriter.java
                        JavaSkelWriter.java JavaServiceImplWriter.java
                        JavaServiceIfaceWriter.java
                        JavaInterfaceWriter.java JavaBeanWriter.java
  Log:
  Generate proper javadoc comments from the WSDL. This code is fancy in that it will crack @tags from the comment and lay them out correctly; so email addresses could cause problems. Maybe we should require whitespace before the @tag, as that handles {@link} too.
  PR: 15902
  Obtained from: Danno Ferrin
  
  Revision  Changes    Path
  1.26      +70 -27    ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java
  
  Index: JavaWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- JavaWriter.java	29 Oct 2003 20:46:26 -0000	1.25
  +++ JavaWriter.java	7 Jan 2004 15:19:38 -0000	1.26
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -63,6 +63,7 @@
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.PrintWriter;
  +import java.util.StringTokenizer;
   
   /**
    * Emitter knows about WSDL writers, one each for PortType, Binding, Service,
  @@ -118,6 +119,9 @@
    */
   public abstract class JavaWriter implements Generator {
   
  +    /** This controls how many characters per line for javadoc comments */
  +    protected final static int LINE_LENGTH = 65;
  +    
       /** Field emitter */
       protected Emitter emitter;
   
  @@ -270,15 +274,73 @@
       }    // closePrintWriter
   
       /**
  +     * Takes out new lines and wraps at Javadoc tags
  +     * @param documentation the raw comments from schema
  +     * @param addTab if true adds a tab character when wrapping (methods)
  +     */
  +    protected String getJavadocDescriptionPart(String documentation, boolean addTab) {
  +        if (documentation == null) {
  +            return "";
  +        }
  +
  +        String doc = documentation.trim();
  +
  +        if (documentation.trim().length() == 0) {
  +            //nothing to do
  +            return doc;
  +        }
  +        
  +        // make @ tags start a new line (for javadoc tags mostly)
  +        // it will have a bad impact on e-mail address and such, but oh well
  +        // you should probobly be spam proofing your e-mail anyway
  +        StringTokenizer st = new StringTokenizer(doc, "@");
  +        StringBuffer newComments;
  +        if (st.hasMoreTokens()) {
  +            newComments = new StringBuffer(st.nextToken());
  +            while (st.hasMoreTokens()) {
  +                newComments.append(addTab ? "\n    * @" : "\n * @");
  +                newComments.append(st.nextToken().trim());
  +            }
  +        } else {
  +            newComments = new StringBuffer(doc);
  +        }
  +        newComments.insert(0, addTab ? "    * " : " * ");
  +        
  +        // tweak comment ending tags by insterting a 
  +        // space between the star and the slash, BUG13407
  +        int pos = newComments.indexOf("*/");
  +        while (pos >= 0) {
  +            newComments.insert(pos + 1, ' ');
  +            pos = newComments.indexOf("*/");
  +        }
  +        
  +        // now pretty it up based on column length
  +        int lineStart = 0;
  +        int newlinePos = 0;
  +        while (lineStart < newComments.length()) {
  +            lineStart = newlinePos + 1;
  +            newlinePos = newComments.indexOf("\n", lineStart);
  +            if (newlinePos == -1) {
  +                newlinePos = newComments.length();
  +            }
  +            if ((lineStart - newlinePos) > LINE_LENGTH) {
  +                lineStart += LINE_LENGTH;
  +                while (!Character.isWhitespace(newComments.charAt(lineStart++)));
  +                newComments.insert(lineStart, addTab ? "\n    *" : "\n *");
  +                lineStart += addTab ? 7 : 3;
  +            }
  +        }
  +        
  +        return newComments.toString();
  +    }
  +    
  +    /**
        * Output a documentation element as a Java comment.
        * 
        * @param pw      
        * @param element 
        */
  -    protected void writeComment(PrintWriter pw, Element element) {
  -
  -        // This controls how many characters per line
  -        final int LINE_LENGTH = 65;
  +    protected void writeComment(PrintWriter pw, Element element, boolean addTab) {
   
           if (element == null) {
               return;
  @@ -292,33 +354,14 @@
   
           String comment = child.getNodeValue();
   
  -        // Strip out stuff that will really mess up our comments
  -        comment = comment.replace('\r', ' ');
  -        comment = comment.replace('\n', ' ');
  -
           if (comment != null) {
               int start = 0;
   
               pw.println();    // blank line
   
  -            // make the comment look pretty
  -            while (start < comment.length()) {
  -                int end = start + LINE_LENGTH;
  -
  -                if (end > comment.length()) {
  -                    end = comment.length();
  -                }
  -
  -                // look for next whitespace
  -                while ((end < comment.length())
  -                        && !Character.isWhitespace(comment.charAt(end))) {
  -                    end++;
  -                }
  -
  -                pw.println("    // " + comment.substring(start, end).trim());
  -
  -                start = end + 1;
  -            }
  +            pw.println(addTab ? "    /**" : "/**");
  +            pw.println(getJavadocDescriptionPart(comment, addTab));
  +            pw.println(addTab ? "     */" : " */");
           }
       }                        // writeComment
   }    // abstract class JavaWriter
  
  
  
  1.57      +2 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java
  
  Index: JavaTestCaseWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- JavaTestCaseWriter.java	16 Dec 2003 14:08:00 -0000	1.56
  +++ JavaTestCaseWriter.java	7 Jan 2004 15:19:38 -0000	1.57
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -166,7 +166,7 @@
   
               PortType portType = binding.getPortType();
   
  -            writeComment(pw, p.getDocumentationElement());
  +            writeComment(pw, p.getDocumentationElement(), true);
   
               writeServiceTestCode(pw, portName, portType, bEntry);
           }
  
  
  
  1.128     +2 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
  
  Index: JavaStubWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
  retrieving revision 1.127
  retrieving revision 1.128
  diff -u -r1.127 -r1.128
  --- JavaStubWriter.java	19 Dec 2003 15:07:13 -0000	1.127
  +++ JavaStubWriter.java	7 Jan 2004 15:19:38 -0000	1.128
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -1024,7 +1024,7 @@
                                   Parameters parms, String soapAction,
                                   String opStyle, boolean oneway, int opIndex) {
   
  -        writeComment(pw, operation.getDocumentationElement());
  +        writeComment(pw, operation.getDocumentationElement(), true);
           pw.println(parms.signature + " {");
           pw.println("        if (super.cachedEndpoint == null) {");
           pw.println(
  
  
  
  1.58      +2 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java
  
  Index: JavaSkelWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- JavaSkelWriter.java	17 Nov 2003 15:14:03 -0000	1.57
  +++ JavaSkelWriter.java	7 Jan 2004 15:19:38 -0000	1.58
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -547,7 +547,7 @@
                                   Parameters parms, String soapAction,
                                   String namespace) {
   
  -        writeComment(pw, operation.getDocumentationElement());
  +        writeComment(pw, operation.getDocumentationElement(), true);
   
           // The skeleton used to have specialized operation signatures.
           // now the same signature is used as the portType
  
  
  
  1.35      +3 -3      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java
  
  Index: JavaServiceImplWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- JavaServiceImplWriter.java	29 Oct 2003 20:46:26 -0000	1.34
  +++ JavaServiceImplWriter.java	7 Jan 2004 15:19:38 -0000	1.35
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -131,7 +131,7 @@
           Service service = sEntry.getService();
   
           // output comments
  -        writeComment(pw, service.getDocumentationElement());
  +        writeComment(pw, service.getDocumentationElement(), false);
   
           // Used to construct the getPort(Class) method.
           Vector getPortIfaces = new Vector();
  @@ -301,7 +301,7 @@
           // Write the private address field for this port
           pw.println();
           pw.println("    // " + Messages.getMessage("getProxy00", portName));
  -        writeComment(pw, p.getDocumentationElement());
  +        writeComment(pw, p.getDocumentationElement(), true);
           pw.println("    private java.lang.String " + portName + "_address = \""
                   + address + "\";");
   
  
  
  
  1.17      +2 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceIfaceWriter.java
  
  Index: JavaServiceIfaceWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceIfaceWriter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JavaServiceIfaceWriter.java	29 Oct 2003 20:46:26 -0000	1.16
  +++ JavaServiceIfaceWriter.java	7 Jan 2004 15:19:38 -0000	1.17
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -123,7 +123,7 @@
       protected void writeFileBody(PrintWriter pw) throws IOException {
   
           // output comments
  -        writeComment(pw, service.getDocumentationElement());
  +        writeComment(pw, service.getDocumentationElement(), false);
   
           // get ports
           Map portMap = service.getPorts();
  
  
  
  1.16      +2 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaInterfaceWriter.java
  
  Index: JavaInterfaceWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaInterfaceWriter.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JavaInterfaceWriter.java	29 Oct 2003 20:46:26 -0000	1.15
  +++ JavaInterfaceWriter.java	7 Jan 2004 15:19:38 -0000	1.16
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -158,7 +158,7 @@
       protected void writeOperation(PrintWriter pw, Operation operation)
               throws IOException {
   
  -        writeComment(pw, operation.getDocumentationElement());
  +        writeComment(pw, operation.getDocumentationElement(), true);
   
           Parameters parms = bEntry.getParameters(operation);
   
  
  
  
  1.53      +1 -26     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java
  
  Index: JavaBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- JavaBeanWriter.java	10 Dec 2003 02:52:27 -0000	1.52
  +++ JavaBeanWriter.java	7 Jan 2004 15:19:38 -0000	1.53
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -70,7 +70,6 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Set;
  -import java.util.StringTokenizer;
   import java.util.Vector;
   
   /**
  @@ -473,30 +472,6 @@
           pw.println();
       }
   
  -    
  -    /**
  -     * Takes out new lines and wraps at Javadoc tags
  -     * @param documentation the raw comments from schema
  -     * @param addTab if true adds a tab character when wrapping (methods)
  -     */
  -    private String getJavadocDescriptionPart(String documentation, boolean addTab) {
  -        String doc = "";
  -        if (documentation == null) return doc;
  -        if (documentation.trim().length() == 0) return doc;
  -
  -        StringTokenizer st2 = new StringTokenizer(documentation.trim(), "\n");
  -
  -        while (st2.hasMoreTokens()) {
  -            String line = st2.nextToken().trim();
  -            doc += line + " ";
  -        }
  -        StringTokenizer st = new StringTokenizer(doc.trim(), "@");
  -        String newComments = st.nextToken();
  -        while (st.hasMoreTokens()) {
  -            newComments += "\n" + (addTab ? "\t" : "") + " * @" + st.nextToken().trim();
  -        }
  -        return newComments;
  -    }
       
       /**
        * Writes the default constructor.