use of com.github.javaparser.ast.body.TypeDeclaration in project Hidoc by yuzhengyang.
the class Jptest method main.
public static void main(String[] args) throws FileNotFoundException {
// parse() 参数可以是 String, File, InputStream等
String filepath = "D:\\code\\projects\\haixin-projects\\hicmp-utils\\hicmp-utils\\hicmp-common-hiutils\\src\\main\\java\\com\\histone\\hiutils\\hiDbUtils\\hiDbAssistUtils\\HiDbModel.java";
CompilationUnit cu = StaticJavaParser.parse(new File(filepath));
List<TypeDeclaration> cds = cu.findAll(TypeDeclaration.class);
List<MethodDeclaration> mds = cu.findAll(MethodDeclaration.class);
mds.forEach(md -> System.out.println(md.toString() + "\n------------------------------\n"));
}
use of com.github.javaparser.ast.body.TypeDeclaration in project peass by DaGeRe.
the class TestSourceDetection method testDirectoryWalker.
@Test
public void testDirectoryWalker() throws FileNotFoundException {
final File file = new File(SOURCE, "DirectoryWalkerTestCase.java");
final CompilationUnit cu = JavaParserProvider.parse(file);
final Map<String, TypeDeclaration<?>> named = TraceReadUtils.getNamedClasses(cu, "");
Assert.assertEquals(4, named.size());
MatcherAssert.assertThat(named.get("DirectoryWalkerTestCase$TestFileFinder").toString(), Matchers.containsString("List results"));
}
use of com.github.javaparser.ast.body.TypeDeclaration in project cornelius by bkushigian.
the class PegTranslator method translate.
public PegNode translate(final CompilationUnit cu, final String canonical) {
if (canonical == null)
return PegNode.unit();
final NodeList<TypeDeclaration<?>> types = cu.getTypes();
types.sort(Comparator.comparing(TypeDeclaration::getNameAsString));
for (TypeDeclaration<?> type : types) {
if (type.isClassOrInterfaceDeclaration()) {
final ClassOrInterfaceDeclaration ctype = type.asClassOrInterfaceDeclaration();
final PegClassVisitor.ClassVisitorResult classVisitorResult = classVisitor.visit(ctype);
if (ctype.isInterface())
continue;
for (MethodDeclaration method : ctype.getMethods()) {
if (canonical.equals(Util.canonicalizeDeclarationName(method))) {
return translate(method, classVisitorResult);
}
}
}
}
return PegNode.unit();
}
use of com.github.javaparser.ast.body.TypeDeclaration in project Matcher by sfPlayer1.
the class TypeResolver method getCls.
public ClassInstance getCls(Node node) {
StringBuilder sb = new StringBuilder();
if (pkg != null) {
sb.append(pkg);
sb.append('/');
}
int pkgEnd = sb.length();
do {
if (node instanceof ClassOrInterfaceDeclaration || node instanceof EnumDeclaration) {
TypeDeclaration<?> typeDecl = (TypeDeclaration<?>) node;
String namePart = typeDecl.getName().getIdentifier();
if (sb.length() > pkgEnd) {
sb.insert(pkgEnd, '$');
sb.insert(pkgEnd, namePart);
} else {
sb.append(namePart);
}
}
} while ((node = node.getParentNode().orElse(null)) != null);
ClassInstance cls = getClsByName(sb.toString());
return cls;
}
Aggregations