Skip to content

Commit 7ccf305

Browse files
Import JavaDoc in the JavaImportTool
1 parent 6bbf4f0 commit 7ccf305

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

JavaImportTool/src/main/java/envision/java/importtool/ASTConverter.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ private void addEmptyLinesAndCommentsBetweenNodes(ASTNode a, ASTNode b) throws C
129129
}
130130
}
131131

132+
public void addJavaDoc(Node node, Javadoc javadoc) throws ConversionException
133+
{
134+
if (javadoc == null) return;
135+
136+
String[] commentLines = source.substring(javadoc.getStartPosition(),
137+
javadoc.getStartPosition()+javadoc.getLength()).split("\\r?\\n");
138+
139+
Node commentNode = new Node(node, "CommentNode", "comment");
140+
node.add(commentNode);
141+
for (String line : commentLines)
142+
{
143+
Node lineNode = new Node(commentNode, "Text", commentNode.child("lines").numChildren());
144+
commentNode.child("lines").add(lineNode);
145+
146+
lineNode.setStringValue(line);
147+
}
148+
}
149+
132150
public void visit(CompilationUnit node) throws ConversionException
133151
{
134152
PackageDeclaration pd = node.getPackage();
@@ -148,7 +166,7 @@ public void visit(AbstractTypeDeclaration type, boolean topLevel) throws Convers
148166
containers.push(cl);
149167

150168
setBodyModifiersAndAnnotations(type);
151-
//TODO: Handle JavaDoc
169+
addJavaDoc(cl, type.getJavadoc());
152170

153171
if (topLevel)
154172
{
@@ -294,6 +312,7 @@ public void visit(MethodDeclaration node, int name) throws ConversionException
294312
me.child("mthKind").setLongValue(node.isConstructor() ? 1 : 0);
295313

296314
setBodyModifiersAndAnnotations(node);
315+
addJavaDoc(me, node.getJavadoc());
297316
processTypeParameters(node.typeParameters());
298317
processParameters(node.parameters());
299318

@@ -328,6 +347,7 @@ public void visit(FieldDeclaration node, int name) throws ConversionException
328347
containers.push(field);
329348

330349
setBodyModifiersAndAnnotations(node);
350+
addJavaDoc(field, node.getJavadoc());
331351
Node type = typeExpression(node.getType(), "typeExpression");
332352
field.setChild("typeExpression", addExtraDimensions(type, vdf.getExtraDimensions()));
333353

@@ -344,6 +364,7 @@ public void visit(AnnotationTypeMemberDeclaration node, int name) throws Convers
344364
containers.push(field);
345365

346366
setBodyModifiersAndAnnotations(node);
367+
addJavaDoc(field, node.getJavadoc());
347368
field.setChild("typeExpression", typeExpression(node.getType(), "typeExpression"));
348369

349370
if (node.getDefault() != null)

0 commit comments

Comments
 (0)