Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Apr 19, 2024
2 parents df6324d + a6883fa commit 94184d3
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 53 deletions.
2 changes: 1 addition & 1 deletion annotationwrapper/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-annotationwrapper-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-annotationwrapper-api</name>
Expand Down
2 changes: 1 addition & 1 deletion annotationwrapper/integrationtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-annotationwrapper-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-annotationwrapper-integrationTest</name>
Expand Down
2 changes: 1 addition & 1 deletion annotationwrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion annotationwrapper/processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-annotationwrapper-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-annotationwrapper-processor</name>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-common</name>
Expand Down
2 changes: 1 addition & 1 deletion compilermessages/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-compilermessages-api</name>
Expand Down
2 changes: 1 addition & 1 deletion compilermessages/integrationtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-compilermessages-integrationTest</name>
Expand Down
2 changes: 1 addition & 1 deletion compilermessages/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion compilermessages/processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-compilermessages-processor</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.toolisticon.aptk.compilermessage.processor;

import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage;
import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessages;
import io.toolisticon.aptk.tools.AbstractAnnotationProcessor;
import io.toolisticon.aptk.tools.FilerUtils;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.AptkCoreMatchers;
import io.toolisticon.aptk.tools.generators.SimpleJavaWriter;
import io.toolisticon.aptk.tools.wrapper.ElementWrapper;
import io.toolisticon.aptk.tools.wrapper.PackageElementWrapper;
import io.toolisticon.spiap.api.SpiService;

import javax.annotation.processing.Processor;
Expand Down Expand Up @@ -33,7 +37,9 @@ public Set<String> getSupportedAnnotationTypes() {
return SUPPORTED_ANNOTATIONS;
}

private Map<TargetCompilerMessageEnum, List<DeclareCompilerMessageWrapper>> compilerMessagesEnumMap = new HashMap<>();
private Set<String> detectedPackages = new HashSet<>();

//private Map<TargetCompilerMessageEnum, List<DeclareCompilerMessageWrapper>> compilerMessagesEnumMap = new HashMap<>();


