in tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/processor/operator/OperatorProcessor.java [273:329]
private void collectOpMethods(
Multimap<String, MethodSpec> groupedMethods, TypeElement opClass, TypeElement annotation) {
boolean opClassDeprecated = opClass.getAnnotation(Deprecated.class) != null;
AnnotationMirror operatorAnnot = getAnnotationMirror(opClass, annotation.getQualifiedName());
if (operatorAnnot == null) {
throw new IllegalArgumentException(
"Annotation "
+ annotation.getSimpleName()
+ " not present on element "
+ opClass.getSimpleName());
}
String opGroup = getAnnotationElementValueAsString("group", operatorAnnot);
String opName = getAnnotationElementValueAsString("name", operatorAnnot);
if (Strings.isNullOrEmpty(opName)) {
opName =
CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, ClassName.get(opClass).simpleName());
}
// Build an endpoint for each method annotated with @Endpoint, which takes in parameter a scope
// and, optionally, a list of arguments
for (ExecutableElement opMethod : ElementFilter.methodsIn(opClass.getEnclosedElements())) {
AnnotationMirror endpointAnnot =
getAnnotationMirror(opMethod, elements.getName(Names.Endpoint.toString()));
if (endpointAnnot != null) {
if (!opMethod.getModifiers().containsAll(Arrays.asList(Modifier.STATIC, Modifier.PUBLIC))) {
throw new IllegalArgumentException(
"Endpoint " + opMethod + " of class " + opClass + " must be static and public");
}
if (opMethod.getParameters().isEmpty()
|| !((TypeElement) types.asElement(opMethod.getParameters().get(0).asType()))
.getQualifiedName()
.equals(elements.getName(Names.Scope.toString()))) {
throw new IllegalArgumentException(
"Endpoint "
+ opMethod
+ " of class "
+ opClass
+ " must take an instance of "
+ Names.Scope
+ " as its first parameter");
}
String endpointGroup = getAnnotationElementValueAsString("group", endpointAnnot);
if (endpointGroup.isEmpty()) {
endpointGroup = opGroup;
}
String endpointName = getAnnotationElementValueAsString("name", endpointAnnot);
if (endpointName.isEmpty()) {
endpointName = opName;
}
boolean describeByClass =
getAnnotationElementValueAsBoolean("describeByClass", endpointAnnot, false);
boolean deprecated = opMethod.getAnnotation(Deprecated.class) != null || opClassDeprecated;
MethodSpec method =
buildOpMethod(endpointName, opClass, opMethod, describeByClass, deprecated);
groupedMethods.put(endpointGroup, method);
}
}
}