Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated JavaDocs #64

Merged
merged 30 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
03513b0
Use separate lexer channel for JavaDoc comments
Clashsoft Jul 16, 2020
1d106ce
Save tokenStream in FragmentMapBuilder
Clashsoft Jul 16, 2020
8712cc5
Include JavaDoc comments in Method and Constructor fragments
Clashsoft Jul 17, 2020
5d19fbd
Include JavaDoc comments in Class Declaration fragments
Clashsoft Jul 17, 2020
19ead06
Include JavaDoc comments in Field fragments
Clashsoft Jul 17, 2020
cb8b358
Merge branch 'develop' into feat/javadoc
Clashsoft Sep 2, 2020
a4a223c
feat: Add Attribute.description property
Clashsoft Sep 2, 2020
b0e3f5a
feat: Add Attribute.getDescriptionLines helper
Clashsoft Sep 2, 2020
f447966
feat: Generate JavaDocs from descriptions in attribute templates
Clashsoft Sep 2, 2020
67343c2
feat: Add descriptions in GenModel
Clashsoft Sep 2, 2020
5b7a72a
feat: Add Attribute.since property
Clashsoft Sep 2, 2020
208b47d
feat: Generate @since in JavaDoc templates
Clashsoft Sep 2, 2020
7b8024b
feat: Set since in GenModel
Clashsoft Sep 2, 2020
ccf5fed
feat: Improve descriptions in GenModel
Clashsoft Sep 2, 2020
47fb2a6
feat: Update generated classes
Clashsoft Sep 2, 2020
414a922
feat: Generate JavaDoc with @since 1.2 for PROPERTY_* constants
Clashsoft Sep 2, 2020
0d2ceae
fix: Make Attribute.getDescriptionLines return a list
Clashsoft Sep 2, 2020
dc4ed8e
chore: Update classModel.yaml
Clashsoft Sep 2, 2020
b1183a1
Merge branch 'develop' into feat/javadoc
Clashsoft Sep 2, 2020
b591001
fix: Restore backwards compatibility in FragmentMapBuilder
Clashsoft Sep 2, 2020
205e828
fix: Ignore revapi breaking change in FulibClassLexer
Clashsoft Sep 2, 2020
40bffa6
feat: Generate JavaDocs for attribute with and without methods
Clashsoft Sep 2, 2020
826925b
feat: Add description for Clazz.imports
Clashsoft Sep 2, 2020
400aa64
feat: Add AssocRole.description and .since properties
Clashsoft Sep 2, 2020
0279aae
refactor: Add javadoc.stg
Clashsoft Sep 2, 2020
450989b
feat: Implement description and since for roles
Clashsoft Sep 2, 2020
44cb832
fix: Add AssocRole.getDescriptionLines
Clashsoft Sep 10, 2020
ea3f9cd
fix: Update generated model classes
Clashsoft Sep 10, 2020
c8ea249
fix: Add missing closing brace to Clazz.imports description
Clashsoft Sep 10, 2020
6b179b9
fix: Deprecate Attribute.getDescriptionLines
Clashsoft Sep 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ acceptedBreaks:
old: "field org.fulib.classmodel.FileFragmentMap.PACKAGE_NEWLINES"
new: "field org.fulib.classmodel.FileFragmentMap.PACKAGE_NEWLINES"
justification: "https://github.com/fujaba/fulib/pull/36"
- code: "java.field.constantValueChanged"
old: "field org.fulib.parser.FulibClassLexer._serializedATN"
new: "field org.fulib.parser.FulibClassLexer._serializedATN"
justification: "ANTLR-generated org.fulib.parser classes are for internal use only"
- code: "java.field.constantValueChanged"
old: "field org.fulib.parser.FulibClassParser.RULE_annotatedType"
new: "field org.fulib.parser.FulibClassParser.RULE_annotatedType"
Expand Down
96 changes: 77 additions & 19 deletions src/gen/java/org/fulib/classmodel/GenModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,109 @@ public void decorate(ClassModelManager mb)
final Clazz ClassModel = mb.haveClass("ClassModel", c -> {
c.attribute("packageName", STRING);
c.attribute("mainJavaDir", STRING);
c.attribute("defaultCollectionType", "CollectionType");
c.attribute("defaultPropertyStyle", STRING, "\"POJO\"");
c
.attribute("defaultCollectionType", "CollectionType")
.setDescription("the default collection type for to-n roles")
.setSince("1.2");
c
.attribute("defaultPropertyStyle", STRING, "\"POJO\"")
.setDescription("the default property style for attributes and roles.\n"
+ "Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.");
});

