|
FAQ
Frequent asked questions
Featured
Yes, the JavaParser don't initialize empty lists. It will be needed to check if it is null when accessing the getter. To initialize a list is necessary to call the setter method with a instance of a List. |
► Sign in to add a comment
Why not initialise List instance variables to Collections.emptyList()? Then client code doesn't have to worry about null checks.
I totally agree, they should return an empty list. There is actually an item dedicated to this in Effective Java. Returning null forces the user to check for null — it would be preferable to return an empty list so iterators and for-each loops just work.
does the parser deal with annotations values? specifically can i get the default value?
the comments(not javadoc) will be lost after 【JavaParser?.parse()】
so, How could I get comments(not javadoc)?
Can anybody help me to use java parser(japa.parser)? and please give some example code to use visitor and expressions and also give some example code how to use when to use the methods and classes of java parser(japa.parser) Please send me the code to my mail ID jebarlin@gmail.com
Q: What is the purpose of the data property in the Node class? Why is it defined as java.lang.Object? The comment says "This attribute can store additional information from semantic analysis." But that doesn't help much. Eclipse finds no references to either of the field, its getter or its setter.
A: This property was designed to do exactly what its javadoc says. There is no reference to this attribute because this project does not implement any kind of semantic analysis. But other projects can use this attribute to associate information to the AST nodes while visiting them. The type of this attribute is java.lang.Object to let compilers implementers be free to store any data type in there. For example, I have written a compiler and used this attribute to store the name bindings and data type bindings.
@jgesser. Thanks for a quick response. Now I see what was meant.
Q: there're the ClassOrInterfaceType? and ReferenceType? type classes. how are they related? they both derive from Type, but there's no inheritance between them. and now i try to check a type of a method parameter against a class type (ClassOrInterfaceType?) and i get it's not an instanceof, but it's an instanceof ReferenceType?; where should i use which?
How would I go about adding or deleting statements from a CompilationUnit??
Hi. Great parser! But I found one bug. Parameters with arrays are not handled. They come in as the primitive types. try compiling something like "public void calculate(double d){}" and you'll see what I mean. The only way to tell if they are arrays is to do .toString().contains("")
@Mark, your example wih calculate(double) im assuming shows the "after" whats the before ?
Is there a way to load any given node from a Java code snippet? That is, to load a partial branch of AST?
Currently, I only see a way to generate a CompilationUnit? out of a .java file.
Currently you have to parse a CompilationUnit?.
But you can create an issue for this suggestion.
is there any way of telling the start line of the method in a MethodCallExpression? for instance if the following code is parsed:
(each on an individual line) then i don't know how to find out on which line the name of the method (doStuff) is, since it only is stored as a string in the MethodCallExpression???, is there any way to do this?
something that would also help me is a way to keep the \n chars when parsing, because then i could simply count for those
I would still need an answer to the above question, is there a solution to this problem?
Because of some Syntax changes in Java 7 (Multiple exception catching, empty generic braces on the initialization of generic objects and switch case statements with Strings), will you provide an update to support also Java7?