Example usage for org.eclipse.jdt.core.dom ASTNode TYPE_PARAMETER

List of usage examples for org.eclipse.jdt.core.dom ASTNode TYPE_PARAMETER

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode TYPE_PARAMETER.

Prototype

int TYPE_PARAMETER

To view the source code for org.eclipse.jdt.core.dom ASTNode TYPE_PARAMETER.

Click Source Link

Document

Node type constant indicating a node of type TypeParameter.

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockElider.java

License:Open Source License

/********************************************************************************/

private String getFormatType(ASTNode n) {
    String typ = null;/*from   w w w. j  a v a  2 s. c  om*/

    if (n instanceof Name) {
        ASTNode p = n.getParent();
        ASTNode pp = p.getParent();
        StructuralPropertyDescriptor spd = n.getLocationInParent();
        switch (p.getNodeType()) {
        case ASTNode.METHOD_INVOCATION:
            if (n.getLocationInParent() == MethodInvocation.NAME_PROPERTY) {
                typ = "CALL" + getMethodType((Name) n);
            }
            break;
        case ASTNode.SIMPLE_TYPE:
        case ASTNode.QUALIFIED_TYPE:
        case ASTNode.TYPE_PARAMETER:
            typ = "TYPE";
            break;
        case ASTNode.METHOD_DECLARATION:
            if (spd == MethodDeclaration.NAME_PROPERTY) {
                typ = "METHODDECL" + getMethodType((Name) n);
            } else if (spd == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY)
                typ = "TYPE";
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            if (pp.getNodeType() == ASTNode.CATCH_CLAUSE)
                typ = "EXCEPTIONDECL";
            else
                typ = "PARAMDECL";
            break;
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            if (pp.getNodeType() == ASTNode.FIELD_DECLARATION)
                typ = "FIELDDECL";
            else
                typ = "LOCALDECL";
            break;
        case ASTNode.ENUM_DECLARATION:
        case ASTNode.TYPE_DECLARATION:
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            typ = "CLASSDECL" + getClassType((Name) n);
            break;
        case ASTNode.MARKER_ANNOTATION:
        case ASTNode.NORMAL_ANNOTATION:
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            typ = "ANNOT";
            break;
        }
    }

    if (typ == null) {
        if (n instanceof SimpleName) {
            IBinding ib = ((Name) n).resolveBinding();
            // BedrockPlugin.logD("BINDING FOR " + ((SimpleName) n).getIdentifier() + " = " + ib);
            if (ib != null && ib.getKind() == IBinding.VARIABLE) {
                IVariableBinding vb = (IVariableBinding) ib;
                if (vb.isEnumConstant())
                    typ = "ENUMC";
                else if (vb.isField()) {
                    typ = "FIELD" + getVariableType((Name) n);
                }
            } else if (ib != null && ib.getKind() == IBinding.METHOD) {
                typ = "CALL" + getMethodType((Name) n);
            } else if (ib != null && ib.getKind() == IBinding.ANNOTATION) {
                typ = "ANNOT";
            } else if (ib != null && ib.getKind() == IBinding.TYPE) {
                typ = "TYPE";
            } else if (ib == null)
                typ = "UNDEF";
        }
    }

    // TODO: indicate whether the name is a user or system name

    return typ;
}

From source file:edu.brown.cs.bubbles.rebase.java.RebaseJavaElider.java

License:Open Source License

/********************************************************************************/

