Search in sources :

Example 6 with UnionType

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

the class ASTNodes method getTopMostType.

/**
	 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
	 * <p>
	 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
	 * 
	 * @param node the starting node, can be <code>null</code>
	 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
	 * @see #getNormalizedNode(ASTNode)
	 */
public static Type getTopMostType(ASTNode node) {
    ASTNode result = null;
    while (node instanceof Type && !(node instanceof UnionType) || node instanceof Name || node instanceof Annotation || node instanceof MemberValuePair || node instanceof Expression) {
        // Expression could maybe be reduced to expression node types that can appear in an annotation
        result = node;
        node = node.getParent();
    }
    if (result instanceof Type)
        return (Type) result;
    return null;
}
Also used : UnionType(org.eclipse.jdt.core.dom.UnionType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) IType(org.eclipse.jdt.core.IType) UnionType(org.eclipse.jdt.core.dom.UnionType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Annotation(org.eclipse.jdt.core.dom.Annotation) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Aggregations

Type (org.eclipse.jdt.core.dom.Type)6 UnionType (org.eclipse.jdt.core.dom.UnionType)6 ArrayType (org.eclipse.jdt.core.dom.ArrayType)5 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)5 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)5 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)3 NameQualifiedType (org.eclipse.jdt.core.dom.NameQualifiedType)3 SimpleType (org.eclipse.jdt.core.dom.SimpleType)3 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)3 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)3 IType (org.eclipse.jdt.core.IType)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 Dimension (org.eclipse.jdt.core.dom.Dimension)2 Expression (org.eclipse.jdt.core.dom.Expression)2 QualifiedType (org.eclipse.jdt.core.dom.QualifiedType)2 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)2 ArrayList (java.util.ArrayList)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 AST (org.eclipse.jdt.core.dom.AST)1