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

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

Introduction

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

Prototype

ChildPropertyDescriptor NAME_PROPERTY

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

Click Source Link

Document

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

Usage

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

License:Open Source License

@Override
public boolean visit(SimpleName node) {
    if (isSameLocalVariable(variableBinding, node)) {
        switch (node.getParent().getNodeType()) {
        case ASSIGNMENT:
            addDefinitionOrUse(node, Assignment.LEFT_HAND_SIDE_PROPERTY);
            break;

        case VARIABLE_DECLARATION_FRAGMENT:
            addDefinitionOrUse(node, VariableDeclarationFragment.NAME_PROPERTY);
            break;

        case SINGLE_VARIABLE_DECLARATION:
            addDefinitionOrUse(node, SingleVariableDeclaration.NAME_PROPERTY);
            break;

        default://  w ww. j a va  2  s .  c o  m
            uses.add(node);
            break;
        }
    }
    return VISIT_SUBTREE;
}

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

License:Open Source License

/**
 * Sets name of variable declaration fragment.
 * @see org.eclipse.emf.codegen.merge.java.facade.JNode#setName(java.lang.String)
 *//*ww  w. j  a va 2s. c  o m*/
public void setName(String name) {
    this.name = name;
    setNodeProperty(variableDeclarationFragment, name, VariableDeclarationFragment.NAME_PROPERTY,
            ASTNode.SIMPLE_NAME);
}

From source file:org.eclipse.recommenders.internal.rcp.JavaElementSelections.java

License:Open Source License

private static boolean isVariableNameSelectionInFieldDeclaration(final ASTNode parent,
        final StructuralPropertyDescriptor locationInParent) {
    final ASTNode superparent = parent.getParent();
    return superparent instanceof FieldDeclaration
            && VariableDeclarationFragment.NAME_PROPERTY == locationInParent;
}

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

License:Open Source License

private boolean isDeclaration(SimpleName name) {
    if (VariableDeclarationFragment.NAME_PROPERTY.equals(name.getLocationInParent())) {
        return true;
    } else if (SingleVariableDeclaration.NAME_PROPERTY.equals(name.getLocationInParent())) {
        return true;
    } else {//ww w .j av  a2 s.  co m
        return false;
    }
}

From source file:org.eclipse.wb.core.model.JavaInfo.java

License:Open Source License

/**
 * Adds {@link ASTNode}'s that represent this {@link JavaInfo} in subtree of given {@link ASTNode}
 * .// w w w .j a v a2 s  .c  o m
 */
public final void addRelatedNodes(ASTNode start) {
    start.accept(new ASTVisitor() {
        @Override
        public void postVisit(ASTNode node) {
            // ignore "button" in "button = new JButton()"
            if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY
                    || node.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
                return;
            }
            if (isRepresentedBy(node)) {
                addRelatedNode(node);
            }
        }

        @Override
        public void endVisit(MethodInvocation node) {
            // support for invocation for "this" component
            if (node.getExpression() == null && isRepresentedBy(null)) {
                addRelatedNode(node);
            }
        }
    });
}

From source file:org.eclipse.wb.internal.core.eval.evaluators.SimpleNameEvaluator.java

License:Open Source License

private Object evaluateAsAssignment(EvaluationContext context, SimpleName simpleName) throws Exception {
    ExpressionValue value = ExecutionFlowUtils2.getValue(context.getFlowDescription(), simpleName);
    if (value != null) {
        Expression expression = value.getExpression();
        // field declaration without initializer
        if (expression.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY
                && expression.getParent().getLocationInParent() == FieldDeclaration.FRAGMENTS_PROPERTY) {
            return null;
        }//from  w ww .ja  v a 2 s  . c  o m
        // parameter of method without invocation
        if (expression.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY) {
            SingleVariableDeclaration parameter = (SingleVariableDeclaration) expression.getParent();
            MethodDeclaration methodDeclaration = AstNodeUtils.getEnclosingMethod(parameter);
            return context.evaluateUnknownParameter(methodDeclaration, parameter);
        }
        // normal Expression
        return AstEvaluationEngine.evaluate(context, expression);
    }
    // no value
    throw new DesignerException(ICoreExceptionConstants.EVAL_NO_SIMPLE_NAME_FOUND, simpleName.getIdentifier());
}

