use of com.codename1.rad.annotations.RADDoc in project CodeRAD by shannah.
the class XMLSchemaGenerator method writeAttributeGroup.
private void writeAttributeGroup(StringBuilder sb, DeclaredType type, String prefix, int depth) {
TypeElement typeEl = (TypeElement) type.asElement();
String groupName = getAttributeGroupName(type, prefix, depth);
indent(sb, indent).append("<xs:attributeGroup name=\"").append(groupName).append("\">\n");
indent += 2;
processingEnvironment.getElementUtils().getAllMembers(typeEl).forEach(el -> {
if (el.getKind() != ElementKind.METHOD)
return;
ExecutableElement methodEl = (ExecutableElement) el;
TypeMirror mirror = processingEnvironment.getTypeUtils().asMemberOf(type, methodEl);
if (mirror.getKind() != TypeKind.EXECUTABLE)
return;
ExecutableType methodType = (ExecutableType) mirror;
if (methodEl.getSimpleName().toString().startsWith("set") && methodEl.getParameters().size() == 1 && methodEl.getReturnType().getKind() == TypeKind.VOID && ((ExecutableElement) el).getEnclosingElement().equals(typeEl)) {
// This is a setter
String propertyName = methodEl.getSimpleName().toString().substring(3);
if (propertyName.isEmpty())
return;
propertyName = toCamelCase(propertyName);
TypeMirror paramTypeMirror = methodType.getParameterTypes().get(0);
List<String> enumValues = null;
TypeElement parameterType = null;
if (paramTypeMirror.getKind() == TypeKind.DECLARED) {
parameterType = (TypeElement) ((DeclaredType) paramTypeMirror).asElement();
enumValues = parameterType.getEnclosedElements().stream().filter(element -> element.getKind().equals(ElementKind.ENUM_CONSTANT)).map(Object::toString).collect(Collectors.toList());
}
String typeAttStr = "xs:string";
if (enumValues != null && !enumValues.isEmpty()) {
typeAttStr = parameterType.getQualifiedName().toString().replace('.', '_');
enumTypes.add(parameterType);
}
indent(sb, indent).append("<xs:attribute name=\"").append(prefix).append(propertyName).append("\" type=\"").append(typeAttStr).append("\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"bind-").append(prefix).append(propertyName).append("\" type=\"").append("xs:string").append("\"/>\n");
return;
}
if (depth > 0 && methodEl.getSimpleName().toString().startsWith("get") && methodEl.getParameters().size() == 0 && methodType.getReturnType().getKind() == TypeKind.DECLARED && ((ExecutableElement) el).getEnclosingElement().equals(typeEl)) {
String propertyName = methodEl.getSimpleName().toString().substring(3);
if (propertyName.isEmpty())
return;
propertyName = toCamelCase(propertyName);
DeclaredType returnType = (DeclaredType) methodType.getReturnType();
RADDoc radDoc = methodEl.getAnnotation(RADDoc.class);
TypeElement returnTypeEl = (TypeElement) ((returnType.asElement().getKind() == ElementKind.CLASS || returnType.asElement().getKind() == ElementKind.INTERFACE) ? returnType.asElement() : null);
if (returnTypeEl != null && ((radDoc != null && radDoc.generateSubattributeHints()) || returnTypeEl.getQualifiedName().contentEquals("com.codename1.ui.plaf.Style") || env.isA(returnType, "com.codename1.rad.nodes.ActionNode.Builder") || methodEl.getSimpleName().contentEquals("getComponentForm") || methodEl.getSimpleName().contentEquals("getParent"))) {
indent(sb, indent).append("<xs:attributeGroup ref=\"").append(getAttributeGroupName(returnType, prefix + propertyName + ".", depth - 1)).append("\"/>\n");
addRequiredAttributeGroup(new AttributeGroup(prefix + propertyName + ".", ((TypeElement) returnTypeEl).getQualifiedName().toString(), depth - 1));
}
}
});
List<TypeMirror> superTypes = new ArrayList<>();
if (typeEl.getSuperclass() != null)
superTypes.add(typeEl.getSuperclass());
superTypes.forEach(superMirror -> {
if (superMirror.getKind() == TypeKind.DECLARED) {
DeclaredType superType = (DeclaredType) superMirror;
Element superTypeEl = superType.asElement();
if (superTypeEl == null)
return;
if (superTypeEl.getKind() == ElementKind.CLASS || superTypeEl.getKind() == ElementKind.INTERFACE) {
indent(sb, indent).append("<xs:attributeGroup ref=\"").append(getAttributeGroupName(superType, prefix, depth)).append("\"/>\n");
addRequiredAttributeGroup(new AttributeGroup(prefix, ((TypeElement) superTypeEl).getQualifiedName().toString(), depth));
}
}
});
indent -= 2;
indent(sb, indent).append("</xs:attributeGroup>\n");
}
Aggregations