KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > javadoc > JavadocNode


1 package org.incava.javadoc;
2
3 import java.awt.Point JavaDoc;
4 import java.io.*;
5 import java.util.*;
6 import org.incava.text.LineMapping;
7 import org.incava.text.Location;
8
9
10 /**
11  * Represents a Javadoc element.
12  */

13 public class JavadocNode
14 {
15     private JavadocDescriptionNode description = null;
16
17     private JavadocTaggedNode[] tagged = new JavadocTaggedNode[0];
18
19     private int startLine;
20
21     private int startColumn;
22
23     private int endLine;
24
25     private int endColumn;
26
27     /**
28      * Parses itself from the given text.
29      */

30     public static JavadocNode parse(String JavaDoc text, int startLine, int startColumn)
31     {
32         JavadocParser parser = new JavadocParser();
33         List subs = parser.parse(text, startLine, startColumn);
34
35         if (subs == null) {
36             return null;
37         }
38         else {
39             // store line positions, for converting string positions (which are
40
// 0-based) to line:column (which are 1-based)
41

42             LineMapping lines = new LineMapping(text, startLine, startColumn);
43             JavadocNode jd = new JavadocNode();
44
45             jd.startLine = startLine;
46             jd.startColumn = startColumn;
47
48             Location end = lines.getLocation(text.length() - 1);
49             jd.endLine = end.line;
50             jd.endColumn = end.column;
51
52             if (subs.size() > 0) {
53                 Iterator it = subs.iterator();
54
55                 Point JavaDoc descPos = (Point JavaDoc)it.next();
56                 if (descPos != null) {
57                     Location[] descLocations = lines.getLocations(descPos);
58
59                     // we could trim whitespace, so that the following descriptions are equivalent:
60

61                     // /** \n
62
// * This is a test. \n
63
// */
64

65                     // /** \n
66
// * This is a test. \n
67
// * @tag something
68
// */
69

70                     jd.description = new JavadocDescriptionNode(text.substring(descPos.x, descPos.y), descLocations[0], descLocations[1]);
71                 }
72
73                 jd.tagged = new JavadocTaggedNode[subs.size() - 1];
74                 for (int i = 0; it.hasNext(); ++i) {
75                     Point JavaDoc pos = (Point JavaDoc)it.next();
76                     Location[] locations = lines.getLocations(pos);
77                     
78                     jd.tagged[i] = new JavadocTaggedNode(text.substring(pos.x, pos.y), locations[0], locations[1]);
79                 }
80             }
81
82             return jd;
83         }
84     }
85
86     public JavadocDescriptionNode getDescription()
87     {
88         return description;
89     }
90
91     public JavadocTaggedNode[] getTaggedComments()
92     {
93         return tagged;
94     }
95
96     public int getStartLine()
97     {
98         return startLine;
99     }
100
101     public int getStartColumn()
102     {
103         return startColumn;
104     }
105
106     public int getEndLine()
107     {
108         return endLine;
109     }
110
111     public int getEndColumn()
112     {
113         return endColumn;
114     }
115
116 }
117
Popular Tags