From source file:org.eclipse.wb.internal.rcp.model.forms.FormToolkitAccess.java

License:Open Source License

private FormToolkitAccess(TypeDeclaration typeDeclaration) {
    // try to find FormToolkit in local variable declaration
    {//from www  . j  a  v  a 2 s.co  m
        ListGatherer<SimpleName> listGatherer = new ListGatherer<SimpleName>() {
            @Override
            public void postVisit(ASTNode node) {
                if (node instanceof SimpleName
                        && node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY) {
                    SimpleName variable = (SimpleName) node;
                    if (AstNodeUtils.isSuccessorOf(variable.resolveTypeBinding(),
                            "org.eclipse.ui.forms.widgets.FormToolkit")) {
                        addResult(variable);
                    }
                }
            }
        };
        typeDeclaration.accept(listGatherer);
        List<SimpleName> variables = listGatherer.getResultList();
        if (!variables.isEmpty()) {
            m_toolkitMethodName = null;
            m_toolkitFieldName = variables.get(0).getIdentifier();
            m_formMethodName = null;
            m_formFieldName = null;
            m_toolkitSource = m_toolkitFieldName;
            return;
        }
    }
    // try to find FormToolkit: method
    {
        ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(typeDeclaration);
        List<IMethodBinding> methodBindings = AstNodeUtils.getMethodBindings(typeBinding.getSuperclass(),
                Modifier.PUBLIC | Modifier.PROTECTED);
        for (IMethodBinding methodBinding : methodBindings) {
            if (methodBinding.getParameterTypes().length == 0 && AstNodeUtils
                    .isSuccessorOf(methodBinding.getReturnType(), "org.eclipse.ui.forms.widgets.FormToolkit")) {
                m_toolkitMethodName = methodBinding.getName();
                m_toolkitFieldName = null;
                m_formMethodName = null;
                m_formFieldName = null;
                m_toolkitSource = m_toolkitMethodName + "()";
                return;
            }
        }
    }
    // try to find FormToolkit: field
    {
        ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(typeDeclaration);
        List<IVariableBinding> fields = AstNodeUtils.getFieldBindings(typeBinding,
                Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE);
        for (IVariableBinding field : fields) {
            if (AstNodeUtils.isSuccessorOf(field.getType(), "org.eclipse.ui.forms.widgets.FormToolkit")) {
                m_toolkitMethodName = null;
                m_toolkitFieldName = field.getName();
                m_formMethodName = null;
                m_formFieldName = null;
                m_toolkitSource = m_toolkitFieldName;
                return;
            }
        }
    }
    // try to find IManagedForm: method
    {
        ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(typeDeclaration);
        List<IMethodBinding> methodBindings = AstNodeUtils.getMethodBindings(typeBinding.getSuperclass(),
                Modifier.PUBLIC | Modifier.PROTECTED);
        for (IMethodBinding methodBinding : methodBindings) {
            if (methodBinding.getParameterTypes().length == 0 && AstNodeUtils
                    .isSuccessorOf(methodBinding.getReturnType(), "org.eclipse.ui.forms.IManagedForm")) {
                m_toolkitMethodName = null;
                m_toolkitFieldName = null;
                m_formMethodName = methodBinding.getName();
                m_formFieldName = null;
                m_toolkitSource = m_formMethodName + "().getToolkit()";
                return;
            }
        }
    }
    // try to find IManagedForm: field
    {
        ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(typeDeclaration);
        List<IVariableBinding> fields = AstNodeUtils.getFieldBindings(typeBinding,
                Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE);
        for (IVariableBinding field : fields) {
            if (AstNodeUtils.isSuccessorOf(field.getType(), "org.eclipse.ui.forms.IManagedForm")) {
                m_toolkitMethodName = null;
                m_toolkitFieldName = null;
                m_formMethodName = null;
                m_formFieldName = field.getName();
                m_toolkitSource = m_formFieldName + ".getToolkit()";
                return;
            }
        }
    }
    // can not find FormToolkit/IManagedForm
    throw new NoFormToolkitError();
}

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

