Skip to content

Commit 8edb415

Browse files
authored
Improve the performance of annotation processing in Eclipse (#1034)
* Cache TypeElement objects to improve performance in Eclipse * Removed the workaround to avoid a bug in Eclipse versions earlier than 4.23
1 parent 7d25b4d commit 8edb415

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

doma-processor/src/main/java/org/seasar/doma/internal/apt/MoreElements.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class MoreElements implements Elements {
4444

4545
private final Elements elementUtils;
4646

47+
private final Map<Class<?>, TypeElement> typeElementCache = new HashMap<>(64);
48+
4749
public MoreElements(Context ctx, ProcessingEnvironment env) {
4850
assertNotNull(ctx, env);
4951
this.ctx = ctx;
@@ -200,15 +202,16 @@ public TypeElement getTypeElementFromBinaryName(String binaryName) {
200202
return getEnclosedTypeElement(topElement, Arrays.asList(parts).subList(1, parts.length));
201203
}
202204
try {
203-
return elementUtils.getTypeElement(binaryName);
205+
return getTypeElement(binaryName);
204206
} catch (NullPointerException ignored) {
205207
return null;
206208
}
207209
}
208210

209211
public TypeElement getTypeElement(Class<?> clazz) {
210212
assertNotNull(clazz);
211-
return elementUtils.getTypeElement(clazz.getCanonicalName());
213+
return typeElementCache.computeIfAbsent(
214+
clazz, k -> elementUtils.getTypeElement(k.getCanonicalName()));
212215
}
213216

214217
private TypeElement getEnclosedTypeElement(TypeElement typeElement, List<String> enclosedNames) {

doma-processor/src/main/java/org/seasar/doma/internal/apt/MoreTypes.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,7 @@ public TypeElement toTypeElement(TypeMirror typeMirror) {
160160
if (element == null) {
161161
return null;
162162
}
163-
TypeElement typeElement = ctx.getMoreElements().toTypeElement(element);
164-
if (typeElement == null) {
165-
return null;
166-
}
167-
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=544288
168-
return ctx.getMoreElements().getTypeElement(typeElement.getQualifiedName());
163+
return ctx.getMoreElements().toTypeElement(element);
169164
}
170165

171166
public DeclaredType toDeclaredType(TypeMirror typeMirror) {

0 commit comments

Comments
 (0)