Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
ygq1001
@ygq1001
2021-07-21 04-01-10屏幕截图.png
@matozoid hi,when I use you data-flow-analyse code.I found something may be wrong. I found it just analyse try block but didn't analyse the catchclause. I can only get "87 START -> 90
90 STEP -> 91
91 STEP -> end"
Danny van Bruggen
@matozoid

@matozoid hi,when I use you data-flow-analyse code.I found something may be wrong. I found it just analyse try block but didn't analyse the catchclause. I can only get "87 START -> 90
90 STEP -> 91
91 STEP -> end"

Okay, open a bug report on that project please. (Or a PR with a fix ;-) )

11 replies
Danny van Bruggen
@matozoid
( holiday time for me )
roshansinghkande
@roshansinghkande

@ftomassetti @matozoid and Javaparser team
Thank you for this awesome library.

Can anyone please suggest a way on how I can achieve the below:

I am trying to migrate from an old library to a new one in some projects. I want to automate the refactoring of this migration.
Specifically I want to refactor the instantiation and population of a request object as below

Current code:

RequestDTO1 req= new RequestDTO1();
req.setParam1(variable1);
req.setParam2(variable2) .......

Target code:

RequestDTO2 req= new RequestDTO2(); // The RequestDTO2 class extends Hashmap
req.put("param1",variable1);
req.put("param2",variable2)......

In a nutshell, want to extract variable1 and variable2 from current code and use it in refactored code.

maggieCC
@mattycc
Hi everyone, do you know if LexicalPreservingPrinter ignores comments parts? I plan to change something in the comments. The compilationUnit varaible is what I want after transformation. However, when I use LexicalPreservingPrinter to print it out. The comment part is as same as the original one without any changes.
5 replies
I test it as following:
CompilationUnit compilationUnit = StaticJavaParser.parse(new FileInputStream(testPath));
        compilationUnit.getAllComments()
            .stream()
            .filter(m -> m.toString().contains("Test block comments"))
            .forEach(m -> {                            
                      String newCom = m.getContent().replace("block", "test");
                      Comment newComNode = m.setContent(newCom);
                      m.replace(m, newComNode);
            });
LexicalPreservingPrinter.setup(compilationUnit);
System.out.println(LexicalPreservingPrinter.print(compilationUnit));
wuguanyu
@wuguanyu
In our project, We use lombok. we use javaparser to analyze java project, we encounter one issue
Unsolved symbol : We are unable to find the method declaration corresponding,
In lombok, some code will generate in compile phase in class , not in java source code, do we have any solution to resolve
wuguanyu
@wuguanyu
@matozoid
Roger Howell
@MysterAitch
@wuguanyu -- see this issue and the others linked from it (short version, JavaParser doesn't run preprocessors such as Lombok - which means that the generated code doesn't yet exist therefore it cannot be parsed)
Danny van Bruggen
@matozoid
Back from holiday :-)
Bar Lerer
@barlerer_gitlab
I have a question.
I have created a simple visitor, that collects a SimpleName from method bodies.
The only issue I have with it is the order of the last attributes (i.e the function name, parameter name and class name)
Everything else appears in order, so why do these names come in last? and not first (As in the order they appear)?
1 reply
mbto
@mbto
Hello. How can I implement .toString() so that it prints exactly as it does in the original file? I have lost the indents in the entity classes.
1 reply
Screenshot_1
mbto
@mbto
Thanks, I extends DefaultPrettyPrinterVisitor and override public void visit(final ArrayInitializerExpr n, final Void arg) изображение
Michiel Borkent
@borkdude
Hey @matozoid ! Thanks for responding on Twitter
Danny van Bruggen
@matozoid
No problem! Sorry for not thinking of the dual license :-#
Siddarth Menon
@sidmenon28:matrix.org
[m]
How do you find static, abstract and private methods in an inheritance chain using the javaparser
1 reply
ygq1001
@ygq1001
I want to use symbol solver to resolve method call. The files are SARD juliet test suite cases, as the picture shows, there are two files, and they are in the same directory.However, both of them don't contain any package info, I have tried to operate as the doc said, but sth went wrong.So, how to resolve it?
5 replies
image.png
1.PNG
image.png
image.png
arshan
@nahsra_twitter

