Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Karthi G
@karthi_:matrix.org
[m]

Hi Team
How to find all object creations and its type

For Example

A a = new A();

I need to know "a" is of which type and need to replace it with another class . I tried with ObjectCreationExpr but I couldn't get that information

3 replies
Chinese News Board
@ralphcnb_twitter

Hello! A year ago, "Danny van Bruggen" and "Jean Pierre Lerbscher" (@jlerbsc) were very helpful. I had one question I was thinking about...

Is the JavaParser "Symbol Solver" basically like the "Linking Pass" inside a compiler? Would "Symbol Solver" do things like link one "FieldDeclaration" to a "ClassOrInterfaceDeclaration" that actually had the 'type' of that Field?

Just curious, don't need any immediate answers right now...

11 replies
Chinese News Board
@ralphcnb_twitter
Capture.PNG
Seham Alharbi
@SehamAAlharbi
Hello, I have been using JavaParser for a few months now, and I would like to know if I can construct a control flow graph and a data flow graph using JavaParser only? or it would be more practical if I use other frameworks such as Soot for such a purpose. Thanks.
3 replies
Hareem-E-Sahar
@Hareem-E-Sahar
is there a way to extract url from each method or do I need to write regex?
3 replies
Chinese News Board
@ralphcnb_twitter
One question - maybe you can help. I have been ignoring this forever... With types I have been removing ONE) Any type-parameters <K, V>, and TWO) everything before the period '.' So 'type' Map.Entry<Integer, Integer> is just Entry. For the purposes of JavaDoc HTML, this is just fine! I need to know one thing - Is there a way to retrieve the "Package Information" from class com.ast.github.javaparser.ast.type.Type ??
3 replies
If I have a Type is there a getContainingPackage() method? The text that is returned from Type.asString() seems to contain the package information (even when I leave it off of the source-code)... so it is 'resolving it` somehow...
Chinese News Board
@ralphcnb_twitter
It's Saturday night. My Upgrader (javadoc) has a Messager class now V1.7. You know, I didn't notice any home-grown annotations in Java Parser, although I haven't looked through all of it yet. I also have my own annotation now too. I'm going add three more for my syntax hiliting - (something like) @HiLiteConstructors or @DontHiLiteFields - upgrader already does all that, but not with annotations... You guys haven't written a Syntax HiLiter yet? It seems (at least to me) that that would be the highest priority for anything that parses the Java Language
9 replies
Hareem-E-Sahar
@Hareem-E-Sahar
How can I trace an object to its type? Suppose the following method is invoked obj.getName()
How can I know what is the type of obj?
1 reply
Hambuch Konrád
@KonradHambuch
Hello everyone! Is there a way to use JavaParser's metamodel as an EMF metamodel? So every java program would be an instance model of that metamodel. This would make easy to write (XTexd) code genrators for AST-s. (e.g. I have a code and a vulnerability pattern and I can generate a query that finds the pattern in the code). Thank you.
2 replies
Nats15555
@Nats15555
hello everyone, how to turn a java file into an AST, I can’t figure it out (show an example please
1 reply
YotamN
@yotamn:matrix.org
[m]
Hey, is there a way to make Javaparser work with incomplete or incorrect code? I want to use it with a decompilation output that is not necessary complete or correct
2 replies
Seham Alharbi
@SehamAAlharbi
Hello, I have been using your great library for a few months, I only used it to visit and modify nodes. However, I was wondering if I can use JP to also insert new nodes? my intention is to get a copy of a BlockStmt of a MethodDeclaration and insert it under a BlockStmt of another MethodDeclaration at a specific line number, is this possible with JP? thanks.
9 replies
Karthi G
@karthi_:matrix.org
[m]

Hi,

I need to search for particular constant in class.

Example

class A{
public static final String CONS = "a";
}

class B{
public void m1(){
String s1 = CONS; //as static import
String s2 = A.CONS;
}
}

I need to search for all occurrence of CONS. I have used FieldAccessExpr but it is not fetching static imports of particular constant. Let me know how to achieve that

5 replies
Fábio Rodrigues Pereira
@fabiopereiragt
Hello everyone, I have been using JP to create a plugin for refactoring. It's working very well! First, I create the parser (CU - compilationUnit) and do the refactoring operations. Afterwards, I write the CompilationUnit instance (changed) to the same source file using Java's FileWriter. However, if this file is open in the Eclipse IDE (when I perform this operation of writing the CU), Eclipse updates the view of this file and leaves the exact position where the user was when he used my plugin. I wouldn't want this update to happen. I'd like it to just make the changes at the specific location without updating the whole file (as if it were an update in CU on the fly), more or less like JDT does. It is possible? In short: What is the best way or method to commit refactoring changes using JavaParser in JAVA Eclipse project? Thank you very much in advance!
2 replies
SiriusBlack
@Nihility981
image.png
12 replies
How to convert 0x01_code to 0x02_code?
Seham Alharbi
@SehamAAlharbi
How to add a node to the childNodes list of a BlockStatm node? I have a node from another BlockStmt node and I need to append it to the children of another BlockStmt node.
1 reply
Chinese News Board
@ralphcnb_twitter
7 replies
Seham Alharbi
@SehamAAlharbi
Hello, I know that JP is mainly an easy to use parser, but could it provide features like checking whether the code transformed and generated by JP contains syntax errors? e.g., variables with clashing names, or eliminating dead code? thanks.
15 replies
Daan van den Heuvel
@daanvdh

@matozoid I've played with your CFG for a bit, and initialy was planning to merge the code with the DFG code. Putting both graphs together would mean that any CFG node owns a set of DFN nodes and the condition would be a DataFlowNode instead of a JP.Node.

  • I argued that 1) it would be nice to have direct access to any DataFlow to determine some branching that is going on in the CFG. Also 2) given a path through the CFG it would make things easier to only walk on DFN nodes that are within the CFG path. 3) I expect that the timecomplexity of these oparations will also be lower if I put both graphs together since I would not have to do lookups (O(log(nodes)) back and forth.
  • However, it's also nice to strictly separate the 2 graphs for maintainabillity purposes (separation of concerns). Then mapping one graph to the other could be done by storing nodes in both graphs in a map with the JavaParser.Node as key (this is already done in the DFN). Then if you want to construct a simple path through the CFG, you could construct it as a linkedHashMap. In this case however you would have to expand all underlying nodes. If you would want to analyse how a certain branch in the CFG is taken, you could simply get the DFG node representing the condition and walk backwards from there.

My personal endgoal is unit test generation for which I need both graphs. But ofcourse it would be nice to create a generic framework. Please let me know what your thoughts are on this.

10 replies
burcualper
@burcualper
Hello everyone I am pretty new to java parser and I am lost and ı cant get out. I even could not import this into my project so I can start what I want to do. I want to get the metrics of a java project so I should use this to reach the metrics. Is there anyone who can help me to start my project, İf I can start it ı would continue. Thanks in advanced.
7 replies
Karthi G
@karthi_:matrix.org
[m]

Hi

How to check if db connection is properly closed using Javaparser? Kindly brief on the steps involved

10 replies
Karthi G
@karthi_:matrix.org
[m]

Hi Team

I need to get nodes from specific starting position to end position. How to do that?

3 replies
Karthi G
@karthi_:matrix.org
[m]
I meant line numbers starting from 5 and ending at 10
Karthi G
@karthi_:matrix.org
[m]

Hi team

Let me know how to construct a node from string

I have below string which I need to construct node from and respective import statements have to be added

CodeBlock cb = CodeBlock.newBlock().withTransaction();
cb.execute(() -> {
// todo
});

2 replies
Nadeen Udantha
@NadeenUdantha_twitter
5 replies
Daan van den Heuvel
@daanvdh
I'm bumping the version of JP in my project from 2.15 to 2.24. What's the best way to solve my compilation errors? I was checking in the change log (link below) , which solved most of my problems. But I still have a missing "getWrappedNode" on "JavaParserSymbolDeclaration".
https://github.com/javaparser/javaparser/blob/master/changelog.md
1 reply
Macumba
@macumbamacaca:matrix.org
[m]
@daanvdh: - maybe @jlerbsc knows what changed? Otherwise open an issue, I guess.
Danny van Bruggen
@matozoid
Sheesh, I hate people who will run a refactoring tool against a random github project to score github points -> javaparser/javaparser#3535
storri
@storri
When the JavaSymbolSolver cannot find a symbol it throws the UnsolvedSymbolException when it cannot find a symbol in a third party library. How can I tell it to ignore certain packages from it?
1 reply
Karthi G
@karthi_:matrix.org
[m]

Hi Team
Why I'm getting below error. My project is Ant based

Exception in thread "main" UnsolvedSymbolException{context='ScheduledReportAPI', name='Solving ScheduledReportAPI', cause='null'}
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:535)
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:99)
at com.github.javaparser.ast.expr.NameExpr.accept(NameExpr.java:79)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getTypeConcrete(JavaParserFacade.java:554)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getType(JavaParserFacade.java:401)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getType(JavaParserFacade.java:383)
at com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext.solveMethodAsUsage(MethodCallExprContext.java:118)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solveMethodAsUsage(JavaParserFacade.java:757)
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:523)
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:99)
at com.github.javaparser.ast.expr.MethodCallExpr.accept(MethodCallExpr.java:116)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getTypeConcrete(JavaParserFacade.java:554)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getType(JavaParserFacade.java:401)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solveArguments(JavaParserFacade.java:303)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solve(JavaParserFacade.java:322)
at com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solve(JavaParserFacade.java:186)
at com.github.javaparser.symbolsolver.JavaSymbolSolver.resolveDeclaration(JavaSymbolSolver.java:161)
at com.github.javaparser.ast.expr.MethodCallExpr.resolve(MethodCallExpr.java:315)
at com.zoho.mickey.refactorer.core.Test.main(Test.java:57)

