|
25 | 25 | import com.github.javaparser.ast.body.AnnotationMemberDeclaration; |
26 | 26 | import com.github.javaparser.ast.body.CallableDeclaration; |
27 | 27 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; |
| 28 | +import com.github.javaparser.ast.body.CompactConstructorDeclaration; |
28 | 29 | import com.github.javaparser.ast.body.ConstructorDeclaration; |
29 | 30 | import com.github.javaparser.ast.body.EnumConstantDeclaration; |
30 | 31 | import com.github.javaparser.ast.body.EnumDeclaration; |
31 | 32 | import com.github.javaparser.ast.body.FieldDeclaration; |
32 | 33 | import com.github.javaparser.ast.body.MethodDeclaration; |
33 | 34 | import com.github.javaparser.ast.body.Parameter; |
| 35 | +import com.github.javaparser.ast.body.RecordDeclaration; |
34 | 36 | import com.github.javaparser.ast.body.TypeDeclaration; |
35 | 37 | import com.github.javaparser.ast.expr.AnnotationExpr; |
36 | 38 | import com.github.javaparser.ast.expr.Name; |
|
62 | 64 | import java.util.Map; |
63 | 65 | import java.util.Optional; |
64 | 66 |
|
65 | | -public class GroovydocJavaVisitor extends VoidVisitorAdapter<Object> { |
| 67 | +public class GroovydocJavaVisitor |
| 68 | + extends VoidVisitorAdapter<Object> { |
66 | 69 | private final List<LinkArgument> links; |
67 | 70 | private SimpleGroovyClassDoc currentClassDoc = null; |
68 | | - private Map<String, GroovyClassDoc> classDocs = new LinkedHashMap<>(); |
69 | | - private String packagePath; |
| 71 | + private final Map<String, GroovyClassDoc> classDocs = new LinkedHashMap<>(); |
| 72 | + private final String packagePath; |
70 | 73 | private final Map<String, String> aliases = new LinkedHashMap<>(); |
71 | | - private List<String> imports = new ArrayList<>(); |
| 74 | + private final List<String> imports = new ArrayList<>(); |
72 | 75 | private static final String FS = "/"; |
73 | 76 |
|
74 | 77 | public GroovydocJavaVisitor(String packagePath, List<LinkArgument> links) { |
@@ -148,7 +151,7 @@ public void visit(AnnotationMemberDeclaration n, Object arg) { |
148 | 151 | n.getJavadocComment().ifPresent(javadocComment -> |
149 | 152 | fieldDoc.setRawCommentText(javadocComment.getContent())); |
150 | 153 | n.getDefaultValue().ifPresent(defValue -> { |
151 | | - fieldDoc.setRawCommentText(fieldDoc.getRawCommentText() + "\n* @default " + defValue.toString()); |
| 154 | + fieldDoc.setRawCommentText(fieldDoc.getRawCommentText() + "\n* @default " + defValue); |
152 | 155 | fieldDoc.setConstantValueExpression(defValue.toString()); |
153 | 156 | }); |
154 | 157 | super.visit(n, arg); |
@@ -181,6 +184,26 @@ public void visit(ClassOrInterfaceDeclaration n, Object arg) { |
181 | 184 | } |
182 | 185 | } |
183 | 186 |
|
| 187 | + @Override |
| 188 | + public void visit(final RecordDeclaration n, final Object arg) { |
| 189 | + SimpleGroovyClassDoc parent = visit(n); |
| 190 | + if (n.isRecordDeclaration()) { |
| 191 | + currentClassDoc.setTokenType(SimpleGroovyDoc.RECORD_DEF); |
| 192 | + } |
| 193 | + super.visit(n,arg); |
| 194 | + if (parent != null) { |
| 195 | + currentClassDoc = parent; |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + @Override |
| 200 | + public void visit(final CompactConstructorDeclaration c, Object arg) { |
| 201 | + SimpleGroovyConstructorDoc meth = new SimpleGroovyConstructorDoc(c.getNameAsString(), currentClassDoc); |
| 202 | + setCompactConstructor(c, meth); |
| 203 | + currentClassDoc.add(meth); |
| 204 | + super.visit(c, arg); |
| 205 | + } |
| 206 | + |
184 | 207 | private String fullName(ClassOrInterfaceType et) { |
185 | 208 | StringBuilder name = new StringBuilder(); |
186 | 209 | et.getScope().ifPresent(sc -> name.append(sc.toString())); |
@@ -303,6 +326,23 @@ private void setConstructorOrMethodCommon(CallableDeclaration<? extends Callable |
303 | 326 | } |
304 | 327 | } |
305 | 328 |
|
| 329 | + private void setCompactConstructor(CompactConstructorDeclaration n, SimpleGroovyExecutableMemberDoc methOrCons) { |
| 330 | + n.getComment().ifPresent(javadocComment -> |
| 331 | + methOrCons.setRawCommentText(javadocComment.getContent())); |
| 332 | + NodeList<Modifier> mods = n.getModifiers(); |
| 333 | + if (currentClassDoc.isInterface()) { |
| 334 | + mods.add(Modifier.publicModifier()); |
| 335 | + } |
| 336 | + setModifiers(mods, methOrCons); |
| 337 | + processAnnotations(methOrCons, n); |
| 338 | + for (TypeParameter param : n.getTypeParameters()) { |
| 339 | + SimpleGroovyParameter p = new SimpleGroovyParameter(param.getNameAsString()); |
| 340 | + processAnnotations(p, param); |
| 341 | + p.setType(makeType(param)); |
| 342 | + methOrCons.add(p); |
| 343 | + } |
| 344 | + } |
| 345 | + |
306 | 346 | @Override |
307 | 347 | public void visit(FieldDeclaration f, Object arg) { |
308 | 348 | String name = f.getVariable(0).getNameAsString(); |
|
0 commit comments