Skip to content

Commit fc9de2c

Browse files
committed
Apply code formatting
1 parent e02ebb5 commit fc9de2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1176
-1300
lines changed

pom.xml

Lines changed: 248 additions & 248 deletions
Large diffs are not rendered by default.

src/main/java/dev/dendrodocs/tool/AnalysisJob.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
* @param classpath absolute paths to JARs that are added to the classpath for type resolution
1212
* @param pretty whether to indent the resulting JSON
1313
*/
14-
public record AnalysisJob(Path project, Path output, List<String> classpath, boolean pretty) {
15-
}
14+
public record AnalysisJob(Path project, Path output, List<String> classpath, boolean pretty) {}

src/main/java/dev/dendrodocs/tool/AnalysisVisitor.java

Lines changed: 400 additions & 406 deletions
Large diffs are not rendered by default.

src/main/java/dev/dendrodocs/tool/Analyzer.java

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import com.github.javaparser.symbolsolver.utils.SymbolSolverCollectionStrategy;
1313
import com.github.javaparser.utils.CollectionStrategy;
1414
import com.github.javaparser.utils.SourceRoot;
15+
import dev.dendrodocs.tool.descriptions.Description;
1516
import java.io.IOException;
1617
import java.util.ArrayList;
1718
import java.util.List;
18-
import dev.dendrodocs.tool.descriptions.Description;
1919
import net.jimblackler.jsonschemafriend.Schema;
2020
import net.jimblackler.jsonschemafriend.SchemaException;
2121
import net.jimblackler.jsonschemafriend.SchemaStore;
@@ -27,66 +27,64 @@
2727
* output that follows LivingDocumentation conventions.
2828
*/
2929
public class Analyzer {
30-
private final ObjectMapper objectMapper;
31-
32-
/** Constructs an Analyzer with the given Jackson ObjectMapper. */
33-
public Analyzer(ObjectMapper objectMapper) {
34-
this.objectMapper = objectMapper;
35-
}
30+
private final ObjectMapper objectMapper;
3631

37-
/**
38-
* Returns a type solver that can resolve from neighboring source code, the classpath provided in
39-
* the {@link AnalysisJob}, and by reflection (which is required to resolve types like Object).
40-
*/
41-
private TypeSolver typeSolverFor(AnalysisJob job) throws IOException {
42-
var typeSolverBuilder = new TypeSolverBuilder();
32+
/** Constructs an Analyzer with the given Jackson ObjectMapper. */
33+
public Analyzer(ObjectMapper objectMapper) {
34+
this.objectMapper = objectMapper;
35+
}
4336

44-
for (String cp : job.classpath()) {
45-
if (cp.toLowerCase().endsWith(".jar")) {
46-
typeSolverBuilder = typeSolverBuilder.withJAR(cp);
47-
}
48-
}
37+
/**
38+
* Returns a type solver that can resolve from neighboring source code, the classpath provided in
39+
* the {@link AnalysisJob}, and by reflection (which is required to resolve types like Object).
40+
*/
41+
private TypeSolver typeSolverFor(AnalysisJob job) throws IOException {
42+
var typeSolverBuilder = new TypeSolverBuilder();
4943

50-
return typeSolverBuilder.withCurrentClassloader().withSourceCode(job.project()).build();
44+
for (String cp : job.classpath()) {
45+
if (cp.toLowerCase().endsWith(".jar")) {
46+
typeSolverBuilder = typeSolverBuilder.withJAR(cp);
47+
}
5148
}
5249

53-
private Boolean validateJson(List<Description> descriptions) {
54-
try {
55-
Schema schema = new SchemaStore().loadSchema(
56-
this.getClass().getResource("/schema.json"));
57-
new Validator().validate(schema, new ObjectMapper().convertValue(descriptions, Object.class));
58-
} catch (SchemaException e) {
59-
e.printStackTrace();
60-
return false;
61-
}
62-
return true;
50+
return typeSolverBuilder.withCurrentClassloader().withSourceCode(job.project()).build();
51+
}
52+
53+
private Boolean validateJson(List<Description> descriptions) {
54+
try {
55+
Schema schema = new SchemaStore().loadSchema(this.getClass().getResource("/schema.json"));
56+
new Validator().validate(schema, new ObjectMapper().convertValue(descriptions, Object.class));
57+
} catch (SchemaException e) {
58+
e.printStackTrace();
59+
return false;
6360
}
61+
return true;
62+
}
6463

65-
/** Execute the given job. An exception is thrown if a file can not be read or parsed. */
66-
public void analyze(AnalysisJob job) throws IOException {
67-
ParserConfiguration parserConfiguration = new ParserConfiguration()
68-
.setSymbolResolver(new JavaSymbolSolver(typeSolverFor(job)));
69-
CollectionStrategy strategy = new SymbolSolverCollectionStrategy(parserConfiguration);
70-
List<Description> descriptions = new ArrayList<>();
64+
/** Execute the given job. An exception is thrown if a file can not be read or parsed. */
65+
public void analyze(AnalysisJob job) throws IOException {
66+
ParserConfiguration parserConfiguration =
67+
new ParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolverFor(job)));
68+
CollectionStrategy strategy = new SymbolSolverCollectionStrategy(parserConfiguration);
69+
List<Description> descriptions = new ArrayList<>();
7170

72-
for (SourceRoot sourceRoot : strategy.collect(job.project()).getSourceRoots()) {
73-
List<ParseResult<CompilationUnit>> results = sourceRoot.tryToParse();
74-
SymbolResolver solver = sourceRoot.getParserConfiguration().getSymbolResolver().orElseThrow();
71+
for (SourceRoot sourceRoot : strategy.collect(job.project()).getSourceRoots()) {
72+
List<ParseResult<CompilationUnit>> results = sourceRoot.tryToParse();
73+
SymbolResolver solver = sourceRoot.getParserConfiguration().getSymbolResolver().orElseThrow();
7574

76-
for (ParseResult<CompilationUnit> result : results) {
77-
CompilationUnit compilationUnit = result.getResult().orElseThrow();
78-
AnalysisVisitor visitor = new AnalysisVisitor(solver);
75+
for (ParseResult<CompilationUnit> result : results) {
76+
CompilationUnit compilationUnit = result.getResult().orElseThrow();
77+
AnalysisVisitor visitor = new AnalysisVisitor(solver);
7978

80-
List<Description> visited = compilationUnit.accept(visitor, this);
81-
descriptions.addAll(visited);
82-
}
83-
}
79+
List<Description> visited = compilationUnit.accept(visitor, this);
80+
descriptions.addAll(visited);
81+
}
82+
}
8483

85-
ObjectWriter writer = job.pretty()
86-
? objectMapper.writerWithDefaultPrettyPrinter()
87-
: objectMapper.writer();
88-
if (validateJson(descriptions)) {
89-
writer.writeValue(job.output().toFile(), descriptions);
90-
}
84+
ObjectWriter writer =
85+
job.pretty() ? objectMapper.writerWithDefaultPrettyPrinter() : objectMapper.writer();
86+
if (validateJson(descriptions)) {
87+
writer.writeValue(job.output().toFile(), descriptions);
9188
}
89+
}
9290
}
Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.dendrodocs.tool;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import java.io.File;
45
import java.io.IOException;
56
import java.nio.file.Path;
67
import java.util.List;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
88
import org.apache.commons.cli.CommandLine;
99
import org.apache.commons.cli.CommandLineParser;
1010
import org.apache.commons.cli.DefaultParser;
@@ -13,38 +13,41 @@
1313
import org.apache.commons.cli.ParseException;
1414

1515
public class Main {
16-
public static void main(String[] args) {
17-
ObjectMapper objectMapper = new ObjectMapper();
18-
Analyzer analyzer = new Analyzer(objectMapper);
16+
public static void main(String[] args) {
17+
ObjectMapper objectMapper = new ObjectMapper();
18+
Analyzer analyzer = new Analyzer(objectMapper);
1919

20-
try {
21-
analyzer.analyze(jobFromArgs(args));
22-
} catch (ParseException | IOException e) {
23-
System.err.println(e.getMessage());
24-
HelpFormatter helpFormatter = new HelpFormatter();
25-
helpFormatter.printHelp("analyzer-java", options(), true);
26-
System.exit(1);
27-
}
20+
try {
21+
analyzer.analyze(jobFromArgs(args));
22+
} catch (ParseException | IOException e) {
23+
System.err.println(e.getMessage());
24+
HelpFormatter helpFormatter = new HelpFormatter();
25+
helpFormatter.printHelp("analyzer-java", options(), true);
26+
System.exit(1);
2827
}
28+
}
2929

30-
private static Options options() {
31-
Options options = new Options();
32-
options.addRequiredOption(null, "output", true, "The file path to save the output JSON to.");
33-
options.addRequiredOption(null, "project", true, "Root directory of the project to analyze.");
34-
options.addOption("p", "pretty", false, "Indent (pretty-print) JSON output.");
35-
options.addOption(null, "classpath", true,
36-
"(Semi)colon-separated list of JAR paths to use during type resolution.");
37-
return options;
38-
}
30+
private static Options options() {
31+
Options options = new Options();
32+
options.addRequiredOption(null, "output", true, "The file path to save the output JSON to.");
33+
options.addRequiredOption(null, "project", true, "Root directory of the project to analyze.");
34+
options.addOption("p", "pretty", false, "Indent (pretty-print) JSON output.");
35+
options.addOption(
36+
null,
37+
"classpath",
38+
true,
39+
"(Semi)colon-separated list of JAR paths to use during type resolution.");
40+
return options;
41+
}
3942

40-
private static AnalysisJob jobFromArgs(String[] args) throws ParseException {
41-
CommandLineParser parser = new DefaultParser();
42-
CommandLine commandLine = parser.parse(options(), args);
43+
private static AnalysisJob jobFromArgs(String[] args) throws ParseException {
44+
CommandLineParser parser = new DefaultParser();
45+
CommandLine commandLine = parser.parse(options(), args);
4346

44-
return new AnalysisJob(
45-
Path.of(commandLine.getOptionValue("project")),
46-
Path.of(commandLine.getOptionValue("output")),
47-
List.of(commandLine.getOptionValue("classpath", "").split(File.pathSeparator)),
48-
commandLine.hasOption("pretty"));
49-
}
50-
}
47+
return new AnalysisJob(
48+
Path.of(commandLine.getOptionValue("project")),
49+
Path.of(commandLine.getOptionValue("output")),
50+
List.of(commandLine.getOptionValue("classpath", "").split(File.pathSeparator)),
51+
commandLine.hasOption("pretty"));
52+
}
53+
}

src/main/java/dev/dendrodocs/tool/descriptions/ArgumentDescription.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,4 @@
99
* @param text Argument value as a string. This can be a constant, expression, variable, etc.
1010
*/
1111
public record ArgumentDescription(
12-
@JsonProperty("Type")
13-
String type,
14-
15-
@JsonProperty("Text")
16-
String text
17-
) implements Description {
18-
19-
}
12+
@JsonProperty("Type") String type, @JsonProperty("Text") String text) implements Description {}

