Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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
Berk Yamanoğlu
@yamanogluberk
Hey, I am using JavaParser to analyze projects written in java 1.8. By analyzing I mean creating a graph that contains information about the project like: Class/Interface/Enums, relationship between those, members of those(fields, methods), for each method accessed fields and methods and which class they belong to etc. I heavily make use of the SymbolSolver but there are some cases that I am stuck. Anyone with information and experience that can help me or guide me maybe?
5 replies
Ayush
@Ayush-D
Hey there, I am using JavaParser to store the AST for the whole code base(Multiple Java files), is there a way I can do this and apply operation on that? As far as I have seen we only are taking one file in CompilationUnit.
Thanks in Advance!!
5 replies
Ayush
@Ayush-D
Hey guys, I have to map the log lines with the method name in the class, but in the compilation unit and printing that using JsonPrinter, doesn't gives me line number of the methods, Like which methods starts from Line [x, y]. So how can I map the logs with the methods now?
2 replies
Ayush
@Ayush-D

Hey Team, I have to find out on which line of method the exception occurred in my programme? Also will I be able to get this in java code where I am not using exception handling techniques(try, catch, throw..). Can stack trace be also useful here to get these information or AST will do the work?

Thanks in Advance)

Ayush
@Ayush-D

Like this code will return NullPointerException: So can we get this information in AST ?

String s=null; System.out.println(s.length());//NullPointerException

OR

int a=50/0;
This line returns ArithmeticException

2 replies
Chinese News Board
@ralphcnb_twitter

Tangentially Related ... I'm buried in Java-Doc stuff. It's lots of Fields, Methods, Constructors & Annotations - and HTML - CSS, but it has been java.lang.reflect Lately. If anyone named Dan or Danny have done this before... JavaParser must use '.class' Files somewhere, right? Question: If I have a '.class' file, but it is in some "Random Directory" - such that none of the normal java.lang.ClassLoader classes can load it with forName(...) does anybody know how to ask that '.class' File what the name of the Package is, and what it's class-name is? Right now, this is what I've got: readClass(...))

If anyone knows anything about it, I'd be all-ears. As usual - it is not on Stack-Underflow (If have checked, and googled it)

  • Sincerely, Ralph Torello

P.S. Gitter doesn't seem to like my Java Doc URL which has parenthesis... If you want to see it, scroll to 'readClass(...)'

11 replies
Chinese News Board
@ralphcnb_twitter

The 'Invokes:' point is right here ... He wrote it in Kotlin but it looks pretty straight-forward. It's not writing this code that is so difficult - it's incorporating it into a project, and documenting it, and explaining it, and making sure the CSS margin: and 'padding:' are all properly aligned, and then checking the spelling & the grammar (so that other people can read it) and then organizing it all so that somebody else on planet-earth earth has a prayer of understanding what you have (Not Spaghetti). The code is literally already written right here:

Tomasetti Using Symbol Solver Page

Given Tomasetti's Example on his Web-Page, all I really have to do is write a Converter that takes a 'MethodDeclaration' (or 'FieldDeclaration', or 'ConstructorDeclaration') returned by the JavaParserFacade that he has written and convert it into an HTML <A HREF=...> Anchor-URL, which would be the easiest thing in the world.

In order to do the reverse ('Invoked By:'), I would just build a table of HTML Anchor-URL's (as 'java.lang.String'), and save those in a java.util.TreeMap. that stores every time a method invokes something or references something, and publish that to HTML.

Ayush
@Ayush-D
Hey Team, How to get the arguments type of a methods using JavaParser, if we have the line number from stack trace?
Like:
MethodName(int, A, float)
--> So we will get the int, A and float
Chinese News Board
@ralphcnb_twitter
An Exception Stack-Trace and the parameters to a Method-Call have absolutely nothing to do with each-other!
Danny van Bruggen
@matozoid
True, but you can find what is on a line - every node has a line number information, and you can see if one of thr nodes on the line is a method call. You can find the arguments there, but you are asking for types like int?
8 replies
Chinese News Board
@ralphcnb_twitter
O.K. How on earth ... If you are testing your code, coming up with inputs and then executing them is the work... How on earth are you going to get Java Parser to execute code to see what causes an exception. 'They' have been playing that to my brain since he asked about checking for exception throws two weeks on Gitter. Is there an example code of that anywhere on the Tomasetti Page?
1 reply
Sachin Pandey
@sachinp328

Hey All,
for a given method i wanted to find full qualified name of the parameters.

NodeList<Parameter> parameters = member.asMethodDeclaration().getParameters();

suppose parameter is of file type i want the output to be java.io.File

how can i get that any suggestions ?

29 replies
Macumba Macaca
@macumbamacaca:matrix.org
[m]
Karthi G
@karthi_:matrix.org
[m]

Hi Team

I'm trying to parse nested directory structure to get compilation units for it and getting Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

How to get rid of this? Please find below the code I use

                ParserConfiguration parserConfiguration = new ParserConfiguration()
                .setSymbolResolver(new JavaSymbolSolver(typeSolver));
        SourceRoot sourceRoot = new SourceRoot(hamcrestCoreDir.toPath());
        sourceRoot.setParserConfiguration(parserConfiguration);
        List<ParseResult<CompilationUnit>> parseResults = null;
        parseResults = sourceRoot.tryToParse("");
        compilationUnits = parseResults.stream().filter(ParseResult::isSuccessful)
                .map(r -> r.getResult().get())
                .collect(Collectors.toMap(c -> c.getStorage().get().getPath().toString(), c -> c));
