Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Peeradon Sukkasem
@littleheart005
Screen Shot 2564-04-07 at 16.06.46.png
Roger Howell
@MysterAitch
@littleheart005 -- double check your source value -- this is usually the source root (i.e. the place where the default package files would be)
e.g. if Duck is in the package headfirst.strategy, the source root will be the folder above headfirst(i.e. the src directory)
1 reply
aiddroid
@aiddroid
Here's a demo for callgraph: https://github.com/aiddroid/java-callgraph
aiddroid
@aiddroid
alt
Danny van Bruggen
@matozoid
Hey, nice work @aiddroid !
Shall I put it on Twitter?
aiddroid
@aiddroid

Shall I put it on Twitter?

ok

Danny van Bruggen
@matozoid
Several people asked if JP has data flow graph/diagram/analysis support, and I wondered how much effort it would be to build it. It's now in a state that the design is right - lots of stuff still missing though - so I thought I would make it public: https://github.com/matozoid/data_flow_analyser_with_javaparser
Feel free to help/comment/ignore :-)
DaGeRe
@DaGeRe
Hi, I'm currently trying to instrument code for monitoring using Javaparser. Therefore, I need to know whether a statement is considered as unreachable by the compiler or not (to eventually add a return statement). From what I've seen now, https://github.com/javaparser/javaparser/blob/master/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/typeinference/ControlFlowLogic.java should do this job, but is not implemented yet. Are there other options for doing this with javaparser (besides implementing ControlFlowLogic myself)?
Danny van Bruggen
@matozoid
Ah, @DaGeRe - you just made me realize that I'm building a control flow analyser, not a data flow analyser. Thanks!
jean pierre Lerbscher
@jlerbsc
@DaGeRe What you need is a control flow graph but it does not exist in JP. But JP (AST) can help you to build a cfg.
Danny van Bruggen
@matozoid
Thanks to @jlerbsc for teaching me a new word :-) https://en.wikipedia.org/wiki/Schmilblick
4 replies
Jonathan Locke
@jonathanl-telenav
Hi All
I saw a discussion on the web somewhere about adding Kotlin support to JavaParser. Has there been any work done on this?
Danny van Bruggen
@matozoid
No, I think that would have to be a separate product. Tons of work!
Jonathan Locke
@jonathanl-telenav
Thanks Danny
Bart Naudts
@bnaudts
Hi, I’m working on a static code analyser (e2immu.org) that uses JavaParser as its source code parser. To be able to analyse its own code, e2immu would need Java 16 language features. I’m not using the JavaParser’s symbol solver. Could you please point me to a time-line for JavaParser’s Java 16 language support? I would consider helping a hand if that can speed things up.
7 replies
Yoshi van den Akker
@yoshivda
Hey, I just opened an issue (javaparser/javaparser#3244) but realised this might actually be a better place for it. I'm struggling with an OrphanComment in a BlockStmt, it doesn't appear when added programmatically (it does output correctly when it's in the parsed file). My project was still stuck on V3.6 of the parser and there it worked fine, but now that I'm upgrading to the latest version all of a sudden the comment fully disappears, leaving behind an empty block. Is this a regression or should I create a block that only contains a comment in another way?
15 replies
Danny van Bruggen
@matozoid
@jonathanl-telenav - if you're still around, today I saw a project that worked on the AST that Kotlin's compiler supplies. Maybe that's usable.
Roger Howell
@MysterAitch
Not caught up with all messages, but just a quick note to say I will get the next release out this weekend
If not sooner
Danny van Bruggen
@matozoid
That's great!
ridhij93
@ridhij93
Hi, Does Javaparser also work for .class files?
2 replies
Danny van Bruggen
@matozoid
@MysterAitch - I noticed a release because dependabot sends me PR's for a new JP dependency :-)
Roger Howell
@MysterAitch
haha yes.. though long overdue... :sweat:
Roger Howell
@MysterAitch
good to see that it's working though! :D
Danny van Bruggen
@matozoid
Is Java 15 support now complete (enough)? Let's tweet it!
... and update sites everywhere :-)
Roger Howell
@MysterAitch
java 16?

