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

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

Introduction

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

Prototype

public final Object getProperty(String propertyName) 

Source Link

Document

Returns the value of the named property of this node, or null if none.

Usage

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

License:Open Source License

/**
 * @param invocation/*w ww .  j a v a  2s .com*/
 *          the not <code>null</code> {@link MethodInvocation}
 * @return not <code>null</code> {@link IMethodBinding} for given {@link MethodInvocation}.
 */
public static IMethodBinding getMethodBinding(MethodInvocation invocation) {
    Assert.isNotNull(invocation);
    // try to get binding from property (copy of binding added by DesignerAST)
    {
        IMethodBinding binding = (IMethodBinding) invocation.getProperty(AstParser.KEY_METHOD_BINDING);
        if (binding != null) {
            return binding;
        }
    }
    // get standard binding
    return invocation.resolveMethodBinding();
}

From source file:org.eclipse.wb.internal.layout.group.model.GroupLayoutParserVisitor2.java

License:Open Source License

@Override
public void endVisit(MethodInvocation node) {
    String identifier = node.getName().getIdentifier();
    Expression nodeExpression = node.getExpression();
    int argumentsSize = node.arguments().size();
    if (identifier.equals(m_codeSupport.ID_ADD_GROUP) || identifier.equals(m_codeSupport.ID_ADD_COMPONENT)
            || identifier.equals(m_codeSupport.ID_ADD_GAP)) {
        if (argumentsSize == 0) {
            throw new IllegalArgumentException("add*() methods with no arguments are not supported.");
        }// w ww.  j  ava2  s  .c o m
        Expression arg0 = (Expression) node.arguments().get(0);
        LayoutInterval parentGroup = (LayoutInterval) nodeExpression
                .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
        // addGroup(Group group)
        if (AstNodeUtils.isSuccessorOf(arg0, m_codeSupport.GROUP_LAYOUT_GROUP_CLASS_NAME)) {
            // add group into group
            LayoutInterval group = (LayoutInterval) arg0
                    .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
            parentGroup.add(group, -1);
            node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, parentGroup);
        }
        if (argumentsSize == 2) {
            Expression arg1 = (Expression) node.arguments().get(1);
            // addGroup(Aligment, Group group)
            if (AstNodeUtils.isSuccessorOf(arg1, m_codeSupport.GROUP_LAYOUT_GROUP_CLASS_NAME)
                    && identifier.equals(m_codeSupport.ID_ADD_GROUP)) {
                // add group into group
                LayoutInterval group = (LayoutInterval) arg1
                        .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
                m_codeSupport.setGroupAlignment(parentGroup, arg0);
                parentGroup.add(group, -1);
                node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, parentGroup);
            }
        }
        // addComponent(Component component)
        if ((argumentsSize == 1 || argumentsSize == 4) && m_codeSupport.isComponent(arg0)) {
            JavaInfo widget = JavaInfoResolver.getJavaInfo(m_container, arg0);
            LayoutInterval group = (LayoutInterval) nodeExpression
                    .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
            if (widget != null) {
                LayoutInterval interval = addChild((AbstractComponentInfo) widget, arg0);
                // addComponent(Component component, int min, int pref, int max)
                if (argumentsSize == 4) {
                    setSizes(interval, (Expression) node.arguments().get(1),
                            (Expression) node.arguments().get(2), (Expression) node.arguments().get(3));
                }
                group.add(interval, -1);
            }
            node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
            return;
        }
        // addGap(int pref)
        if (AstNodeUtils.isSuccessorOf(arg0, int.class) && argumentsSize == 1) {
            LayoutInterval group = (LayoutInterval) nodeExpression
                    .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
            LayoutInterval space = new LayoutInterval(SINGLE);
            setSize(space, (Expression) node.arguments().get(0));
            group.add(space, -1);
            node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
        }
        // addGap(int min, int pref, int max)
        if (AstNodeUtils.isSuccessorOf(arg0, int.class) && argumentsSize == 3) {
            LayoutInterval group = (LayoutInterval) nodeExpression
                    .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
            LayoutInterval space = new LayoutInterval(SINGLE);
            setSizes(space, (Expression) node.arguments().get(0), (Expression) node.arguments().get(1),
                    (Expression) node.arguments().get(2));
            group.add(space, -1);
            node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
        }
        if (argumentsSize > 1 && argumentsSize != 4 && identifier.equals(m_codeSupport.ID_ADD_COMPONENT)) {
            // addComponent(Component component, Alignment alignment)
            JavaInfo widget = null;
            LayoutInterval group = (LayoutInterval) nodeExpression
                    .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
            Expression arg1 = (Expression) node.arguments().get(1);
            Expression widgetArg;
            Expression alignmentArg;
            if (m_codeSupport.isComponent(arg0)) {
                // JDK GL
                widgetArg = arg0;
                alignmentArg = arg1;
            } else {
                // standalone GL & SWT GL
                widgetArg = arg1;
                alignmentArg = arg0;
            }
            widget = JavaInfoResolver.getJavaInfo(m_container, widgetArg);
            if (widget != null) {
                LayoutInterval interval = addChild((AbstractComponentInfo) widget, widgetArg);
                m_codeSupport.setAlignment(interval, alignmentArg);
                // addComponent(Component component, Alignment alignment, int min, int pref, int max)
                if (argumentsSize == 5) {
                    setSizes(interval, (Expression) node.arguments().get(2),
                            (Expression) node.arguments().get(3), (Expression) node.arguments().get(4));
                }
                group.add(interval, -1);
            }
            node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
        }
    } else if (identifier.equals(GroupLayoutCodeSupport.ID_ADD_PREFERRED_GAP)) {
        LayoutInterval group = (LayoutInterval) nodeExpression
                .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
        if (group.isSequential()) {
            LayoutInterval space = new LayoutInterval(SINGLE);
            switch (argumentsSize) {
            case 1:
                // addPreferredGap(ComponentPlacement)
                m_codeSupport.setPaddingType(space, (Expression) node.arguments().get(0));
                break;
            case 3:
            case 4: {
                // also cover standalone lib methods
                Expression arg0 = (Expression) node.arguments().get(0);
                Expression arg1 = (Expression) node.arguments().get(1);
                if (m_codeSupport.isComponent(arg0) && m_codeSupport.isComponent(arg1)) {
                    // addPreferredGap(JComponent, JComponent, ComponentPlacement)
                    m_codeSupport.setPaddingType(space, (Expression) node.arguments().get(2));
                } else {
                    // addPreferredGap(ComponentPlacement, int, int)
                    m_codeSupport.setPaddingType(space, (Expression) node.arguments().get(0));
                    setSizes(space, (Expression) node.arguments().get(1), (Expression) node.arguments().get(2));
                }
                break;
            }
            case 5:
                // addPreferredGap(JComponent, JComponent, ComponentPlacement, int, int)
                m_codeSupport.setPaddingType(space, (Expression) node.arguments().get(2));
                setSizes(space, (Expression) node.arguments().get(3), (Expression) node.arguments().get(4));
                break;
            }
            group.add(space, -1);
        }
        node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
    } else if (identifier.equals(GroupLayoutCodeSupport.ID_ADD_CONTAINER_GAP)) {
        LayoutInterval group = (LayoutInterval) nodeExpression
                .getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
        LayoutInterval space = new LayoutInterval(SINGLE);
        if (argumentsSize == 2) {
            setGapSizes(space, (Expression) node.arguments().get(0), (Expression) node.arguments().get(1));
        }
        group.add(space, -1);
        node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, group);
    } else if (identifier.equals(GroupLayoutCodeSupport.ID_CREATE_SEQUENTIAL_GROUP) && argumentsSize == 0) {
        LayoutInterval sequentialGroup = new LayoutInterval(SEQUENTIAL);
        node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, sequentialGroup);
    } else if (identifier.equals(GroupLayoutCodeSupport.ID_CREATE_PARALLEL_GROUP)) {
        LayoutInterval parallelGroup = new LayoutInterval(PARALLEL);
        if (argumentsSize > 0) {
            m_codeSupport.setGroupAlignment(parallelGroup, (Expression) node.arguments().get(0));
            // createParallelGroup(Alignment, boolean)
            if (argumentsSize > 1) {
                setGroupResizeable(parallelGroup, (Expression) node.arguments().get(1));
            }
        }
        node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, parallelGroup);
    } else if (identifier.equals(GroupLayoutCodeSupport.ID_CREATE_BASELINE_GROUP)) {
        // createBaselineGroup(boolean, boolean)
        LayoutInterval parallelGroup = new LayoutInterval(PARALLEL);
        parallelGroup.setGroupAlignment(BASELINE);
        if (argumentsSize > 0) {
            setGroupResizeable(parallelGroup, (Expression) node.arguments().get(0));
        }
        node.setProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP, parallelGroup);
    } else if (m_methodName.startsWith(identifier) && node.arguments().size() == 1) {
        ASTNode arg0 = (ASTNode) node.arguments().get(0);
        if (arg0 instanceof MethodInvocation) {
            MethodInvocation mi = (MethodInvocation) arg0;
            m_rootGroup = (LayoutInterval) mi.getProperty(GroupLayoutCodeSupport.PROPERTY_NAME_GROUP);
        }
    }
}

