Skip to content

Commit e053209

Browse files
committed
Report parameters on superclasses.
1 parent c3ccca5 commit e053209

File tree

8 files changed

+70
-6
lines changed

8 files changed

+70
-6
lines changed

src/main/java/uk/co/spudsoft/params4j/doclet/AbstractAsciiDocOption.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import jdk.javadoc.doclet.Doclet;
2222

2323
/**
24-
*
24+
* Abstract option for configuring a {@link jdk.javadoc.doclet.Doclet}.
25+
*
2526
* @author njt
2627
*/
2728
public abstract class AbstractAsciiDocOption implements Doclet.Option {
@@ -31,6 +32,14 @@ public abstract class AbstractAsciiDocOption implements Doclet.Option {
3132
private final List<String> names;
3233
private final String parameters;
3334

35+
/**
36+
* Constructor.
37+
*
38+
* @param argumentCount The number of arguments, this option will consume.
39+
* @param description Description of the argument.
40+
* @param name The parameter as it would be specified on the command line (or in addiitonalOptions in the maven plugin).
41+
* @param parameters The name of the parameter to the option.
42+
*/
3443
public AbstractAsciiDocOption(int argumentCount, String description, String name, String parameters) {
3544
this.argumentCount = argumentCount;
3645
this.description = description;

src/main/java/uk/co/spudsoft/params4j/doclet/AsciiDocDocTreeWalker.java

-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
public class AsciiDocDocTreeWalker extends DocTreePathScanner<Void, Void> {
4747

4848
private final DocletEnvironment environment;
49-
private final AsciiDocOptions options;
5049
private final Writer writer;
5150
private final Reporter reporter;
5251
private final TreePath path;
@@ -59,7 +58,6 @@ public class AsciiDocDocTreeWalker extends DocTreePathScanner<Void, Void> {
5958

6059
public AsciiDocDocTreeWalker(DocletEnvironment environment, AsciiDocOptions options, Writer writer, Reporter reporter, TreePath path) {
6160
this.environment = environment;
62-
this.options = options;
6361
this.writer = writer;
6462
this.reporter = reporter;
6563
this.path = path;

src/main/java/uk/co/spudsoft/params4j/doclet/AsciiDocDoclet.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
*
3030
* Although additional classes can be provided it will only record setters and/or fields (preferring setters, but falling back to
3131
* fields).
32-
*
32+
*
33+
* Runs through the specified elements in the {@link jdk.javadoc.doclet.DocletEnvironment} and
34+
* uses an {@link uk.co.spudsoft.params4j.doclet.AsciiDocElementVisitor} to walk through the
35+
* Java {@link javax.lang.model.element.Element}.
36+
*
3337
* @author njt
3438
*/
3539
public class AsciiDocDoclet implements Doclet {

src/main/java/uk/co/spudsoft/params4j/doclet/AsciiDocElementVisitor.java

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.lang.model.element.TypeParameterElement;
3030
import javax.lang.model.element.VariableElement;
3131
import javax.lang.model.type.DeclaredType;
32+
import javax.lang.model.type.TypeMirror;
3233
import javax.lang.model.util.SimpleTypeVisitor14;
3334
import javax.tools.Diagnostic;
3435
import jdk.javadoc.doclet.DocletEnvironment;
@@ -109,6 +110,18 @@ public Void visitType(TypeElement e, Void p) {
109110

110111
e.getEnclosedElements().forEach(enclosed -> enclosed.accept(this, null));
111112

113+
for (TypeMirror superMirror = e.getSuperclass(); superMirror != null;) {
114+
115+
Element superElement = environment.getTypeUtils().asElement(superMirror);
116+
if (superElement instanceof TypeElement) {
117+
TypeElement superTypeElement = (TypeElement) superElement;
118+
superTypeElement.getEnclosedElements().forEach(enclosed -> enclosed.accept(this, null));
119+
superMirror = superTypeElement.getSuperclass();
120+
} else {
121+
superMirror = null;
122+
}
123+
}
124+
112125
writer.write("|===\n");
113126
} catch (IOException ex) {
114127
reporter.print(Diagnostic.Kind.ERROR, "Failed to write to file: " + ex.getMessage());

src/main/java/uk/co/spudsoft/params4j/doclet/AsciiDocOptions.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import jdk.javadoc.doclet.Doclet.Option;
2424

2525
/**
26+
* All the options for configuration the {@link uk.co.spudsoft.params4j.doclet.AsciiDocDoclet}.
2627
*
2728
* @author njt
2829
*/

src/main/java/uk/co/spudsoft/params4j/doclet/TypeWriter.java

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class TypeWriter {
5050

5151
public void writeReferenceTree(DocletEnvironment environment, DocTreePath currentPath, ReferenceTree refTree) {
5252
Element element = environment.getDocTrees().getElement(new DocTreePath(currentPath, refTree));
53-
TypeMirror type = environment.getDocTrees().getType(new DocTreePath(currentPath, refTree));
5453
if (element instanceof ExecutableElement) {
5554
TypeElement typeElement = (TypeElement) element.getEnclosingElement();
5655
ExecutableElement methodElement = (ExecutableElement) element;

src/test/java/uk/co/spudsoft/params4j/doclet/AsciiDocDocletTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testAsciiDoc() throws IOException {
102102
, "-d"
103103
, "target/parameter-docs"
104104
, "--include-classes"
105-
, "commentcap.Parameters,commentcap.Credentials"
105+
, "commentcap.Parameters,commentcap.Credentials,commentcap.ProtectedCredentials"
106106
, "--include-classes"
107107
, "commentcap.DataSource"
108108
, "-link"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2023 njt
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package commentcap;
18+
19+
/**
20+
* Credentials with some protection.
21+
*
22+
* @author njt
23+
*/
24+
public class ProtectedCredentials extends Credentials {
25+
26+
private String protection;
27+
28+
public String getProtection() {
29+
return protection;
30+
}
31+
32+
/**
33+
* The protection to apply to the credentials.
34+
* @param protection
35+
*/
36+
public void setProtection(String protection) {
37+
this.protection = protection;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)