y'know... I just had a look and I think you're right! (just gotta fix the sealed classes thing to be second preview in java 16, not release...)

https://github.com/javaparser/javaparser/blob/master/FEATURES.md#jdk-16-current---march-2021

Roger Howell
@MysterAitch

RecordDeclaration's @sincementioned 3.21.0, and the features document also mentions it (says it was released on 11/april) but I don't see it on github releases or maven central...

now i'm wondering if I was a complete muppet and somehow completely skipped a version?? or thought it'd been released??

meh... it happens...
haha
Roger Howell
@MysterAitch
just pushed v3.22.1 which has parsing support up to java 16 and solver support up to java 15
Danny van Bruggen
@matozoid
Oh, I said 15 because the title on Gitter said 1-14. Updated that. You can decide if you want to claim Java 16 support or not.
"Introduce the character sequences sealed, non-sealed, and permits as contextual keywords."... Good luck with those "contextual" keywords...
DARAM PRASHANTH KUMAR
@prashanthdaram:matrix.org
[m]
@matozoid: For each method in source code, i am looking to identify variables declared in method body along with line number. I am not able to find the way, how to print method name along with variables declared in method body
2 replies
this is source file :
import java.awt.GraphicsConfiguration ;
import javax.swing.JFrame ;
public class JFrameExample {
public static void demo(int x, int y) {
System.out.println("X= "+x+" Y="+y);
}
static GraphicsConfiguration gc;
public static void main(String[] args ){
int x = 10;
int y = 20;
demo(x,y);
JFrame frame=new JFrame ( gc ) ;
frame.setTitle ("Welecome to JavaTutorial.net" ) ;
gc.getBounds();
gc.getDevice();
frame.setVisible(true);
}
}

The parser file i am developing is : import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.ModuleDeclaration;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

public class Lab2Driver {

public static String a;
public static String b;
public static String c;
public static String d;
public static String [] arr = new String [5];
public static String [] imp = new String [5];
List<Object> list = new ArrayList<Object>();
List<Object> list1 = new ArrayList<Object>();

public void run() throws IOException {


    //we need to read the content of the file
    String content = FileUtils.readFileToString(new File("C:\\Users\\prash\\Desktop\\Lab1Demo\\src\\JFrameExample.java"));

    //we need to create a parser object
    ASTParser parser = ASTParser.newParser(AST.JLS8);

    //we need to give the content to the parser
    parser.setSource(content.toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    cu.accept(new ASTVisitor() {
@Override
public boolean visit(VariableDeclarationFragment node) {
// TODO Auto-generated method stub
//System.out.println("(\"========================PART:2===========================\")");
//System.out.println("Variables decleared on the method body: ");
//System.out.println("Line Number: "+ cu.getLineNumber(node.getName().getStartPosition())+ " Variable Name: "+node.getName());
String m = "Line Number: "+ cu.getLineNumber(node.getName().getStartPosition())+ " Variable Name: "+node.getName();
list1.add(m);
return super.visit(node);
}
Thiago Henrique Hüpner
@Thihup
Is there already some compiler project using the JavaParser? If not, would anybody like to start a new one?
Danny van Bruggen
@matozoid
@Thihup I tried to build a Java interpreter with JP a few months ago but quit when it got complex :-)
I can send you what I had if you like.
Thiago Henrique Hüpner
@Thihup
@matozoid I'd really appreciate it if you could share it with me ;)
Danny van Bruggen
@matozoid
@Thihup - here, I published it on github, I have no shame :-) https://github.com/matozoid/javainterpreter
ridhij93
@ridhij93
Hi, Is there a way to get tokens in an expression using JavaParser. In particular, if there is an AssignExpr : x=y+z, I want the information like x is written and y and z are read. (something similar to use boxes and def boxes in SOOT)