Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit d3446b3

Browse files
author
Aleksi Salmela
committed
Reorder the CommandAnnotationProcessor.
1 parent 85fb10d commit d3446b3

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/core/CommandAnnotationProcessor.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,33 @@ public class CommandAnnotationProcessor extends AbstractProcessor {
3131
private static final String COMMAND_PACKAGE_NAME = "fi.helsinki.cs.tmc.cli.command";
3232
private static final String TAB = " ";
3333

34-
//TODO reorder
34+
@Override
35+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
36+
Map<String, String> map = new HashMap<>();
37+
38+
for (Element elem : roundEnv.getElementsAnnotatedWith(Command.class)) {
39+
if (elem.getKind() != ElementKind.CLASS) {
40+
logger.warn("Element with command annotation is not class: " + elem.toString());
41+
return false;
42+
}
43+
Command command = elem.getAnnotation(Command.class);
44+
logger.info("Element with annotation: " + elem.toString());
45+
logger.info("Element name with annotation: " + elem.getClass().getCanonicalName());
46+
47+
TypeElement classElement = (TypeElement) elem;
48+
map.put(
49+
command.name(),
50+
processingEnv.getElementUtils().getBinaryName(classElement).toString());
51+
}
52+
53+
try {
54+
generateSourceFile(map);
55+
} catch (IOException ex) {
56+
logger.warn("Failed to create source file." + ex);
57+
}
58+
return true;
59+
}
60+
3561
private void generateSourceFile(Map<String, String> map) throws IOException {
3662
JavaFileObject jfo =
3763
processingEnv.getFiler().createSourceFile(PACKAGE_NAME + "." + CLASS_NAME);
@@ -83,31 +109,4 @@ private void generateSourceFile(Map<String, String> map) throws IOException {
83109
bwriter.flush();
84110
}
85111
}
86-
87-
@Override
88-
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
89-
Map<String, String> map = new HashMap<>();
90-
91-
for (Element elem : roundEnv.getElementsAnnotatedWith(Command.class)) {
92-
if (elem.getKind() != ElementKind.CLASS) {
93-
logger.warn("Element with command annotation is not class: " + elem.toString());
94-
return false;
95-
}
96-
Command command = elem.getAnnotation(Command.class);
97-
logger.info("Element with annotation: " + elem.toString());
98-
logger.info("Element name with annotation: " + elem.getClass().getCanonicalName());
99-
100-
TypeElement classElement = (TypeElement) elem;
101-
map.put(
102-
command.name(),
103-
processingEnv.getElementUtils().getBinaryName(classElement).toString());
104-
}
105-
106-
try {
107-
generateSourceFile(map);
108-
} catch (IOException ex) {
109-
logger.warn("Failed to create source file." + ex);
110-
}
111-
return true;
112-
}
113112
}

0 commit comments

Comments
 (0)