License:Apache License

public String getName() {
    SimpleName name = (SimpleName) getRewrite().get(getFirstFragment(),
            VariableDeclarationFragment.NAME_PROPERTY);
    if (name != null) {
        return (String) getRewrite().get(name, SimpleName.IDENTIFIER_PROPERTY);
    }//w  w w  . j  av  a  2  s .  c  o  m
    return null;
}

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

License:Apache License

public void setName(String name) throws NotEditableException {
    editLock();/*from   www . j  ava  2  s  .  co  m*/

    getRewrite().set(getFirstFragment(), VariableDeclarationFragment.NAME_PROPERTY,
            getAST().newSimpleName(name), getEditGroup());
}

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

License:Apache License

@SuppressWarnings("unchecked")
public void updateSafePropertyBinding(String getter, String setter, CalleeArgument calleeArgument) {
    Block block = (Block) getRewrite().get(methodDecl, MethodDeclaration.BODY_PROPERTY);
    if (block == null) {
        block = getAST().newBlock();// w ww.  jav a 2s .c  o  m
        getRewrite().set(methodDecl, MethodDeclaration.BODY_PROPERTY, block, getEditGroup());
    }
    ListRewrite block_stmts = getRewrite().getListRewrite(block, Block.STATEMENTS_PROPERTY);
    for (ASTNode object : (List<ASTNode>) block_stmts.getRewrittenList()) {
        block_stmts.remove(object, getEditGroup());
    }

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

    /**
     * Object __old = <getter>()
     */
    SimpleType objcobj_type = getAST().newSimpleType(getAST().newName("Object"));
    MethodInvocation getter_inv = getAST().newMethodInvocation();
    getRewrite().set(getter_inv, MethodInvocation.NAME_PROPERTY, getAST().newName(getter), getEditGroup());

    Name old_obj = getAST().newName("__old");
    VariableDeclarationFragment vdf = getAST().newVariableDeclarationFragment();
    getRewrite().set(vdf, VariableDeclarationFragment.NAME_PROPERTY, old_obj, getEditGroup());
    getRewrite().set(vdf, VariableDeclarationFragment.INITIALIZER_PROPERTY, getter_inv, getEditGroup());
    VariableDeclarationExpression vde = getAST().newVariableDeclarationExpression(vdf);
    getRewrite().set(vde, VariableDeclarationExpression.TYPE_PROPERTY,
            ASTNode.copySubtree(getAST(), objcobj_type), getEditGroup());
    insertStatement(block_stmts, vde);

    /**
     * <ObjCRuntimeFQ>.associateObjCObject(this, <argument>)
     */
    MethodInvocation assoc_inv = getAST().newMethodInvocation();
    getRewrite().set(assoc_inv, MethodInvocation.EXPRESSION_PROPERTY, objc_runtime, getEditGroup());
    getRewrite().set(assoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("associateObjCObject"),
            getEditGroup());
    ListRewrite assoc_inv_args = getRewrite().getListRewrite(assoc_inv, MethodInvocation.ARGUMENTS_PROPERTY);
    assoc_inv_args.insertLast(getAST().newThisExpression(), getEditGroup());
    assoc_inv_args.insertLast(getAST().newSimpleName(calleeArgument.getName()), getEditGroup());

    /**
     * if (<arg> != null) { ObjCRuntime.associateObjCObject(this, <arg>); }
     */
    {
        Block con_block = getAST().newBlock();
        ListRewrite con_block_stmt = getRewrite().getListRewrite(con_block, Block.STATEMENTS_PROPERTY);
        insertStatement(con_block_stmt, assoc_inv);

        InfixExpression con_obj_nonnull = getAST().newInfixExpression();
        getRewrite().set(con_obj_nonnull, InfixExpression.OPERATOR_PROPERTY,
                InfixExpression.Operator.NOT_EQUALS, getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.LEFT_OPERAND_PROPERTY,
                getAST().newSimpleName(calleeArgument.getName()), getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.RIGHT_OPERAND_PROPERTY, getAST().newNullLiteral(),
                getEditGroup());

        IfStatement if_obj_nonnull = getAST().newIfStatement();
        getRewrite().set(if_obj_nonnull, IfStatement.EXPRESSION_PROPERTY, con_obj_nonnull, getEditGroup());
        getRewrite().set(if_obj_nonnull, IfStatement.THEN_STATEMENT_PROPERTY, con_block, getEditGroup());
        block_stmts.insertLast(if_obj_nonnull, getEditGroup());
    }

    /**
     * <setter>(...)
     */
    MethodInvocation setter_inv = getAST().newMethodInvocation();
    getRewrite().set(setter_inv, MethodInvocation.NAME_PROPERTY, getAST().newName(setter), getEditGroup());
    ListRewrite setter_inv_args = getRewrite().getListRewrite(setter_inv, MethodInvocation.ARGUMENTS_PROPERTY);
    setter_inv_args.insertLast(getAST().newSimpleName(calleeArgument.getName()), getEditGroup());
    insertStatement(block_stmts, setter_inv);

    /**
     * <ObjCRuntimeFQ>.dissociateObjCObject(this, old)
     */
    MethodInvocation unassoc_inv = getAST().newMethodInvocation();
    getRewrite().set(unassoc_inv, MethodInvocation.EXPRESSION_PROPERTY,
            ASTNode.copySubtree(getAST(), objc_runtime), getEditGroup());
    getRewrite().set(unassoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("dissociateObjCObject"),
            getEditGroup());
    ListRewrite unassoc_inv_args = getRewrite().getListRewrite(unassoc_inv,
            MethodInvocation.ARGUMENTS_PROPERTY);
    unassoc_inv_args.insertLast(getAST().newThisExpression(), getEditGroup());
    unassoc_inv_args.insertLast(ASTNode.copySubtree(getAST(), old_obj), getEditGroup());

    /**
     * if (__old != null) { ObjCRuntime.dissociateObjCObject(this, __old); }
     */
    {
        Block con_block = getAST().newBlock();
        ListRewrite con_block_stmt = getRewrite().getListRewrite(con_block, Block.STATEMENTS_PROPERTY);
        insertStatement(con_block_stmt, unassoc_inv);

        InfixExpression con_obj_nonnull = getAST().newInfixExpression();
        getRewrite().set(con_obj_nonnull, InfixExpression.OPERATOR_PROPERTY,
                InfixExpression.Operator.NOT_EQUALS, getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.LEFT_OPERAND_PROPERTY,
                ASTNode.copySubtree(getAST(), old_obj), getEditGroup());
        getRewrite().set(con_obj_nonnull, InfixExpression.RIGHT_OPERAND_PROPERTY, getAST().newNullLiteral(),
                getEditGroup());

        IfStatement if_obj_nonnull = getAST().newIfStatement();
        getRewrite().set(if_obj_nonnull, IfStatement.EXPRESSION_PROPERTY, con_obj_nonnull, getEditGroup());
        getRewrite().set(if_obj_nonnull, IfStatement.THEN_STATEMENT_PROPERTY, con_block, getEditGroup());
        block_stmts.insertLast(if_obj_nonnull, getEditGroup());
    }
}