use of com.thoughtworks.qdox.model.JavaMethod in project maven-plugins by apache.
the class AbstractFixJavadocMojo method processFix.
/**
* Process the given {@link JavaClass}, ie add missing javadoc tags depending user parameters.
*
* @param javaClass not null
* @throws IOException if any
* @throws MojoExecutionException if any
*/
private void processFix(JavaClass javaClass) throws IOException, MojoExecutionException {
// Skipping inner classes
if (javaClass.isInner()) {
return;
}
File javaFile = new File(javaClass.getSource().getURL().getFile());
// the original java content in memory
final String originalContent = StringUtils.unifyLineSeparators(FileUtils.fileRead(javaFile, encoding));
if (getLog().isDebugEnabled()) {
getLog().debug("Analyzing " + javaClass.getFullyQualifiedName());
}
final StringWriter stringWriter = new StringWriter();
BufferedReader reader = null;
boolean changeDetected = false;
try {
reader = new BufferedReader(new StringReader(originalContent));
int lineNumber = 0;
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lineNumber++;
final String indent = autodetectIndentation(line);
// fixing classes
if (javaClass.getComment() == null && javaClass.getAnnotations() != null && javaClass.getAnnotations().length != 0) {
if (lineNumber == javaClass.getAnnotations()[0].getLineNumber()) {
changeDetected |= fixClassComment(stringWriter, originalContent, javaClass, indent);
takeCareSingleComment(stringWriter, originalContent, javaClass);
}
} else {
if (lineNumber == javaClass.getLineNumber()) {
changeDetected |= fixClassComment(stringWriter, originalContent, javaClass, indent);
takeCareSingleComment(stringWriter, originalContent, javaClass);
}
}
// fixing fields
if (javaClass.getFields() != null) {
for (JavaField field : javaClass.getFields()) {
if (lineNumber == field.getLineNumber()) {
changeDetected |= fixFieldComment(stringWriter, javaClass, field, indent);
}
}
}
// fixing methods
if (javaClass.getMethods() != null) {
for (JavaMethod method : javaClass.getMethods()) {
if (lineNumber == method.getLineNumber()) {
changeDetected |= fixMethodComment(stringWriter, originalContent, method, indent);
takeCareSingleComment(stringWriter, originalContent, method);
}
}
}
stringWriter.write(line);
stringWriter.write(EOL);
}
reader.close();
reader = null;
} finally {
IOUtil.close(reader);
}
if (changeDetected) {
if (getLog().isInfoEnabled()) {
getLog().info("Saving changes to " + javaClass.getFullyQualifiedName());
}
if (outputDirectory != null && !outputDirectory.getAbsolutePath().equals(getProjectSourceDirectory().getAbsolutePath())) {
String path = StringUtils.replace(javaFile.getAbsolutePath().replaceAll("\\\\", "/"), project.getBuild().getSourceDirectory().replaceAll("\\\\", "/"), "");
javaFile = new File(outputDirectory, path);
javaFile.getParentFile().mkdirs();
}
writeFile(javaFile, encoding, stringWriter.toString());
} else {
if (getLog().isDebugEnabled()) {
getLog().debug("No changes made to " + javaClass.getFullyQualifiedName());
}
}
}
use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayIT method requiredAppearsInSetterJavadoc.
@Test
public void requiredAppearsInSetterJavadoc() throws IOException {
JavaMethod javaMethod = classWithRequired.getMethodBySignature("setRequiredProperty", new Type[] { new Type("java.lang.String") });
String javaDocComment = javaMethod.getComment();
assertThat(javaDocComment, containsString("(Required)"));
}
use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.
the class RequiredIT method requiredAppearsInGetterJavadoc.
@Test
public void requiredAppearsInGetterJavadoc() throws IOException {
JavaMethod javaMethod = classWithRequired.getMethodBySignature("getRequiredProperty", new Type[] {});
String javaDocComment = javaMethod.getComment();
assertThat(javaDocComment, containsString("(Required)"));
}
use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.
the class RequiredIT method requiredAppearsInSetterJavadoc.
@Test
public void requiredAppearsInSetterJavadoc() throws IOException {
JavaMethod javaMethod = classWithRequired.getMethodBySignature("setRequiredProperty", new Type[] { new Type("java.lang.String") });
String javaDocComment = javaMethod.getComment();
assertThat(javaDocComment, containsString("(Required)"));
}
use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.
the class DescriptionIT method descriptionAppearsInSetterJavadoc.
@Test
public void descriptionAppearsInSetterJavadoc() throws IOException {
JavaMethod javaMethod = classWithDescription.getMethodBySignature("setDescription", new Type[] { new Type("java.lang.String") });
String javaDocComment = javaMethod.getComment();
assertThat(javaDocComment, containsString("A description for this property"));
}
Aggregations