private String getFormatType(ASTNode n) {
    String typ = null;//from  www.  j a v a2s. co  m

    if (n instanceof Name) {
        ASTNode p = n.getParent();
        ASTNode pp = p.getParent();
        StructuralPropertyDescriptor spd = n.getLocationInParent();
        switch (p.getNodeType()) {
        case ASTNode.METHOD_INVOCATION:
            if (n.getLocationInParent() == MethodInvocation.NAME_PROPERTY) {
                typ = "CALL" + getMethodType((Name) n);
            }
            break;
        case ASTNode.SIMPLE_TYPE:
        case ASTNode.QUALIFIED_TYPE:
        case ASTNode.TYPE_PARAMETER:
            typ = "TYPE";
            break;
        case ASTNode.METHOD_DECLARATION:
            if (spd == MethodDeclaration.NAME_PROPERTY) {
                typ = "METHODDECL" + getMethodType((Name) n);
            } else if (spd == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY)
                typ = "TYPE";
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            if (pp.getNodeType() == ASTNode.CATCH_CLAUSE)
                typ = "EXCEPTIONDECL";
            else
                typ = "PARAMDECL";
            break;
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            if (pp.getNodeType() == ASTNode.FIELD_DECLARATION)
                typ = "FIELDDECL";
            else
                typ = "LOCALDECL";
            break;
        case ASTNode.ENUM_DECLARATION:
        case ASTNode.TYPE_DECLARATION:
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            typ = "CLASSDECL" + getClassType((Name) n);
            break;
        case ASTNode.MARKER_ANNOTATION:
        case ASTNode.NORMAL_ANNOTATION:
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            typ = "ANNOT";
            break;
        }
    }

    if (typ == null) {
        if (n instanceof SimpleName) {
            RebaseJavaSymbol js = RebaseJavaAst.getDefinition(n);
            if (js == null)
                js = RebaseJavaAst.getReference(n);
            if (js != null) {
                switch (js.getSymbolKind()) {
                case ENUM:
                    typ = "ENUMC";
                    break;
                case FIELD:
                    typ = "FIELD" + getVariableType((Name) n);
                    break;
                case METHOD:
                case CONSTRUCTOR:
                    typ = "CALL" + getMethodType((Name) n);
                    break;
                case ANNOTATION:
                    typ = "ANNOT";
                    break;
                case CLASS:
                case INTERFACE:
                    typ = "TYPE";
                    break;
                default:
                    break;
                }
            } else {
                RebaseJavaType jt = RebaseJavaAst.getJavaType(n);
                if (jt != null && !jt.isErrorType())
                    typ = "TYPE";
                else
                    typ = getTypeFromContext(n);
                if (typ == null)
                    typ = "UNDEF";
            }
        }
    }

    // TODO: indicate whether the name is a user or system name

    return typ;
}

From source file:edu.brown.cs.bubbles.rebase.newjava.RebaseJavaElider.java

License:Open Source License

/********************************************************************************/

private String getFormatType(ASTNode n) {
    String typ = null;//  ww w .ja  va2 s. c  o  m

    if (n instanceof Name) {
        ASTNode p = n.getParent();
        ASTNode pp = p.getParent();
        StructuralPropertyDescriptor spd = n.getLocationInParent();
        switch (p.getNodeType()) {
        case ASTNode.METHOD_INVOCATION:
            if (n.getLocationInParent() == MethodInvocation.NAME_PROPERTY) {
                typ = "CALL" + getMethodType((Name) n);
            }
            break;
        case ASTNode.SIMPLE_TYPE:
        case ASTNode.QUALIFIED_TYPE:
        case ASTNode.TYPE_PARAMETER:
            typ = "TYPE";
            break;
        case ASTNode.METHOD_DECLARATION:
            if (spd == MethodDeclaration.NAME_PROPERTY) {
                typ = "METHODDECL" + getMethodType((Name) n);
            } else if (spd == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY)
                typ = "TYPE";
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            if (pp.getNodeType() == ASTNode.CATCH_CLAUSE)
                typ = "EXCEPTIONDECL";
            else
                typ = "PARAMDECL";
            break;
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            if (pp.getNodeType() == ASTNode.FIELD_DECLARATION)
                typ = "FIELDDECL";
            else
                typ = "LOCALDECL";
            break;
        case ASTNode.ENUM_DECLARATION:
        case ASTNode.TYPE_DECLARATION:
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            typ = "CLASSDECL" + getClassType((Name) n);
            break;
        case ASTNode.MARKER_ANNOTATION:
        case ASTNode.NORMAL_ANNOTATION:
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            typ = "ANNOT";
            break;
        }
    }

    if (typ == null) {
        if (n instanceof SimpleName) {
            JcompSymbol js = JcompAst.getDefinition(n);
            if (js == null)
                js = JcompAst.getReference(n);
            if (js != null) {
                switch (js.getSymbolKind()) {
                case ENUM:
                    typ = "ENUMC";
                    break;
                case FIELD:
                    typ = "FIELD" + getVariableType((Name) n);
                    break;
                case METHOD:
                case CONSTRUCTOR:
                    typ = "CALL" + getMethodType((Name) n);
                    break;
                case ANNOTATION:
                    typ = "ANNOT";
                    break;
                case CLASS:
                case INTERFACE:
                    typ = "TYPE";
                    break;
                default:
                    break;
                }
            } else {
                JcompType jt = JcompAst.getJavaType(n);
                if (jt != null && !jt.isErrorType())
                    typ = "TYPE";
                else
                    typ = getTypeFromContext(n);
                if (typ == null)
                    typ = "UNDEF";
            }
        }
    }

    // TODO: indicate whether the name is a user or system name

    return typ;
}

