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
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...
<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
??
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...
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
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
@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.
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.
Hi
How to check if db connection is properly closed using Javaparser? Kindly brief on the steps involved
Hi Team
I need to get nodes from specific starting position to end position. How to do that?
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
});
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)
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)
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?
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);
}
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.
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