use of org.gradle.build.docs.dsl.source.model.ClassMetaData in project gradle by gradle.
the class JavadocConverter method parse.
public DocComment parse(final PropertyMetaData propertyMetaData, final GenerationListener listener) {
listener.start(String.format("property %s", propertyMetaData));
try {
ClassMetaData ownerClass = propertyMetaData.getOwnerClass();
String rawCommentText = propertyMetaData.getRawCommentText();
try {
CommentSource commentSource = new InheritedPropertyCommentSource(propertyMetaData, listener);
DocCommentImpl docComment = parse(rawCommentText, ownerClass, commentSource, listener);
adjustGetterComment(docComment);
return docComment;
} catch (Exception e) {
throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nProperty: %s%nComment: %s", ownerClass.getClassName(), propertyMetaData.getName(), rawCommentText), e);
}
} finally {
listener.finish();
}
}
use of org.gradle.build.docs.dsl.source.model.ClassMetaData in project gradle by gradle.
the class JavadocLinkConverter method resolveValue.
/**
* Converts a javadoc value link into docbook.
*/
public Node resolveValue(String fieldName, ClassMetaData classMetaData, GenerationListener listener) {
String[] parts = fieldName.split("#");
ClassMetaData targetClass;
if (parts[0].length() > 0) {
String targetClassName = typeNameResolver.resolve(parts[0], classMetaData);
targetClass = repository.find(targetClassName);
if (targetClass == null) {
listener.warning(String.format("Could not locate target class '%s' for field value link '%s'", targetClass, fieldName));
Element element = document.createElement("UNHANDLED-VALUE");
element.appendChild(document.createTextNode(targetClassName + ":" + parts[1]));
return element;
}
} else {
targetClass = classMetaData;
}
String value = targetClass.getConstants().get(parts[1]);
if (value == null) {
listener.warning(String.format("Field '%s' does not have any value", fieldName));
Element element = document.createElement("NO-VALUE-FOR_FIELD");
element.appendChild(document.createTextNode(targetClass.getClassName() + ":" + parts[1]));
return element;
}
return createLiteralNode(value);
}
use of org.gradle.build.docs.dsl.source.model.ClassMetaData 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.ClassMetaData in project gradle by gradle.
the class GenerateDefaultImportsTask method generate.
@TaskAction
public void generate() throws IOException {
SimpleClassMetaDataRepository<ClassMetaData> repository = new SimpleClassMetaDataRepository<>();
repository.load(getMetaDataFile().getAsFile().get());
final Set<String> excludedPrefixes = new HashSet<>();
final Set<String> excludedPackages = new HashSet<>();
for (String excludePattern : excludePatterns) {
if (excludePattern.endsWith(".**")) {
String baseName = excludePattern.substring(0, excludePattern.length() - 3);
excludedPrefixes.add(baseName + '.');
excludedPackages.add(baseName);
} else {
excludedPackages.add(excludePattern);
}
}
final Set<String> packages = new LinkedHashSet<>();
final Multimap<String, String> simpleNames = LinkedHashMultimap.create();
repository.each(new Action<ClassMetaData>() {
public void execute(ClassMetaData classMetaData) {
if (classMetaData.getOuterClassName() != null) {
// Ignore inner classes
return;
}
String packageName = classMetaData.getPackageName();
if (excludedPackages.contains(packageName)) {
return;
}
for (String excludedPrefix : excludedPrefixes) {
if (packageName.startsWith(excludedPrefix)) {
return;
}
}
simpleNames.put(classMetaData.getSimpleName(), classMetaData.getClassName());
packages.add(packageName);
}
});
try (PrintWriter mappingFileWriter = new PrintWriter(new FileWriter(getMappingDestFile().getAsFile().get()))) {
for (Map.Entry<String, Collection<String>> entry : simpleNames.asMap().entrySet()) {
if (entry.getValue().size() > 1) {
System.out.println(String.format("Multiple DSL types have short name '%s'", entry.getKey()));
for (String className : entry.getValue()) {
System.out.println(" * " + className);
}
}
mappingFileWriter.print(entry.getKey());
mappingFileWriter.print(":");
for (String className : entry.getValue()) {
mappingFileWriter.print(className);
mappingFileWriter.print(";");
}
mappingFileWriter.println();
}
}
try (PrintWriter writer = new PrintWriter(new FileWriter(getImportsDestFile().getAsFile().get()))) {
for (String packageName : packages) {
writer.print("import ");
writer.print(packageName);
writer.println(".*");
}
}
}
use of org.gradle.build.docs.dsl.source.model.ClassMetaData in project gradle by gradle.
the class ClassDocSuperTypeBuilder method build.
/**
* Builds and attaches the supertypes of the given class
*/
void build(ClassDoc classDoc) {
ClassMetaData classMetaData = classDoc.getClassMetaData();
String superClassName = classMetaData.getSuperClassName();
if (superClassName != null) {
// Assume this is a class and so has implemented all properties and methods somewhere in the superclass hierarchy
ClassDoc superClass = model.getClassDoc(superClassName);
classDoc.setSuperClass(superClass);
superClass.addSubClass(classDoc);
}
List<String> interfaceNames = classMetaData.getInterfaceNames();
for (String interfaceName : interfaceNames) {
ClassDoc superInterface = model.findClassDoc(interfaceName);
if (superInterface != null) {
classDoc.getInterfaces().add(superInterface);
superInterface.addSubClass(classDoc);
}
}
}
Aggregations