Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Stamann committed Feb 9, 2024
2 parents 9180ee1 + 94b6ec0 commit 003e873
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 86 deletions.
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.maven.archetypes</groupId>
<artifactId>annotationprocessor-archetype</artifactId>
<version>0.8.0</version>
<version>0.9.0</version>
<packaging>maven-archetype</packaging>

<name>annotationprocessor-archetype</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<artifactId>aptk-annotationwrapper-api</artifactId>
</dependency>

<dependency>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-api</artifactId>
</dependency>

<dependency>
<groupId>io.toolisticon.spiap</groupId>
<artifactId>spiap-api</artifactId>
Expand Down Expand Up @@ -112,7 +117,17 @@
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-annotationwrapper-api</artifactId>
<version>${aptk.version}</version>
</path>>
</path>
<path>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-processor</artifactId>
<version>${aptk.version}</version>
</path>
<path>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-api</artifactId>
<version>${aptk.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import ${package}.api.${annotationName};

import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage;
import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessageCodePrefix;
import io.toolisticon.aptk.tools.AbstractAnnotationProcessor;
import io.toolisticon.aptk.tools.ElementUtils;
import io.toolisticon.aptk.tools.FilerUtils;
Expand Down Expand Up @@ -35,6 +37,7 @@
*/

@SpiService(Processor.class)
@DeclareCompilerMessageCodePrefix("${annotationName}")
public class ${annotationName}Processor extends AbstractAnnotationProcessor {

private final static Set<String> SUPPORTED_ANNOTATIONS = createSupportedAnnotationSet(${annotationName}.class);
Expand Down Expand Up @@ -79,7 +82,7 @@ void processAnnotation(TypeElementWrapper wrappedTypeElement, ${annotationName}W

}


@DeclareCompilerMessage(code = "ERROR_002", enumValueName = "ERROR_VALUE_MUST_NOT_BE_EMPTY", message = "Value must not be empty")
boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wrapper annotation) {

// ----------------------------------------------------------
Expand All @@ -93,7 +96,7 @@ boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wr
.validateAndIssueMessages();

if(annotation.value().isEmpty()) {
wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY);
wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY);
result = false;
}
return result;
Expand All @@ -110,6 +113,7 @@ boolean validateUsage(TypeElementWrapper wrappedTypeElement, ${annotationName}Wr
* @param wrappedTypeElement The TypeElement representing the annotated class
* @param annotation The ${annotationName} annotation
*/
@DeclareCompilerMessage(code = "ERROR_001", enumValueName = "ERROR_COULD_NOT_CREATE_CLASS", message = "Could not create class ${symbol_dollar}{0} : ${symbol_dollar}{1}")
private void createClass(TypeElementWrapper wrappedTypeElement, ${annotationName}Wrapper annotation) {


Expand All @@ -129,7 +133,7 @@ private void createClass(TypeElementWrapper wrappedTypeElement, ${annotationName
javaWriter.writeTemplate("/${annotationName}.tpl", model);
javaWriter.close();
} catch (IOException e) {
wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS, filePath, e.getMessage());
wrappedTypeElement.compilerMessage().asError().write(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS, filePath, e.getMessage());
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ${annotationName}ProcessorMessagesTest {
@Test
public void test_enum() {

MatcherAssert.assertThat(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS.getCode(), Matchers.startsWith("${annotationName}"));
MatcherAssert.assertThat(${annotationName}ProcessorMessages.ERROR_COULD_NOT_CREATE_CLASS.getMessage(), Matchers.containsString("create class"));
MatcherAssert.assertThat(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS.getCode(), Matchers.startsWith("${annotationName}"));
MatcherAssert.assertThat(${annotationName}ProcessorCompilerMessages.ERROR_COULD_NOT_CREATE_CLASS.getMessage(), Matchers.containsString("create class"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
import io.toolisticon.cute.CompileTestBuilder;
import io.toolisticon.cute.JavaFileObjectUtils;
import io.toolisticon.cute.Cute;
import io.toolisticon.cute.CuteApi;
import org.junit.Before;
import org.junit.Test;

import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;


/**
Expand All @@ -23,54 +21,59 @@
public class ${annotationName}ProcessorTest {


CompileTestBuilder.CompilationTestBuilder compileTestBuilder;
CuteApi.BlackBoxTestSourceFilesInterface compileTestBuilder;

@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);

compileTestBuilder = CompileTestBuilder
.compilationTest()
.addProcessors(${annotationName}Processor.class);
compileTestBuilder = Cute
.blackBoxTest()
.given()
.processors(${annotationName}Processor.class);
}


@Test
public void test_valid_usage() {

compileTestBuilder
.addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsage.java"))
.compilationShouldSucceed()
.andSourceFiles("testcases/TestcaseValidUsage.java")
.whenCompiled()
.thenExpectThat().compilationSucceeds()
.executeTest();
}

@Test
public void test_invalid_usage_with_empty_value() {

compileTestBuilder
.addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageWithEmptyValue.java"))
.compilationShouldFail()
.expectErrorMessageThatContains(${annotationName}ProcessorMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode())
.andSourceFiles("testcases/TestcaseInvalidUsageWithEmptyValue.java")
.whenCompiled()
.thenExpectThat().compilationFails()
.andThat().compilerMessage().ofKindError().contains(${annotationName}ProcessorCompilerMessages.ERROR_VALUE_MUST_NOT_BE_EMPTY.getCode())
.executeTest();
}

@Test
public void test_invalid_usage_on_enum() {

compileTestBuilder
.addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageOnEnum.java"))
.compilationShouldFail()
.expectErrorMessageThatContains(CoreMatcherValidationMessages.IS_CLASS.getCode())
.andSourceFiles("testcases/TestcaseInvalidUsageOnEnum.java")
.whenCompiled()
.thenExpectThat().compilationFails()
.andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_CLASS.getCode())
.executeTest();
}

@Test
public void test_Test_invalid_usage_on_interface() {

compileTestBuilder
.addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidUsageOnInterface.java"))
.compilationShouldFail()
.expectErrorMessageThatContains(CoreMatcherValidationMessages.IS_CLASS.getCode())
.andSourceFiles("testcases/TestcaseInvalidUsageOnInterface.java")
.whenCompiled()
.thenExpectThat().compilationFails()
.andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_CLASS.getCode())
.executeTest();
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@


<!-- project dependency versions -->
<cute.version>0.12.0</cute.version>
<cute.version>1.0.1</cute.version>
<spiap.version>0.11.0</spiap.version>
<aptk.version>0.20.2</aptk.version>
<aptk.version>0.22.11</aptk.version>

<!-- versions of test dependencies -->
<junit.version>4.13.1</junit.version>
Expand Down Expand Up @@ -562,6 +562,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-compilermessages-api</artifactId>
<version>${aptk.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.toolisticon.spiap</groupId>
<artifactId>spiap-api</artifactId>
Expand Down

0 comments on commit 003e873

Please sign in to comment.