Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Roger Howell
@MysterAitch
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)
Danny van Bruggen
@matozoid
Yes, tokens are available with getTokenRange, but it does not seem to be what you are asking for.
Use and def boxes, that's not part of the scope right now. But it can be built on top of JP.
ridhij93
@ridhij93
getTokenRange() gets the entire expression
If there is anything that can print separate tokens that would also work for me.
Danny van Bruggen
@matozoid
Yes, check the methods on the returned TokenRange object.
ridhij93
@ridhij93
Thanks!
ridhij93
@ridhij93
Can I also find out which classes a class extends or interfaces it implements?
Danny van Bruggen
@matozoid
For that you'll need the symbol solver. The book(let) explains how all of that works.
nashid
@nashid
Did anyone attempt to build a control flow analysis with Java Parser? Are there examples available?
I would be also interested to know anyone built a basic Reaching definition data-flow analysis with Java Parser? Any help is appreciated.
Bart Naudts
@bnaudts
Hi Nashid, while not the immediate goal of the project, the static code analyser that I'm working on (e2immu.org) uses JavaParser and does more than basic control+data flow analysis.
16 replies
Danny van Bruggen
@matozoid
Danny van Bruggen
@matozoid
That one (mine :-) ) is something I wrote after users kept asking for a control flow analyser. I have no use for it myself, so I just implemented what seemed useful. Feedback would be very welcome :-)
9 replies
maggieCC
@mattycc
Hi everybody. Do you know is there any method to get the type of parameters? For example, "m.create(name)", the type of "name" is NameStr. Can we get the type which is NameStr with Javaparser? Or the only way is to search for the whole java file and find the declaration place?
Danny van Bruggen
@matozoid
@mattycc that's the job of the symbol solver. The book has a manual for it.
maggieCC
@mattycc
Thanks so much. I've tried that but got an error of UnsolvedSymbolException even I added the whole java package and jar path to the combinationTypeSolver.
Danny van Bruggen
@matozoid
ygq1001
@ygq1001
hi, there. I'm trying to build a code property graph in method level by using JavaParser. However, for now, I have no idea about how to build CFG and PDG while the AST built.
9 replies
Ryan Warren
@ryantbwarren
Hi, I am trying to extract the number of JavaTokens present in a given TokenRange. My current approach is to iterate over the TokenRange with a counter but I wasn't sure if there might be a better solution? Many thanks!
2 replies
ygq1001
@ygq1001
Hi, I want to know if there is a way to compare two nodes and decide whether they are the same node. Is there a unique identifier for the node?
2 replies
ygq1001
@ygq1001
well, I'm trying to get all tokens in nodes. I find that the tokens contain whitespace like \r\n and comment. I have set parser configuration "ParserConfiguration().setAttributeComments(false);" . But comments still are in the tokenrange. Is there a way to ignore these unimportant tokens? Thanks
2 replies