Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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)
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