Skip to content

Commit

Permalink
#66 added TypeDoc basics
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Kowalzik authored and Mathias Kowalzik committed Feb 20, 2018
1 parent e2ed298 commit fb81fc1
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ public class EndpointNode {
private final List<MethodNode> traceMethods;
private final Set<TypeNode> types;
private final PrintConfiguration printConfiguration;
private final String doc;


EndpointNode(final String serviceName, final String serviceURL, final String template, final List<MethodNode> methods, final PrintConfiguration printConfiguration) {
/**
* Constructor.
*
* @param serviceName {@link #getServiceName()}
* @param serviceURL {@link #getServiceURL()}
* @param doc {@link #getDoc()}
* @param template {@link #getTemplate()}
* @param methods {@link #getMethods}
* @param printConfiguration {@link #getPrintConfiguration()}
*/
EndpointNode(final String serviceName, final String serviceURL, final String doc, final String template, final List<MethodNode> methods, final PrintConfiguration printConfiguration) {
this.serviceName = serviceName;
this.serviceURL = serviceURL;
this.doc = doc;
this.template = template;
this.methods = methods;
this.printConfiguration = printConfiguration;
Expand Down Expand Up @@ -69,10 +81,20 @@ private Set<TypeNode> collectTypes() {
return new HashSet<>(typeMap.values());
}

/**
* Name of this EndpointNode, usually this is the Name of the Java Class of the Endpoint.
*
* @return serviceName
*/
public String getServiceName() {
return serviceName;
}

/**
* Base URL of this EndpointNode corresponds to value of @RequestMapping on the Java Class.
*
* @return serviceURL
*/
public String getServiceURL() {
return serviceURL;
}
Expand Down Expand Up @@ -128,4 +150,14 @@ public List<MethodNode> getPutMethods() {
public PrintConfiguration getPrintConfiguration() {
return printConfiguration;
}

/**
* Documentation of this Endpointnode, this is the pure content of the JavaDoc of the Endpoint Java Class,
* without any formatting characters or indentation.
*
* @return doc
*/
public String getDoc() {
return doc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.leandreck.endpoints.processor.model;

import static java.util.stream.Collectors.toList;
import static javax.lang.model.type.TypeKind.DECLARED;

import java.util.ArrayList;
Expand All @@ -38,12 +37,14 @@ public class EndpointNodeFactory {

private final MethodNodeFactory methodNodeFactory;
private final TemplateConfiguration configuration;
private final Elements elementUtils;

public EndpointNodeFactory(final TemplateConfiguration configuration,
final Types typeUtils,
final Elements elementUtils) {
this.configuration = configuration;
this.methodNodeFactory = new MethodNodeFactory(configuration, typeUtils, elementUtils);
this.elementUtils = elementUtils;
}

public EndpointNode createEndpointNode(final TypeElement typeElement) {
Expand All @@ -55,7 +56,9 @@ public EndpointNode createEndpointNode(final TypeElement typeElement) {
final String template = defineTemplate(annotation);
final List<MethodNode> methods = defineMethods(typeElement, (DeclaredType) typeElement.asType());

return new EndpointNode(name, url, template, methods, configuration.getGlobalPrintConfiguration());
final String doc = elementUtils.getDocComment(typeElement);

return new EndpointNode(name, url, doc, template, methods, configuration.getGlobalPrintConfiguration());
}

private List<MethodNode> defineMethods(final TypeElement typeElement, final DeclaredType containingType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ public class MethodNode {
private final List<String> httpMethods;
private final Set<TypeNode> types;
private final List<TypeNode> methodParameterTypes;
private final String doc;

MethodNode(final String name, final boolean ignored) {
MethodNode(final String name) {
this.name = name;
this.url = "";
this.ignored = ignored;
this.ignored = true;
this.returnType = null;
this.httpMethods = Collections.emptyList();
this.requestBodyType = null;
this.pathVariableTypes = Collections.emptyList();
this.queryParameterTypes = Collections.emptyList();
this.methodParameterTypes = Collections.emptyList();
this.types = collectTypes();
this.doc = null;
}

MethodNode(final String name, final String url, final boolean ignored, final List<String> httpMethods,
MethodNode(final String name, final String url, final String doc, final List<String> httpMethods,
final TypeNode returnType, final TypeNode requestBodyType, final List<TypeNode> pathVariableTypes,
final List<TypeNode> queryParameterTypes) {
this.name = name;
this.ignored = ignored;
this.ignored = false;
this.url = url;
this.returnType = returnType;
this.httpMethods = httpMethods;
Expand All @@ -64,6 +66,7 @@ public class MethodNode {
this.methodParameterTypes.addAll(pathVariableTypes);
this.methodParameterTypes.addAll(queryParameterTypes);
this.types = collectTypes();
this.doc = doc;
}

private Set<TypeNode> collectTypes() {
Expand Down Expand Up @@ -161,4 +164,14 @@ public List<TypeNode> getFunctionParameterTypes() {

return Collections.unmodifiableList(functionParameters);
}

/**
* Documentation of this MethodNode, this is the pure content of the JavaDoc of the Java Method,
* without any formatting characters or indentation.
*
* @return doc
*/
public String getDoc() {
return doc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ class MethodNodeFactory {

private final TypeNodeFactory typeNodeFactory;
private final RequestMappingFactory requestMappingFactory;
private final Elements elementUtils;

MethodNodeFactory(final TemplateConfiguration configuration,
final Types typeUtils,
final Elements elementUtils) {
typeNodeFactory = new TypeNodeFactory(configuration, typeUtils, elementUtils);
requestMappingFactory = new RequestMappingFactory();
this.elementUtils = elementUtils;
}

MethodNode createMethodNode(final ExecutableElement methodElement, final DeclaredType containingType) {
Expand All @@ -58,7 +60,7 @@ MethodNode createMethodNode(final ExecutableElement methodElement, final Declare
final String name = defineName(methodElement);
final boolean ignored = defineIgnored(methodElement, requestMapping);
if (ignored) {
return new MethodNode(name, true);
return new MethodNode(name);
}
final String url = defineUrl(requestMapping);
final List<String> httpMethods = defineHttpMethods(requestMapping);
Expand All @@ -68,8 +70,8 @@ MethodNode createMethodNode(final ExecutableElement methodElement, final Declare
final TypeNode requestBodyType = defineRequestBodyType(parameters, containingType);
final List<TypeNode> pathVariables = definePathVariableTypes(parameters, containingType);
final List<TypeNode> queryParams = defineQueryParamsTypes(parameters, containingType);

return new MethodNode(name, url, false, httpMethods, returnType, requestBodyType, pathVariables, queryParams);
final String doc = elementUtils.getDocComment(methodElement);
return new MethodNode(name, url, doc, httpMethods, returnType, requestBodyType, pathVariables, queryParams);
}

private TypeNode defineReturnType(final ExecutableElement methodElement, final DeclaredType containingType) {
Expand Down Expand Up @@ -109,7 +111,7 @@ private TypeNode defineRequestBodyType(final List<? extends VariableElement> par
final VariableElement paramElement = optionalRequestBody.get();
requestBodyType = typeNodeFactory.createTypeNode(paramElement, null, containingType);
} else {
requestBodyType = null; // reverted any | null-Type => typeNodeFactory.createTypeNode("body", null, null, null);
requestBodyType = null;
}

return requestBodyType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public abstract class TypeNode {

protected static final String EMPTY_JAVA_DOC = "";
private final boolean optional;

protected TypeNode(final boolean optional) {
Expand Down Expand Up @@ -183,4 +184,14 @@ public boolean equals(Object o) {
public int hashCode() {
return getTypeName().hashCode();
}

/**
* Documentation of this TypeNode, this is the pure content of the JavaDoc of the Java Type or Element,
* without any formatting characters or indentation.
*
* @return doc
*/
public String getDoc() {
return EMPTY_JAVA_DOC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import java.util.Set;

import static java.util.stream.Collectors.toList;
import static org.leandreck.endpoints.processor.model.TypeNode.EMPTY_JAVA_DOC;
import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind.OPTIONAL;
import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind.TYPEVAR;

/**
*/
Expand Down Expand Up @@ -98,7 +98,8 @@ public TypeNode createTypeNode(final TypeMirror typeMirror) {
*/
public TypeNode createTypeNode(final TypeMirror typeMirror, final DeclaredType containingType) {
final String fieldName = "TYPE-ROOT";
return initType(fieldName, null, false, defineKind(typeMirror), typeMirror, containingType);
final String doc = EMPTY_JAVA_DOC + "FIXME: createTypeNode(final TypeMirror typeMirror, final DeclaredType containingType)";
return initType(fieldName, null, false, defineKind(typeMirror), typeMirror, containingType, doc);
}

/**
Expand All @@ -111,7 +112,8 @@ public TypeNode createTypeNode(final TypeMirror typeMirror, final DeclaredType c
* @return concrete Instance of a {@link TypeNode}
*/
public TypeNode createTypeNode(final String fieldName, final String parameterName, final TypeMirror typeMirror, final DeclaredType containingType) {
return initType(fieldName, parameterName, false, defineKind(typeMirror), typeMirror, containingType);
final String doc = EMPTY_JAVA_DOC + "FIXME: createTypeNode(final String fieldName, final String parameterName, final TypeMirror typeMirror, final DeclaredType containingType)";
return initType(fieldName, parameterName, false, defineKind(typeMirror), typeMirror, containingType, doc);
}

/**
Expand All @@ -130,7 +132,9 @@ TypeNode createTypeNode(final VariableElement variableElement, final String para
final boolean optionalByAnnotation = VariableAnnotations.isOptionalByAnnotation(variableElement);
final boolean optionalByType = OPTIONAL.equals(typeNodeKind);

return initType(fieldName, parameterName, optionalByAnnotation || optionalByType, typeNodeKind, typeMirror, containingType);
final String doc = elementUtils.getDocComment(variableElement);

return initType(fieldName, parameterName, optionalByAnnotation || optionalByType, typeNodeKind, typeMirror, containingType, doc);
}

public List<TypeNode> defineChildren(final TypeElement typeElement, final DeclaredType typeMirror) {
Expand Down Expand Up @@ -184,23 +188,23 @@ private boolean filterVariableElements(final VariableElement variableElement, fi
}


private TypeNode initType(final String fieldName, final String parameterName, final boolean optional, final TypeNodeKind typeNodeKind, final TypeMirror typeMirror, final DeclaredType containingType) {
private TypeNode initType(final String fieldName, final String parameterName, final boolean optional, final TypeNodeKind typeNodeKind, final TypeMirror typeMirror, final DeclaredType containingType, final String doc) {
final String key = typeMirror.toString();
if (nodes.containsKey(key) && !TypeKind.TYPEVAR.equals(typeMirror.getKind())) {
final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional);
final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional, doc);
proxyNode.setNode(nodes.get(key));
return proxyNode;
}

try {
final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional);
final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional, doc);
nodes.put(key, proxyNode);

final ConcreteTypeNodeFactory nodeFactory = factories.get(typeNodeKind);
final TypeNode newTypeNode = nodeFactory.createTypeNode(fieldName, parameterName, optional, typeMirror, containingType);
proxyNode.setNode(newTypeNode);
nodes.put(key, newTypeNode);
return newTypeNode;
return proxyNode;
} catch (Exception e) {
throw new UnkownTypeProcessingException(e);
}
Expand Down Expand Up @@ -270,11 +274,13 @@ class ProxyNode extends TypeNode {
private TypeNode delegate;
private final String fieldName;
private final String parameterName;
private String doc;

private ProxyNode(final String fieldName, final String parameterName, boolean optional) {
private ProxyNode(final String fieldName, final String parameterName, final boolean optional, final String doc) {
super(optional);
this.fieldName = fieldName;
this.parameterName = parameterName;
this.doc = doc;
}

private void setNode(TypeNode delegate) {
Expand Down Expand Up @@ -365,5 +371,10 @@ public boolean equals(Object o) {
public int hashCode() {
return delegate.hashCode();
}

@Override
public String getDoc() {
return doc;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class SimpleTypeNodeFactory implements ConcreteTypeNodeFactory {

private final Types typeUtils;
private final Elements elementUtils;

private final TemplateConfiguration configuration;
private final TypeNodeFactory typeNodeFactory;
Expand All @@ -53,13 +54,15 @@ class SimpleTypeNodeFactory implements ConcreteTypeNodeFactory {
typeUtils = null;
configuration = null;
typeNodeFactory = null;
elementUtils = null;
objectMirror = null;
}

private SimpleTypeNodeFactory(final TypeNodeFactory typeNodeFactory, final Types typeUtils, final Elements elementUtils, final TemplateConfiguration configuration) {
this.typeNodeFactory = typeNodeFactory;
this.configuration = configuration;
this.typeUtils = typeUtils;
this.elementUtils = elementUtils;
objectMirror = TypeNodeUtils.getObjectMirror(elementUtils);
}

Expand All @@ -74,6 +77,8 @@ public TypeNode createTypeNode(final String fieldName, final String parameterNam
final TypeScriptType typeScriptTypeAnnotation = TypeNodeUtils.getAnnotationForClass(typeMirror, TypeScriptType.class, typeUtils);
final String typeName = TypeNodeUtils.defineName(typeMirror, typeScriptTypeAnnotation, this::defineNameFromSimpleType);

final String doc = elementUtils.getDocComment(typeElement);

return new SimpleTypeNode(
optional,
fieldName,
Expand All @@ -82,7 +87,7 @@ public TypeNode createTypeNode(final String fieldName, final String parameterNam
defineVariableType(typeName, typeMirror),
defineTypeParameters(typeMirror),
TypeNodeUtils.defineTemplate(configuration.getInterfaceTemplate(), typeScriptTypeAnnotation, typeElement),
typeNodeFactory.defineChildren(typeElement, (DeclaredType) typeMirror));
typeNodeFactory.defineChildren(typeElement, (DeclaredType) typeMirror), doc);
}

private List<TypeNode> defineTypeParameters(final TypeMirror typeMirror) {
Expand Down Expand Up @@ -130,6 +135,7 @@ class SimpleTypeNode extends TypeNode {
private final String template;
private final List<TypeNode> typeParameters;
private final List<TypeNode> children;
private final String doc;

//lazy
private Set<TypeNode> imports;
Expand All @@ -142,7 +148,8 @@ class SimpleTypeNode extends TypeNode {
final String variableType,
final List<TypeNode> typeParameters,
final String template,
final List<TypeNode> children) {
final List<TypeNode> children,
final String doc) {
super(optional);
this.fieldName = fieldName;
this.parameterName = parameterName;
Expand All @@ -151,6 +158,7 @@ class SimpleTypeNode extends TypeNode {
this.typeParameters = typeParameters;
this.template = template;
this.children = children;
this.doc = doc;
type = defineType();
}

Expand Down Expand Up @@ -250,5 +258,10 @@ public Set<TypeNode> getImports() {
public String getVariableType() {
return variableType;
}

@Override
public String getDoc() {
return doc;
}
}
}
Loading

0 comments on commit fb81fc1

Please sign in to comment.