Skip to content

Commit db1895c

Browse files
committed
[#6] provide documentation ghpages
Added page about testing annotation processors fixed logic to disable navigation on submenu items
1 parent 51dabf5 commit db1895c

File tree

4 files changed

+102
-17
lines changed

4 files changed

+102
-17
lines changed

docs/_includes/navigation.html

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ul>
99
{% for p in rootpages %}
1010

11-
{% if p.used_in_navigation != null && p.used_in_navigation == true %}
11+
{% if p.used_in_navigation != null and p.used_in_navigation == true %}
1212
{% assign menu_name = p.menu_name %}
1313

1414
{% if menu_name == null %}
@@ -31,18 +31,23 @@
3131

3232
<li><a {% if page.url contains subpageDirectory %} class="current"{% endif %} href="#">{{ menu_name }}</a>
3333

34+
3435
{% if p.isSection == true and subpages != empty %}
3536
<ul>
3637

38+
3739
{% for p2 in subpages %}
38-
{% assign p2menu_name = p2.menu_name %}
39-
{% if p2menu_name == null %}
40-
{% assign p2menu_name = p2.title %}
41-
{% endif %}
42-
43-
<a href="{{ p2.url || relative_url}}">
44-
<li>{{p2menu_name}}</li>
45-
</a>
40+
{% assign p2menu_name = p2.menu_name %}
41+
{% if p2menu_name == null %}
42+
{% assign p2menu_name = p2.title %}
43+
{% endif %}
44+
45+
{% if p2.used_in_navigation != null and p2.used_in_navigation == true %}
46+
47+
<a href="{{ p2.url || relative_url}}">
48+
<li>{{p2menu_name}}</li>
49+
</a>
50+
{% endif %}
4651
{% endfor %}
4752
</ul>
4853
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: default
3-
used_in_navigation: true
3+
used_in_navigation: false
44
menu_name: About Annotation Processors
55
order: 1
66
---

docs/documentation/gettingStarted.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ order: 2
88

99
# Prerequisites
1010

11-
There are not much preconditions regarding the usage of the annotation processor toolkit.
11+
There are not many preconditions regarding the usage of the annotation processor toolkit.
1212
You just need a JDK 6 or higher to get started.
1313

1414
Nevertheless we recommend you to use Maven for building your annotation processor project.
15-
This page explains what needs to added to your Maven configuration to enable the annotation processor toolkit support to your project.
15+
This page explains what needs to be configured in your Maven configuration to enable the annotation processor toolkit in your projects.
1616

1717
# Build and dependency management
1818
## Dependency mangement
@@ -48,7 +48,7 @@ We recommend you to repackage all 3rd party dependencies of your annotation proc
4848

4949
This should be done for several reasons:
5050

51-
1. To get rid of versioning conflicts between the dependencies of your annotation processor and code to be processed.
51+
1. To get rid of versioning conflicts between the dependencies of your annotation processor and of the code to be processed.
5252
2. You need to add just one provided scope dependency to the code you want to be processed, since provided dependencies aren't handled transitively by Maven
5353

5454
In Maven, this can be done by using the shade plugin:
@@ -133,6 +133,10 @@ To enable the annotation processor toolkit support use the _de.holisticon.annota
133133

134134
## Declare which annotations are processed by the annotation processor
135135

136+
There are two approaches to tell the compiler which annotations are supported by an annnotation processor.
137+
138+
It can either be done by annotation or by overwriting the _getSupportedAnnotationTypes_ method declared by the _javax.annotation.processing.AbstractProcessor_ class.
139+
136140
### By annotation
137141

138142
Supported annotations can be defined by adding the _SupportedAnnotationTypes_ annotation to your annotation processor class:
@@ -156,17 +160,17 @@ An alternative approach is to overwrite the _getSupportedAnnotationTypes_ method
156160
return SUPPORTED_ANNOTATION_TYPES;
157161
}
158162

159-
The logic to load supported annotations is implemented in _javax.annotation.processing.AbstractProcessor.getSupportedAnnotationTypes()_.
163+
The logic to configure supported annotations by the _SupportedAnnotationTypes_ annotation is implemented in _javax.annotation.processing.AbstractProcessor.getSupportedAnnotationTypes()_.
160164
So overwriting of this method might break configuration by annotation.
161165

162-
## Setup annotation processor SPI
166+
## Setup annotation processor detection
163167

