From bd69693c52321a0f8c1cfacbc5acbbdf145900df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20=C3=96qvist?= <jesper.oqvist@cs.lth.se> Date: Fri, 2 Feb 2018 12:46:35 +0100 Subject: [PATCH] Keep doc comments for aspect-declared types An error in an if-condition (|| instead of &&) lead to all documentation comments being discarded for aspect-declared types. fixes #284 (bitbucket) --- ChangeLog | 5 +++++ src/jastadd/ast/ASTNameBinding.jrag | 6 +++--- src/jastadd/ast/Comments.jrag | 6 ++++++ src/jastadd/ast/JaddCodeGen.jrag | 22 ++++++++++------------ src/jastadd/ast/JastAddCodeGen.jadd | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a4d8d61..851c9d33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-02-02 Jesper Öqvist <jesper.oqvist@cs.lth.se> + + * Documentation comments are now kept for aspect-declared types (classes, + interfaces, enums) and included in the generated code. + 2017-08-29 Jesper Öqvist <jesper.oqvist@cs.lth.se> * Added the --concurrent option to generate thread-safe attribute evaluation code. diff --git a/src/jastadd/ast/ASTNameBinding.jrag b/src/jastadd/ast/ASTNameBinding.jrag index 5944dd41..733586fd 100644 --- a/src/jastadd/ast/ASTNameBinding.jrag +++ b/src/jastadd/ast/ASTNameBinding.jrag @@ -41,7 +41,7 @@ aspect Lookup { public TypeDecl Grammar.findClassDecl(String name, String comment, String fileName, int beginLine, String enclosingAspect) { comment = comment.trim(); - if (!comment.startsWith("//") || !comment.startsWith("/*")) { + if (!comment.startsWith("//") && !comment.startsWith("/*")) { comment = ""; } TypeDecl t = lookup(name); @@ -58,7 +58,7 @@ aspect Lookup { public TypeDecl Grammar.findInterfaceDecl(String name, String comment, String fileName, int beginLine, String enclosingAspect) { comment = comment.trim(); - if (!comment.startsWith("//") || !comment.startsWith("/*")) { + if (!comment.startsWith("//") && !comment.startsWith("/*")) { comment = ""; } TypeDecl t = lookup(name); @@ -74,7 +74,7 @@ aspect Lookup { public TypeDecl Grammar.findEnumDecl(String name, String comment, String fileName, int beginLine, String enclosingAspect) { comment = comment.trim(); - if (!comment.startsWith("//") || !comment.startsWith("/*")) { + if (!comment.startsWith("//") && !comment.startsWith("/*")) { comment = ""; } TypeDecl t = lookup(name); diff --git a/src/jastadd/ast/Comments.jrag b/src/jastadd/ast/Comments.jrag index 9f508101..cdab7b66 100644 --- a/src/jastadd/ast/Comments.jrag +++ b/src/jastadd/ast/Comments.jrag @@ -28,12 +28,18 @@ aspect Comments { + /** + * Helper class for documentation comment handling. + */ class JavaDocParser { private static final String NL = System.getProperty("line.separator", "\n"); int i; char[] javadoc; StringBuilder out; + /** + * Strips comment syntax, returning only the raw comment text. + */ String parse(String comments) { if (comments == null) return ""; diff --git a/src/jastadd/ast/JaddCodeGen.jrag b/src/jastadd/ast/JaddCodeGen.jrag index 897d2580..ba48bc39 100644 --- a/src/jastadd/ast/JaddCodeGen.jrag +++ b/src/jastadd/ast/JaddCodeGen.jrag @@ -120,7 +120,7 @@ aspect JaddCodeGen { } /** - * Emits the (nta) child initialization method + * Emits the (nta) child initialization method. */ public void ASTDecl.emitChildInitMethod(PrintWriter out) { TemplateContext tt = templateContext(); @@ -162,7 +162,7 @@ aspect JaddCodeGen { } /** - * Emits the constructor body for tree building constructors + * Emits the constructor body for tree building constructors. */ public void ASTDecl.emitBuildingConstructorBody(PrintWriter out) { TemplateContext tt = templateContext(); @@ -200,7 +200,8 @@ aspect JaddCodeGen { /** * Emits annotation on the constructor with information about the arguments. - * Three arrays are generated for the constructor, one with the name of the + * + * <p>Three arrays are generated for the constructor, one with the name of the * children, one with the type and one with the kind(Child, List, Opt or Token). */ private void ASTDecl.emitConstructorAnnotation(PrintWriter out){ @@ -248,19 +249,17 @@ aspect JaddCodeGen { } /** - * Constructor to build trees bottom up + * Constructor to build trees bottom up. */ public void ASTDecl.emitBuildingConstructor(PrintWriter out) { if (components().isEmpty()) { // We only build constructors if there are components. return; } - if(config().generateAnnotations()){ + if (config().generateAnnotations()){ emitConstructorAnnotation(out); } - - out.print(config().indent + "public " + name() + "." + name() + "("); int paramIndex = 0; for (Component c : components()) { @@ -327,10 +326,9 @@ aspect JaddCodeGen { * List nodes use the minimum list size as the initial child * array size. */ - syn String ASTDecl.initialChildArraySize() { - return String.format("(i + 1 > %d || !(this instanceof %s)) ? i + 1 : %d", - config().minListSize(), config().listType(), config().minListSize()); - } + syn String ASTDecl.initialChildArraySize() = + String.format("(i + 1 > %d || !(this instanceof %s)) ? i + 1 : %d", + config().minListSize(), config().listType(), config().minListSize()); /** * Checks that ASTNode.state can be evaluated. @@ -627,7 +625,7 @@ aspect JaddCodeGen { jp.root = grammar(); // The file name is not meaningful, as the component is completely generated - // from a node type specification + // from a node type specification. jp.setFileName(""); try { diff --git a/src/jastadd/ast/JastAddCodeGen.jadd b/src/jastadd/ast/JastAddCodeGen.jadd index e5c7a148..30fd1d1a 100644 --- a/src/jastadd/ast/JastAddCodeGen.jadd +++ b/src/jastadd/ast/JastAddCodeGen.jadd @@ -281,7 +281,7 @@ aspect JastAddCodeGen { stream.println("}"); stream.close(); } catch (FileNotFoundException f) { - System.err.format("Could not create file %s in %s%n", file.getName(), file.getParent()); + System.err.format("Could not create file %s in %s.%n", file.getName(), file.getParent()); System.exit(1); } } -- GitLab