/******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Zend Technologies *******************************************************************************/ package org2.eclipse.php.internal.core.ast.nodes; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org2.eclipse.php.internal.core.PHPVersion; import org2.eclipse.php.internal.core.ast.match.ASTMatcher; import org2.eclipse.php.internal.core.ast.visitor.Visitor; /** * Represents a dispaching expression * <pre>e.g.<pre> foo()->bar(), * $myClass->foo()->bar(), * A::$a->foo() */ public class MethodInvocation extends Dispatch { private FunctionInvocation method; /** * The structural property of this node type. */ public static final ChildPropertyDescriptor DISPATCHER_PROPERTY = new ChildPropertyDescriptor(MethodInvocation.class, "dispatcher", VariableBase.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$ public static final ChildPropertyDescriptor METHOD_PROPERTY = new ChildPropertyDescriptor(MethodInvocation.class, "method", FunctionInvocation.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$ @Override ChildPropertyDescriptor getDispatcherProperty() { return MethodInvocation.DISPATCHER_PROPERTY; } /** * A list of property descriptors (element type: * {@link StructuralPropertyDescriptor}), * or null if uninitialized. */ private static final List<StructuralPropertyDescriptor> PROPERTY_DESCRIPTORS; static { List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(2); propertyList.add(METHOD_PROPERTY); propertyList.add(DISPATCHER_PROPERTY); PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList); } public MethodInvocation(AST ast) { super(ast); } public MethodInvocation(int start, int end, AST ast, VariableBase dispatcher, FunctionInvocation method) { super(start, end, ast, dispatcher); if (method == null) { throw new IllegalArgumentException(); } setMethod(method); } public void accept0(Visitor visitor) { final boolean visit = visitor.visit(this); if (visit) { childrenAccept(visitor); } visitor.endVisit(this); } public void childrenAccept(Visitor visitor) { getDispatcher().accept(visitor); method.accept(visitor); } public void traverseTopDown(Visitor visitor) { accept(visitor); getDispatcher().accept(visitor); method.traverseTopDown(visitor); } public void traverseBottomUp(Visitor visitor) { getDispatcher().traverseBottomUp(visitor); method.traverseBottomUp(visitor); accept(visitor); } public void toString(StringBuffer buffer, String tab) { buffer.append(tab).append("<MethodInvocation"); //$NON-NLS-1$ appendInterval(buffer); buffer.append(">\n"); //$NON-NLS-1$ buffer.append(TAB).append(tab).append("<Dispatcher>\n"); //$NON-NLS-1$ getDispatcher().toString(buffer, TAB + TAB + tab); buffer.append("\n").append(TAB).append(tab).append("</Dispatcher>\n"); //$NON-NLS-1$ //$NON-NLS-2$ buffer.append(TAB).append(tab).append("<Property>\n"); //$NON-NLS-1$ method.toString(buffer, TAB + TAB + tab); buffer.append("\n").append(TAB).append(tab).append("</Property>\n"); //$NON-NLS-1$ //$NON-NLS-2$ buffer.append(tab).append("</MethodInvocation>"); //$NON-NLS-1$ } public int getType() { return ASTNode.METHOD_INVOCATION; } /** * The method component of this method invocation expression * @return method component of this method invocation expression */ public FunctionInvocation getMethod() { return method; } public FunctionInvocation getMember() { return getMethod(); } /** * Sets the method component of this field access. * * @param method the new expression node * @exception IllegalArgumentException if: * <ul> * <li>the node belongs to a different AST</li> * <li>the node already has a parent</li> * <li>a cycle in would be created</li> * </ul> */ public void setMethod(FunctionInvocation method) { if (method == null) { throw new IllegalArgumentException(); } ASTNode oldChild = this.method; preReplaceChild(oldChild, method, METHOD_PROPERTY); this.method = method; postReplaceChild(oldChild, method, METHOD_PROPERTY); } final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == METHOD_PROPERTY) { if (get) { return getMethod(); } else { setMethod((FunctionInvocation) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); } /* * Method declared on ASTNode. */ public boolean subtreeMatch(ASTMatcher matcher, Object other) { // dispatch to correct overloaded match method return matcher.match(this, other); } @Override ASTNode clone0(AST target) { final VariableBase dispatcher = ASTNode.copySubtree(target, getDispatcher()); final FunctionInvocation field = ASTNode.copySubtree(target, getMethod()); final MethodInvocation result = new MethodInvocation(getStart(), getEnd(), target, dispatcher, field); return result; } @Override List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersion apiLevel) { return PROPERTY_DESCRIPTORS; } /** * Resolves and returns the binding for the Constructor accessed by this * expression. * * @return the binding, or <code>null</code> if the binding cannot be * resolved */ public IMethodBinding resolveConstructorBinding() { // Aptana Mod // return this.ast.getBindingResolver().resolveConstructor(this); return null; } /** * Resolves and returns the binding for the method invoked by this * expression. * * @return the binding, or <code>null</code> if the binding cannot be * resolved */ public IMethodBinding resolveMethodBinding() { // Aptana Mod // return this.ast.getBindingResolver().resolveMethod(this); return null; } }