From source file:org.autorefactor.refactoring.ASTHelper.java

License:Open Source License

/**
 * Returns whether the two provided nodes structurally match.
 *
 * @param matcher the AST matcher//from   w w w  . ja  v  a 2 s . c  om
 * @param node1 the first node to compare
 * @param node2 the second node to compare
 * @return true if the two provided nodes structurally match, false otherwise
 */
public static boolean match(ASTMatcher matcher, ASTNode node1, ASTNode node2) {
    if (sameClass(node1, node2)) {
        // FIXME JNR implement all expressions
        // TODO JNR
        // can we match "this.ast" and the unqualified "ast" for example?
        // can we match "MyClass.CONSTANT" and the unqualified "CONSTANT" for example?
        // can we use IVariableBindings to compare them?
        switch (node1.getNodeType()) {
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            return matcher.match((AnnotationTypeDeclaration) node1, node2);
        case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
            return matcher.match((AnnotationTypeMemberDeclaration) node1, node2);
        case ASTNode.ANONYMOUS_CLASS_DECLARATION:
            return matcher.match((AnonymousClassDeclaration) node1, node2);
        case ASTNode.ARRAY_ACCESS:
            return matcher.match((ArrayAccess) node1, node2);
        case ASTNode.ARRAY_CREATION:
            return matcher.match((ArrayCreation) node1, node2);
        case ASTNode.ARRAY_INITIALIZER:
            return matcher.match((ArrayInitializer) node1, node2);
        case ASTNode.ARRAY_TYPE:
            return matcher.match((ArrayType) node1, node2);
        case ASTNode.ASSERT_STATEMENT:
            return matcher.match((AssertStatement) node1, node2);
        case ASTNode.ASSIGNMENT:
            return matcher.match((Assignment) node1, node2);
        case ASTNode.BLOCK:
            return matcher.match((Block) node1, node2);
        case ASTNode.BLOCK_COMMENT:
            return matcher.match((BlockComment) node1, node2);
        case ASTNode.BOOLEAN_LITERAL:
            return matcher.match((BooleanLiteral) node1, node2);
        case ASTNode.BREAK_STATEMENT:
            return matcher.match((BreakStatement) node1, node2);
        case ASTNode.CAST_EXPRESSION:
            return matcher.match((CastExpression) node1, node2);
        case ASTNode.CATCH_CLAUSE:
            return matcher.match((CatchClause) node1, node2);
        case ASTNode.CHARACTER_LITERAL:
            return matcher.match((CharacterLiteral) node1, node2);
        case ASTNode.CLASS_INSTANCE_CREATION:
            return matcher.match((ClassInstanceCreation) node1, node2);
        case ASTNode.COMPILATION_UNIT:
            return matcher.match((CompilationUnit) node1, node2);
        case ASTNode.CONDITIONAL_EXPRESSION:
            return matcher.match((ConditionalExpression) node1, node2);
        case ASTNode.CONSTRUCTOR_INVOCATION:
            return matcher.match((ConstructorInvocation) node1, node2);
        case ASTNode.CONTINUE_STATEMENT:
            return matcher.match((ContinueStatement) node1, node2);
        case ASTNode.DO_STATEMENT:
            return matcher.match((DoStatement) node1, node2);
        case ASTNode.EMPTY_STATEMENT:
            return matcher.match((EmptyStatement) node1, node2);
        case ASTNode.ENHANCED_FOR_STATEMENT:
            return matcher.match((EnhancedForStatement) node1, node2);
        case ASTNode.ENUM_DECLARATION:
            return matcher.match((EnumDeclaration) node1, node2);
        case ASTNode.ENUM_CONSTANT_DECLARATION:
            return matcher.match((EnumConstantDeclaration) node1, node2);
        case ASTNode.EXPRESSION_STATEMENT:
            return matcher.match((ExpressionStatement) node1, node2);
        case ASTNode.FIELD_ACCESS:
            return matcher.match((FieldAccess) node1, node2);
        case ASTNode.FIELD_DECLARATION:
            return matcher.match((FieldDeclaration) node1, node2);
        case ASTNode.FOR_STATEMENT:
            return matcher.match((ForStatement) node1, node2);
        case ASTNode.IF_STATEMENT:
            return matcher.match((IfStatement) node1, node2);
        case ASTNode.IMPORT_DECLARATION:
            return matcher.match((ImportDeclaration) node1, node2);
        case ASTNode.INFIX_EXPRESSION:
            return matcher.match((InfixExpression) node1, node2);
        case ASTNode.INITIALIZER:
            return matcher.match((Initializer) node1, node2);
        case ASTNode.INSTANCEOF_EXPRESSION:
            return matcher.match((InstanceofExpression) node1, node2);
        case ASTNode.JAVADOC:
            return matcher.match((Javadoc) node1, node2);
        case ASTNode.LABELED_STATEMENT:
            return matcher.match((LabeledStatement) node1, node2);
        case ASTNode.LINE_COMMENT:
            return matcher.match((LineComment) node1, node2);
        case ASTNode.MARKER_ANNOTATION:
            return matcher.match((MarkerAnnotation) node1, node2);
        case ASTNode.MEMBER_REF:
            return matcher.match((MemberRef) node1, node2);
        case ASTNode.MEMBER_VALUE_PAIR:
            return matcher.match((MemberValuePair) node1, node2);
        case ASTNode.METHOD_DECLARATION:
            return matcher.match((MethodDeclaration) node1, node2);
        case ASTNode.METHOD_INVOCATION:
            return matcher.match((MethodInvocation) node1, node2);
        case ASTNode.METHOD_REF:
            return matcher.match((MethodRef) node1, node2);
        case ASTNode.METHOD_REF_PARAMETER:
            return matcher.match((MethodRefParameter) node1, node2);
        case ASTNode.MODIFIER:
            return matcher.match((Modifier) node1, node2);
        case ASTNode.NORMAL_ANNOTATION:
            return matcher.match((NormalAnnotation) node1, node2);
        case ASTNode.NULL_LITERAL:
            return matcher.match((NullLiteral) node1, node2);
        case ASTNode.NUMBER_LITERAL:
            return matcher.match((NumberLiteral) node1, node2);
        case ASTNode.PACKAGE_DECLARATION:
            return matcher.match((PackageDeclaration) node1, node2);
        case ASTNode.PARAMETERIZED_TYPE:
            return matcher.match((ParameterizedType) node1, node2);
        case ASTNode.PARENTHESIZED_EXPRESSION:
            return matcher.match((ParenthesizedExpression) node1, node2);
        case ASTNode.POSTFIX_EXPRESSION:
            return matcher.match((PostfixExpression) node1, node2);
        case ASTNode.PREFIX_EXPRESSION:
            return matcher.match((PrefixExpression) node1, node2);
        case ASTNode.PRIMITIVE_TYPE:
            return matcher.match((PrimitiveType) node1, node2);
        case ASTNode.QUALIFIED_NAME:
            return matcher.match((QualifiedName) node1, node2);
        case ASTNode.QUALIFIED_TYPE:
            return matcher.match((QualifiedType) node1, node2);
        case ASTNode.RETURN_STATEMENT:
            return matcher.match((ReturnStatement) node1, node2);
        case ASTNode.SIMPLE_NAME:
            return matcher.match((SimpleName) node1, node2);
        case ASTNode.SIMPLE_TYPE:
            return matcher.match((SimpleType) node1, node2);
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            return matcher.match((SingleMemberAnnotation) node1, node2);
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            return matcher.match((SingleVariableDeclaration) node1, node2);
        case ASTNode.STRING_LITERAL:
            return matcher.match((StringLiteral) node1, node2);
        case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
            return matcher.match((SuperConstructorInvocation) node1, node2);
        case ASTNode.SUPER_FIELD_ACCESS:
            return matcher.match((SuperFieldAccess) node1, node2);
        case ASTNode.SUPER_METHOD_INVOCATION:
            return matcher.match((SuperMethodInvocation) node1, node2);
        case ASTNode.SWITCH_CASE:
            return matcher.match((SwitchCase) node1, node2);
        case ASTNode.SWITCH_STATEMENT:
            return matcher.match((SwitchStatement) node1, node2);
        case ASTNode.SYNCHRONIZED_STATEMENT:
            return matcher.match((SynchronizedStatement) node1, node2);
        case ASTNode.TAG_ELEMENT:
            return matcher.match((TagElement) node1, node2);
        case ASTNode.TEXT_ELEMENT:
            return matcher.match((TextElement) node1, node2);
        case ASTNode.THIS_EXPRESSION:
            return matcher.match((ThisExpression) node1, node2);
        case ASTNode.THROW_STATEMENT:
            return matcher.match((ThrowStatement) node1, node2);
        case ASTNode.TRY_STATEMENT:
            return matcher.match((TryStatement) node1, node2);
        case ASTNode.TYPE_DECLARATION:
            return matcher.match((TypeDeclaration) node1, node2);
        case ASTNode.TYPE_DECLARATION_STATEMENT:
            return matcher.match((TypeDeclarationStatement) node1, node2);
        case ASTNode.TYPE_LITERAL:
            return matcher.match((TypeLiteral) node1, node2);
        case ASTNode.TYPE_PARAMETER:
            return matcher.match((TypeParameter) node1, node2);
        case ASTNode.UNION_TYPE:
            return matcher.match((UnionType) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
            return matcher.match((VariableDeclarationExpression) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            return matcher.match((VariableDeclarationFragment) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_STATEMENT:
            return matcher.match((VariableDeclarationStatement) node1, node2);
        case ASTNode.WHILE_STATEMENT:
            return matcher.match((WhileStatement) node1, node2);
        case ASTNode.WILDCARD_TYPE:
            return matcher.match((WildcardType) node1, node2);
        default:
            throw new NotImplementedException(node1);
        }
    }
    return false;
}

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMethod.java

License:Open Source License

public void setTypeParameters(String[] typeParameters) {
    this.typeParameters = typeParameters;
    setListNodeProperty(getASTNode(), typeParameters, MethodDeclaration.TYPE_PARAMETERS_PROPERTY,
            ASTNode.TYPE_PARAMETER);
}

From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.OrganizeImportsHelper.java

License:Open Source License

private static int internalGetPossibleTypeKinds(ASTNode node) {
    int kind = ALL_TYPES;

    int mask = ALL_TYPES | VOIDTYPE;

    ASTNode parent = node.getParent();//from  w w  w.  j  a  va  2s  . c o m
    while (parent instanceof QualifiedName) {
        if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
            return REF_TYPES;
        }
        node = parent;
        parent = parent.getParent();
        mask = REF_TYPES;
    }
    while (parent instanceof Type) {
        if (parent instanceof QualifiedType) {
            if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) {
                return mask & (REF_TYPES);
            }
            mask &= REF_TYPES;
        } else if (parent instanceof ParameterizedType) {
            if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
                return mask & REF_TYPES_AND_VAR;
            }
            mask &= CLASSES | INTERFACES;
        } else if (parent instanceof WildcardType) {
            if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) {
                return mask & REF_TYPES_AND_VAR;
            }
        }
        node = parent;
        parent = parent.getParent();
    }

    switch (parent.getNodeType()) {
    case ASTNode.TYPE_DECLARATION:
        if (node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) {
            kind = INTERFACES;
        } else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
            kind = CLASSES;
        }
        break;
    case ASTNode.ENUM_DECLARATION:
        kind = INTERFACES;
        break;
    case ASTNode.METHOD_DECLARATION:
        if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY) {
            kind = CLASSES;
        } else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
            kind = ALL_TYPES | VOIDTYPE;
        }
        break;
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        kind = PRIMITIVETYPES | ANNOTATIONS | ENUMS;
        break;
    case ASTNode.INSTANCEOF_EXPRESSION:
        kind = REF_TYPES;
        break;
    case ASTNode.THROW_STATEMENT:
        kind = CLASSES;
        break;
    case ASTNode.CLASS_INSTANCE_CREATION:
        if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) {
            kind = CLASSES;
        } else {
            kind = CLASSES | INTERFACES;
        }
        break;
    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        int superParent = parent.getParent().getNodeType();
        if (superParent == ASTNode.CATCH_CLAUSE) {
            kind = CLASSES;
        }
        break;
    case ASTNode.TAG_ELEMENT:
        kind = REF_TYPES;
        break;
    case ASTNode.MARKER_ANNOTATION:
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
    case ASTNode.NORMAL_ANNOTATION:
        kind = ANNOTATIONS;
        break;
    case ASTNode.TYPE_PARAMETER:
        if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) {
            kind = INTERFACES;
        } else {
            kind = REF_TYPES_AND_VAR;
        }
        break;
    case ASTNode.TYPE_LITERAL:
        kind = REF_TYPES;
        break;
    default:
    }
    return kind & mask;
}