Package com.iizigo.java.refactor
Class RefactorHelper
java.lang.Object
com.iizigo.java.refactor.RefactorHelper
Utility class for refactoring: adding, removing and updating annotations and member value pairs.
- Author:
- Christopher Mindus
- Method SummaryModifier and TypeMethodDescription- static void- addAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, String annotationFQN, String param, String value, boolean allowMultiple) Refactor operation that adds an annotation to an element with a value/pair initialized with a StringLiteral value.- static void- addAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Adds the given- Annotationto the- IJavaElement.- static void- addEventMethod- (org.eclipse.jdt.core.IType type, String methodName, AnnotationType annotation, String refName) Refactor operation to add an event method with an annotation.- static voidAdds an import to the compilation unit of the given- IJavaElement.- static void- addInterface- (org.eclipse.jdt.core.IType type, String interfaceFQN) Refactor operation that adds an interface to an element.- static void- addMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) Adds the- MemberValuePairto the- NormalAnnotation.- static boolean- compareFieldNames- (org.eclipse.jdt.core.dom.FieldDeclaration fieldDeclaration, org.eclipse.jdt.core.IField field) Compares the- FieldDeclarationand- IField.- static boolean- compareMethods- (org.eclipse.jdt.core.dom.MethodDeclaration methodOne, org.eclipse.jdt.core.dom.MethodDeclaration methodTwo) Compares the two- MethodDeclaration.- static boolean- compareMethods- (org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration, org.eclipse.jdt.core.IMethod method) Compares the- MethodDeclarationand- IMethod.- static boolean- compareTypeNames- (org.eclipse.jdt.core.dom.AbstractTypeDeclaration abstractTypeDeclaration, org.eclipse.jdt.core.IType type) Compares the- AbstractTypeDeclarationand- IType.- static org.eclipse.text.edits.TextEdit- createAddAnnotationTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Creates a- TextEditobject representing the add annotation change to the source code of the Java elements compilation unit.- static org.eclipse.text.edits.TextEdit- createAddImportTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, String qualifiedName) Creates a- TextEditobject representing the add import change to the source code of the Java elements compilation unit.- static org.eclipse.text.edits.TextEdit- createAddMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) Creates a- TextEditobject representing the change of adding the- MemberValuePairto the- NormalAnnotation.- static org.eclipse.text.edits.TextEdit- createRemoveAnnotationTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Creates a- TextEditobject representing the remove annotation change to the source code of the Java elements compilation unit.- static org.eclipse.text.edits.TextEdit- createRemoveMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) Creates a- TextEditobject representing the change of removing the- MemberValuePairfrom the- NormalAnnotation.- static org.eclipse.text.edits.TextEdit- createUpdateMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.MemberValuePair memberValuePair, org.eclipse.jdt.core.dom.ASTNode value) Creates a- TextEditobject representing the change of updating the- MemberValuePairwith the- ASTNodevalue.- static org.eclipse.text.edits.TextEdit- createUpdateSingleMemberAnnotationTextEdit- (org.eclipse.jdt.core.dom.SingleMemberAnnotation annotation, org.eclipse.jdt.core.dom.ASTNode value) Creates a- TextEditobject representing the change of updating the- SingleMemberAnnotationwith the- ASTNodevalue.- static org.eclipse.jdt.core.IAnnotation- getAnnotation- (Class<? extends Annotation> annotation, org.eclipse.jdt.core.IAnnotatable annotatable) Returns the JDT- IAnnotationthat corresponds to the given- Annotationclass on the- IAnnotatableelement.- static org.eclipse.jdt.core.dom.Annotation- getAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, Class<? extends Annotation> annotation) - static String- getAnnotationName- (org.eclipse.jdt.core.dom.Annotation annotation) Returns the annotations type name.- static List<org.eclipse.jdt.core.dom.Annotation>- getAnnotations- (org.eclipse.jdt.core.IJavaElement javaElement) Returns a list of all the- Annotationthat are present on the given- IJavaElement- static org.eclipse.jdt.core.dom.Expression- getAnnotationValue- (org.eclipse.jdt.core.dom.NormalAnnotation normalAnnotation, String memberName) Returns the- NormalAnnotationmember value pair value with the given member name.- static Object- getAnnotationValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) Returns the JDT- IAnnotationmember value pair value with the given member name.- static Boolean- getBooleanValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Booleanvalue.- static Boolean- getBooleanValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) Returns the member value with the given member name from the- IAnnotationas a- Booleanvalue.- static org.eclipse.jdt.core.ICompilationUnit- getCompilationUnitFromJavaElement- (org.eclipse.jdt.core.IJavaElement javaElement) Returns a- ICompilationUnitfor the given- IJavaElement.- static String- getEnumValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Stringvalue.- static String- getEnumValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) Returns the member value with the given member name from the- IAnnotationas a- Stringvalue.- static org.eclipse.jdt.core.dom.FieldDeclaration- getFieldDeclaration- (org.eclipse.jdt.core.IField field) Returns the- FieldDeclarationthat corresponds to the given- IField.- static org.eclipse.jdt.core.ILocalVariable- getLocalVariable- (org.eclipse.jdt.core.IMethod method, int offset) Returns the- ILocalVariableat the given offset position in the source file.- static org.eclipse.jdt.core.ILocalVariable- getLocalVariable- (org.eclipse.jdt.core.IMethod method, String paramName) Returns the- ILocalVariablewith the given name within the declared- IMethod.- static org.eclipse.jdt.core.dom.MemberValuePair- getMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation normalAnnotation, String memberName) Returns the- MemberValuePairwith the given member name from the- NormalAnnotation.- static org.eclipse.jdt.core.dom.MethodDeclaration- getMethodDeclaration- (org.eclipse.jdt.core.IMethod method) Returns the- MethodDeclarationthat corresponds to the given- IMethod.- static org.eclipse.jdt.core.dom.SingleVariableDeclaration- getSingleVariableDeclaration- (org.eclipse.jdt.core.ILocalVariable javaElement) Returns the- SingleVariableDeclarationthat corresponds to the given- ILocalVariable.- static List<org.eclipse.jdt.core.dom.SingleVariableDeclaration>- getSingleVariableDeclarations- (org.eclipse.jdt.core.IMethod method) Returns a list of all the- SingleVariableDeclarationfor the given- IMethod.- static String- getStringValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Stringvalue.- static String- getStringValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) Returns the member value with the given member name from the- IAnnotationas a- Stringvalue.- static org.eclipse.jdt.core.dom.AbstractTypeDeclaration- getTypeDeclaration- (org.eclipse.jdt.core.IType type) Returns the- AbstractTypeDeclarationthat corresponds to the given- IType.- static boolean- isAnnotationPresent- (org.eclipse.jdt.core.IJavaElement javaElement, String annotationName) Checks if the annotation with the given name is present on the- IJavaElement.- static boolean- isAnnotationPresent- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Checks if the given- Annotationis present on the- IJavaElement.- static void- removeAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Removes the given- Annotationfrom the- IJavaElement.- static void- removeMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) Removes the- MemberValuePairfrom the- NormalAnnotation.- static void- updateMemberValuePair- (org.eclipse.jdt.core.dom.MemberValuePair memberValuePair, org.eclipse.jdt.core.dom.ASTNode value) Updates the- MemberValuePairvalue with the given- ASTNode.- static void- updateSingleMemberAnnotation- (org.eclipse.jdt.core.dom.SingleMemberAnnotation annotation, org.eclipse.jdt.core.dom.ASTNode value) Updates the value of the- SingleMemberAnnotationwith the given- ASTNode.
- Method Details- addAnnotationpublic static void addAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, String annotationFQN, String param, String value, boolean allowMultiple) throws org.eclipse.core.runtime.CoreException Refactor operation that adds an annotation to an element with a value/pair initialized with a StringLiteral value. The import is added too if required. No checking if the annotation already exists is done as repeatable annotations is supported.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element which is used to get the compilation unit to add annotation to.
- annotationFQN- Fully qualified name of annotation. It is assumed to have a non-empty package name.
- param- A parameter as specified by the annotation.
- value- The string value that will become a StringLiteral.
- allowMultiple- Flag to enable multiple annotations or not.
- Throws:
- org.eclipse.core.runtime.CoreException- The exception is thrown if the import rewrite fails.
 