src/main/java/dev/dendrodocs/tool/descriptions/AssignmentDescription.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111
* @param right Right-hand side of the assignment as a string.
1212
*/
1313
public record AssignmentDescription(
14-
@JsonProperty("Left")
15-
String left,
16-
17-
@JsonProperty("Operator")
18-
String operator,
19-
20-
@JsonProperty("Right")
21-
String right
22-
) implements Description {
14+
@JsonProperty("Left") String left,
15+
@JsonProperty("Operator") String operator,
16+
@JsonProperty("Right") String right)
17+
implements Description {
2318

2419
/**
2520
* Identifies the statement as an assignment.

src/main/java/dev/dendrodocs/tool/descriptions/AttributeArgumentDescription.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
* at compile time.
1313
*/
1414
public record AttributeArgumentDescription(
15-
@JsonProperty("Name")
16-
String name,
17-
18-
@JsonProperty("Type")
19-
String type,
20-
21-
@JsonProperty("Value")
22-
String value
23-
) implements Description {
24-
25-
}
15+
@JsonProperty("Name") String name,
16+
@JsonProperty("Type") String type,
17+
@JsonProperty("Value") String value)
18+
implements Description {}

src/main/java/dev/dendrodocs/tool/descriptions/AttributeDescription.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414
* annotation.
1515
*/
1616
public record AttributeDescription(
17-
@JsonProperty("Type")
18-
String type,
19-
20-
@JsonProperty("Name")
21-
String name,
22-
23-
@JsonInclude(Include.NON_EMPTY)
24-
@JsonProperty("Arguments")
25-
List<Description> arguments
26-
) implements Description {
27-
28-
}
17+
@JsonProperty("Type") String type,
18+
@JsonProperty("Name") String name,
19+
@JsonInclude(Include.NON_EMPTY) @JsonProperty("Arguments") List<Description> arguments)
20+
implements Description {}

src/main/java/dev/dendrodocs/tool/descriptions/ConstructorDescription.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414
* @param statements List of statements from the constructor body.
1515
*/
1616
public record ConstructorDescription(
17-
@JsonUnwrapped
18-
MemberDescription member,
19-
20-
@JsonProperty("Parameters")
21-
@JsonInclude(Include.NON_EMPTY)
22-
List<Description> parameters,
23-
24-
@JsonProperty("Statements")
25-
@JsonInclude(Include.NON_EMPTY)
26-
List<Description> statements
27-
) implements Description {
28-
29-
}
17+
@JsonUnwrapped MemberDescription member,
18+
@JsonProperty("Parameters") @JsonInclude(Include.NON_EMPTY) List<Description> parameters,
19+
@JsonProperty("Statements") @JsonInclude(Include.NON_EMPTY) List<Description> statements)
20+
implements Description {}

0 commit comments

Comments
 (0)