this project is so cool! congratulations on that

i wanted to replace a given MethodCallExpr with two consecutive statements (they both happen to also be MethodCallExpr, but i don't think this is important), but this didn't seem possible with the ModifierVisitor API, unless i am missing something?

i read the book (which was great) but it didn't seem to cover this use case, is there any documentation to point to for this?

arshan
@nahsra_twitter
i need to be able to do this while still supporting using the LexicalPreservingPrinter
arshan
@nahsra_twitter
yeah, just typing this out made me realize i'm trying to replace a naked MethodCallExpr with a statement, which was causing some type confusion in my head
i guess if i want to replace statements, i need to look at the visit() signatures that BlockStmt?
arshan
@nahsra_twitter
^ this worked really well, thanks for coming to my TED talk
Danny van Bruggen
@matozoid
Thanks for the talk @nahsra_twitter :-D
Also: often the solution to "how can I do this to node type X" is to look at the node types that contain type X instead. Like, sometimes people look at Name when they should be looking at VariableDeclaration instead. Also: there is a cool alternative for visitors: http://javaparser.org/functional-tree-traversal/
cs manitoba
@ridhamshah:matrix.org
[m]

hello,

I want to install gradle of javaparser in my eclipse so how can I do that?

one more thing I want to generate the AST tree for the Jlex: A Lexical Analyzer Generator for Java(TM) https://www.cs.princeton.edu/~appel/modern/java/JLex/).

How can I install and generate please guide me.

3 replies
arshan
@nahsra_twitter

i believe i'm running into this issue: javaparser/javaparser#2264

i have a different, minimal test case, but i don't want to just spam that here -- i am curious if any one of the common names i see in the committers repo is up for consulting / a bounty on the issue

7 replies
derekpham
@derekpham
hi, can someone please explain to me how lexical preserving printer works? I have a ModifierVisitor that replaces certain ExpressionStmt with new ExpressionStmt. Looking at the CompilationUnit after the visitor finishes, it seems like pretty printing / toString shows the modifications. However, lexical printing just prints out the original file.
2 replies
Roger Howell
@MysterAitch
v3.23.1 is now showing on maven central :+1:
Screenshot from 2021-10-06 06-01-55.png
1 reply
Screenshot from 2021-10-06 05-59-36.png
Danny van Bruggen
@matozoid
Awesome!
Who owns this by they way? https://twitter.com/JavaParserOrg
I forgot... but it would be nice if that account tweeted the release.
arshan
@nahsra_twitter
i know this is kind of a simple question after i've been using the library for a few weeks, but i'm not sure how to introduce an enum reference?
i see EnumDeclaration* types but i would have expected something like EnumExpr to be available
hoping for some hints, i'm guessing it might be a NameExpr but wondering if anyone can save me the 15 minutes of building sample code then inspecting the CompilationUnit =P
arshan
@nahsra_twitter
ahh FieldAccessExpr
StaticJavaParser was my friend, that made that really easy
apixandru
@apixandru
hey all, does this library have "find usages" type of index capabilities?
Danny van Bruggen
@matozoid
@nahsra_twitter - if you're still here, I wrote an article about that: http://javaparser.org/inspecting-an-ast/ - might be useful!
Cheikh Saadbouh
@cheikh-sadbouh
Hello everyone, how to get specific AST node at the given position in the source code using JavaParser Library ? example
Node getNodeAt(int line,ComputationalUnit cu)
5 replies
Hambuch Konrád
@KonradHambuch
Hi everyone, as I see JavaParserJsonDeserializer can only work with boolean variables if they are string ("true", "false") in the JSON. Is there a reason for that? Otherwise I get a Cast exception. (class javax.json.JsonValueImpl cannot be cast to class javax.json.JsonString)
1 reply