- addInterfacepublic static void addInterface- (org.eclipse.jdt.core.IType type, String interfaceFQN) throws org.eclipse.core.runtime.CoreException Refactor operation that adds an interface to an element.- Parameters:
- type- The type.
- interfaceFQN- Fully qualified name of the interface. It is assumed to have a non-empty package name.
- Throws:
- org.eclipse.core.runtime.CoreException- The exception is thrown if the import rewrite fails.
 
- addEventMethodpublic static void addEventMethod- (org.eclipse.jdt.core.IType type, String methodName, AnnotationType annotation, String refName) throws org.eclipse.core.runtime.CoreException Refactor operation to add an event method with an annotation.- Parameters:
- type- The class.
- methodName- The method name.
- annotation- The annotation.
- refName- Reference name.
- Throws:
- org.eclipse.core.runtime.CoreException
 
- addImportpublic static void addImport- (org.eclipse.jdt.core.IJavaElement javaElement, String qualifiedName) throws org.eclipse.core.runtime.CoreException Adds an import to the compilation unit of the given- IJavaElement.- The following types of Java elements are supported: - IJavaElement.COMPILATION_UNIT
- IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element which is used to get the compilation unit to add the import to.
- qualifiedName- The import to add.
- Throws:
- org.eclipse.core.runtime.CoreException- The exception is thrown if the import rewrite fails.
 
