Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Aug 28, 2024
2 parents 94184d3 + 21922b2 commit 1bffff0
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 25 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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.0</version>
</parent>

<name>aptk-annotationwrapper-integrationTest</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.toolisticon.aptk.tools.AnnotationUtils;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
import io.toolisticon.aptk.tools.wrapper.TypeElementWrapper;
import io.toolisticon.cute.CompileTestBuilder;
import io.toolisticon.cute.CompileTestBuilderApi;
import io.toolisticon.cute.PassIn;
Expand Down Expand Up @@ -115,6 +116,21 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
.compilationShouldSucceed()
.executeTest();
}

@Test
public void testWrappingWithElementWrapper() {
unitTestBuilder.defineTestWithPassedInElement(TestUsage.class, new APTKUnitTestProcessor<TypeElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
TypeElementWrapper typeElementWrapper = TypeElementWrapper.wrap(typeElement);
ExampleTestAnnotationWrapper testAnnotationWrapper = ExampleTestAnnotationWrapper.wrap(typeElementWrapper);

MatcherAssert.assertThat(testAnnotationWrapper._annotatedElement(), Matchers.is(typeElement));
}
})
.compilationShouldSucceed()
.executeTest();
}

@PassIn
@TestDefaultsAnnotation(withoutDefault = "ABC")
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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.0</version>
</parent>

<name>aptk-annotationwrapper-processor</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ ${state.visibilityModifier}class ${atw.simpleName}Wrapper !{if atw.customInterfa
${state.visibilityModifier}static ${atw.simpleName}Wrapper wrap(Element element) {
return isAnnotated(element) ? new ${atw.simpleName}Wrapper(element) : null;
}

/**
* Gets the AnnotationMirror from passed element for this wrappers annotation type and creates a wrapper instance.
* @param element The element to read the annotations from
* @return The wrapped AnnotationMirror if Element is annotated with this wrappers annotation type, otherwise null.
*/
${state.visibilityModifier}static ${atw.simpleName}Wrapper wrap(ElementWrapper element) {
return wrap(element.unwrap());
}

/**
* Wraps an AnnotationMirror.
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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.0</version>
</parent>

<name>aptk-compilermessages-processor</name>
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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.0</version>
</parent>

<name>aptk-example-annotations</name>
Expand Down
1 change: 1 addition & 0 deletions example/example-usecase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.apt_generated_tests/
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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.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.27.0</version>
<version>0.28.0</version>
</parent>

<name>aptk-tools</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Abstract base class for writers of java code and resources.
*/
public class FileObjectSimpleWriter<T extends FileObject> extends SimpleWriter{
public class FileObjectSimpleWriter<T extends FileObject> extends SimpleWriter implements AutoCloseable{

private final T fileObject;
private final Writer foWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* A simple writer for writing kotlin source files.
*/
public class SimpleKotlinWriter extends SimpleWriter {
public class SimpleKotlinWriter extends SimpleWriter implements AutoCloseable{

final static String KAPT_KOTLIN_GENERATED = "kapt.kotlin.generated";
private final static Pattern PACKAGE_PATTERN = Pattern.compile("(\\w+?(?:[.]\\w+?)*)[.]\\w*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Simple helper class to open and read a resource file.
*/
public class SimpleResourceReader {
public class SimpleResourceReader implements AutoCloseable{

private final FileObject fileObject;
private final BufferedReader foReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public String getSimpleName() {
public boolean hasSimpleName(String name) {
return name != null && this.getSimpleName().equals(name);
}

/**
* Checks if element has all passed modifiers are present.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ public boolean hasNestingKind(NestingKind nestingKind) {
public boolean isNested() {
return getNestingKind().isNested();
}

/**
* Gets the nested name of the element.
* If the TypeElement isn't a nested type the simple name will be returned.
*
* @return the nested name of the element
*/
public String getNestedName() {

String name = getSimpleName();

TypeElementWrapper current = this;

while (current.isNested()) {

current = current.getOuterType().get();
name = current.getSimpleName() + "." + name;

}

return name;
}

/**
* Returns the qualified name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ private static class EmbeddedTestClass implements Cloneable, Serializable {
private static class ChildTestClass extends EmbeddedTestClass implements WhatsUp {

}

private static class OuterNestedClass {

@PassIn
private static class InnerNestedClass {



}
}


@Test
public void test_wrapAndUnwrap() {
Expand Down Expand Up @@ -69,6 +80,18 @@ public void test_isNested() {
MatcherAssert.assertThat("Shoud not have found nesting kind", !unit.isNested());
}


@Test
public void test_getNestedName() {
CompileTestBuilder.unitTest().<TypeElement>defineTestWithPassedInElement(OuterNestedClass.InnerNestedClass.class, PassIn.class, (processingEnvironment, element) -> {

TypeElementWrapper unit = TypeElementWrapper.wrap(element);
MatcherAssert.assertThat(unit.getNestedName(), Matchers.is(TypeElementWrapperTest.class.getSimpleName() + "." + OuterNestedClass.class.getSimpleName() + "." + OuterNestedClass.InnerNestedClass.class.getSimpleName() ));

})
.executeTest();
}

@Test
public void test_getQualifiedName_and_hasQualifiedName() {
CompileTestBuilder.unitTest().<TypeElement>defineTestWithPassedInElement(EmbeddedTestClass.class, PassIn.class, (processingEnvironment, element) -> {
Expand Down

0 comments on commit 1bffff0

Please sign in to comment.