Karthi G
@karthi_:matrix.org
[m]

Hi Team
What is the reason for below error

Exception in thread "main" java.lang.IllegalStateException: The node is not inserted in a CompilationUnit
at com.github.javaparser.ast.Node.lambda$getSymbolResolver$8(Node.java:790)
at java.util.Optional.orElseThrow(Optional.java:290)
at com.github.javaparser.ast.Node.getSymbolResolver(Node.java:790)
at com.github.javaparser.ast.type.ClassOrInterfaceType.resolve(ClassOrInterfaceType.java:315)
at com.github.javaparser.ast.type.ClassOrInterfaceType.resolve(ClassOrInterfaceType.java:64)
at com.zoho.mickey.refactorer.core.Test.lambda$0(Test.java:49)
at java.util.Optional.ifPresent(Optional.java:159)
at com.zoho.mickey.refactorer.core.Test.main(Test.java:43)

1 reply
peterphan
@peterphan

Hello, I'm having trouble with the LexicalPreservingPrinter not preserving AST changes for VariableDeclarations. See https://github.com/peterphan/refactor-with-javaparser/tree/master for more details

Anyone know if I'm doing something wrong or whether this is a bug with the printer?

1 reply
GrigLog
@GrigLog
Hello. Is there any functionality in JavaParser to compare ASTrees? The project I work with has got like half of its names changed between versions and I want to make a list of all renamings, by detecting similar files.
1 reply
Chinese News Board
@ralphcnb_twitter
    public static void syntaxHiLite() throws Exception
    {   
        String                  srcStr  = FileRW.loadFileToString("Torello/Java/Q.java");
        CompilationUnit         cu      = StaticJavaParser.parse(srcStr);
        Optional<TokenRange>    tokROpt = cu.getTokenRange();
        TokenRange              tr      = tokROpt.isPresent() ? tokROpt.get() : null;  // THROWS NPE!
        JavaToken               tok     = tr.getBegin();
        Category                cat     = tok.getCategory();

        do
        {
            Optional<JavaToken> optTok      = tok.getNextToken();
            boolean             printColor  = true;

            switch (tok.getCategory())
            {
                case COMMENT    :   System.out.print(C.BGREEN); break;
                case IDENTIFIER :   System.out.print(C.BCYAN); break;
                case KEYWORD    :   System.out.print(C.BYELLOW); break;
                case LITERAL    :   System.out.print(C.BRED); break;
                case OPERATOR   :   System.out.print(C.BBLUE); break;
                default         :   printColor = false;
            }

            System.out.print(tok.asString() + (printColor ? C.RESET : ""));

            tok = optTok.isPresent() ? optTok.get() : null;
            cat = (tok != null) ? tok.getCategory() : null;
        } 
        while (tok != null);
    }