final Clazz Clazz = mb.haveClass("Clazz", c -> {
c.attribute("name", STRING);
c.attribute("propertyStyle", STRING);
c.attribute("modified", BOOLEAN);
c.attribute("imports", STRING).setCollectionType(CollectionType.LinkedHashSet);
c
.attribute("propertyStyle", STRING)
.setDescription("the default property style for attributes and roles.\n"
+ "Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.");
c
.attribute("modified", BOOLEAN)
.setDescription("a boolean indicating whether this attribute was modified. For internal use only.");
c
.attribute("imports", STRING)
.setCollectionType(CollectionType.LinkedHashSet)
.setDescription("the set of imported members.\n"
+ "Elements can have one of the formats {@code org.example.Foo}, {@code static org.example.Foo.bar},\n"
+ "{@code import org.example.Foo;} or {@code import static org.example.Foo.bar;}")
.setSince("1.2");
});

final Clazz Attribute = mb.haveClass("Attribute", c -> {
c.attribute("name", STRING);
c.attribute("type", STRING);
c.attribute("collectionType", "CollectionType");
c.attribute("collectionType", "CollectionType").setDescription("the collection type").setSince("1.2");
c.attribute("initialization", STRING);
c.attribute("propertyStyle", STRING);
c.attribute("modified", BOOLEAN);
c
.attribute("propertyStyle", STRING)
.setDescription("the property style.\n"
+ "Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.");
c
.attribute("modified", BOOLEAN)
.setDescription("a boolean indicating whether this attribute was modified. For internal use only.");
c
.attribute("description", STRING)
.setDescription("the description of this attribute, used for generating JavaDocs")
.setSince("1.3");
c
.attribute("since", STRING)
.setDescription("the version when this attribute was introduced, used for generating JavaDocs")
.setSince("1.3");
});

final Clazz AssocRole = mb.haveClass("AssocRole", c -> {
c.attribute("name", STRING);
c.attribute("cardinality", INT);
c.attribute("collectionType", "CollectionType");
c.attribute("aggregation", BOOLEAN);
c.attribute("propertyStyle", STRING);
c.attribute("modified", BOOLEAN);
c.attribute("collectionType", "CollectionType").setDescription("the collection type").setSince("1.2");
c
.attribute("aggregation", BOOLEAN)
.setDescription("a boolean indicating whether this role is an aggregation,\n"
+ "i.e. whether the target objects are {@code removeYou}'d completely when using {@code without*} methods or\n"
+ "{@code removeYou} on the source object");
c
.attribute("propertyStyle", STRING)
.setDescription("the property style.\n"
+ "Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.");
c
.attribute("description", STRING)
.setDescription("the description of this role, used for generating JavaDocs")
.setSince("1.3");
c
.attribute("since", STRING)
.setDescription("the version when this role was introduced, used for generating JavaDocs")
.setSince("1.3");
c
.attribute("modified", BOOLEAN)
.setDescription("a boolean indicating whether this role was modified. For internal use only.");
});

final Clazz FMethod = mb.haveClass("FMethod", c -> {
c.attribute("methodBody", STRING);
c.attribute("modified", BOOLEAN);
c.attribute("modifiers", STRING, "\"public\"");
c
.attribute("modified", BOOLEAN)
.setDescription("a boolean indicating whether this method was modified. For internal use only.");
c
.attribute("modifiers", STRING, "\"public\"")
.setDescription("the modifiers. Defaults to \"public\"")
.setSince("1.2");
c.attribute("annotations", STRING);
});

mb.associate(ClassModel, "classes", MANY, Clazz, "model", ONE);
mb
.associate(ClassModel, "classes", MANY, Clazz, "model", ONE)
.setDescription("the classes contained in this model")
.setSince("1.2");

mb.associate(Clazz, "attributes", MANY, Attribute, "clazz", ONE);
mb.associate(Clazz, "attributes", MANY, Attribute, "clazz", ONE).setDescription("the attributes").setSince("1.2");

mb.associate(Clazz, "roles", MANY, AssocRole, "clazz", ONE);
mb.associate(Clazz, "roles", MANY, AssocRole, "clazz", ONE).setDescription("the roles").setSince("1.2");

mb.associate(Clazz, "methods", MANY, FMethod, "clazz", ONE);
mb.associate(Clazz, "methods", MANY, FMethod, "clazz", ONE).setDescription("the methods").setSince("1.2");

mb.associate(Clazz, "superClass", ONE, Clazz, "subClasses", MANY);
mb
.associate(Clazz, "subClasses", MANY, Clazz, "superClass", ONE)
.setDescription("the subclasses")
.setSince("1.2");

mb.associate(AssocRole, "other", ONE, AssocRole, "other", ONE);

Expand Down
2 changes: 1 addition & 1 deletion src/main/antlr/FulibClass.g4
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ DOUBLE: 'double';
THIS: 'this';
NEW: 'new';