- addAnnotationpublic static void addAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) throws org.eclipse.jdt.core.JavaModelException Adds the given- Annotationto the- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element which is used to get the compilation unit to add annotation to.
- annotation- The annotation to add.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- removeAnnotationpublic static void removeAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) throws org.eclipse.jdt.core.JavaModelException Removes the given- Annotationfrom the- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- Java element to operate on.
- annotation- The annotation to remove.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- addMemberValuePairpublic static void addMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) throws org.eclipse.jdt.core.JavaModelException Adds the- MemberValuePairto the- NormalAnnotation.- Parameters:
- annotation- The normal annotation to add the member value pair to.
- memberValuePair- The member value pair to add.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- removeMemberValuePairpublic static void removeMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) throws org.eclipse.jdt.core.JavaModelException Removes the- MemberValuePairfrom the- NormalAnnotation.- Parameters:
- annotation- The normal annotation from which to remove the member value pair.
- memberValuePair- The member value pair to remove.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- updateMemberValuePairpublic static void updateMemberValuePair- (org.eclipse.jdt.core.dom.MemberValuePair memberValuePair, org.eclipse.jdt.core.dom.ASTNode value) throws org.eclipse.jdt.core.JavaModelException Updates the- MemberValuePairvalue with the given- ASTNode.- Parameters:
- memberValuePair- The member value pair to update.
- value- The value to set.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- updateSingleMemberAnnotationpublic static void updateSingleMemberAnnotation- (org.eclipse.jdt.core.dom.SingleMemberAnnotation annotation, org.eclipse.jdt.core.dom.ASTNode value) throws org.eclipse.jdt.core.JavaModelException Updates the value of the- SingleMemberAnnotationwith the given- ASTNode.- Parameters:
- annotation- The single member annotation to update.
- value- The value to set.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createAddImportTextEditpublic static org.eclipse.text.edits.TextEdit createAddImportTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, String qualifiedName) throws org.eclipse.core.runtime.CoreException Creates a- TextEditobject representing the add import change to the source code of the Java elements compilation unit. The compilation unit itself is not modified.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element will be used to create a- CompilationUnitwhich will in turn be used to create an- ImportRewrite.
- qualifiedName- The import to add.
- Returns:
- Text edit object describing the add import changes.
- Throws:
- org.eclipse.core.runtime.CoreException- The exception is thrown if the import rewrite fails.
 
