ftomassetti / analyze-java-code-examples Goto Github PK
View Code? Open in Web Editor NEWSome examples of code extracting information from Java source files using JavaParser
Some examples of code extracting information from Java source files using JavaParser
Hello,
First of all thank you for making this guide!
However, when I try to implement your code I run into an error concerning the JavaParser parse function
Specifically in the listClasses method:
new DirExplorer((level, path, file) -> path.endsWith(".java"), (level, path, file) -> {
System.out.println(path);
System.out.println(Strings.repeat("=", path.length()));
try {
new VoidVisitorAdapter<Object>() {
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
System.out.println(" * " + n.getName());
}
}.visit(JavaParser.parse(file), null);
System.out.println(); // empty line
} catch (ParseException | IOException e) {
new RuntimeException(e);
}
}).explore(projectDir);
}
the function call to visit(JavaParser.parse(file), null)
gives a Non-static method 'parse(java.io.File, java.nio.charset.Charset)' cannot be referenced from a static context
error.
Could this be due to compatibility errors due to versioning?
After running ModifyingCode.java code,but source code not change, print ok . why;
Hi @ftomassetti ,
First of all, thank you very much for your explanations in your blog and your examples here. I'm trying to use JavaParser and JavaSymbolSolver to find all the declarations of variables belonging to specific classes (although project-defined ones) and I've started using this example and trying to combine with examples of JavaSymbolSolver in JavaSymbolSolverExamples, but using the build.gradle in this example and adding the dependency for JavaSymbolSolver found the build.gradle of that JavaSymbolSolver examples, I obtain one non-relevant error with node.getBeginLine() and node.getEndLine() methods. The important thing that I'm not able to solve is the use of ReflectionTypeSolver.
As I said before, I'm trying to find the way to search inside all code of one project to obtain all variables of one type. For example, finding all the variables of type javax.swing.JFrame. I would be grateful if you could help me.
new VoidVisitorAdapter<Object>() {
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
System.out.println(" * " + n.getName());
}
}.visit(StaticJavaParser.parse(BFile_sourcePath), null);
package test;
public class B {
public void print() {
new BInternal(){}.test();
}
}
class BInternal {
void test() {
}
}
only print
* B
* BInternal
need print
* B$1
also
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.