Example usage for org.eclipse.jdt.core.dom MethodInvocation NAME_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom MethodInvocation NAME_PROPERTY

Introduction

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

Prototype

ChildPropertyDescriptor NAME_PROPERTY

To view the source code for org.eclipse.jdt.core.dom MethodInvocation NAME_PROPERTY.

Click Source Link

Document

The "name" structural property of this node type (child type: SimpleName ).

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;/*w  ww.j a  v a2 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) {
            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.java.RebaseJavaElider.java

License:Open Source License

private String getTypeFromContext(ASTNode n) {
    ASTNode p = null;//from  www. jav  a 2  s  .c om

    while (n != null) {
        switch (n.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
        case ASTNode.QUALIFIED_NAME:
            break;
        case ASTNode.SIMPLE_TYPE:
        case ASTNode.QUALIFIED_TYPE:
        case ASTNode.WILDCARD_TYPE:
            return "TYPE";
        case ASTNode.METHOD_INVOCATION:
            if (p != null && p.getLocationInParent() == MethodInvocation.NAME_PROPERTY)
                return "CALL";
            else
                return null;
        default:
            return null;
        }
        p = n;
        n = n.getParent();
    }

    return null;
}

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

License:Open Source License

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

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

    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.rules.PrimitiveWrapperCreationRefactoring.java

License:Open Source License

private boolean replaceMethodName(MethodInvocation node, String methodName) {
    final SimpleName name = this.ctx.getASTBuilder().simpleName(methodName);
    this.ctx.getRefactorings().set(node, MethodInvocation.NAME_PROPERTY, name);
    return DO_NOT_VISIT_SUBTREE;
}

From source file:org.autorefactor.refactoring.rules.UseStringContainsRefactoring.java

License:Open Source License

private boolean replaceWithStringContains(InfixExpression ie, MethodInvocation node, boolean negate) {
    final Refactorings r = this.ctx.getRefactorings();
    final ASTBuilder b = this.ctx.getASTBuilder();
    r.set(node, MethodInvocation.NAME_PROPERTY, b.simpleName("contains"));
    if (negate) {
        r.replace(ie, b.not(b.move(node)));
    } else {//from www . j a va2  s .c om
        r.replace(ie, b.move(node));
    }
    return DO_NOT_VISIT_SUBTREE;
}

From source file:org.eclipse.recommenders.jdt.templates.SnippetCodeBuilder.java

License:Open Source License

private boolean isUnqualifiedMethodInvocation(SimpleName name) {
    if (!MethodInvocation.NAME_PROPERTY.equals(name.getLocationInParent())) {
        return false;
    }/*  w  w w .j  a v  a 2  s . co  m*/
    MethodInvocation methodInvocation = (MethodInvocation) name.getParent();
    if (methodInvocation.getExpression() != null) {
        return false;
    }
    return true;
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java

License:Open Source License

/**
 * @return <code>true</code> if given {@link ASTNode} is single variable {@link SimpleName} or
 *         {@link FieldAccess} like "this.fieldName".
 *///from w  w  w . j a v a  2  s . c  om
public static boolean isVariable(ASTNode variable) {
    // FieldAccess
    if (variable instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) variable;
        return fieldAccess.getExpression() instanceof ThisExpression;
    }
    // SimpleName
    if (variable instanceof SimpleName) {
        StructuralPropertyDescriptor locationInParent = variable.getLocationInParent();
        if (locationInParent == MethodInvocation.NAME_PROPERTY || locationInParent == SimpleType.NAME_PROPERTY
                || locationInParent == FieldAccess.NAME_PROPERTY
                || locationInParent == QualifiedName.NAME_PROPERTY
                || locationInParent == MethodDeclaration.NAME_PROPERTY
                || locationInParent == TypeDeclaration.NAME_PROPERTY) {
            return false;
        }
        // variable has binding
        return getVariableBinding(variable) != null;
    }
    // unknown ASTNode
    return false;
}

From source file:org.moe.natjgen.ConstructorEditor.java

License:Apache License

