1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
package org.incava.java;
import java.awt.Point;
import java.io.*;
import java.util.*;
import org.incava.log.Log;
/**
* Represents a Javadoc element.
*/
public class JavadocNode
{
private JavadocDescriptionNode description = null;
private JavadocTaggedNode[] tagged = new JavadocTaggedNode[0];
private int startLine;
private int startColumn;
private int endLine;
private int endColumn;
/**
* Parses itself from the given text.
*/
public static JavadocNode parse(String text, int startLine, int startColumn)
{
List subs = (new JavadocParser()).parse(text, startLine, startColumn);
if (subs == null) {
return null;
}
else {
// store line positions, for converting string positions (which are
// 0-based) to line:column (which are 1-based)
LineMapping lines = new LineMapping(text, startLine, startColumn);
JavadocNode jd = new JavadocNode();
jd.startLine = startLine;
jd.startColumn = startColumn;
Location end = lines.getLocation(text.length() - 1);
jd.endLine = end.line;
jd.endColumn = end.column;
if (subs.size() > 0) {
Iterator it = subs.iterator();
Point descPos = (Point)it.next();
if (descPos != null) {
Location[] descLocations = lines.getLocations(descPos);
// we could trim whitespace, so that the following descriptions are equivalent:
// /** \n
// * This is a test. \n
// */
// /** \n
// * This is a test. \n
// * @tag something
// */
jd.description = new JavadocDescriptionNode(text.substring(descPos.x, descPos.y), descLocations[0], descLocations[1]);
}
jd.tagged = new JavadocTaggedNode[subs.size() - 1];
for (int i = 0; it.hasNext(); ++i) {
Point pos = (Point)it.next();
Location[] locations = lines.getLocations(pos);
jd.tagged[i] = new JavadocTaggedNode(text.substring(pos.x, pos.y), locations[0], locations[1]);
}
}
return jd;
}
}
public JavadocDescriptionNode getDescription()
{
return description;
}
public JavadocTaggedNode[] getTaggedComments()
{
return tagged;
}
public int getStartLine()
{
return startLine;
}
public int getStartColumn()
{
return startColumn;
}
public int getEndLine()
{
return endLine;
}
public int getEndColumn()
{
return endColumn;
}
}
|