net.thevpc.commons.md.doc.java.JPRootDoc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thevpc-common-md-doc Show documentation
Show all versions of thevpc-common-md-doc Show documentation
Javadoc distiller to Markdown Library
/**
* ====================================================================
* Nuts : Network Updatable Things Service
* (universal package manager)
*
* is a new Open Source Package Manager to help install packages
* and libraries for runtime execution. Nuts is the ultimate companion for
* maven (and other build managers) as it helps installing all package
* dependencies at runtime. Nuts is not tied to java and is a good choice
* to share shell scripts and other 'things' . Its based on an extensible
* architecture to help supporting a large range of sub managers / repositories.
*
*
* Copyright [2020] [thevpc]
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
* ====================================================================
*/
package net.thevpc.commons.md.doc.java;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.PackageDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import net.thevpc.commons.md.doc.JDClassDoc;
import net.thevpc.commons.md.doc.JDRootDoc;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
*
* @author vpc
*/
public class JPRootDoc implements JDRootDoc {
private Map classes = new HashMap();
public void parseSrcFolder(Path path, Predicate packageFilter) {
try {
//support for maven
if(Files.isRegularFile(path.resolve("pom.xml"))
&& Files.isDirectory(path.resolve("src/main/java"))
){
path=path.resolve("src/main/java");
}
Path path0=path;
Files.walk(path0).filter(x -> Files.isRegularFile(x)
&& x.getFileName().toString().endsWith(".java")
).forEach(file -> {
String pck =
StreamSupport.stream(file.subpath(path0.getNameCount(), file.getNameCount()).spliterator(), false)
.map(Path::toString)
.collect(Collectors.joining("."));
if (packageFilter == null || packageFilter.test(pck)) {
parseFile(file);
}
});
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
public void parseFile(Path path) {
try {
new VoidVisitorAdapter