Search in sources :

Example 6 with EnumDeclaration

use of org.eclipse.jdt.core.dom.EnumDeclaration in project flux by eclipse.

the class Bindings method getBindingOfParentTypeContext.

/**
	 * Returns the type binding of the node's type context or null if the node is inside
	 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
	 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
	 * 
	 * @param node an AST node
	 * @return the type binding of the node's parent type context, or <code>null</code>
	 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
    StructuralPropertyDescriptor lastLocation = null;
    while (node != null) {
        if (node instanceof AbstractTypeDeclaration) {
            AbstractTypeDeclaration decl = (AbstractTypeDeclaration) node;
            if (lastLocation == decl.getBodyDeclarationsProperty() || lastLocation == decl.getJavadocProperty()) {
                return decl.resolveBinding();
            } else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
                return decl.resolveBinding();
            }
        } else if (node instanceof AnonymousClassDeclaration) {
            return ((AnonymousClassDeclaration) node).resolveBinding();
        }
        lastLocation = node.getLocationInParent();
        node = node.getParent();
    }
    return null;
}
Also used : AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) StructuralPropertyDescriptor(org.eclipse.jdt.core.dom.StructuralPropertyDescriptor) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) EnumDeclaration(org.eclipse.jdt.core.dom.EnumDeclaration)

Aggregations

EnumDeclaration (org.eclipse.jdt.core.dom.EnumDeclaration)6 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)5 AnnotationTypeDeclaration (org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)3 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)3 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)3 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 Annotation (org.eclipse.jdt.core.dom.Annotation)2 ArrayType (org.eclipse.jdt.core.dom.ArrayType)2 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)2 StructuralPropertyDescriptor (org.eclipse.jdt.core.dom.StructuralPropertyDescriptor)2 Type (org.eclipse.jdt.core.dom.Type)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1