use of org.gradle.build.docs.dsl.source.model.TypeMetaData in project gradle by gradle.
the class ClassDocExtensionsBuilder method build.
private void build(ClassExtensionDoc extensionDoc) {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
LinkRenderer linkRenderer = new LinkRenderer(doc, model);
for (Map.Entry<String, ClassDoc> entry : extensionDoc.getExtensionClasses().entrySet()) {
String id = entry.getKey();
ClassDoc type = entry.getValue();
PropertyMetaData propertyMetaData = new PropertyMetaData(id, extensionDoc.getTargetClass().getClassMetaData());
propertyMetaData.setType(new TypeMetaData(type.getName()));
Element para = doc.createElement("para");
para.appendChild(doc.createTextNode("The "));
para.appendChild(linkRenderer.link(propertyMetaData.getType(), listener));
para.appendChild(doc.createTextNode(String.format(" added by the %s plugin.", extensionDoc.getPluginId())));
PropertyDoc propertyDoc = new PropertyDoc(propertyMetaData, Collections.singletonList(para), Collections.<ExtraAttributeDoc>emptyList());
extensionDoc.getExtraProperties().add(propertyDoc);
para = doc.createElement("para");
para.appendChild(doc.createTextNode("Configures the "));
para.appendChild(linkRenderer.link(propertyMetaData.getType(), listener));
para.appendChild(doc.createTextNode(String.format(" added by the %s plugin.", extensionDoc.getPluginId())));
MethodMetaData methodMetaData = new MethodMetaData(id, extensionDoc.getTargetClass().getClassMetaData());
methodMetaData.addParameter("configClosure", new TypeMetaData(Closure.class.getName()));
MethodDoc methodDoc = new MethodDoc(methodMetaData, Collections.singletonList(para));
extensionDoc.getExtraBlocks().add(new BlockDoc(methodDoc, propertyDoc, propertyMetaData.getType(), false));
}
}
use of org.gradle.build.docs.dsl.source.model.TypeMetaData in project gradle by gradle.
the class ClassDocMethodsBuilder method build.
/**
* Builds the methods and script blocks of the given class. Assumes properties have already been built.
*/
public void build(ClassDoc classDoc) {
Set<String> signatures = new HashSet<String>();
for (Element tr : children(classDoc.getMethodsTable(), "tr")) {
List<Element> cells = children(tr, "td");
if (cells.size() != 1) {
throw new RuntimeException(String.format("Expected 1 cell in <tr>, found: %s", tr));
}
String methodName = cells.get(0).getTextContent().trim();
Collection<MethodMetaData> methods = classDoc.getClassMetaData().findDeclaredMethods(methodName);
if (methods.isEmpty()) {
throw new RuntimeException(String.format("No metadata for method '%s.%s()'. Available methods: %s", classDoc.getName(), methodName, classDoc.getClassMetaData().getDeclaredMethodNames()));
}
for (MethodMetaData method : methods) {
DocComment docComment = javadocConverter.parse(method, listener);
MethodDoc methodDoc = new MethodDoc(method, docComment.getDocbook());
if (methodDoc.getDescription() == null) {
throw new RuntimeException(String.format("Docbook content for '%s %s' does not contain a description paragraph.", classDoc.getName(), method.getSignature()));
}
PropertyDoc property = classDoc.findProperty(methodName);
boolean multiValued = false;
if (property != null && method.getParameters().size() == 1 && method.getParameters().get(0).getType().getSignature().equals(Closure.class.getName())) {
TypeMetaData type = property.getMetaData().getType();
if (type.getName().equals("java.util.List") || type.getName().equals("java.util.Collection") || type.getName().equals("java.util.Set") || type.getName().equals("java.util.Iterable")) {
type = type.getTypeArgs().get(0);
multiValued = true;
}
classDoc.addClassBlock(new BlockDoc(methodDoc, property, type, multiValued));
} else {
classDoc.addClassMethod(methodDoc);
signatures.add(method.getOverrideSignature());
}
}
}
for (ClassDoc supertype : classDoc.getSuperTypes()) {
for (MethodDoc method : supertype.getClassMethods()) {
if (signatures.add(method.getMetaData().getOverrideSignature())) {
classDoc.addClassMethod(method);
}
}
}
}
use of org.gradle.build.docs.dsl.source.model.TypeMetaData in project gradle by gradle.
the class JavadocLinkConverter method doResolve.
private Node doResolve(String link, ClassMetaData classMetaData, GenerationListener listener) {
Matcher matcher = LINK_PATTERN.matcher(link);
if (!matcher.matches()) {
return null;
}
String className = null;
if (matcher.group(1).length() > 0) {
className = typeNameResolver.resolve(matcher.group(1), classMetaData);
if (className == null) {
return null;
}
}
if (matcher.group(2) == null) {
return linkRenderer.link(new TypeMetaData(className), listener);
}
ClassMetaData targetClass;
if (className != null) {
targetClass = repository.find(className);
if (targetClass == null) {
return null;
}
} else {
targetClass = classMetaData;
}
String methodSignature = matcher.group(3);
if (matcher.group(5) != null) {
StringBuilder signature = new StringBuilder();
signature.append(methodSignature);
signature.append("(");
if (matcher.group(5).length() > 0) {
String[] types = PARAM_DELIMITER.split(matcher.group(5));
for (int i = 0; i < types.length; i++) {
String type = types[i];
Matcher typeMatcher = TYPE_PATTERN.matcher(type);
if (!typeMatcher.matches()) {
return null;
}
if (i > 0) {
signature.append(", ");
}
signature.append(typeNameResolver.resolve(typeMatcher.group(1), classMetaData));
String suffix = typeMatcher.group(2);
if (suffix.equals("...")) {
suffix = "[]";
}
signature.append(suffix);
}
}
signature.append(")");
methodSignature = signature.toString();
}
if (targetClass.isEnum() && targetClass.getEnumConstant(methodSignature) != null) {
return linkRenderer.link(targetClass.getEnumConstant(methodSignature), listener);
}
MethodMetaData method = findMethod(methodSignature, targetClass);
if (method == null) {
return null;
}
return linkRenderer.link(method, listener);
}
use of org.gradle.build.docs.dsl.source.model.TypeMetaData in project gradle by gradle.
the class LinkRenderer method link.
Node link(TypeMetaData type, final GenerationListener listener) {
final Element linkElement = document.createElement("classname");
type.visitSignature(new TypeMetaData.SignatureVisitor() {
public void visitText(String text) {
linkElement.appendChild(document.createTextNode(text));
}
public void visitType(String name) {
linkElement.appendChild(addType(name, listener));
}
});
linkElement.normalize();
if (linkElement.getChildNodes().getLength() == 1 && linkElement.getFirstChild() instanceof Element) {
return linkElement.getFirstChild();
}
return linkElement;
}
Aggregations