Skip to content

Commit ae95fc9

Browse files
committed
Refine exception and messages
1 parent 7f0d684 commit ae95fc9

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

processor/src/main/java/org/sharedtype/processor/AnnotationProcessorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
6666
return ANNOTATION_CONSUMED;
6767
}
6868
if (annotations.size() > 1) {
69-
throw new SharedTypeInternalError(String.format("Only '%s' is expected.", ANNOTATION_QUALIFIED_NAME));
69+
throw new SharedTypeInternalError(String.format("Only annotation %s is expected.", ANNOTATION_QUALIFIED_NAME));
7070
}
7171
TypeElement annotation = annotations.iterator().next();
7272
checkArgument(annotation.getQualifiedName().contentEquals(ANNOTATION_QUALIFIED_NAME), "Wrong anno: %s", annotation);
@@ -88,7 +88,7 @@ void doProcess(Set<? extends Element> elements) {
8888
ctx.warning("Type '%s' is ignored or invalid, but annotated with '%s'.", typeElement.getQualifiedName().toString(), ANNOTATION_QUALIFIED_NAME);
8989
}
9090
} else {
91-
throw new UnsupportedOperationException("Unsupported element: " + element);
91+
throw new SharedTypeInternalError(String.format("Unsupported element: %s of kind %s", element, element.getKind()));
9292
}
9393
}
9494
List<TypeDef> resolvedDefs = resolver.resolve(discoveredDefs);

processor/src/main/java/org/sharedtype/processor/parser/EnumTypeDefParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ private List<EnumValueInfo> parseEnumConstants(TypeElement enumTypeElement, List
9292
" Is this class from a dependency jar/compiled class file? Please refer to the documentation for more information.",
9393
enumConstant, enumTypeElement);
9494
} else {
95-
throw new SharedTypeInternalError(String.format("Unsupported tree, kind: %s, tree: %s, element: %s", tree.getKind(), tree, enumConstant));
95+
throw new SharedTypeInternalError(String.format(
96+
"Unsupported tree during parsing enum %s, kind: %s, tree: %s, element: %s", enumTypeElement, tree.getKind(), tree, enumConstant));
9697
}
9798
}
9899
return res;
@@ -114,10 +115,10 @@ private Object resolveValue(TypeElement enumTypeElement, VariableTree tree, int
114115
}
115116
} catch (IndexOutOfBoundsException e) {
116117
throw new SharedTypeInternalError(String.format(
117-
"Initializer has incorrect number of arguments: %s in tree: %s, argIndex: %s", init, tree, ctorArgIdx));
118+
"Initializer in enum %s has incorrect number of arguments: %s in tree: %s, argIndex: %s", enumTypeElement, init, tree, ctorArgIdx));
118119
}
119120
}
120-
throw new SharedTypeInternalError(String.format("Unsupported initializer: %s in tree: %s", init, tree));
121+
throw new SharedTypeInternalError(String.format("Unsupported initializer in enum %s: %s in tree: %s", enumTypeElement, init, tree));
121122
}
122123

123124
@RequiredArgsConstructor

processor/src/main/java/org/sharedtype/processor/parser/type/TypeInfoParserImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public TypeInfo parse(TypeMirror typeMirror) {
4646
} else if (typeKind == TypeKind.EXECUTABLE) {
4747
return parse(((ExecutableType) typeMirror).getReturnType());
4848
}
49-
throw new SharedTypeInternalError(String.format("Unsupported field type, element: %s, typeKind: %s", typeMirror, typeKind)); // TODO: context info
49+
throw new SharedTypeInternalError(String.format("Unsupported type: %s, typeKind: %s", typeMirror, typeKind));
5050
}
5151

5252
private TypeInfo parseDeclared(DeclaredType declaredType) {

processor/src/main/java/org/sharedtype/processor/resolver/LoopTypeResolver.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public List<TypeDef> resolve(List<TypeDef> typeDefs) {
7878
}
7979
}
8080
} else {
81-
throw new SharedTypeInternalError("Unsupported type: " + typeDef.getClass());
81+
throw new SharedTypeInternalError("Unsupported TypeDef type: " + typeDef.getClass());
8282
}
8383

8484
resolveTypeInfo(processingDefStack, processingInfoStack);
@@ -113,11 +113,10 @@ private void resolveTypeInfo(Deque<TypeDef> processingDefStack, Deque<TypeInfo>
113113
}
114114
} else if (typeInfo instanceof TypeVariableInfo) {
115115
TypeVariableInfo typeVariableInfo = (TypeVariableInfo) typeInfo;
116-
throw new UnsupportedOperationException("Type variable not supported yet: " + typeVariableInfo);
116+
throw new SharedTypeInternalError("TypeVariableInfo is not supported yet: " + typeVariableInfo);
117117
} else {
118-
throw new SharedTypeInternalError(
119-
String.format("Only ConcreteTypeInfo needs to be resolved, but got typeInfo: %s with %s", typeInfo, typeInfo.getClass())
120-
);
118+
throw new SharedTypeInternalError(String.format(
119+
"Only ConcreteTypeInfo needs to be resolved, but got: %s of %s", typeInfo, typeInfo.getClass()));
121120
}
122121
}
123122
}

0 commit comments

Comments
 (0)