DOC_COMMENT: '/**' .*? '*/' -> channel(2);
DOC_COMMENT: '/**' .*? '*/' -> channel(3); // TODO named JAVADOC channel (requires separate lexer + parser grammars)
BLOCK_COMMENT: '/*' .*? '*/' -> channel(2);
LINE_COMMENT: '//' .*? '\n' -> channel(2);

Expand Down
106 changes: 97 additions & 9 deletions src/main/java/org/fulib/classmodel/AssocRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class AssocRole
Expand All @@ -22,6 +25,10 @@ public class AssocRole
public static final String PROPERTY_modified = "modified";
public static final String PROPERTY_clazz = "clazz";
public static final String PROPERTY_other = "other";
/** @since 1.3 */
public static final String PROPERTY_description = "description";
/** @since 1.3 */
public static final String PROPERTY_since = "since";

// =============== Fields ===============

Expand All @@ -34,6 +41,8 @@ public class AssocRole
private CollectionType collectionType;
private boolean aggregation;
private String propertyStyle;
private String description;
private String since;
private boolean modified;

// =============== Properties ===============
Expand Down Expand Up @@ -171,9 +180,9 @@ public CollectionType getCollectionType()

/**
* @param value
* the new collection type
* the collection type
*
* @return this instance, to allow method chaining
* @return this
*
* @since 1.2
*/
Expand Down Expand Up @@ -217,7 +226,8 @@ public AssocRole setRoleType(String value)

/**
* @return a boolean indicating whether this role is an aggregation,
* i.e. whether the target objects are {@code removeYou}'d completely when using {@code without*} methods or {@code removeYou} on the source object
* i.e. whether the target objects are {@code removeYou}'d completely when using {@code without*} methods or
* {@code removeYou} on the source object
*/
public boolean getAggregation()
{
Expand All @@ -227,9 +237,10 @@ public boolean getAggregation()
/**
* @param value
* a boolean indicating whether this role is an aggregation,
* i.e. whether the target objects are {@code removeYou}'d completely when using {@code without*} methods or {@code removeYou} on the source object
* i.e. whether the target objects are {@code removeYou}'d completely when using {@code without*} methods or
* {@code removeYou} on the source object
*
* @return this instance, to allow method chaining
* @return this
*/
public AssocRole setAggregation(boolean value)
{
Expand All @@ -245,7 +256,8 @@ public AssocRole setAggregation(boolean value)
}

/**
* @return the property style of this role
* @return the property style.
* Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.
*/
public String getPropertyStyle()
{
Expand All @@ -254,10 +266,10 @@ public String getPropertyStyle()

/**
* @param value
* the property style to use for this role.
* the property style.
* Currently, only {@link Type#POJO}, {@link Type#BEAN} and {@link Type#JAVA_FX} are supported.
*
* @return this instance, to allow method chaining
* @return this
*/
public AssocRole setPropertyStyle(String value)
{
Expand All @@ -272,6 +284,80 @@ public AssocRole setPropertyStyle(String value)
return this;
}

/**
* @return the description of this role, used for generating JavaDocs
*
* @since 1.3
*/
public String getDescription()
{
return this.description;
}

/**
* @param value
* the description of this role, used for generating JavaDocs
*
* @return this
*
* @since 1.3
*/
public AssocRole setDescription(String value)
{
if (Objects.equals(value, this.description))
{
return this;
}

final String oldValue = this.description;
this.description = value;
this.firePropertyChange(PROPERTY_description, oldValue, value);
return this;
}

/**
* @return the lines of the description of this attribute, used for generating JavaDocs
*
* @since 1.3
* @deprecated for internal use only
*/
@Deprecated
public List<String> getDescriptionLines()
{
return this.getDescription() == null ? Collections.emptyList() : Arrays.asList(this.getDescription().split("\n"));
}

/**
* @return the version when this role was introduced, used for generating JavaDocs
*
* @since 1.3
*/
public String getSince()
{
return this.since;
}

/**
* @param value
* the version when this role was introduced, used for generating JavaDocs
*
* @return this
*
* @since 1.3
*/
public AssocRole setSince(String value)
{
if (Objects.equals(value, this.since))
{
return this;
}

final String oldValue = this.since;
this.since = value;
this.firePropertyChange(PROPERTY_since, oldValue, value);
return this;
}

/**
* @return a boolean indicating whether this role was modified. For internal use only.
*/
Expand All @@ -284,7 +370,7 @@ public boolean getModified()
* @param value
* a boolean indicating whether this role was modified. For internal use only.
*
* @return this instance, to allow method chaining
* @return this
*/
public AssocRole setModified(boolean value)
{
Expand Down Expand Up @@ -372,6 +458,8 @@ public String toString()
final StringBuilder result = new StringBuilder();
result.append(' ').append(this.getName());
result.append(' ').append(this.getPropertyStyle());
result.append(' ').append(this.getDescription());
result.append(' ').append(this.getSince());
return result.substring(1);
}
}
Loading