Skip to content

Commit d6acf7b

Browse files
author
Soroosh Sarabadani
committed
document processor
1 parent 92068e7 commit d6acf7b

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/annotation/AccumulativeMappingWriter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
import javax.annotation.processing.ProcessingEnvironment;
1111
import javax.tools.StandardLocation;
1212

13+
/**
14+
* The writer is able to load an existing resource file as a Map and override it with the new
15+
* mappings added to the existing mappings. Every entry corresponds to a line in the resource file
16+
* where key and values are separated by comma.
17+
*/
1318
class AccumulativeMappingWriter {
19+
1420
private Map<String, String> mappings = new ConcurrentHashMap<>();
1521
private final String resourcePath;
1622
private final ProcessingEnvironment processingEnvironment;
@@ -41,11 +47,17 @@ public AccumulativeMappingWriter loadExistingMappings() {
4147
return this;
4248
}
4349

50+
/**
51+
* Add a new mapping
52+
*/
4453
public AccumulativeMappingWriter add(String key, String value) {
4554
this.mappings.put(key, value);
4655
return this;
4756
}
4857

58+
/**
59+
* Generates or overrise the resource file with the given path ({@linkAccumulativeMappingWriter#resourcePath})
60+
*/
4961
public void flush() {
5062
PrintWriter printWriter = null;
5163
try {

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/annotation/TypeParameterResolver.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import javax.lang.model.type.TypeVariable;
1616
import javax.lang.model.util.Types;
1717

18+
/**
19+
* This class can resolve a type parameter in the given index to the actual type defined.
20+
*/
1821
class TypeParameterResolver {
1922

2023
private final DeclaredType interestedClass;
@@ -26,6 +29,14 @@ public TypeParameterResolver(DeclaredType interestedClass, int interestedTypeArg
2629
this.interestedTypeArgumentIndex = interestedTypeArgumentIndex;
2730
}
2831

32+
/**
33+
* @param typeUtils Type utilities, During the annotation processing processingEnv.getTypeUtils()
34+
* can be passed.
35+
* @param declaredType Class or Interface which extends or implements the interestedClass, and the
36+
* interest is getting the actual declared type is used.
37+
* @return the type of the parameter if it can be resolved from the the given declareType,
38+
* otherwise it returns null
39+
*/
2940
public TypeMirror resolve(Types typeUtils, DeclaredType declaredType) {
3041
final var chain = findChain(typeUtils, declaredType);
3142
var lastIndex = chain.size() - 1;
@@ -78,6 +89,8 @@ private List<DeclaredType> findChain(Types typeUtils, DeclaredType declaredType)
7889
var superclass = (DeclaredType) superElement.getSuperclass();
7990

8091
final var matchingInterfaces = getMatchingInterfaces(typeUtils, superElement);
92+
//if chain of interfaces is not empty, there is no reason to continue the lookup
93+
// as interfaces do not extend the classes
8194
if (matchingInterfaces.size() > 0) {
8295
result.addAll(matchingInterfaces);
8396
return result;
@@ -126,18 +139,18 @@ private List<DeclaredType> findChainOfInterfaces(Types typeUtils, DeclaredType p
126139
var matchingInterfaces =
127140
((TypeElement) parentInterface.asElement())
128141
.getInterfaces().stream()
129-
.filter(i -> typeUtils.isAssignable(i, interestedClass))
130-
.map(i -> (DeclaredType) i)
131-
.collect(Collectors.toList());
142+
.filter(i -> typeUtils.isAssignable(i, interestedClass))
143+
.map(i -> (DeclaredType) i)
144+
.collect(Collectors.toList());
132145
while (matchingInterfaces.size() > 0) {
133146
result.addAll(matchingInterfaces);
134147
final var lastFoundInterface = matchingInterfaces.get(matchingInterfaces.size() - 1);
135148
matchingInterfaces =
136149
((TypeElement) lastFoundInterface.asElement())
137150
.getInterfaces().stream()
138-
.filter(i -> typeUtils.isAssignable(i, interestedClass))
139-
.map(i -> (DeclaredType) i)
140-
.collect(Collectors.toList());
151+
.filter(i -> typeUtils.isAssignable(i, interestedClass))
152+
.map(i -> (DeclaredType) i)
153+
.collect(Collectors.toList());
141154
}
142155
return result;
143156
}

0 commit comments

Comments
 (0)