public static class TargetCompilerMessageEnum {
Expand Down Expand Up @@ -90,16 +96,34 @@ public boolean processAnnotations(Set<? extends TypeElement> annotations, RoundE
// process Services annotation
for (Element element : getAnnotatedElements(roundEnv, DeclareCompilerMessage.class)) {

// Just detect the package names - by doing this the processor will have a better compatibility with incremental compilations
detectedPackages.add(ElementWrapper.wrap(element).getPackageName());

List<DeclareCompilerMessageWrapper> compilerMessageWrappers = DeclareCompilerMessageWrapper.wrap(element);
for (DeclareCompilerMessageWrapper compilerMessageWrapper : compilerMessageWrappers) {
TargetCompilerMessageEnum target = compilerMessageWrapper.getTarget();
compilerMessagesEnumMap.computeIfAbsent(target, e -> new ArrayList<DeclareCompilerMessageWrapper>()).add(compilerMessageWrapper);
}
}

} else {


final Map<TargetCompilerMessageEnum, List<DeclareCompilerMessageWrapper>> compilerMessagesEnumMap = new HashMap<>();

for (String detectedPackage : detectedPackages) {
List<Element> detectedAnnotatedElements = PackageElementWrapper.getByFqn(detectedPackage).get()
.filterFlattenedEnclosedElementTree()
// handle Repeatable annotation as well
.applyFilter(AptkCoreMatchers.BY_ANNOTATION).filterByOneOf(DeclareCompilerMessage.class, DeclareCompilerMessages.class)
.getResult();


for (Element annotatedElement : detectedAnnotatedElements) {
List<DeclareCompilerMessageWrapper> compilerMessageWrappers = DeclareCompilerMessageWrapper.wrap(annotatedElement);
for (DeclareCompilerMessageWrapper compilerMessageWrapper : compilerMessageWrappers) {
TargetCompilerMessageEnum target = compilerMessageWrapper.getTarget();
compilerMessagesEnumMap.computeIfAbsent(target, e -> new ArrayList<DeclareCompilerMessageWrapper>()).add(compilerMessageWrapper);
}
}
}


// create those compiler message enums
for (Map.Entry<TargetCompilerMessageEnum, List<DeclareCompilerMessageWrapper>> entry : compilerMessagesEnumMap.entrySet()) {

Expand Down
2 changes: 1 addition & 1 deletion cute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-cute</name>
Expand Down
2 changes: 1 addition & 1 deletion example/example-annotationprocessor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-example-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-example-annotationprocessor</name>
Expand Down
2 changes: 1 addition & 1 deletion example/example-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-example-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-example-annotations</name>
Expand Down
2 changes: 1 addition & 1 deletion example/example-usecase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-example-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-example-usecase</name>
Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-example-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/java16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>integrationtest-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-integrationtest-java16</name>
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/java17/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>integrationtest-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-integrationtest-java17</name>
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/java9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>integrationtest-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-integrationtest-java9</name>
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>integrationtest-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
<packaging>pom</packaging>

<name>aptk-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion templating/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-templating</name>
Expand Down
2 changes: 1 addition & 1 deletion tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-parent</artifactId>
<version>0.26.0</version>
<version>0.27.0</version>
</parent>

<name>aptk-tools</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,33 @@ public static String getQualifiedName(TypeMirror typeMirror) {
return null;
}

/**
* Gets the binary name of the wrapped TypeMirror.
*
* @return the binary name of the TypeMirror if wrapped TypeMirror is a DeclaredType or the binary name of the component type if wrapped TypeMirror is an Array or the simple name if for primitive types, otherwise null.
*/
public String getBinaryName() {
return getBinaryName(typeMirror);
}

/**
* Gets the binary name of the passed TypeMirror.
*
* @param typeMirror the TypeMirror to check
* @return the binary name of the TypeMirror if wrapped TypeMirror is a DeclaredType or the binary name of the component type if wrapped TypeMirror is an Array or the simple name if for primitive types, otherwise null.
*/
public static String getBinaryName(TypeMirror typeMirror) {
if (isDeclared(typeMirror)) {
return TypeElementWrapper.wrap ((TypeElement) (getDeclaredType(typeMirror).asElement())).getBinaryName();
} else if (isArray(typeMirror)) {
return getBinaryName(getArrayType(typeMirror).getComponentType());
} else if (isPrimitive(typeMirror)) {
return typeMirror.toString();
}

return null;
}

/**
* Gets the simple name of the wrapped TypeMirror.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ public boolean hasQualifiedName(String name) {
return name != null && getQualifiedName().equals(name);
}

/**
* Gets the binary name for the type element.
*/
public String getBinaryName() {

// According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html the binary name looks like:
// -- The binary name of a top level type (§7.6) is its canonical name (§6.7).
// -- The binary name of a member type (§8.5, §9.5) consists of the binary name of its immediately enclosing type, followed by $, followed by the simple name of the member.

if (this.isNested()) {
// Safe to call since its of nested kind
TypeElementWrapper enclosingTypeElement = this.getOuterType().get();
return enclosingTypeElement.getBinaryName() + "$" + this.getSimpleName();
} else {
return this.getQualifiedName();
}

}


/**
* Gets the direct superclass
Expand Down Expand Up @@ -267,6 +286,7 @@ public List<VariableElementWrapper> getEnumValues() {

/**
* Returns the record components of this class or interface element in declaration order.
*
* @return the record components, or an empty list if there are none
*/
public List<RecordComponentElementWrapper> getRecordComponents() {
Expand All @@ -283,6 +303,7 @@ public List<RecordComponentElementWrapper> getRecordComponents() {

/**
* Returns the permitted classes of this class or interface element in declaration order.
*
* @return the permitted classes, or an empty list if there are none
*/
public List<TypeMirrorWrapper> getPermittedSubclasses() {
Expand Down
Loading

0 comments on commit 94184d3

Please sign in to comment.