From source file:org.eclipse.wb.internal.swing.java6.model.GroupLayoutParserVisitor.java

License:Open Source License

@Override
public void endVisit(final MethodInvocation node) {
    try {//from w  ww.j a v a  2s .com
        final String identifier = node.getName().getIdentifier();
        final Expression nodeExpression = node.getExpression();
        final int argumentsSize = node.arguments().size();
        if (identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_GROUP)
                || identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_COMPONENT)
                || identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_GAP)) {
            if (argumentsSize == 0) {
                throw new IllegalArgumentException(Messages.GroupLayoutParserVisitor_addWithoutArguments);
            }
            final Expression arg0 = (Expression) node.arguments().get(0);
            final GroupInfo parentGroup = (GroupInfo) nodeExpression
                    .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
            // addGroup(Group group)
            if (AstNodeUtils.isSuccessorOf(arg0, GroupLayoutInfo.GROUP_LAYOUT_GROUP_CLASS_NAME)) {
                // add group into group
                final GroupInfo group = (GroupInfo) arg0.getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                parentGroup.add(group);
                node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, parentGroup);
            }
            if (argumentsSize == 2) {
                Expression arg1 = (Expression) node.arguments().get(1);
                // addGroup(Aligment, Group group)
                if (AstNodeUtils.isSuccessorOf(arg1, GroupLayoutInfo.GROUP_LAYOUT_GROUP_CLASS_NAME)
                        && identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_GROUP)) {
                    // add group into group
                    final ParallelGroupInfo group = (ParallelGroupInfo) arg1
                            .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                    setGroupAlignment(group, arg0);
                    parentGroup.add(group);
                    node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, parentGroup);
                }
            }
            // addComponent(Component component)
            if ((argumentsSize == 1 || argumentsSize == 4)
                    && AstNodeUtils.isSuccessorOf(arg0, Component.class)) {
                final JavaInfo widget = JavaInfoResolver.getJavaInfo(m_container, arg0);
                final GroupInfo group = (GroupInfo) nodeExpression
                        .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                if (widget != null) {
                    WidgetSpringInfo widgetSpring = addChild((IAbstractComponentInfo) widget, m_container);
                    //   TODO: checkForJTextField(widget, interval);
                    // addComponent(Component component, int min, int pref, int max)
                    if (argumentsSize == 4) {
                        setSizes(widgetSpring, (Expression) node.arguments().get(1),
                                (Expression) node.arguments().get(2), (Expression) node.arguments().get(3));
                    }
                    group.add(widgetSpring);
                }
                node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
            }
            // addGap(int pref)
            if (AstNodeUtils.isSuccessorOf(arg0, int.class) && argumentsSize == 1) {
                final GroupInfo group = (GroupInfo) nodeExpression
                        .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                GapSpringInfo gapSpring = new GapSpringInfo();
                setSize(gapSpring, (Expression) node.arguments().get(0));
                group.add(gapSpring);
                node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
            }
            // addGap(int min, int pref, int max)
            if (AstNodeUtils.isSuccessorOf(arg0, int.class) && argumentsSize == 3) {
                final GroupInfo group = (GroupInfo) nodeExpression
                        .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                GapSpringInfo gapSpring = new GapSpringInfo();
                setSizes(gapSpring, (Expression) node.arguments().get(0), (Expression) node.arguments().get(1),
                        (Expression) node.arguments().get(2));
                group.add(gapSpring);
                node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
            }
            if (argumentsSize > 1 && argumentsSize != 4) {
                // addComponent(Component component, Alignment alignment)
                JavaInfo widget = null;
                final GroupInfo group = (GroupInfo) nodeExpression
                        .getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
                Expression arg1 = (Expression) node.arguments().get(1);
                if (AstNodeUtils.isSuccessorOf(arg0, Component.class)
                        && identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_COMPONENT)) {
                    widget = JavaInfoResolver.getJavaInfo(m_container, arg0);
                }
                if (widget != null) {
                    WidgetSpringInfo widgetSpring = addChild((IAbstractComponentInfo) widget, m_container);
                    Alignment alignment = (Alignment) JavaInfoEvaluationHelper.getValue(arg1);
                    widgetSpring.setAlignment(alignment);
                    //                  checkForJTextField(widget, interval);
                    // addComponent(Component component, Alignment alignment, int min, int pref, int max)
                    if (argumentsSize == 5) {
                        setSizes(widgetSpring, (Expression) node.arguments().get(2),
                                (Expression) node.arguments().get(3), (Expression) node.arguments().get(4));
                    }
                    group.add(widgetSpring);
                }
                node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
            }
        } else if (identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_PREFERRED_GAP)) {
            final GroupInfo group = (GroupInfo) nodeExpression.getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
            // parent group should be sequential
            Assert.instanceOf(SequentialGroupInfo.class, group);
            GapSpringInfo gapSpring = new GapSpringInfo();
            switch (argumentsSize) {
            case 1: {
                // addPreferredGap(ComponentPlacement)
                setPlacementType(gapSpring, (Expression) node.arguments().get(0));
                break;
            }
            case 3: {
                final Expression arg0 = (Expression) node.arguments().get(0);
                final Expression arg1 = (Expression) node.arguments().get(1);
                final Expression arg2 = (Expression) node.arguments().get(2);
                // addPreferredGap(JComponent, JComponent, ComponentPlacement)
                if (AstNodeUtils.isSuccessorOf(arg0, JComponent.class)) {
                    setGapWidgets(gapSpring, arg0, arg1);
                    setPlacementType(gapSpring, arg2);
                } else {
                    // addPreferredGap(ComponentPlacement, int, int)
                    setPlacementType(gapSpring, arg0);
                    setGapSizes(gapSpring, arg1, arg2);
                }
                break;
            }
            case 5: {
                // addPreferredGap(JComponent, JComponent, ComponentPlacement, int, int)
                final Expression arg0 = (Expression) node.arguments().get(0);
                final Expression arg1 = (Expression) node.arguments().get(1);
                final Expression arg2 = (Expression) node.arguments().get(2);
                final Expression arg3 = (Expression) node.arguments().get(3);
                final Expression arg4 = (Expression) node.arguments().get(4);
                setGapWidgets(gapSpring, arg0, arg1);
                setPlacementType(gapSpring, arg2);
                setGapSizes(gapSpring, arg3, arg4);
                break;
            }
            }
            group.add(gapSpring);
            node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
        } else if (identifier.equals(GroupLayoutInfo.IDENTIFIER_ADD_CONTAINER_GAP)) {
            final GroupInfo group = (GroupInfo) nodeExpression.getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
            // parent group should be sequential
            Assert.instanceOf(SequentialGroupInfo.class, group);
            GapSpringInfo gapSpring = new GapSpringInfo(true);
            if (argumentsSize == 2) {
                setGapSizes(gapSpring, (Expression) node.arguments().get(0),
                        (Expression) node.arguments().get(1));
            }
            group.add(gapSpring);
            node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, group);
        } else if (identifier.equals(GroupLayoutInfo.IDENTIFIER_CREATE_SEQUENTIAL_GROUP)
                && argumentsSize == 0) {
            final SequentialGroupInfo sequentialGroup = new SequentialGroupInfo();
            node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, sequentialGroup);
        } else if (identifier.equals(GroupLayoutInfo.IDENTIFIER_CREATE_PARALLEL_GROUP)) {
            // createParallelGroup()
            final ParallelGroupInfo parallelGroup = new ParallelGroupInfo();
            if (argumentsSize > 0) {
                setGroupAlignment(parallelGroup, (Expression) node.arguments().get(0));
                // createParallelGroup(Alignment, boolean)
                if (argumentsSize > 1) {
                    setGroupResizeable(parallelGroup, (Expression) node.arguments().get(1));
                }
            }
            node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, parallelGroup);
        } else if (identifier.equals(GroupLayoutInfo.IDENTIFIER_CREATE_BASELINE_GROUP) && argumentsSize == 2) {
            // createBaselineGroup(boolean, boolean)
            final ParallelGroupInfo parallelGroup = new ParallelGroupInfo();
            parallelGroup.setGroupAlignment(Alignment.BASELINE);
            setGroupResizeable(parallelGroup, (Expression) node.arguments().get(0));
            setGroupAnchorBaselineToTop(parallelGroup, (Expression) node.arguments().get(1));
            node.setProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP, parallelGroup);
        } else if (m_methodName.startsWith(identifier) && node.arguments().size() == 1) {
            final ASTNode arg0 = (ASTNode) node.arguments().get(0);
            if (arg0 instanceof MethodInvocation) {
                final MethodInvocation mi = (MethodInvocation) arg0;
                m_rootGroup = (SpringInfo) mi.getProperty(GroupLayoutInfo.PROPERTY_NAME_GROUP);
            }
        }
    } catch (Throwable e) {
        throw ReflectionUtils.propagate(e);
    }
}