Skip to content

Commit

Permalink
Remove unnecessary/empty Javadocs
Browse files Browse the repository at this point in the history
Closes #659
  • Loading branch information
joelittlejohn committed Dec 13, 2016
1 parent c8ae443 commit 52ca7aa
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package org.jsonschema2pojo.rules;

import java.util.Iterator;

import javax.annotation.Nullable;

import org.jsonschema2pojo.Schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JDocComment;
import com.sun.codemodel.JDocCommentable;
import com.sun.codemodel.JFieldVar;
import org.jsonschema2pojo.Schema;

import javax.annotation.Nullable;
import java.util.Iterator;

/**
* Applies the "required" schema rule.
*
* @see <a
* href="http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7">http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7</a>
*/
public class NotRequiredRule implements Rule<JDocCommentable, JDocComment> {
public class NotRequiredRule implements Rule<JDocCommentable, JDocCommentable> {

/**
* Text added to JavaDoc to indicate that a field is not required
Expand Down Expand Up @@ -62,8 +63,7 @@ protected NotRequiredRule(RuleFactory ruleFactory) {
* not required.
*/
@Override
public JDocComment apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {
JDocComment javadoc = generatableType.javadoc();
public JDocCommentable apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {

// Since NotRequiredRule is executed for all fields that do not have "required" present,
// we need to recognize whether the field is part of the RequiredArrayRule.
Expand All @@ -73,17 +73,17 @@ public JDocComment apply(String nodeName, JsonNode node, JDocCommentable generat
for (Iterator<JsonNode> iterator = requiredArray.elements(); iterator.hasNext(); ) {
String requiredArrayItem = iterator.next().asText();
if (nodeName.equals(requiredArrayItem)) {
return javadoc;
return generatableType;
}
}
}

if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()
&& generatableType instanceof JFieldVar) {
javadoc.append(NOT_REQUIRED_COMMENT_TEXT);
generatableType.javadoc().append(NOT_REQUIRED_COMMENT_TEXT);
((JFieldVar) generatableType).annotate(Nullable.class);
}

return javadoc;
return generatableType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package org.jsonschema2pojo.rules;

import static org.apache.commons.lang3.StringUtils.*;

import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.Schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JDefinedClass;
Expand All @@ -27,11 +32,6 @@
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;

import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.Schema;

import static org.apache.commons.lang3.StringUtils.capitalize;


/**
* Applies the schema rules that represent a property definition.
Expand Down Expand Up @@ -166,9 +166,6 @@ private boolean isArray(JsonNode node) {
private JMethod addGetter(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node) {
JMethod getter = c.method(JMod.PUBLIC, field.type(), getGetterName(jsonPropertyName, field.type(), node));

// add @returns
getter.javadoc().addReturn().append("The " + ruleFactory.getNameHelper().getPropertyName(jsonPropertyName, node));

JBlock body = getter.body();
body._return(field);

Expand All @@ -178,9 +175,6 @@ private JMethod addGetter(JDefinedClass c, JFieldVar field, String jsonPropertyN
private JMethod addSetter(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node) {
JMethod setter = c.method(JMod.PUBLIC, void.class, getSetterName(jsonPropertyName, node));

// add @param
setter.javadoc().addParam(ruleFactory.getNameHelper().getPropertyName(jsonPropertyName, node)).append("The " + jsonPropertyName);

JVar param = setter.param(field.type(), field.name());
JBlock body = setter.body();
body.assign(JExpr._this().ref(field), param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.databind.JsonNode;
import org.jsonschema2pojo.Schema;
import com.sun.codemodel.JDocComment;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JDocCommentable;
import com.sun.codemodel.JFieldVar;

/**
* Applies the "required" schema rule.
*
*
* @see <a
* href="http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7">http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7</a>
*/
public class RequiredRule implements Rule<JDocCommentable, JDocComment> {

/**
* Text added to JavaDoc to indicate that a field is required
*/
public static final String REQUIRED_COMMENT_TEXT = "\n(Required)";
public class RequiredRule implements Rule<JDocCommentable, JDocCommentable> {

private final RuleFactory ruleFactory;

Expand All @@ -50,7 +45,7 @@ protected RequiredRule(RuleFactory ruleFactory) {
* <p>
* The required rule simply adds a note to the JavaDoc comment to mark a
* property as required.
*
*
* @param nodeName
* the name of the schema node for which this "required" rule has
* been added
Expand All @@ -64,11 +59,10 @@ protected RequiredRule(RuleFactory ruleFactory) {
* required.
*/
@Override
public JDocComment apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {
JDocComment javadoc = generatableType.javadoc();
public JDocCommentable apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {

if (node.asBoolean()) {
javadoc.append(REQUIRED_COMMENT_TEXT);
generatableType.javadoc().append("\n(Required)");

if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
&& generatableType instanceof JFieldVar) {
Expand All @@ -86,6 +80,6 @@ public JDocComment apply(String nodeName, JsonNode node, JDocCommentable generat
}
}

return javadoc;
return generatableType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Rule<JDefinedClass, JDefinedClass> getPropertyRule() {
*
* @return a schema rule that can handle the "required" declaration.
*/
public Rule<JDocCommentable, JDocComment> getRequiredRule() {
public Rule<JDocCommentable, JDocCommentable> getRequiredRule() {
return new RequiredRule(this);
}

Expand All @@ -167,7 +167,7 @@ public Rule<JDocCommentable, JDocComment> getRequiredRule() {
*
* @return a schema rule that can handle the "required" declaration.
*/
public Rule<JDocCommentable, JDocComment> getNotRequiredRule() {
public Rule<JDocCommentable, JDocCommentable> getNotRequiredRule() {
return new NotRequiredRule(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void shouldUpdateJavaDoc() throws JClassAlreadyExistsException {


assertThat(fooBarJavaDoc.size(), is(1));
assertThat((String) fooBarJavaDoc.get(0), is(RequiredRule.REQUIRED_COMMENT_TEXT));
assertThat((String) fooBarJavaDoc.get(0), is("\n(Required)"));

assertThat(fooJavaDoc.size(), is(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JDocComment;
import com.sun.codemodel.JDocCommentable;

public class RequiredRuleTest {

Expand All @@ -42,11 +42,11 @@ public void applyAddsTextWhenRequired() throws JClassAlreadyExistsException {
ObjectMapper mapper = new ObjectMapper();
BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(true);

JDocComment result = rule.apply("fooBar", descriptionNode, jclass, null);
JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);

assertThat(result, sameInstance(jclass.javadoc()));
assertThat(result.size(), is(1));
assertThat((String) result.get(0), is(RequiredRule.REQUIRED_COMMENT_TEXT));
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(1));
assertThat((String) result.javadoc().get(0), is("\n(Required)"));

}

Expand All @@ -58,10 +58,10 @@ public void applySkipsTextWhenNotRequired() throws JClassAlreadyExistsException
ObjectMapper mapper = new ObjectMapper();
BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(false);

JDocComment result = rule.apply("fooBar", descriptionNode, jclass, null);
JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);

assertThat(result, sameInstance(jclass.javadoc()));
assertThat(result.size(), is(0));
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(0));
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* Copyright © 2010-2014 Nokia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jsonschema2pojo.integration;

import static org.hamcrest.Matchers.notNullValue;
Expand Down

0 comments on commit 52ca7aa

Please sign in to comment.