forked from boskworks/bosk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
22 additions
and
22 deletions.
There are no files selected for viewing
32 changes: 16 additions & 16 deletions
32
...java/io/vena/bosk/refs/RefsProcessor.java → .../java/io/vena/bosk/refs/RefProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
package io.vena.bosk.refs; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import javax.annotation.processing.AbstractProcessor; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.annotation.processing.SupportedAnnotationTypes; | ||
import javax.annotation.processing.SupportedSourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.element.VariableElement; | ||
import javax.lang.model.type.TypeKind; | ||
import javax.lang.model.type.TypeMirror; | ||
import javax.lang.model.util.ElementFilter; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static javax.lang.model.SourceVersion.RELEASE_8; | ||
|
||
@SupportedAnnotationTypes("io.vena.bosk.refs.annotations.Refs") | ||
@SupportedAnnotationTypes("io.vena.bosk.refs.annotations.Ref") | ||
@SupportedSourceVersion(RELEASE_8) | ||
public class RefsProcessor extends AbstractProcessor { | ||
public class RefProcessor extends AbstractProcessor { | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
Map<TypeElement, List<Element>> fieldsByClass = new LinkedHashMap<>(); | ||
annotations.forEach(annotation -> { | ||
for (Element element: roundEnv.getElementsAnnotatedWith(annotation)) { | ||
TypeMirror type = element.asType(); | ||
if (type.getKind() == TypeKind.DECLARED) { | ||
generateRefsClass(element); | ||
} | ||
TypeElement enclosingType = ((TypeElement)element.getEnclosingElement()); | ||
fieldsByClass.computeIfAbsent(enclosingType, et -> new ArrayList<>()) | ||
.add(element); | ||
} | ||
}); | ||
if (!fieldsByClass.isEmpty()) { | ||
generateRefsClass(fieldsByClass); | ||
} | ||
return false; | ||
} | ||
|
||
private static void generateRefsClass(Element type) { | ||
System.out.println("----- Processing " + type); | ||
for (VariableElement field: ElementFilter.fieldsIn(singletonList(type))) { | ||
System.out.println("\tField " + field); | ||
} | ||
private static void generateRefsClass(Map<TypeElement, List<Element>> fieldsByClass) { | ||
System.out.println("RefProcessor: " + fieldsByClass); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
bosk-refs/src/main/resources/META-INF/services/javax.annotation.processing.Processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
io.vena.bosk.refs.RefsProcessor | ||
io.vena.bosk.refs.RefProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters