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

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

Introduction

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

Prototype

ChildPropertyDescriptor NAME_PROPERTY

To view the source code for org.eclipse.jdt.core.dom MethodDeclaration 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;/* w w  w . j  a v a 2  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) {
            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  w w  w.ja  va 2 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) {
            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;//from ww w  . 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) {
            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:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java

License:Open Source License

/**
 * Finds and returns the <code>ASTNode</code> for the given source text
 * selection, if it is an entire constructor call or the class name portion
 * of a constructor call or constructor declaration, or null otherwise.
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 *//*from   w  w  w. jav  a 2  s.  com*/
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
    ASTNode node = ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
    if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
        return node;
    if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration) node).isConstructor())
        return node;
    if (node.getNodeType() == ASTNode.BLOCK) {
        ClassInstanceCreation cic = getClassInstanceCreation(node);
        return cic;
    }

    // we have some sub node. Make sure its the right child of the parent
    StructuralPropertyDescriptor location = node.getLocationInParent();
    ASTNode parent = node.getParent();
    if (location == ClassInstanceCreation.TYPE_PROPERTY) {
        return parent;
    } else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration) parent).isConstructor()) {
        return parent;
    }
    return null;
}

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

License:Open Source License

public void setName(String name) {
    this.name = name;
    setNodeProperty(getASTNode(), name, MethodDeclaration.NAME_PROPERTY, ASTNode.SIMPLE_NAME);
}

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   ww  w . j a  v a  2s  . co  m
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 ConstructorEditor(AbstractUnitManager manager, MethodDeclaration decl, boolean isNew) {
    super(manager, decl, isNew);
    if (isNew) {/* w  w  w.j  a  v  a2  s . co  m*/
        getRewrite().set(decl, MethodDeclaration.NAME_PROPERTY,
                getAST().newSimpleName(getManager().getUnitName()), getEditGroup());
        getRewrite().set(decl, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.TRUE, getEditGroup());
    }
}

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

License:Apache License

public String getName() {
    SimpleName name = (SimpleName) getRewrite().get(methodDecl, MethodDeclaration.NAME_PROPERTY);
    if (name != null) {
        return (String) getRewrite().get(name, SimpleName.IDENTIFIER_PROPERTY);
    }/*from   w  w w . j  ava2  s. com*/
    return null;
}

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

License:Apache License

public void setName(String methodName) throws GeneratorException {
    editLock();/* ww w .  j  a  v a  2  s .c om*/

    SimpleName property = (SimpleName) getRewrite().get(methodDecl, MethodDeclaration.NAME_PROPERTY);
    if (property == null || !property.getFullyQualifiedName().equals(methodName)) {
        getRewrite().set(methodDecl, MethodDeclaration.NAME_PROPERTY, getAST().newName(methodName),
                getEditGroup());
    }
}