164-
Since annotation processors are internally using the SPI you need to create a file _javax.annotation.processing.Processor_ in _/src/main/resources_.
168+
Since annotation processors are internally detected via a _Service Provider Interface (SPI)_ you need to create a file _javax.annotation.processing.Processor_ in _/src/main/resources_.
165169
The file just contains a list of full qualified annotation processor class names (one per line).
166170
So just add you full qualified class name of your annotation processor to it.
167171

168172
# Applying the annotation processor
169-
Your annotation processor will be automatically applied if it resides in class path during the compilation.
173+
Your annotation processor will be automatically detected and applied if it resides in class path during the compilation.
170174
Therefore you should add it as a provided dependency to your projects.
171175

172176

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
layout: default
3+
used_in_navigation: true
4+
menu_name: Testing Annotation Processors
5+
order: 3
6+
---
7+
8+
# Testing Annotation Processors
9+
10+
Testing of annotation processors is very tricky. Your annotation processors heavily rely on the _ProcessingEnvironment_ tools.
11+
Those tools offer you access to the java compile time model and cannot be mocked or simulated very easily in unit tests.
12+
13+
So best way to test your annotation processors is to actually do a compile time test. Doing this all tools offered by the _ProcessingEnvironment_ are provided by the compiler.
14+
This can be done by using the com.google.testing.compile compile-testing framework which allows to do compilations of some test source code during your tests and to check the outcomes.
15+
One thing to mention is that JDK >=6 is supported up to version 0.9 - all following versions are base on JDK >=8.
16+
17+
This project simplifies testing even more by hiding the complexity of using the compile-testing framework.
18+
19+
We will show you what needs to be done in the following...
20+
21+
## Setting up a test
22+
23+
Setting up a junit test is quite easy. This framework is using parameterized unit tests to do some testing.
24+
25+
Here's a small example for a testcase that validates the compile outcome. This is quite useful for annotation processors that are doing validations about the usage of annotations:
26+
27+
package de.holisticon.example.annotationprocessortoolkit.annotationprocessor;
28+
29+
import de.holisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorTest;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
import org.junit.runners.Parameterized;
33+
34+
import java.util.Arrays;
35+
import java.util.List;
36+
37+
38+
@RunWith(Parameterized.class)
39+
public class MethodWithOneStringParameterAndVoidReturnTypeProcessorTest extends AbstractAnnotationProcessorTest<MethodWithOneStringParameterAndVoidReturnTypeAnnotationProcessor> {
40+
41+
42+
public MethodWithOneStringParameterAndVoidReturnTypeProcessorTest(String description, String resource, String[] errors, String[] warnings) {
43+
super(description, resource, errors, warnings);
44+
}
45+
46+
@Override
47+
protected MethodWithOneStringParameterAndVoidReturnTypeAnnotationProcessor getAnnotationProcessor() {
48+
return new MethodWithOneStringParameterAndVoidReturnTypeAnnotationProcessor();
49+
}
50+
51+
@Parameterized.Parameters(name = "{index}: \"{0}\"")
52+
public static List<Object[]> data() {
53+
54+
return Arrays.asList(new Object[][]{
55+
{"Test valid usage", "testcases/methodWithOneStringParameterAndVoidReturn/ValidUsageTest.java", new String[]{}, new String[]{}},
56+
{"Test invalid usage : non void return type", "testcases/methodWithOneStringParameterAndVoidReturn/InvalidUsageNonVoidReturnType.java", new String[]{"Method must have void return type"}, new String[]{}},
57+
{"Test invalid usage : non String parameter", "testcases/methodWithOneStringParameterAndVoidReturn/InvalidUsageNonStringParameter.java", new String[]{"Method must have parameters of types [java.lang.String], but has parameters of types [java.lang.Object]"}, new String[]{}},
58+
59+
});
60+
61+
}
62+
63+
64+
@Test
65+
public void testCorrectnessOfAdviceArgumentAnnotation() {
66+
super.test();
67+
}
68+
69+
So basically you need to do the following things:
70+
71+
1. Create a test class which should extend the abstract _AbstractAnnotationProcessorTest<YourAnnotationPracessor>_ class
72+
2. Implement the abstract method _getAnnotationProcessor_ declared by the _AbstractAnnotationProcessorTest<YourAnnotationPracessor>_ class. It should return an instance of the annotation processor to use.
73+
3. Add the annotation _@Parameterized_ to the class
74+
4. Create a constructor with parameters _(String description, String resource, String[] errors, String[] warnings)_ which delegates to super constructor.
75+
5. Create a method that provides the parameterized test data. (Annotated with _@Parameterized.Parameters_)
76+
6. Add a test method which delegated to super.test()

0 commit comments

Comments
 (0)