public void setBodyAsSuperInitWithFieldSetters(String[] setters, String[] getters) {
    if (setters == null || getters == null || setters.length != getters.length) {
        throw new IllegalArgumentException();
    }//from w w w  . j a v a2s  .  c om

    Block block = getAST().newBlock();
    getRewrite().set(methodDecl, MethodDeclaration.BODY_PROPERTY, block, getEditGroup());
    ListRewrite block_stmts = getRewrite().getListRewrite(block, Block.STATEMENTS_PROPERTY);
    SuperConstructorInvocation invoke = getAST().newSuperConstructorInvocation();
    block_stmts.insertLast(invoke, getEditGroup());
    ListRewrite invoke_args = getRewrite().getListRewrite(invoke,
            SuperConstructorInvocation.ARGUMENTS_PROPERTY);
    TypeLiteral literal = getAST().newTypeLiteral();
    invoke_args.insertLast(literal, getEditGroup());
    getRewrite().set(literal, TypeLiteral.TYPE_PROPERTY,
            getAST().newSimpleType(getAST().newName(getManager().getUnitName())), getEditGroup());

    for (int i = 0; i < setters.length; i++) {
        MethodInvocation setfieldinvoke = getAST().newMethodInvocation();
        Statement stmt = getAST().newExpressionStatement(setfieldinvoke);
        block_stmts.insertLast(stmt, getEditGroup());
        getRewrite().set(setfieldinvoke, MethodInvocation.NAME_PROPERTY, getAST().newSimpleName(setters[i]),
                getEditGroup());
        ListRewrite arglrw = getRewrite().getListRewrite(setfieldinvoke, MethodInvocation.ARGUMENTS_PROPERTY);
        arglrw.insertLast(getAST().newSimpleName(getters[i]), getEditGroup());
    }
}

From source file:org.moe.natjgen.FieldEditor.java

License:Apache License

public void setInitializer(Type type, long const64, long const32) throws NotEditableException {
    editLock();//w w  w .  j a v a 2 s .  co  m

    Expression v64 = getExpressionForConstantValue(type.getKind(), const64);
    Expression v32;
    if (type.getDowngradeAnnotation() == null) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NIntAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NUIntAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NFloatAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(Type.Float, const32);
    } else {
        throw new IllegalStateException();
    }

    /**
     * <NatJFQ>
     */
    Name objc_runtime = getAST().newName(Constants.NatJFQ);

    /**
     * <NatJFQ>.is64Bit()
     */
    MethodInvocation assoc_inv = getAST().newMethodInvocation();
    getRewrite().set(assoc_inv, MethodInvocation.EXPRESSION_PROPERTY, objc_runtime, getEditGroup());
    getRewrite().set(assoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("is64Bit"), getEditGroup());

    /**
     * <NatJFQ>.is64Bit() ? <v64> : <v32>
     */
    ConditionalExpression cond = getAST().newConditionalExpression();
    getRewrite().set(cond, ConditionalExpression.EXPRESSION_PROPERTY, assoc_inv, getEditGroup());
    getRewrite().set(cond, ConditionalExpression.THEN_EXPRESSION_PROPERTY, v64, getEditGroup());
    getRewrite().set(cond, ConditionalExpression.ELSE_EXPRESSION_PROPERTY, v32, getEditGroup());

    /**
     * Add additional casting required by byte, short and char
     */
    if (type.getKind() == Type.Byte || type.getKind() == Type.Short || type.getKind() == Type.Char) {
        CastExpression cast = getAST().newCastExpression();
        if (type.getKind() == Type.Byte) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.BYTE));
        } else if (type.getKind() == Type.Short) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.SHORT));
        } else if (type.getKind() == Type.Char) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.CHAR));
        } else {
            throw new IllegalStateException();
        }
        ParenthesizedExpression parenthesized = getAST().newParenthesizedExpression();
        parenthesized.setExpression(cond);
        cast.setExpression(parenthesized);
        getRewrite().set(getFirstFragment(), VariableDeclarationFragment.INITIALIZER_PROPERTY, cast,
                getEditGroup());
    } else {
        getRewrite().set(getFirstFragment(), VariableDeclarationFragment.INITIALIZER_PROPERTY, cond,
                getEditGroup());
    }
}