- createAddAnnotationTextEditpublic static org.eclipse.text.edits.TextEdit createAddAnnotationTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the add annotation change to the source code of the Java elements compilation unit. The compilation unit itself is not modified.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- Element to operate on.
- annotation- The annotation to add.
- Returns:
- Text edit object describing the add annotation changes. Returns a MultiTextEditif the given Java element isn't supported.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createRemoveAnnotationTextEditpublic static org.eclipse.text.edits.TextEdit createRemoveAnnotationTextEdit- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the remove annotation change to the source code of the Java elements compilation unit. The compilation unit itself is not modified.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- Element to operate on.
- annotation- The annotation to remove.
- Returns:
- Text edit object describing the add annotation changes. Returns a MultiTextEditif the given Java element isn't supported.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createAddMemberValuePairTextEditpublic static org.eclipse.text.edits.TextEdit createAddMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the change of adding the- MemberValuePairto the- NormalAnnotation. The underlying compilation unit itself is not modified.- Parameters:
- annotation- The normal annotation to add the member value pair to.
- memberValuePair- The member value pair to add.
- Returns:
- Text edit object describing the add member value pair change.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createRemoveMemberValuePairTextEditpublic static org.eclipse.text.edits.TextEdit createRemoveMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.NormalAnnotation annotation, org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the change of removing the- MemberValuePairfrom the- NormalAnnotation. The underlying compilation unit itself is not modified.- Parameters:
- annotation- The normal annotation to remove the member value pair from.
- memberValuePair- The member value pair to remove.
- Returns:
- Text edit object describing the remove member value pair change.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createUpdateMemberValuePairTextEditpublic static org.eclipse.text.edits.TextEdit createUpdateMemberValuePairTextEdit- (org.eclipse.jdt.core.dom.MemberValuePair memberValuePair, org.eclipse.jdt.core.dom.ASTNode value) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the change of updating the- MemberValuePairwith the- ASTNodevalue. The underlying compilation unit itself is not modified.- Parameters:
- memberValuePair- The member value pair to update.
- value- The value to set.
- Returns:
- Text edit object describing the update member value pair change.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- createUpdateSingleMemberAnnotationTextEditpublic static org.eclipse.text.edits.TextEdit createUpdateSingleMemberAnnotationTextEdit- (org.eclipse.jdt.core.dom.SingleMemberAnnotation annotation, org.eclipse.jdt.core.dom.ASTNode value) throws org.eclipse.jdt.core.JavaModelException Creates a- TextEditobject representing the change of updating the- SingleMemberAnnotationwith the- ASTNodevalue. The underlying compilation unit itself is not modified.- Parameters:
- annotation- The single member annotation to update.
- value- The value to set.
- Returns:
- Text edit object describing the update single member annotation change.
- Throws:
- org.eclipse.jdt.core.JavaModelException- A- JavaModelExceptionis thrown when the underlying compilation units buffer could not be accessed.
 
- getCompilationUnitFromJavaElementpublic static org.eclipse.jdt.core.ICompilationUnit getCompilationUnitFromJavaElement- (org.eclipse.jdt.core.IJavaElement javaElement) Returns a- ICompilationUnitfor the given- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element.
- Returns:
- A compilation unit.
 
- getTypeDeclarationpublic static org.eclipse.jdt.core.dom.AbstractTypeDeclaration getTypeDeclaration- (org.eclipse.jdt.core.IType type) Returns the- AbstractTypeDeclarationthat corresponds to the given- IType.- Parameters:
- type- The type.
- Returns:
- A type declaration or null if not found.
 
- getMethodDeclarationpublic static org.eclipse.jdt.core.dom.MethodDeclaration getMethodDeclaration- (org.eclipse.jdt.core.IMethod method) Returns the- MethodDeclarationthat corresponds to the given- IMethod.- Parameters:
- method- The method.
- Returns:
- a method declaration or null if not found.
 
- getFieldDeclarationpublic static org.eclipse.jdt.core.dom.FieldDeclaration getFieldDeclaration- (org.eclipse.jdt.core.IField field) Returns the- FieldDeclarationthat corresponds to the given- IField.- Parameters:
- field- The field.
- Returns:
- A field declaration or null if not found.
 
- getSingleVariableDeclarationpublic static org.eclipse.jdt.core.dom.SingleVariableDeclaration getSingleVariableDeclaration- (org.eclipse.jdt.core.ILocalVariable javaElement) Returns the- SingleVariableDeclarationthat corresponds to the given- ILocalVariable.- Parameters:
- javaElement- The local variable.
- Returns:
- A single variable declaration or null if not found.
 
- getAnnotationNameReturns the annotations type name. If the annotation name is a simple name, the result is the name's identifier. If the name is a qualified name, the result is the name of the qualifier followed by "." followed by the name's identifier.- Parameters:
- annotation- The annotation.
- Returns:
- The annotation name. The simple name or the fully qualified name.
 
