Package org.jtool.srcmodel
Class JavaElementUtil
java.lang.Object
org.jtool.srcmodel.JavaElementUtil
A root object for a Java model element.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.jdt.core.dom.ASTNode
findAncestorNode
(org.eclipse.jdt.core.dom.ASTNode node, int sort) Finds an ancestor of an AST node for this model element, having a specified sort.static JavaClass
findDeclaringClass
(org.eclipse.jdt.core.dom.ITypeBinding tbinding, JavaProject jproject) Finds a class having given type binding information within a given project.static JavaField
findDeclaringField
(org.eclipse.jdt.core.dom.IVariableBinding vbinding, JavaProject jproject) Finds a having given variable binding information within a given project.static JavaMethod
findDeclaringMethod
(org.eclipse.jdt.core.dom.IMethodBinding mbinding, JavaProject jproject) Finds a method having given method binding information within a given project.static JavaClass
findEnclosingClass
(org.eclipse.jdt.core.dom.ASTNode node, JavaProject jproject) Finds a class that encloses a given model element within a given project.static JavaMethod
findEnclosingMethod
(org.eclipse.jdt.core.dom.ASTNode node, JavaProject jproject) Finds a method that encloses a given model element within a given project.static QualifiedName
findQualifiedName
(org.eclipse.jdt.core.dom.ITypeBinding tbinding) Finds the fully-qualified name of a class having given type binding information.static boolean
isPrimitiveType
(String type) Tests if the string indicates the primitive type.static boolean
Tests if the string indicates thevoid
type.
-
Method Details
-
findQualifiedName
Finds the fully-qualified name of a class having given type binding information.- Parameters:
tbinding
- the type binding information on the class- Returns:
- the fully-qualified name
-
findDeclaringClass
public static JavaClass findDeclaringClass(org.eclipse.jdt.core.dom.ITypeBinding tbinding, JavaProject jproject) Finds a class having given type binding information within a given project.- Parameters:
tbinding
- the type binding information on the classjproject
- the project which the class might exist in- Returns:
- the found class, or
null
if no class is found
-
findDeclaringMethod
public static JavaMethod findDeclaringMethod(org.eclipse.jdt.core.dom.IMethodBinding mbinding, JavaProject jproject) Finds a method having given method binding information within a given project.- Parameters:
mbinding
- the method binding information on the methodjproject
- the project which the class might exist in- Returns:
- the found method, or
null
if no method is found
-
findDeclaringField
public static JavaField findDeclaringField(org.eclipse.jdt.core.dom.IVariableBinding vbinding, JavaProject jproject) Finds a having given variable binding information within a given project.- Parameters:
vbinding
- the variable binding information on the fieldjproject
- the project which the class might exist in- Returns:
- the found field, or
null
if no field is found
-
findAncestorNode
public static org.eclipse.jdt.core.dom.ASTNode findAncestorNode(org.eclipse.jdt.core.dom.ASTNode node, int sort) Finds an ancestor of an AST node for this model element, having a specified sort.- Parameters:
node
- the base AST nodesort
- the value representing the sort (e.g.,ASTNode.TYPE_DECLARATION
for the type declaration)- Returns:
- the found ancestor, or
null
if no AST node is found
-
findEnclosingClass
public static JavaClass findEnclosingClass(org.eclipse.jdt.core.dom.ASTNode node, JavaProject jproject) Finds a class that encloses a given model element within a given project.- Parameters:
node
- the enclosed model elementjproject
- the project that the model element exists- Returns:
- the found class, or
null
if there is no class enclosing the model element
-
findEnclosingMethod
public static JavaMethod findEnclosingMethod(org.eclipse.jdt.core.dom.ASTNode node, JavaProject jproject) Finds a method that encloses a given model element within a given project.- Parameters:
node
- the enclosed model elementjproject
- the project that the model element exists- Returns:
- the found method, or
null
if there is no method enclosing the model element
-
isVoid
Tests if the string indicates thevoid
type.- Parameters:
type
- the type string- Returns:
true
if the string indicates thevoid
type, otherwisefalse
-
isPrimitiveType
Tests if the string indicates the primitive type.- Parameters:
type
- the type string- Returns:
true
if the string indicates the primitive type, otherwisefalse
-