Class Ast
- Object
-
- Ast
-
-
Constructor Summary
Constructors Constructor Description Ast()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NodeToken
addComment(Node n, String comment)
static NodeToken
addComment(Node n, String comment, boolean first)
static void
addComment(Node n, NodeToken comment)
static void
addComment(Node n, NodeToken comment, boolean first)
Add the comment to the first regular token in the tree, as a "special token" (comment).static void
addDeclaration(ClassOrInterfaceBody c, ClassOrInterfaceBodyDeclaration d)
static void
addFirstSpecial(NodeToken n, NodeToken s)
Adds the comment to the first regular token in the tree, *before* all other special tokens.static void
addImport(CompilationUnit u, ImportDeclaration i)
static void
addNthSpecial(NodeToken n, NodeToken s, int i)
Adds the comment to the first regular token in the tree, before the ith special token.static void
applyVisitorInsertComments(String javafilename, Node root, Writer output, AnnotateVisitor visitor)
static void
applyVisitorReformat(Reader input, Writer output, Visitor visitor)
static PrimaryExpression
assignment2primaryexpression(Expression n)
static String
classnameForSourceOutput(Class<?> c)
static boolean
contains(Node n, String s)
static Node
create(String type, Class<?>[] argTypes, Object[] args, String stringRep)
static Node
create(String type, String stringRep)
Creates an AST from a String.static String
fieldName(Name n)
static String
fieldName(PrimaryExpression pe)
static void
findLineAndCol(Node n, NodeToken comment, boolean first)
Add the comment to the first regular token in the tree.static String
format(Node n)
static String
formatCurrentLine(Node n)
static String
formatEntireTree(Node n)
static String
getBody(MethodDeclaration m)
static Class<?>
getClass(@ClassGetName String s)
static Class<?>
getClass(Node n)
static @BinaryName String
getClassName(Node d)
Return the fully qualified name of the class containing the node.static @Nullable @BinaryName String
getClassNameForType(TypeDeclaration d)
Returns the classname if the given type declaration declares a ClassOrInterfaceDeclaration.static Constructor<?>
getConstructor(Class<?> c, ConstructorDeclaration constructordecl)
static Constructor<?>
getConstructor(ConstructorDeclaration constructordecl)
static String
getFullName(MethodDeclaration method)
static String
getFullSignature(MethodDeclaration method)
static List<Invariant>
getInvariants(PptTopLevel ppt, PptMap ppt_map)
This code is taken from and modified from daikon.PrintInvariants.print_invariants.static Method
getMethod(Class<?> c, MethodDeclaration methoddecl)
static Method
getMethod(MethodDeclaration methoddecl)
static String
getMethodDeclarator(MethodDeclaration m)
static Modifiers
getModifiers(ClassOrInterfaceDeclaration n)
static Modifiers
getModifiers(MethodDeclaration n)
static String
getName(ConstructorDeclaration m)
static String
getName(FormalParameter p)
static String
getName(MethodDeclaration m)
static @Nullable String
getPackage(CompilationUnit u)
static List<FormalParameter>
getParameters(ConstructorDeclaration cd)
static List<FormalParameter>
getParameters(MethodDeclaration m)
static List<FormalParameter>
getParametersNoImplicit(ConstructorDeclaration cd)
static @Nullable Node
getParent(Class<?> type, Node child)
static Enumeration
getPrimarySuffixes(PrimaryExpression p)
Returns an Enumeration of PrimarySuffix objects (but the static type of the elements is only known to be Node).static String
getReturnType(MethodDeclaration m)
static String
getType(FormalParameter fp)
static Set<String>
getVariableNames(Node expr)
static boolean
isAccessModifier(String s)
static boolean
isArray(Type n)
static boolean
isImplementation(Class<?> c, MethodDeclaration methdecl)
static boolean
isImplementation(MethodDeclaration methdecl)
static boolean
isInAnonymousClass(Node node)
static boolean
isInner(ClassOrInterfaceDeclaration n)
static boolean
isInterface(ClassOrInterfaceBody n)
static boolean
isInterface(ClassOrInterfaceDeclaration n)
static boolean
isMain(MethodDeclaration md)
Return true if this is the main method for this class.static boolean
isOverride(Class<?> c, MethodDeclaration methdecl)
static boolean
isOverride(MethodDeclaration methdecl)
static boolean
isPrimitive(Type n)
static boolean
isReference(Type n)
static boolean
isStatic(ClassOrInterfaceDeclaration n)
static boolean
isStatic(MethodDeclaration n)
static boolean
modifierPresent(Modifiers modifiers, String modifierString)
static NodeToken
nodeTokenAfter(Node n)
static boolean
paramsMatch(Class<?>[] params, List<FormalParameter> ast_params)
static String
quickFixForInternalComment(String s)
This method translates a line likestatic void
removeAnnotations(MethodDeclaration m)
static void
removeMethodDeclAnnotations(MethodDeclaration method)
static String
removeWhitespace(String arg)
Removes whitespace around punctuation: ., (, ), [, ].static void
setAccess(MethodDeclaration m, String access)
static void
setBody(MethodDeclaration m, String body)
static void
setName(MethodDeclaration m, String name)
-
-
-
Constructor Detail
-
Ast
public Ast()
-
-
Method Detail
-
applyVisitorInsertComments
public static void applyVisitorInsertComments(String javafilename, Node root, Writer output, AnnotateVisitor visitor)
-
applyVisitorReformat
public static void applyVisitorReformat(Reader input, Writer output, Visitor visitor)
-
formatEntireTree
public static String formatEntireTree(Node n)
-
quickFixForInternalComment
public static String quickFixForInternalComment(String s)
This method translates a line like
intoa statement; // a comment
a statement; // a comment//
- Parameters:
s
- a Java code line that might contain a comment- Returns:
- the line with its comment, if any, tweaked
-
formatCurrentLine
public static String formatCurrentLine(Node n)
-
create
public static Node create(String type, String stringRep)
Creates an AST from a String.- Parameters:
type
- the type of the resultstringRep
- the string to parse- Returns:
- an AST created from the string
-
create
public static Node create(String type, Class<?>[] argTypes, Object[] args, String stringRep)
-
isAccessModifier
public static boolean isAccessModifier(String s)
-
getName
public static String getName(FormalParameter p)
-
getType
public static String getType(FormalParameter fp)
-
getName
public static String getName(MethodDeclaration m)
-
getName
public static String getName(ConstructorDeclaration m)
-
getPackage
public static @Nullable String getPackage(CompilationUnit u)
-
getFullName
public static String getFullName(MethodDeclaration method)
-
getFullSignature
public static String getFullSignature(MethodDeclaration method)
-
getClassNameForType
public static @Nullable @BinaryName String getClassNameForType(TypeDeclaration d)
Returns the classname if the given type declaration declares a ClassOrInterfaceDeclaration. Otherwise returns null.
-
getClassName
public static @BinaryName String getClassName(Node d)
Return the fully qualified name of the class containing the node.
-
setName
public static void setName(MethodDeclaration m, String name)
-
assignment2primaryexpression
public static PrimaryExpression assignment2primaryexpression(Expression n)
-
fieldName
public static String fieldName(PrimaryExpression pe)
-
addComment
public static NodeToken addComment(Node n, String comment)
-
addComment
public static NodeToken addComment(Node n, String comment, boolean first)
-
addComment
public static void addComment(Node n, NodeToken comment)
-
addComment
public static void addComment(Node n, NodeToken comment, boolean first)
Add the comment to the first regular token in the tree, as a "special token" (comment).If first is true, then it is inserted before all other special tokens; otherwise, it is inserted after them.
Postcondition (make sure you preserve it if you modify this method): comment.beginLine and comment.beginColumn have been assigned the line and column number where this comment will go.
-
findLineAndCol
public static void findLineAndCol(Node n, NodeToken comment, boolean first)
Add the comment to the first regular token in the tree. If first is true, then it is inserted before all other special tokens; otherwise, it is inserted after them.Exception: If first is true, may heuristically place the comment it in the middle of the list of special tokens (comments), in order to place it at the same column as the real node.
Postcondition (make sure you preserve it if you modify this method): comment.beginLine and comment.beginColumn have been assigned the line and column number where this comment will go.
-
addNthSpecial
public static void addNthSpecial(NodeToken n, NodeToken s, int i)
Adds the comment to the first regular token in the tree, before the ith special token.
-
addFirstSpecial
public static void addFirstSpecial(NodeToken n, NodeToken s)
Adds the comment to the first regular token in the tree, *before* all other special tokens.
-
nodeTokenAfter
public static NodeToken nodeTokenAfter(Node n)
-
removeAnnotations
public static void removeAnnotations(MethodDeclaration m)
-
removeWhitespace
public static String removeWhitespace(String arg)
Removes whitespace around punctuation: ., (, ), [, ].- Parameters:
arg
- a string- Returns:
- the string with whitespace removed
-
getMethod
public static Method getMethod(MethodDeclaration methoddecl)
-
getMethod
public static Method getMethod(Class<?> c, MethodDeclaration methoddecl)
-
getConstructor
public static Constructor<?> getConstructor(ConstructorDeclaration constructordecl)
-
getConstructor
public static Constructor<?> getConstructor(Class<?> c, ConstructorDeclaration constructordecl)
-
paramsMatch
public static boolean paramsMatch(Class<?>[] params, List<FormalParameter> ast_params)
-
isOverride
public static boolean isOverride(MethodDeclaration methdecl)
-
isOverride
public static boolean isOverride(Class<?> c, MethodDeclaration methdecl)
-
isImplementation
public static boolean isImplementation(MethodDeclaration methdecl)
-
isImplementation
public static boolean isImplementation(Class<?> c, MethodDeclaration methdecl)
-
addDeclaration
public static void addDeclaration(ClassOrInterfaceBody c, ClassOrInterfaceBodyDeclaration d)
-
setAccess
public static void setAccess(MethodDeclaration m, String access)
-
removeMethodDeclAnnotations
public static void removeMethodDeclAnnotations(MethodDeclaration method)
-
setBody
public static void setBody(MethodDeclaration m, String body)
-
getBody
public static String getBody(MethodDeclaration m)
-
getReturnType
public static String getReturnType(MethodDeclaration m)
-
getMethodDeclarator
public static String getMethodDeclarator(MethodDeclaration m)
-
getParameters
public static List<FormalParameter> getParameters(MethodDeclaration m)
-
getParametersNoImplicit
public static List<FormalParameter> getParametersNoImplicit(ConstructorDeclaration cd)
-
getParameters
public static List<FormalParameter> getParameters(ConstructorDeclaration cd)
-
addImport
public static void addImport(CompilationUnit u, ImportDeclaration i)
-
getVariableNames
public static Set<String> getVariableNames(Node expr)
-
getPrimarySuffixes
public static Enumeration getPrimarySuffixes(PrimaryExpression p)
Returns an Enumeration of PrimarySuffix objects (but the static type of the elements is only known to be Node).
-
isMain
public static boolean isMain(MethodDeclaration md)
Return true if this is the main method for this class.
-
getInvariants
public static List<Invariant> getInvariants(PptTopLevel ppt, PptMap ppt_map)
This code is taken from and modified from daikon.PrintInvariants.print_invariants. The main modification is that instead of printing the invariants, we return a list of them. modifications involve removing code that I don't need here, like printing of debugging info.[[ TODO: instead of duplicating code, you should add this method to PrintInvariants (or wherever it belongs) and have PrintInvariants.print_invariants call it. ]]
-
isStatic
public static boolean isStatic(ClassOrInterfaceDeclaration n)
-
isStatic
public static boolean isStatic(MethodDeclaration n)
-
getModifiers
public static Modifiers getModifiers(ClassOrInterfaceDeclaration n)
-
getModifiers
public static Modifiers getModifiers(MethodDeclaration n)
-
modifierPresent
public static boolean modifierPresent(Modifiers modifiers, String modifierString)
-
isInner
public static boolean isInner(ClassOrInterfaceDeclaration n)
-
isInAnonymousClass
public static boolean isInAnonymousClass(Node node)
-
isInterface
public static boolean isInterface(ClassOrInterfaceBody n)
-
isInterface
public static boolean isInterface(ClassOrInterfaceDeclaration n)
-
isPrimitive
public static boolean isPrimitive(Type n)
-
isReference
public static boolean isReference(Type n)
-
classnameForSourceOutput
public static String classnameForSourceOutput(Class<?> c)
-
-