- compareTypeNamespublic static boolean compareTypeNames- (org.eclipse.jdt.core.dom.AbstractTypeDeclaration abstractTypeDeclaration, org.eclipse.jdt.core.IType type) Compares the- AbstractTypeDeclarationand- IType.- Parameters:
- abstractTypeDeclaration- The type declaration.
- type- The type.
- Returns:
- trueif the names match.
 
- compareMethodspublic static boolean compareMethods- (org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration, org.eclipse.jdt.core.IMethod method) Compares the- MethodDeclarationand- IMethod.- Parameters:
- methodDeclaration- The method declaration.
- method- The method.
- Returns:
- trueif the method names and parameter types match.
 
- compareMethodspublic static boolean compareMethods- (org.eclipse.jdt.core.dom.MethodDeclaration methodOne, org.eclipse.jdt.core.dom.MethodDeclaration methodTwo) Compares the two- MethodDeclaration.- Parameters:
- methodOne- The first method declaration.
- methodTwo- The second method declaration.
- Returns:
- trueif the method names and parameter types match.
 
- compareFieldNamespublic static boolean compareFieldNames- (org.eclipse.jdt.core.dom.FieldDeclaration fieldDeclaration, org.eclipse.jdt.core.IField field) Compares the- FieldDeclarationand- IField.- Parameters:
- fieldDeclaration- The field declaration.
- field- The field.
- Returns:
- trueif the field names match.
 
- isAnnotationPresentpublic static boolean isAnnotationPresent- (org.eclipse.jdt.core.IJavaElement javaElement, org.eclipse.jdt.core.dom.Annotation annotation) Checks if the given- Annotationis present on the- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The checked element.
- annotation- The annotation.
- Returns:
- trueif the annotation is present.
 
- isAnnotationPresentpublic static boolean isAnnotationPresent- (org.eclipse.jdt.core.IJavaElement javaElement, String annotationName) Checks if the annotation with the given name is present on the- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The checked element.
- annotationName- The annotation name.
- Returns:
- trueif the annotation is present.
 
- getAnnotationspublic static List<org.eclipse.jdt.core.dom.Annotation> getAnnotations- (org.eclipse.jdt.core.IJavaElement javaElement) Returns a list of all the- Annotationthat are present on the given- IJavaElement- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The element.
- Returns:
- a list of annotations.
 
- getSingleVariableDeclarationspublic static List<org.eclipse.jdt.core.dom.SingleVariableDeclaration> getSingleVariableDeclarations- (org.eclipse.jdt.core.IMethod method) Returns a list of all the- SingleVariableDeclarationfor the given- IMethod.- Parameters:
- method- The method.
- Returns:
- a list of single variable declarations.
 
- getLocalVariablepublic static org.eclipse.jdt.core.ILocalVariable getLocalVariable- (org.eclipse.jdt.core.IMethod method, int offset) Returns the- ILocalVariableat the given offset position in the source file.- Parameters:
- method- The method in which the local variable is declared.
- offset- The character index of the local variable in the source file. The offset must be >= to the start position of the node representing the local variable and <= the nodes start position plus length.
- Returns:
- The local variable or null if not found.
 
- getLocalVariablepublic static org.eclipse.jdt.core.ILocalVariable getLocalVariable- (org.eclipse.jdt.core.IMethod method, String paramName) Returns the- ILocalVariablewith the given name within the declared- IMethod.- Parameters:
- method- The method in which the local variable is declared.
- paramName- The local variable name.
- Returns:
- the local variable or null if not found.
 
- getAnnotationpublic static org.eclipse.jdt.core.dom.Annotation getAnnotation- (org.eclipse.jdt.core.IJavaElement javaElement, Class<? extends Annotation> annotation) Returns the AST- Annotationthat corresponds to the given- Annotationclass on the- IJavaElement.- The following types of Java elements are supported: - IJavaElement.PACKAGE_DECLARATION
- IJavaElement.TYPE
- IJavaElement.FIELD
- IJavaElement.METHOD
- IJavaElement.LOCAL_VARIABLE
 - Parameters:
- javaElement- The Java element to query.
- annotation- The- Annotationclass.
- Returns:
- the AST annotation or null if not found.
 
- getAnnotationpublic static org.eclipse.jdt.core.IAnnotation getAnnotation- (Class<? extends Annotation> annotation, org.eclipse.jdt.core.IAnnotatable annotatable) throws org.eclipse.jdt.core.JavaModelException Returns the JDT- IAnnotationthat corresponds to the given- Annotationclass on the- IAnnotatableelement.- Parameters:
- annotation- The- Annotationclass.
- annotatable- A package declaration, a type, a method, a field or a local variable in a compilation unit.
- Returns:
- The annotation or null if not found.
- Throws:
- org.eclipse.jdt.core.JavaModelException- If the annotatable element does not exist or if an exception occurs while accessing its corresponding resource.
 
- getAnnotationValuepublic static org.eclipse.jdt.core.dom.Expression getAnnotationValue- (org.eclipse.jdt.core.dom.NormalAnnotation normalAnnotation, String memberName) Returns the- NormalAnnotationmember value pair value with the given member name.- Parameters:
- normalAnnotation- The normal annotation.
- memberName- The member value pair member name.
- Returns:
- the value expression or null if not found.
 
- getAnnotationValuepublic static Object getAnnotationValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) throws org.eclipse.jdt.core.JavaModelException Returns the JDT- IAnnotationmember value pair value with the given member name.- Parameters:
- annotation- The annotation.
- memberName- The member name.
- Returns:
- An object representing the member value pairs value.
- Throws:
- org.eclipse.jdt.core.JavaModelException- If the annotation does not exist or if an exception occurs while accessing its corresponding resource.
 
- getMemberValuePairpublic static org.eclipse.jdt.core.dom.MemberValuePair getMemberValuePair- (org.eclipse.jdt.core.dom.NormalAnnotation normalAnnotation, String memberName) Returns the- MemberValuePairwith the given member name from the- NormalAnnotation.- Parameters:
- normalAnnotation- The normal annotation.
- memberName- The member name of the member value pair to return.
- Returns:
- A member value pair or null if no member value pair with the given member name can be found.
 
- getStringValuepublic static String getStringValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Stringvalue.- Parameters:
- annotation- The AST annotation.
- memberName- The member name.
- Returns:
- The member value as a String or null if no member with the member name can be found.
 
- getStringValuepublic static String getStringValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) throws org.eclipse.jdt.core.JavaModelException Returns the member value with the given member name from the- IAnnotationas a- Stringvalue.- Parameters:
- annotation- The JDT annotation.
- memberName- The member name.
- Returns:
- The member value as a String or null if no member with the member name can be found.
- Throws:
- org.eclipse.jdt.core.JavaModelException- If the annotation does not exist or if an exception occurs while accessing its corresponding resource.
 
- getBooleanValuepublic static Boolean getBooleanValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Booleanvalue.- Parameters:
- annotation- The AST annotation.
- memberName- The member name.
- Returns:
- The member value as a Boolean or null if no member with the member name can be found.
 
- getBooleanValuepublic static Boolean getBooleanValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) throws org.eclipse.jdt.core.JavaModelException Returns the member value with the given member name from the- IAnnotationas a- Booleanvalue.- Parameters:
- annotation- The JDT annotation.
- memberName- The member name.
- Returns:
- The member value as a Boolean or null if no member with the member name can be found.
- Throws:
- org.eclipse.jdt.core.JavaModelException- If the annotation does not exist or if an exception occurs while accessing its corresponding resource.
 
- getEnumValuepublic static String getEnumValue- (org.eclipse.jdt.core.dom.Annotation annotation, String memberName) Returns the member value with the given member name from the- Annotationas a- Stringvalue. The returned String value is the name of the enum constant.- Parameters:
- annotation- The AST annotation.
- memberName- The member name.
- Returns:
- The member value as a String or null if no member with the member name can be found.
 
- getEnumValuepublic static String getEnumValue- (org.eclipse.jdt.core.IAnnotation annotation, String memberName) throws org.eclipse.jdt.core.JavaModelException Returns the member value with the given member name from the- IAnnotationas a- Stringvalue. The returned String value is the name of the enum constant.- Parameters:
- annotation- The JDT annotation.
- memberName- The member name.
- Returns:
- the member value as a String or null if no member with the member name can be found.
- Throws:
- org.eclipse.jdt.core.JavaModelException- If the annotation does not exist or if an exception occurs while accessing its corresponding resource.