Skip to content

Commit

Permalink
javadoc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrimble committed Dec 1, 2015
1 parent 5669165 commit 51997ab
Showing 1 changed file with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
import com.sun.codemodel.JTypeVar;
import com.sun.codemodel.JVar;

/**
* Adds methods for dynamically getting, setting, and building properties by name.
*
* @author Christian Trimble
*
*/
public class DynamicPropertiesRule implements Rule<JDefinedClass, JDefinedClass> {

public static final String NOT_FOUND_VALUE_FIELD = "NOT_FOUND_VALUE";
Expand All @@ -65,6 +71,33 @@ public DynamicPropertiesRule(RuleFactory ruleFactory) {
this.ruleFactory = ruleFactory;
}

/**
* This rule adds dynamic getter, setter and builder methods based on the properties and additional properties
* defined in a schema.
* <p>
* If accessors are being generated, then methods for getting and setting properties by name will be added. These
* methods first attempt to call the appropriate getter or setter for the property. It no property with the supplied
* name is defined, then the additional properties map is used.
* <p>
* If builders are being generated, then a method for building properties by name will be added. This method first
* attempts to call the builder for the property. If no property with the supplied name is defined, then the additional
* properties map is used.
* <p>
* The methods generated by this class throw an IllegalArgumentException, if the name specified for the property is unknown and
* additional properties are not enabled. A ClassCastException will be thrown, when the value being set is incompatible with the
* type of the named property.
*
* @param nodeName
* the name of the node for which dynamic getters, setters, and builders are being added.
* @param node
* the properties node, containing property names and their
* definition
* @param jclass
* the Java type which will have the given properties added
* @param currentSchema
* the schema being implemented
* @return the given jclass
*/
@Override
public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema currentSchema) {
if (!ruleFactory.getGenerationConfig().isIncludeDynamicAccessors()) {
Expand Down Expand Up @@ -260,16 +293,6 @@ private JMethod addPublicWithMethod(JDefinedClass jclass, JsonNode propertiesNod
return method;
}

/**
* protected boolean set$( String name, Object value ) { switch( name ) { //
* cases for the properties defined on this schema. default: return
* super.set$( name, value ); // if extends return false; // if not extends.
* } }
*
* @param jclass
* @param currentSchema
* @param node
*/
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode, Schema currentSchema) {
JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
Expand Down

0 comments on commit 51997ab

Please # to comment.