2 replies
Ayush
@Ayush-D
Hey JP team, How we can check using AST that parameter value is null is the method call?
Chinese News Board
@ralphcnb_twitter
Is this it? This is it, right? They just read this to me in ear-drum-implant (I hate it): Node.finalAll(MethodCallExpr.class)), MethodCallExpr, getArguments), Expression, isNullLiteralExpr)
NOTE: Gitter cannot link to method-links in a JavaDoc Page because the URL's have parenthesis in them... I'm leaving it as is.
Chinese News Board
@ralphcnb_twitter
ACTUALLY: If you replace the parenthesis, '(' and ')' with the URL Escape Sequences '%28' and '%29' it works.

Node.finalAll(MethodCallExpr.class),
MethodCallExpr,
getArguments,
Expression,
isNullLiteralExpr
Ayush
@Ayush-D
I am actually trying to check if a parameter is being passed null value in a function call from another class so for this what do you suggest? As this information would not be present in the AST of my class.
And also please let me know if there is some way to retrieve values of parameters being passed to functions during runtime.
4 replies
kanran2024
@kanran2024
can this parser be used to provide content assist for the java language?
devfat
@devfat
Can javaparser be used to modify pom.xml? Such as update dependencies version
Björn Kautler
@Vampire
How should it? JavaParser is for parsing and generating Java code. pom.xml is XML.
Ayush
@Ayush-D

Can I find all the occurrence of an object using JavaParser? How can I filter this information in AST?

Example:

Class A = null;
if (A.someMethod() ) {
... do something
}
if (B.someMethod() ) {
... do something
}
if (A.someOtherMethod() ) {
... do something
}

So we should get A object is used in 2 places. {additional} can we get line numbers also?

4 replies
abego
@abego

I see in JavaParserClassDeclaration this code:

    @Deprecated
    @Override
    public SymbolReference<TypeDeclaration> solveType(String name, TypeSolver typeSolver) {...}

If this method solveType is deprecated what is the suggested alternative?

1 reply
Karthi G
@karthi_:matrix.org
[m]

Hi Team,

I am currently trying a serialize and de-serialize node to write and read from file. Once I de-serialize the node when I call findCompilationUnit() api it returns empty.
Is there a way to get the compilation unit of the node after deserialization?
Also let me know if there is a option to serialize and de-serialize node without losing its compilation unit?

3 replies
Zueyjajie
@Zueyjajie
Hi, could you please tell me, is Java parser requires jdk or only jre?
1 reply
Chinese News Board
@ralphcnb_twitter

This has happened a few times before, and I just go ahead and change it, but I THINK (not sure) this is a bug. Java seems to have no problems (neither compiler-errors, nor warnings) about private methods in an interface... JavaParser always complains about it, though...

The Line where it says 'private' is not allowed here. is complaining about a private method in an interface. It has
done this several times in the past few years, and I always just go and make it something like default

Upgrading File: javadoc/Torello/HTML/Tools/JavaDoc/HiLiter.html
Processing File: [Torello/HTML/Tools/JavaDoc/HiLiter.java], (Java Source Code File):
    Processor [MainFilesProcessor], Fatal Error:  Exception Thrown:
    ************************************************************************
    THROWN: com.github.javaparser.ParseProblemException
    Throwable.getMessage():
        (line 153,col 5) 'private' is not allowed here.

    StackTrace:
        260:  com.github.javaparser.StaticJavaParser.handleResult()
        229:  com.github.javaparser.StaticJavaParser.parse()
        110:  Torello.HTML.Tools.JavaDoc.JavaSourceCodeFile.HATRED()
        172:  Torello.HTML.Tools.JavaDoc.JavaSourceCodeFile.<init>()
        603:  Torello.HTML.Tools.JavaDoc.MainFilesProcessor.run()
        318:  Torello.HTML.Tools.JavaDoc.MainFilesProcessor.runAll()
        1163: Torello.HTML.Tools.JavaDoc.Upgrade.upgrade()
        107:  Torello.Build.Stages.S03Upgrade.upgrade()
        70:   Torello.Build.Build.main()
8 replies
abego
@abego

I am currently working on a large software migration project and verify the quality of the generated Java code with some tools that are using JavaParser. While writing the actual checks with JavaParser was quite easy it turned out performance was the real problem. Processing the code base (more than 20 000 classes) took several hours to complete.

By profiling my applications I identified several places in the current JavaParser code that affect the performance and memory usage. And I came up with some solutions that sped up the runtime significantly. E.g. with three little changes I was able to reduce the time for one tool run from more than 2 hours to less than 15 minutes.

I published my enhancements to the JavaParser code and created pull requests.

Let me know what you think,

Udo

(javaparser/javaparser#3655 javaparser/javaparser#3656 javaparser/javaparser#3657 javaparser/javaparser#3658 )

3 replies
Saif Ur Rahman
@saifsmailbox98
Hi
Is the JavaParser: Visited ebook freely available?
(without the membership fee)
1 reply
Björn Kautler
@Vampire
What membership fee? You pay a one-time price and you can freely choose the amount, so choose 0 if you don't want to reward the authors.