public class JavaParserUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JavaParserUtils.StringLiteralConcatenateVisitor
Visitor that combines added String literals, see
concatenateAddedStringLiterals(com.github.javaparser.ast.Node) . |
Constructor and Description |
---|
JavaParserUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
clearAnnotations(com.github.javaparser.ast.Node node)
Side-effects
node by removing all annotations from anywhere inside its subtree. |
static void |
concatenateAddedStringLiterals(com.github.javaparser.ast.Node node)
Side-effects node by combining any added String literals in node's subtree into their
concatenation.
|
static String |
getFullyQualifiedName(com.github.javaparser.ast.body.TypeDeclaration<?> type,
com.github.javaparser.ast.CompilationUnit compilationUnit)
Returns the fully qualified name of a type appearing in a given compilation unit.
|
static com.github.javaparser.ast.body.TypeDeclaration<?> |
getTypeDeclarationByName(com.github.javaparser.ast.CompilationUnit root,
String name)
Given the compilation unit node for a source file, returns the top level type definition with
the given name.
|
public static com.github.javaparser.ast.body.TypeDeclaration<?> getTypeDeclarationByName(com.github.javaparser.ast.CompilationUnit root, String name)
root
- compilation unit to searchname
- name of a top level type declaration in root
root
named name
public static String getFullyQualifiedName(com.github.javaparser.ast.body.TypeDeclaration<?> type, com.github.javaparser.ast.CompilationUnit compilationUnit)
type
- a type declarationcompilationUnit
- the compilation unit containing type
type
if compilationUnit
contains a package
declaration, or just the name of type
otherwisepublic static void clearAnnotations(com.github.javaparser.ast.Node node)
node
by removing all annotations from anywhere inside its subtree.node
- a JavaParser Nodepublic static void concatenateAddedStringLiterals(com.github.javaparser.ast.Node node)
"a" + "b"
becomes "ab"
. This occurs
even if, when reading from left to right, the two string literals are not added directly. For
example, the expression 1 + "a" + "b"
parses as (1 + "a") + "b"
}, but it is
transformed into 1 + "ab"
.
This is the same transformation performed by javac automatically. Javac seems to ignore string literals surrounded in parentheses, so this method does as well.
node
- a JavaParser Node