Is That right? That's all it would be??? I started on this an hour ago. I am surprised. Did I miss something?
It seem to be working just fine...
AndreaMatteucci
@AndreaMatteucci
Hi, i have a question: How can I read a package with java parser?
1 reply
burcualper
@burcualper
hello, ı want to see the if the methods are public or not what should I do basically I will check each attribute and methods declarations public static private
3 replies
Chinese News Board
@ralphcnb_twitter

So... If I wanted to insert a little "deal-y" (the technical term, since this is one of Dallas Brain-Control's ideas, not mine, but...), anyway, if I wanted a little notice of some-kind indicating - for all the Exception's that I've written knowing whether the Exception was a Checked or a Runtime Exception - that would be a task for the Symbol-Solver part of Java Parser? There's no way to find that type of question out other than be going through the class inheritance list (which demands using the Symbol Solver). Is that correct? I would be inserting a little HTML <IMG> and maybe a text-notice into my Java Doc HTML Pages... It would have to be a Symbol-Solver extension?

Also, for Symbol Solver simply giving it a CLASSPATH isn't really how it works? I was looking at the book for that last week before the weekend. I just love 'their' ideas.

9 replies
Navneet
@aaaaaaax777:matrix.org
[m]
Hello everyone. I just started working with javaparser typesolvers in order to get the class of the method calls. Some of the calls are resolved just fine while others give Unresolved symbol exception. From what I have observed so far it seems to be happening with the methods that are defined within the class itself. Any pointers would be appreciated.
2 replies
Karthi G
@karthi_:matrix.org
[m]

Hi,

I'm using compilationUnit.getStorage().get().save() api to persist my changes to file. My query is on the implementation part of api. Whether the api will rewrite the entire file or it will rewrite only the specific change to the file

2 replies
sunilhyd
@sunilhyd
I was trying to build JavaParserVisited by running mvn clean package I get and error
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 28 source files to E:\javademo\javaparser-visited-master\target\classes
[INFO] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java: Some input files use or override a deprecated API.
[INFO] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java: Recompile with -Xlint:deprecation for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java:[10,37] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: package com.github.javaparser.printer
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintComplete.java:[6,37] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: package com.github.javaparser.printer
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java:[21,9] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: class org.javaparser.examples.chapter4.PrettyPrintVisitorComplete
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java:[21,47] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: class org.javaparser.examples.chapter4.PrettyPrintVisitorComplete
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintVisitorComplete.java:[23,54] package PrettyPrinterConfiguration does not exist
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintComplete.java:[16,9] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: class org.javaparser.examples.chapter4.PrettyPrintComplete
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintComplete.java:[16,47] cannot find symbol
symbol: class PrettyPrinterConfiguration
location: class org.javaparser.examples.chapter4.PrettyPrintComplete
[ERROR] /E:/javademo/javaparser-visited-master/src/main/java/org/javaparser/examples/chapter4/PrettyPrintComplete.java:[18,54] package PrettyPrinterConfiguration does not exist
[INFO] 8 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I am using Java18. Is the Compiler the issue? Or is the mvn command wrong?
12 replies
TIanyi
@IanyiT_twitter
Hi, I am an undergraduate student studying in china. And want to step into translation due to interests.
I think this book may be a good start, but I am not sure if authors will agree it. If it is ok to translate it and put it on the github?
1 reply