Skip to content

Commit 3ec9663

Browse files
committed
Polish the org.seasar.doma.internal package
1 parent 0b90577 commit 3ec9663

File tree

99 files changed

+2073
-1752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2073
-1752
lines changed

src/main/java/org/seasar/doma/internal/ClassNames.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
public class ClassNames {
1010

11-
public static String normalizeBinaryName(String binaryName) {
11+
public static String normalizeBinaryName(CharSequence binaryName) {
1212
assertNotNull(binaryName);
13-
String packageName = ClassUtil.getPackageName(binaryName);
14-
List<String> enclosingNames = ClassUtil.getEnclosingNames(binaryName);
15-
String simpleName = ClassUtil.getSimpleName(binaryName);
13+
String name = binaryName.toString();
14+
String packageName = ClassUtil.getPackageName(name);
15+
List<String> enclosingNames = ClassUtil.getEnclosingNames(name);
16+
String simpleName = ClassUtil.getSimpleName(name);
1617
String base = "";
1718
if (packageName.length() > 0) {
1819
base = packageName + ".";

src/main/java/org/seasar/doma/internal/apt/Context.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class Context {
1111

1212
private boolean initialized;
1313

14-
private Elements elements;
14+
private MoreElements moreElements;
1515

16-
private Types types;
16+
private MoreTypes moreTypes;
1717

1818
private Options options;
1919

@@ -35,8 +35,8 @@ public void init() {
3535
if (initialized) {
3636
throw new AptIllegalStateException("already initialized");
3737
}
38-
elements = new Elements(this, env);
39-
types = new Types(this, env);
38+
moreElements = new MoreElements(this, env);
39+
moreTypes = new MoreTypes(this, env);
4040
options = new Options(this, env);
4141
reporter = new Reporter(env);
4242
resources = new Resources(this, env);
@@ -46,14 +46,14 @@ public void init() {
4646
initialized = true;
4747
}
4848

49-
public Elements getElements() {
49+
public MoreElements getMoreElements() {
5050
assertInitialized();
51-
return elements;
51+
return moreElements;
5252
}
5353

54-
public Types getTypes() {
54+
public MoreTypes getMoreTypes() {
5555
assertInitialized();
56-
return types;
56+
return moreTypes;
5757
}
5858

5959
public Options getOptions() {

src/main/java/org/seasar/doma/internal/apt/Elements.java renamed to src/main/java/org/seasar/doma/internal/apt/MoreElements.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
import javax.lang.model.type.DeclaredType;
1313
import javax.lang.model.type.TypeMirror;
1414
import javax.lang.model.util.ElementFilter;
15+
import javax.lang.model.util.Elements;
1516
import javax.lang.model.util.SimpleElementVisitor8;
1617
import org.seasar.doma.ParameterName;
1718
import org.seasar.doma.internal.apt.def.TypeParametersDef;
1819

19-
public class Elements implements javax.lang.model.util.Elements {
20+
public class MoreElements implements Elements {
2021

2122
private final Context ctx;
2223

23-
private final javax.lang.model.util.Elements elementUtils;
24+
private final Elements elementUtils;
2425

25-
public Elements(Context ctx, ProcessingEnvironment env) {
26+
public MoreElements(Context ctx, ProcessingEnvironment env) {
2627
assertNotNull(ctx, env);
2728
this.ctx = ctx;
2829
this.elementUtils = env.getElementUtils();
@@ -36,8 +37,8 @@ public PackageElement getPackageElement(CharSequence name) {
3637

3738
// delegate to elementUtils
3839
@Override
39-
public TypeElement getTypeElement(CharSequence name) {
40-
return elementUtils.getTypeElement(name);
40+
public TypeElement getTypeElement(CharSequence canonicalName) {
41+
return elementUtils.getTypeElement(canonicalName);
4142
}
4243

4344
// delegate to elementUtils
@@ -120,18 +121,6 @@ public boolean isFunctionalInterface(TypeElement type) {
120121
return elementUtils.isFunctionalInterface(type);
121122
}
122123

123-
public String getBinaryNameAsString(TypeElement type) {
124-
assertNotNull(type);
125-
Name binaryName = elementUtils.getBinaryName(type);
126-
return binaryName.toString();
127-
}
128-
129-
public String getPackageName(Element element) {
130-
assertNotNull(element);
131-
PackageElement packageElement = elementUtils.getPackageOf(element);
132-
return packageElement.getQualifiedName().toString();
133-
}
134-
135124
public String getParameterName(VariableElement variableElement) {
136125
assertNotNull(variableElement);
137126
ParameterName parameterName = variableElement.getAnnotation(ParameterName.class);
@@ -167,11 +156,11 @@ public TypeParameterElement visitTypeParameter(TypeParameterElement e, Void aVoi
167156
null);
168157
}
169158

170-
public TypeElement getTypeElement(String binaryName) {
159+
public TypeElement getTypeElementFromBinaryName(String binaryName) {
171160
assertNotNull(binaryName);
172161
String[] parts = binaryName.split("\\$");
173162
if (parts.length > 1) {
174-
TypeElement topElement = getTypeElement(parts[0]);
163+
TypeElement topElement = getTypeElementFromBinaryName(parts[0]);
175164
if (topElement == null) {
176165
return null;
177166
}
@@ -206,15 +195,15 @@ public AnnotationMirror getAnnotationMirror(
206195
Element element, Class<? extends Annotation> annotationClass) {
207196
assertNotNull(element, annotationClass);
208197
return getAnnotationMirrorInternal(
209-
element, type -> ctx.getTypes().isSameTypeWithErasure(type, annotationClass));
198+
element, type -> ctx.getMoreTypes().isSameTypeWithErasure(type, annotationClass));
210199
}
211200

212201
public AnnotationMirror getAnnotationMirror(Element element, String annotationClassName) {
213202
assertNotNull(element, annotationClassName);
214203
return getAnnotationMirrorInternal(
215204
element,
216205
type -> {
217-
TypeElement typeElement = ctx.getTypes().toTypeElement(type);
206+
TypeElement typeElement = ctx.getMoreTypes().toTypeElement(type);
218207
if (typeElement == null) {
219208
return false;
220209
}
@@ -272,11 +261,10 @@ public TypeParametersDef getTypeParametersDef(Parameterizable element) {
272261
return new TypeParametersDef(map);
273262
}
274263

275-
public List<String> getTypeParameterNames(
276-
List<? extends TypeParameterElement> typeParameterElements) {
264+
List<String> getTypeParameterNames(List<? extends TypeParameterElement> typeParameterElements) {
277265
assertNotNull(typeParameterElements);
278266
List<TypeMirror> typeMirrors =
279267
typeParameterElements.stream().map(TypeParameterElement::asType).collect(toList());
280-
return ctx.getTypes().getTypeParameterNames(typeMirrors);
268+
return ctx.getMoreTypes().getTypeParameterNames(typeMirrors);
281269
}
282270
}

src/main/java/org/seasar/doma/internal/apt/Types.java renamed to src/main/java/org/seasar/doma/internal/apt/MoreTypes.java

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
import javax.lang.model.util.SimpleTypeVisitor6;
2626
import javax.lang.model.util.SimpleTypeVisitor8;
2727
import javax.lang.model.util.TypeKindVisitor8;
28+
import javax.lang.model.util.Types;
2829

29-
public class Types implements javax.lang.model.util.Types {
30+
public class MoreTypes implements Types {
3031

3132
private final Context ctx;
3233

33-
private final javax.lang.model.util.Types typeUtils;
34+
private final Types typeUtils;
3435

35-
public Types(Context ctx, ProcessingEnvironment env) {
36+
public MoreTypes(Context ctx, ProcessingEnvironment env) {
3637
assertNotNull(ctx, env);
3738
this.ctx = ctx;
3839
this.typeUtils = env.getTypeUtils();
@@ -141,11 +142,13 @@ public TypeMirror asMemberOf(DeclaredType containing, Element element) {
141142
return typeUtils.asMemberOf(containing, element);
142143
}
143144

145+
// delegate to typeUtils
144146
@Override
145147
public boolean isAssignable(TypeMirror t1, TypeMirror t2) {
146148
return typeUtils.isAssignable(t1, t2);
147149
}
148150

151+
// delegate to typeUtils
149152
@Override
150153
public boolean isSameType(TypeMirror t1, TypeMirror t2) {
151154
return typeUtils.isSameType(t1, t2);
@@ -157,7 +160,7 @@ public TypeElement toTypeElement(TypeMirror typeMirror) {
157160
if (element == null) {
158161
return null;
159162
}
160-
return ctx.getElements().toTypeElement(element);
163+
return ctx.getMoreElements().toTypeElement(element);
161164
}
162165

163166
public DeclaredType toDeclaredType(TypeMirror typeMirror) {
@@ -198,7 +201,7 @@ public ArrayType visitArray(ArrayType t, Void p) {
198201

199202
public boolean isAssignableWithErasure(TypeMirror lhs, Class<?> rhs) {
200203
assertNotNull(lhs, rhs);
201-
TypeElement typeElement = ctx.getElements().getTypeElement(rhs);
204+
TypeElement typeElement = ctx.getMoreElements().getTypeElement(rhs);
202205
if (typeElement == null) {
203206
return false;
204207
}
@@ -237,19 +240,10 @@ public boolean isAssignableWithErasure(TypeMirror lhs, TypeMirror rhs) {
237240

238241
public boolean isSameTypeWithErasure(TypeMirror typeMirror, Class<?> clazz) {
239242
assertNotNull(typeMirror, clazz);
240-
if (typeMirror.getKind() == TypeKind.VOID) {
241-
return clazz == void.class;
242-
}
243-
if (clazz.isArray()) {
244-
TypeElement componentType = ctx.getElements().getTypeElement(clazz.getComponentType());
245-
ArrayType arrayType = ctx.getTypes().getArrayType(componentType.asType());
246-
if (arrayType == null) {
247-
return false;
248-
}
249-
return isSameTypeWithErasure(typeMirror, arrayType);
243+
if (clazz.isPrimitive() || clazz.isArray()) {
244+
return typeUtils.isSameType(typeMirror, getTypeMirror(clazz));
250245
}
251-
252-
TypeElement typeElement = ctx.getElements().getTypeElement(clazz);
246+
TypeElement typeElement = ctx.getMoreElements().getTypeElement(clazz);
253247
if (typeElement == null) {
254248
return false;
255249
}
@@ -290,31 +284,7 @@ public String getTypeName(TypeMirror typeMirror) {
290284
return p.toString();
291285
}
292286

293-
public String getBoxedTypeName(TypeMirror typeMirror) {
294-
assertNotNull(typeMirror);
295-
switch (typeMirror.getKind()) {
296-
case BOOLEAN:
297-
return Boolean.class.getName();
298-
case BYTE:
299-
return Byte.class.getName();
300-
case SHORT:
301-
return Short.class.getName();
302-
case INT:
303-
return Integer.class.getName();
304-
case LONG:
305-
return Long.class.getName();
306-
case FLOAT:
307-
return Float.class.getName();
308-
case DOUBLE:
309-
return Double.class.getName();
310-
case CHAR:
311-
return Character.class.getName();
312-
default:
313-
return getTypeName(typeMirror);
314-
}
315-
}
316-
317-
public List<String> getTypeParameterNames(List<TypeMirror> typeMirrors) {
287+
List<String> getTypeParameterNames(List<TypeMirror> typeMirrors) {
318288
assertNotNull(typeMirrors);
319289
TypeParameterNameBuilder builder = new TypeParameterNameBuilder();
320290
List<String> names = new ArrayList<>();
@@ -371,7 +341,11 @@ public TypeMirror getTypeMirror(Class<?> clazz) {
371341
if (clazz == double.class) {
372342
return typeUtils.getPrimitiveType(TypeKind.DOUBLE);
373343
}
374-
TypeElement typeElement = ctx.getElements().getTypeElement(clazz);
344+
if (clazz.isArray()) {
345+
TypeMirror componentType = getTypeMirror(clazz.getComponentType());
346+
return typeUtils.getArrayType(componentType);
347+
}
348+
TypeElement typeElement = ctx.getMoreElements().getTypeElement(clazz);
375349
if (typeElement == null) {
376350
throw new AptIllegalStateException(clazz.getName());
377351
}
@@ -440,7 +414,7 @@ public Void visitWildcard(WildcardType t, StringBuilder p) {
440414

441415
protected Void defaultAction(TypeMirror e, StringBuilder p) {
442416
p.append(e);
443-
throw new IllegalArgumentException(p.toString());
417+
return null;
444418
}
445419
}
446420

@@ -467,7 +441,7 @@ public Void visitTypeVariable(TypeVariable t, StringBuilder p) {
467441
}
468442
processedVariables.add(t);
469443
TypeParameterElement typeParameterElement =
470-
ctx.getElements().toTypeParameterElement(t.asElement());
444+
ctx.getMoreElements().toTypeParameterElement(t.asElement());
471445
if (typeParameterElement == null) {
472446
return null;
473447
}
@@ -479,7 +453,7 @@ public Void visitTypeVariable(TypeVariable t, StringBuilder p) {
479453
}
480454
Iterator<? extends TypeMirror> it = bounds.iterator();
481455
TypeMirror first = it.next();
482-
if (bounds.size() == 1 && ctx.getTypes().isSameTypeWithErasure(first, Object.class)) {
456+
if (bounds.size() == 1 && ctx.getMoreTypes().isSameTypeWithErasure(first, Object.class)) {
483457
return null;
484458
}
485459
p.append(" extends ");

src/main/java/org/seasar/doma/internal/apt/annot/Annotations.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public AllArgsConstructorAnnot newAllArgsConstructorAnnot(TypeElement typeElemen
2929
public AnnotateWithAnnot newAnnotateWithAnnot(TypeElement typeElement) {
3030
assertNotNull(typeElement);
3131
AnnotationMirror annotateWith =
32-
ctx.getElements().getAnnotationMirror(typeElement, AnnotateWith.class);
32+
ctx.getMoreElements().getAnnotationMirror(typeElement, AnnotateWith.class);
3333
if (annotateWith == null) {
3434
for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) {
3535
TypeElement ownerElement =
36-
ctx.getElements().toTypeElement(annotationMirror.getAnnotationType().asElement());
36+
ctx.getMoreElements().toTypeElement(annotationMirror.getAnnotationType().asElement());
3737
if (ownerElement == null) {
3838
continue;
3939
}
40-
annotateWith = ctx.getElements().getAnnotationMirror(ownerElement, AnnotateWith.class);
40+
annotateWith = ctx.getMoreElements().getAnnotationMirror(ownerElement, AnnotateWith.class);
4141
if (annotateWith != null) {
4242
break;
4343
}
@@ -46,7 +46,7 @@ public AnnotateWithAnnot newAnnotateWithAnnot(TypeElement typeElement) {
4646
return null;
4747
}
4848
}
49-
Map<String, AnnotationValue> values = ctx.getElements().getValuesWithDefaults(annotateWith);
49+
Map<String, AnnotationValue> values = ctx.getMoreElements().getValuesWithDefaults(annotateWith);
5050
AnnotationValue annotations = values.get(AnnotateWithAnnot.ANNOTATIONS);
5151
ArrayList<AnnotationAnnot> annotationsValue = new ArrayList<>();
5252
for (AnnotationMirror annotationMirror : AnnotationValueUtil.toAnnotationList(annotations)) {
@@ -226,7 +226,7 @@ private <ANNOT> ANNOT newInstance(
226226
Class<? extends java.lang.annotation.Annotation> annotationClass,
227227
BiFunction<AnnotationMirror, Map<String, AnnotationValue>, ANNOT> biFunction) {
228228
AnnotationMirror annotationMirror =
229-
ctx.getElements().getAnnotationMirror(element, annotationClass);
229+
ctx.getMoreElements().getAnnotationMirror(element, annotationClass);
230230
return newInstance(annotationMirror, biFunction);
231231
}
232232

@@ -235,7 +235,7 @@ private <ANNOT> ANNOT newInstance(
235235
String annotationClassName,
236236
BiFunction<AnnotationMirror, Map<String, AnnotationValue>, ANNOT> biFunction) {
237237
AnnotationMirror annotationMirror =
238-
ctx.getElements().getAnnotationMirror(element, annotationClassName);
238+
ctx.getMoreElements().getAnnotationMirror(element, annotationClassName);
239239
return newInstance(annotationMirror, biFunction);
240240
}
241241

@@ -245,7 +245,8 @@ private <ANNOT> ANNOT newInstance(
245245
if (annotationMirror == null) {
246246
return null;
247247
}
248-
Map<String, AnnotationValue> values = ctx.getElements().getValuesWithDefaults(annotationMirror);
248+
Map<String, AnnotationValue> values =
249+
ctx.getMoreElements().getValuesWithDefaults(annotationMirror);
249250
return biFunction.apply(annotationMirror, values);
250251
}
251252
}

src/main/java/org/seasar/doma/internal/apt/cttype/AbstractCtType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ protected AbstractCtType(Context ctx, TypeMirror type) {
2222
assertNotNull(ctx, type);
2323
this.ctx = ctx;
2424
this.type = type;
25-
this.typeElement = ctx.getTypes().toTypeElement(type);
25+
this.typeElement = ctx.getMoreTypes().toTypeElement(type);
2626
if (typeElement != null) {
2727
qualifiedName = typeElement.getQualifiedName().toString();
2828
} else {
29-
qualifiedName = ctx.getTypes().getTypeName(type);
29+
qualifiedName = ctx.getMoreTypes().getTypeName(type);
3030
}
3131
}
3232

@@ -72,6 +72,6 @@ public boolean isTypevar() {
7272

7373
@Override
7474
public boolean isSameType(CtType other) {
75-
return ctx.getTypes().isSameTypeWithErasure(type, other.getType());
75+
return ctx.getMoreTypes().isSameTypeWithErasure(type, other.getType());
7676
}
7777
}

src/main/java/org/seasar/doma/internal/apt/cttype/BasicCtType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class BasicCtType extends AbstractCtType {
1515
BasicCtType(Context ctx, TypeMirror type, TypeMirror wrapperType) {
1616
super(ctx, type);
1717
assertNotNull(wrapperType);
18-
this.boxedType = ctx.getTypes().boxIfPrimitive(type);
18+
this.boxedType = ctx.getMoreTypes().boxIfPrimitive(type);
1919
this.wrapperType = wrapperType;
2020
}
2121

0 commit comments

Comments
 (0)