@@ -0,0 +1,220 @@
package org2.eclipse.php.internal.core.ast.nodes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
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;
import org2.eclipse.php.internal.core.compiler.ast.nodes.ASTNodeKinds;

public class ChainingInstanceCall extends Expression {

private PHPArrayDereferenceList arrayDereferenceList;
// private ASTNode.NodeList<VariableBase> chainingMethodOrProperty = new
// ASTNode.NodeList<VariableBase>(
// CHAINING_METHOD_OR_PROPERTY);
private List<VariableBase> chainingMethodOrProperty = new LinkedList<VariableBase>();

public static final ChildPropertyDescriptor ARRAY_DEREFERENCE_LIST = new ChildPropertyDescriptor(
ChainingInstanceCall.class,
"arrayDereferenceList", PHPArrayDereferenceList.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$
// public static final ChildListPropertyDescriptor
// CHAINING_METHOD_OR_PROPERTY = new ChildListPropertyDescriptor(
// ChainingInstanceCall.class,
// "chainingMethodOrProperty", VariableBase.class, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(ARRAY_DEREFERENCE_LIST);
// propertyList.add(CHAINING_METHOD_OR_PROPERTY);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public ChainingInstanceCall(int start, int end, AST ast,
PHPArrayDereferenceList arrayDereferenceList,
List<VariableBase> chainingMethodOrProperty) {
super(start, end, ast);

this.arrayDereferenceList = arrayDereferenceList;
if (chainingMethodOrProperty != null) {
this.chainingMethodOrProperty.addAll(chainingMethodOrProperty);
}
}

public ChainingInstanceCall(AST ast,
PHPArrayDereferenceList arrayDereferenceList,
List<VariableBase> chainingMethodOrProperty) {
super(ast);

setArrayDereferenceList(arrayDereferenceList);
if (chainingMethodOrProperty != null) {
this.chainingMethodOrProperty.addAll(chainingMethodOrProperty);
}
}

public List<VariableBase> getChainingMethodOrProperty() {
return chainingMethodOrProperty;
}

public void setChainingMethodOrProperty(
ASTNode.NodeList<VariableBase> chainingMethodOrProperty) {
this.chainingMethodOrProperty = chainingMethodOrProperty;
}

public void setArrayDereferenceList(
PHPArrayDereferenceList arrayDereferenceList) {
ASTNode oldChild = this.arrayDereferenceList;
preReplaceChild(oldChild, arrayDereferenceList, ARRAY_DEREFERENCE_LIST);
this.arrayDereferenceList = arrayDereferenceList;
postReplaceChild(oldChild, arrayDereferenceList, ARRAY_DEREFERENCE_LIST);
}

public PHPArrayDereferenceList getArrayDereferenceList() {
return arrayDereferenceList;
}

public int getKind() {
return ASTNodeKinds.USE_STATEMENT;
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

public void childrenAccept(Visitor visitor) {
if (arrayDereferenceList != null) {

arrayDereferenceList.accept(visitor);
}
if (chainingMethodOrProperty != null) {
for (VariableBase variableBase : chainingMethodOrProperty) {
variableBase.accept(visitor);
}
}

}

public void traverseTopDown(Visitor visitor) {
accept(visitor);
if (arrayDereferenceList != null) {

arrayDereferenceList.traverseTopDown(visitor);
}
if (chainingMethodOrProperty != null) {
for (VariableBase variableBase : chainingMethodOrProperty) {
variableBase.traverseTopDown(visitor);
}
}
}

public void traverseBottomUp(Visitor visitor) {
if (arrayDereferenceList != null) {

arrayDereferenceList.traverseBottomUp(visitor);
}
if (chainingMethodOrProperty != null) {
for (VariableBase variableBase : chainingMethodOrProperty) {
variableBase.traverseBottomUp(visitor);
}
}
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<ChainingInstanceCall"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
// buffer.append(TAB).append(tab).append("<arrayDereferenceList>\n"); //$NON-NLS-1$
if (arrayDereferenceList != null) {
buffer.append(TAB).append(tab)
.append("<PHPArrayDereferenceList>\n"); //$NON-NLS-1$
arrayDereferenceList.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(TAB).append(tab).append("</PHPArrayDereferenceList>"); //$NON-NLS-1$
}
if (chainingMethodOrProperty != null) {
buffer.append(TAB).append(tab)
.append("<ChainingMethodOrProperty>\n"); //$NON-NLS-1$
for (VariableBase variableBase : chainingMethodOrProperty) {
variableBase.toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab)
.append("</ChainingMethodOrProperty>"); //$NON-NLS-1$
}
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</ChainingInstanceCall>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.FUNCTION_NAME;
}

/*
* 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) {
PHPArrayDereferenceList arrayDereferenceList = ASTNode.copySubtree(
target, getArrayDereferenceList());

final List<VariableBase> chainingMethodOrProperty = ASTNode
.copySubtrees(target, getChainingMethodOrProperty());
final ChainingInstanceCall result = new ChainingInstanceCall(
this.getStart(), this.getEnd(), target, arrayDereferenceList,
chainingMethodOrProperty);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

/*
* (omit javadoc for this method) Method declared on ASTNode.
*/
final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
// if (property == CHAINING_METHOD_OR_PROPERTY) {
// return getChainingMethodOrProperty();
// }
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == ARRAY_DEREFERENCE_LIST) {
if (get) {
return getArrayDereferenceList();
} else {
setArrayDereferenceList((PHPArrayDereferenceList) child);
return null;
}
}

// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

}
@@ -21,8 +21,12 @@

/**
* Represents a class declaration
*
* <pre>
*
* <pre>e.g.
*
* <pre>
* <pre>e.g.<pre>
* class MyClass { },
* class MyClass extends SuperClass implements Interface1, Interface2 {
* const MY_CONSTANT = 3;
@@ -31,24 +35,32 @@
* private function myFunction($a) { }
* }
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class ClassDeclaration extends TypeDeclaration {

public static final int MODIFIER_NONE = 0;
public static final int MODIFIER_ABSTRACT = 1;
public static final int MODIFIER_FINAL = 2;
public static final int MODIFIER_TRAIT = 3;

private int modifier;
private Expression superClass;

/**
* The structural property of this node type.
*/
public static final ChildPropertyDescriptor NAME_PROPERTY = new ChildPropertyDescriptor(ClassDeclaration.class, "name", Identifier.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor INTERFACES_PROPERTY = new ChildListPropertyDescriptor(ClassDeclaration.class, "interfaces", Identifier.class, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor BODY_PROPERTY = new ChildPropertyDescriptor(ClassDeclaration.class, "body", Block.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor SUPER_CLASS_PROPERTY = new ChildPropertyDescriptor(ClassDeclaration.class, "superClass", Expression.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
public static final SimplePropertyDescriptor MODIFIER_PROPERTY = new SimplePropertyDescriptor(ClassDeclaration.class, "modifier", Integer.class, OPTIONAL); //$NON-NLS-1$
public static final ChildPropertyDescriptor NAME_PROPERTY = new ChildPropertyDescriptor(
ClassDeclaration.class,
"name", Identifier.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor INTERFACES_PROPERTY = new ChildListPropertyDescriptor(
ClassDeclaration.class,
"interfaces", Identifier.class, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor BODY_PROPERTY = new ChildPropertyDescriptor(
ClassDeclaration.class, "body", Block.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor SUPER_CLASS_PROPERTY = new ChildPropertyDescriptor(
ClassDeclaration.class,
"superClass", Expression.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
public static final SimplePropertyDescriptor MODIFIER_PROPERTY = new SimplePropertyDescriptor(
ClassDeclaration.class, "modifier", Integer.class, OPTIONAL); //$NON-NLS-1$

@Override
protected ChildPropertyDescriptor getBodyProperty() {
@@ -66,14 +78,14 @@ protected ChildPropertyDescriptor getNameProperty() {
}

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
* or null if uninitialized.
* 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>(5);
List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(
5);
propertyList.add(NAME_PROPERTY);
propertyList.add(INTERFACES_PROPERTY);
propertyList.add(BODY_PROPERTY);
@@ -82,7 +94,9 @@ protected ChildPropertyDescriptor getNameProperty() {
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

private ClassDeclaration(int start, int end, AST ast, int modifier, Identifier className, Expression superClass, Identifier[] interfaces, Block body) {
private ClassDeclaration(int start, int end, AST ast, int modifier,
Identifier className, Expression superClass,
Identifier[] interfaces, Block body) {
super(start, end, ast, className, interfaces, body);

setModifier(modifier);
@@ -95,8 +109,12 @@ public ClassDeclaration(AST ast) {
super(ast);
}

public ClassDeclaration(int start, int end, AST ast, int modifier, Identifier className, Expression superClass, List interfaces, Block body) {
this(start, end, ast, modifier, className, superClass, interfaces == null ? null : (Identifier[]) interfaces.toArray(new Identifier[interfaces.size()]), body);
public ClassDeclaration(int start, int end, AST ast, int modifier,
Identifier className, Expression superClass, List interfaces,
Block body) {
this(start, end, ast, modifier, className, superClass,
interfaces == null ? null : (Identifier[]) interfaces
.toArray(new Identifier[interfaces.size()]), body);
}

public void accept0(Visitor visitor) {
@@ -125,6 +143,7 @@ public void traverseTopDown(Visitor visitor) {
if (superClass != null) {
superClass.traverseTopDown(visitor);
}
Identifier[] interfaces = getInterfaces();
for (Object object : interfaces()) {
final ASTNode node = (ASTNode) object;
node.traverseTopDown(visitor);
@@ -137,6 +156,7 @@ public void traverseBottomUp(Visitor visitor) {
if (superClass != null) {
superClass.traverseBottomUp(visitor);
}
Identifier[] interfaces = getInterfaces();
for (Object object : interfaces()) {
final ASTNode node = (ASTNode) object;
node.traverseBottomUp(visitor);
@@ -147,14 +167,14 @@ public void traverseBottomUp(Visitor visitor) {

public static String getModifier(int modifier) {
switch (modifier) {
case MODIFIER_NONE:
return ""; //$NON-NLS-1$
case MODIFIER_ABSTRACT:
return "abstract"; //$NON-NLS-1$
case MODIFIER_FINAL:
return "final"; //$NON-NLS-1$
default:
throw new IllegalArgumentException();
case MODIFIER_NONE:
return ""; //$NON-NLS-1$
case MODIFIER_ABSTRACT:
return "abstract"; //$NON-NLS-1$
case MODIFIER_FINAL:
return "final"; //$NON-NLS-1$
default:
throw new IllegalArgumentException();
}
}

@@ -198,12 +218,13 @@ public int getModifier() {
* Sets the modifier of this class declaration
*
* @param new modifier of this class declaration
* @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>
* @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 final void setModifier(int value) {
preValueChange(MODIFIER_PROPERTY);
@@ -218,16 +239,19 @@ public Expression getSuperClass() {
/**
* Sets the super class name of this class declaration
*
* @param the super class name of this class declaration
* @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>
* @param the
* super class name of this class declaration
* @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 setSuperClass(Expression id) {
if (id != null && !(id instanceof Identifier) && !(id instanceof NamespaceName)) {
if (id != null && !(id instanceof Identifier)
&& !(id instanceof NamespaceName)) {
throw new IllegalArgumentException();
}
// an Assignment may occur inside a Expression - must check cycles
@@ -237,7 +261,8 @@ public void setSuperClass(Expression id) {
postReplaceChild(oldChild, id, SUPER_CLASS_PROPERTY);
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == SUPER_CLASS_PROPERTY) {
if (get) {
return getSuperClass();
@@ -250,7 +275,8 @@ final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, bool
return super.internalGetSetChildProperty(property, get, child);
}

final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int child) {
final int internalGetSetIntProperty(SimplePropertyDescriptor property,
boolean get, int child) {
if (property == MODIFIER_PROPERTY) {
if (get) {
return getModifier();
@@ -263,7 +289,7 @@ final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean g
return super.internalGetSetIntProperty(property, get, child);
}

/*
/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
@@ -274,17 +300,20 @@ public boolean subtreeMatch(ASTMatcher matcher, Object other) {
@Override
ASTNode clone0(AST target) {
final Block body = ASTNode.copySubtree(target, getBody());
final Expression superName = ASTNode.copySubtree(target, getSuperClass());
final Expression superName = ASTNode.copySubtree(target,
getSuperClass());
final int modifier = getModifier();
final List interfaces = ASTNode.copySubtrees(target, interfaces());
final Identifier name = ASTNode.copySubtree(target, getName());

final ClassDeclaration result = new ClassDeclaration(getStart(), getEnd(), target, modifier, name, superName, interfaces, body);
final ClassDeclaration result = new ClassDeclaration(getStart(),
getEnd(), target, modifier, name, superName, interfaces, body);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersion apiLevel) {
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}
}
@@ -20,40 +20,52 @@
import org2.eclipse.php.internal.core.ast.visitor.Visitor;

/**
* Represents a class instantiation.
* This class holds the class name as an expression and
* array of constructor parameters
* <pre>e.g.<pre> new MyClass(),
* Represents a class instantiation. This class holds the class name as an
* expression and array of constructor parameters
*
* <pre>e.g.
*
* <pre>
* new MyClass(),
* new $a('start'),
* new foo()(1, $a)
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class ClassInstanceCreation extends Expression {
public class ClassInstanceCreation extends VariableBase {

private ClassName className;
private ASTNode.NodeList<Expression> ctorParams = new ASTNode.NodeList<Expression>(CTOR_PARAMS_PROPERTY);

private ASTNode.NodeList<Expression> ctorParams = new ASTNode.NodeList<Expression>(
CTOR_PARAMS_PROPERTY);
private ChainingInstanceCall chainingInstanceCall;
/**
* The structural property of this node type.
*/
public static final ChildPropertyDescriptor CLASSNAME_PROPERTY = new ChildPropertyDescriptor(ClassInstanceCreation.class, "className", ClassName.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor CTOR_PARAMS_PROPERTY = new ChildListPropertyDescriptor(ClassInstanceCreation.class, "ctorParams", Expression.class, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor CLASSNAME_PROPERTY = new ChildPropertyDescriptor(
ClassInstanceCreation.class,
"className", ClassName.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor CTOR_PARAMS_PROPERTY = new ChildListPropertyDescriptor(
ClassInstanceCreation.class,
"ctorParams", Expression.class, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor CHAINING_INSTANCE_CALL_PROPERTY = new ChildPropertyDescriptor(
ClassInstanceCreation.class,
"className", ClassName.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
* or null if uninitialized.
* 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);
List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(
2);
propertyList.add(CLASSNAME_PROPERTY);
propertyList.add(CTOR_PARAMS_PROPERTY);
propertyList.add(CHAINING_INSTANCE_CALL_PROPERTY);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public ClassInstanceCreation(int start, int end, AST ast, ClassName className, Expression[] ctorParams) {
public ClassInstanceCreation(int start, int end, AST ast,
ClassName className, Expression[] ctorParams) {
super(start, end, ast);
if (className == null || ctorParams == null) {
throw new IllegalArgumentException();
@@ -77,15 +89,21 @@ public void accept0(Visitor visitor) {
visitor.endVisit(this);
}

public ClassInstanceCreation(int start, int end, AST ast, ClassName className, List ctorParams) {
this(start, end, ast, className, ctorParams == null ? null : (Expression[]) ctorParams.toArray(new Expression[ctorParams.size()]));
public ClassInstanceCreation(int start, int end, AST ast,
ClassName className, List ctorParams) {
this(start, end, ast, className, ctorParams == null ? null
: (Expression[]) ctorParams.toArray(new Expression[ctorParams
.size()]));
}

public void childrenAccept(Visitor visitor) {
className.accept(visitor);
for (ASTNode node : this.ctorParams) {
node.accept(visitor);
}
// if (chainingInstanceCall != null) {
// chainingInstanceCall.accept(visitor);
// }
}

public void traverseTopDown(Visitor visitor) {
@@ -94,13 +112,19 @@ public void traverseTopDown(Visitor visitor) {
for (ASTNode node : this.ctorParams) {
node.traverseTopDown(visitor);
}
// if (chainingInstanceCall != null) {
// chainingInstanceCall.traverseTopDown(visitor);
// }
}

public void traverseBottomUp(Visitor visitor) {
className.traverseBottomUp(visitor);
for (ASTNode node : this.ctorParams) {
node.traverseBottomUp(visitor);
}
// if (chainingInstanceCall != null) {
// chainingInstanceCall.traverseBottomUp(visitor);
// }
accept(visitor);
}

@@ -115,6 +139,10 @@ public void toString(StringBuffer buffer, String tab) {
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab).append("</ConstructorParameters>\n"); //$NON-NLS-1$
// if (chainingInstanceCall != null) {
// chainingInstanceCall.toString(buffer, TAB + tab);
// buffer.append("\n"); //$NON-NLS-1$
// }
buffer.append(tab).append("</ClassInstanceCreation>"); //$NON-NLS-1$
}

@@ -134,13 +162,15 @@ public ClassName getClassName() {
/**
* Sets the class name of this instansiation.
*
* @param classname the new class name
* @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>
* @param classname
* the new class name
* @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 setClassName(ClassName classname) {
if (classname == null) {
@@ -152,20 +182,38 @@ public void setClassName(ClassName classname) {
postReplaceChild(oldChild, classname, CLASSNAME_PROPERTY);
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
public ChainingInstanceCall getChainingInstanceCall() {
return chainingInstanceCall;
}

public void setChainingInstanceCall(
ChainingInstanceCall chainingInstanceCall) {
this.chainingInstanceCall = chainingInstanceCall;
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == CLASSNAME_PROPERTY) {
if (get) {
return getClassName();
} else {
setClassName((ClassName) child);
return null;
}
} else if (property == CHAINING_INSTANCE_CALL_PROPERTY) {
if (get) {
return getChainingInstanceCall();
} else {
setChainingInstanceCall((ChainingInstanceCall) child);
return null;
}
}
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

public List internalGetChildListProperty(ChildListPropertyDescriptor property) {
public List internalGetChildListProperty(
ChildListPropertyDescriptor property) {
if (property == CTOR_PARAMS_PROPERTY) {
return ctorParams();
}
@@ -181,14 +229,14 @@ public Expression[] getCtorParams() {

/**
* List of expressions that were given to the the constructor
*
* @return list of expressions that were given to the the constructor
*
* @return list of expressions that were given to the the constructor
*/
public List<Expression> ctorParams() {
return this.ctorParams;
}

/*
/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
@@ -200,24 +248,26 @@ public boolean subtreeMatch(ASTMatcher matcher, Object other) {
ASTNode clone0(AST target) {
final List params = ASTNode.copySubtrees(target, ctorParams());
final ClassName cn = ASTNode.copySubtree(target, getClassName());
final ClassInstanceCreation result = new ClassInstanceCreation(this.getStart(), this.getEnd(), target, cn, params);
final ClassInstanceCreation result = new ClassInstanceCreation(
this.getStart(), this.getEnd(), target, cn, params);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersion apiLevel) {
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

/**
* Resolves and returns the binding for the constructor invoked by this
* expression.
*
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
*
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
public IMethodBinding resolveConstructorBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveConstructor(this);
// TODO? Shalom - return this.ast.getBindingResolver().resolveConstructor(this);
return null;
}

@@ -27,9 +27,9 @@
*/
public class Comment extends ASTNode {

public final static int TYPE_SINGLE_LINE = 1 << 1;
public final static int TYPE_MULTILINE = 1 << 2;
public final static int TYPE_PHPDOC = 1 << 3;
public final static int TYPE_SINGLE_LINE = 0;
public final static int TYPE_MULTILINE = 1;
public final static int TYPE_PHPDOC = 2;

private int commentType;

@@ -1,14 +1,3 @@
/*******************************************************************************
* Copyright (c) 2012 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;
@@ -24,7 +24,6 @@
* <pre>e.g.<pre> echo "hello",
* echo "hello", "world"
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class EchoStatement extends Statement {

private ASTNode.NodeList<Expression> expressions = new ASTNode.NodeList<Expression>(EXPRESSIONS_PROPERTY);
@@ -11,125 +11,112 @@
*******************************************************************************/
package org2.eclipse.php.internal.core.ast.nodes;

import com.aptana.editor.php.core.typebinding.ITypeBinding;

/**
* Base class for all expression in PHP
*/
public abstract class Expression extends ASTNode
{
public Expression(int start, int end, AST ast)
{
public abstract class Expression extends ASTNode {

public Expression(int start, int end, AST ast) {
super(start, end, ast);
}

public Expression(AST ast)
{

public Expression(AST ast) {
super(ast);
}

/**
* A static scalar expression is a "compile-time evaluated scalar" i.e. expression that can be evaluated before
* execution time. In PHP static scalars can be scalars, unary operations or array creations nodes it can be used in
* declare statement, formal parameter list, static statement and class constant declaration
* A static scalar expression is a "compile-time evaluated scalar"
* i.e. expression that can be evaluated before execution time.
*
* In PHP static scalars can be scalars, unary operations or array creations nodes
* it can be used in declare statement, formal parameter list,
* static statement and class constant declaration
* @return true if the expression is static scalar, false otherwise
*/
public boolean isStaticScalar()
{
public boolean isStaticScalar() {
final int type = getType();
if (type != ASTNode.SCALAR && type != ASTNode.UNARY_OPERATION && type != ARRAY_CREATION)
{
if (type != ASTNode.SCALAR && type != ASTNode.UNARY_OPERATION && type != ARRAY_CREATION) {
return false;
}

// check the context of the expression
final ASTNode parent = getParent();
if (parent == null)
{
if (parent == null) {
return false;
}
final int parentType = parent.getType();

// check - formal parameter and declare statement
if (parentType == ASTNode.FORMAL_PARAMETER || parentType == ASTNode.DECLARE_STATEMENT
|| parentType == ASTNode.CONSTANT_DECLARATION)
{
// check - formal parameter and declare statement
if (parentType == ASTNode.FORMAL_PARAMETER || parentType == ASTNode.DECLARE_STATEMENT || parentType == ASTNode.CONSTANT_DECLARATION) {
return true;
}
// check - static statement
if (parentType == ASTNode.ASSIGNMENT)
{
if (parentType == ASTNode.ASSIGNMENT) {
final ASTNode grandpa = parent.getParent();
if (grandpa == null)
{
if (grandpa == null) {
return false;
}

if (grandpa.getType() == ASTNode.STATIC_STATEMENT)
{

if (grandpa.getType() == ASTNode.STATIC_STATEMENT) {
return true;
}
return false;
}

// array elements nodes are static scalars only if their parent array creation
// are static scalars. like static $a = array( '5' => 4 )
if (parentType == ASTNode.ARRAY_ELEMENT)
{
// array elements nodes are static scalars only if their parent array creation
// are static scalars. like static $a = array( '5' => 4 )
if (parentType == ASTNode.ARRAY_ELEMENT) {
final ASTNode grandpa = parent.getParent();
if (grandpa == null || grandpa.getType() != ASTNode.ARRAY_CREATION)
{
if (grandpa == null || grandpa.getType() != ASTNode.ARRAY_CREATION) {
return false;
}

Expression grandpaExpression = (Expression) grandpa;
return grandpaExpression.isStaticScalar();
}

// check recursively for static scalars
if (parentType == ASTNode.SCALAR || parentType == ASTNode.UNARY_OPERATION || parentType == ARRAY_CREATION)
{

// check recursively for static scalars
if (parentType == ASTNode.SCALAR || parentType == ASTNode.UNARY_OPERATION || parentType == ARRAY_CREATION) {
final Expression parentExpression = (Expression) parent;
return parentExpression.isStaticScalar();
return parentExpression.isStaticScalar();
}

return false;
}

/**
* @return true if this is expression is the "null" expression
*/
public boolean isNullExpression()
{
if (getType() == ASTNode.SCALAR)
{
public boolean isNullExpression() {
if (getType() == ASTNode.SCALAR) {
final Scalar scalar = (Scalar) this;
if (scalar.getScalarType() == Scalar.TYPE_STRING && scalar.getStringValue().equalsIgnoreCase("null")) { //$NON-NLS-1$
return true;
}
}
return false;
}

}
/**
* Resolves and returns the binding for the type of this expression.
*
* @return the binding, or <code>null</code> if the binding cannot be resolved
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
public ITypeBinding resolveTypeBinding()
{
return (ITypeBinding)getBinding();
public ITypeBinding resolveTypeBinding() {
// Aptana Mod
return (ITypeBinding)getBinding(); // (this.ast.getBindingResolver().resolveExpressionType(this);
}

/**
* Resolves and returns the constant expression value
*
* @return the binding, or <code>null</code> if the binding cannot be resolved
*/
public Object resolveConstantExpressionValue()
{
// TODO: Shalom - return this.ast.getBindingResolver().resolveConstantExpressionValue(this);
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
public Object resolveConstantExpressionValue() {
// Aptana Mod
// return this.ast.getBindingResolver().resolveConstantExpressionValue(this);
return null;
}
}
@@ -189,7 +189,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IVariableBinding resolveFieldBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveField(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveField(this);
return null;
}
}
@@ -26,7 +26,6 @@
* public $a = 3;
* final private static $var;
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class FieldsDeclaration extends BodyDeclaration {

private final ASTNode.NodeList<SingleFieldDeclaration> fields = new ASTNode.NodeList<SingleFieldDeclaration>(FIELDS_PROPERTY);
@@ -202,7 +201,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public final IVariableBinding resolveTypeBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveVariable(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveVariable(this);
return null;
}
}
@@ -373,7 +373,8 @@ ASTNode clone0(AST target) {
* resolved
*/
public final ITypeBinding resolveTypeBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveTypeParameter(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveTypeParameter(this);
return null;
}

@@ -0,0 +1,173 @@
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;

public class FullyQualifiedTraitMethodReference extends Expression {

private NamespaceName className;
private Identifier functionName;

public static final ChildPropertyDescriptor CLASS_NAME = new ChildPropertyDescriptor(
FullyQualifiedTraitMethodReference.class,
"className", NamespaceName.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor FUNCTION_NAME = new ChildPropertyDescriptor(
FullyQualifiedTraitMethodReference.class,
"functionName", Identifier.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(CLASS_NAME);
propertyList.add(FUNCTION_NAME);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public FullyQualifiedTraitMethodReference(int start, int end, AST ast,
NamespaceName className, Identifier functionName) {
super(start, end, ast);
setClassName(className);
setFunctionName(functionName);
}

public FullyQualifiedTraitMethodReference(AST ast) {
super(ast);
}

public NamespaceName getClassName() {
return className;
}

public void setClassName(NamespaceName className) {
if (className == null) {
throw new IllegalArgumentException();
}

ASTNode oldChild = this.className;
preReplaceChild(oldChild, className, CLASS_NAME);
this.className = className;
postReplaceChild(oldChild, className, CLASS_NAME);
}

public Identifier getFunctionName() {
return functionName;
}

public void setFunctionName(Identifier functionName) {
ASTNode oldChild = this.functionName;
preReplaceChild(oldChild, functionName, FUNCTION_NAME);
this.functionName = functionName;
postReplaceChild(oldChild, functionName, FUNCTION_NAME);
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

public void childrenAccept(Visitor visitor) {
className.accept(visitor);
functionName.accept(visitor);

}

public void traverseTopDown(Visitor visitor) {
accept(visitor);
className.traverseTopDown(visitor);
functionName.traverseTopDown(visitor);
}

public void traverseBottomUp(Visitor visitor) {
className.traverseBottomUp(visitor);
functionName.traverseBottomUp(visitor);
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<FunctionName"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(" functionName='").append(functionName.getName())
.append("'");
buffer.append(">\n"); //$NON-NLS-1$
className.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</FunctionName>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.FULLY_QUALIFIED_TRAIT_METHOD_REFERENCE;
}

/*
* 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) {
NamespaceName className = ASTNode.copySubtree(target, getClassName());
final FullyQualifiedTraitMethodReference result = new FullyQualifiedTraitMethodReference(
this.getStart(), this.getEnd(), target, className, functionName);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

// @Override
// Object internalGetSetObjectProperty(SimplePropertyDescriptor property,
// boolean get, Object value) {
// if (property == FUNCTION_NAME) {
// if (get) {
// return getFunctionName();
// } else {
// setFunctionName((String) value);
// return null;
// }
// }
// return super.internalGetSetObjectProperty(property, get, value);
// }

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == CLASS_NAME) {
if (get) {
return getClassName();
} else {
setClassName((NamespaceName) child);
return null;
}
} else if (property == FUNCTION_NAME) {
if (get) {
return getFunctionName();
} else {
setFunctionName((Identifier) child);
return null;
}
}

// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

}
@@ -30,7 +30,6 @@
*
* function foo(); -abstract function in class declaration
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class FunctionDeclaration extends Statement {

private boolean isReference;
@@ -301,7 +300,7 @@ final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, bool
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == FORMAL_PARAMETERS_PROPERTY) {
return formalParameters();
@@ -341,7 +340,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IFunctionBinding resolveFunctionBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveFunction(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveFunction(this);
return null;
}
}
@@ -20,41 +20,53 @@
import org2.eclipse.php.internal.core.ast.visitor.Visitor;

/**
* Represents function invocation.
* Holds the function name and the invocation parameters.
* <pre>e.g.<pre> foo(),
* Represents function invocation. Holds the function name and the invocation
* parameters.
*
* <pre>e.g.
*
* <pre>
* foo(),
* $a(),
* foo($a, 'a', 12)
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class FunctionInvocation extends VariableBase {

private FunctionName functionName;
private final ASTNode.NodeList<Expression> parameters = new ASTNode.NodeList<Expression>(PARAMETERS_PROPERTY);

private final ASTNode.NodeList<Expression> parameters = new ASTNode.NodeList<Expression>(
PARAMETERS_PROPERTY);
private PHPArrayDereferenceList arrayDereferenceList;
/**
* The "expressions" structural property of this node type.
*/
public static final ChildPropertyDescriptor FUNCTION_PROPERTY =
new ChildPropertyDescriptor(FunctionInvocation.class, "functionName", FunctionName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor PARAMETERS_PROPERTY =
new ChildListPropertyDescriptor(FunctionInvocation.class, "parameters", Expression.class, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor FUNCTION_PROPERTY = new ChildPropertyDescriptor(
FunctionInvocation.class,
"functionName", FunctionName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor PARAMETERS_PROPERTY = new ChildListPropertyDescriptor(
FunctionInvocation.class,
"parameters", Expression.class, CYCLE_RISK); //$NON-NLS-1$
public static final ChildPropertyDescriptor ARRAY_DEREFERENCE_LIST = new ChildPropertyDescriptor(
FunctionInvocation.class,
"arrayDereferenceList", PHPArrayDereferenceList.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
* or null if uninitialized.
* 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);
List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(
2);
propertyList.add(FUNCTION_PROPERTY);
propertyList.add(PARAMETERS_PROPERTY);
propertyList.add(ARRAY_DEREFERENCE_LIST);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

private FunctionInvocation(int start, int end, AST ast, FunctionName functionName, Expression[] parameters) {
}

private FunctionInvocation(int start, int end, AST ast,
FunctionName functionName, Expression[] parameters,
PHPArrayDereferenceList arrayDereferenceList) {
super(start, end, ast);

if (functionName == null || parameters == null) {
@@ -65,14 +77,26 @@ private FunctionInvocation(int start, int end, AST ast, FunctionName functionNam
for (Expression expression : parameters) {
this.parameters.add(expression);
}
this.arrayDereferenceList = arrayDereferenceList;
}

public FunctionInvocation(AST ast) {
super(ast);
}

public FunctionInvocation(int start, int end, AST ast, FunctionName functionName, List parameters) {
this(start, end, ast, functionName, parameters == null ? null : (Expression[]) parameters.toArray(new Expression[parameters.size()]));
public FunctionInvocation(int start, int end, AST ast,
FunctionName functionName, List parameters) {
this(start, end, ast, functionName, parameters == null ? null
: (Expression[]) parameters.toArray(new Expression[parameters
.size()]), null);
}

public FunctionInvocation(int start, int end, AST ast,
FunctionName functionName, List parameters,
PHPArrayDereferenceList arrayDereferenceList) {
this(start, end, ast, functionName, parameters == null ? null
: (Expression[]) parameters.toArray(new Expression[parameters
.size()]), arrayDereferenceList);
}

public void accept0(Visitor visitor) {
@@ -81,13 +105,16 @@ public void accept0(Visitor visitor) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}
}

public void childrenAccept(Visitor visitor) {
functionName.accept(visitor);
for (ASTNode node : parameters) {
node.accept(visitor);
}
if (arrayDereferenceList != null) {
arrayDereferenceList.accept(visitor);
}
}

public void traverseTopDown(Visitor visitor) {
@@ -96,13 +123,19 @@ public void traverseTopDown(Visitor visitor) {
for (ASTNode node : parameters) {
node.traverseTopDown(visitor);
}
if (arrayDereferenceList != null) {
arrayDereferenceList.traverseTopDown(visitor);
}
}

public void traverseBottomUp(Visitor visitor) {
functionName.traverseBottomUp(visitor);
for (ASTNode node : parameters) {
node.traverseBottomUp(visitor);
}
if (arrayDereferenceList != null) {
arrayDereferenceList.traverseBottomUp(visitor);
}
accept(visitor);
}

@@ -118,6 +151,10 @@ public void toString(StringBuffer buffer, String tab) {
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab).append("</Parameters>\n"); //$NON-NLS-1$
if (arrayDereferenceList != null) {
arrayDereferenceList.toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(tab).append("</FunctionInvocation>"); //$NON-NLS-1$
}

@@ -137,14 +174,16 @@ public FunctionName getFunctionName() {
/**
* Sets the function name of this instantiation.
*
* @param functionname the new class name
* @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>
*/
* @param functionname
* the new class name
* @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 setFunctionName(FunctionName functionname) {
if (functionname == null) {
throw new IllegalArgumentException();
@@ -154,28 +193,45 @@ public void setFunctionName(FunctionName functionname) {
this.functionName = functionname;
postReplaceChild(oldChild, functionname, FUNCTION_PROPERTY);
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {

public PHPArrayDereferenceList getArrayDereferenceList() {
return arrayDereferenceList;
}

public void setArrayDereferenceList(
PHPArrayDereferenceList arrayDereferenceList) {
this.arrayDereferenceList = arrayDereferenceList;
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == FUNCTION_PROPERTY) {
if (get) {
return getFunctionName();
} else {
setFunctionName((FunctionName) child);
return null;
}
} else if (property == ARRAY_DEREFERENCE_LIST) {
if (get) {
return getArrayDereferenceList();
} else {
setArrayDereferenceList((PHPArrayDereferenceList) child);
return null;
}
}
// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == PARAMETERS_PROPERTY) {
return parameters();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

/**
* @deprecated use {@link #parameters()}
*/
@@ -188,8 +244,9 @@ public Expression[] getParameters() {
*/
public List<Expression> parameters() {
return parameters;
}
/*
}

/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
@@ -199,25 +256,34 @@ public boolean subtreeMatch(ASTMatcher matcher, Object other) {

@Override
ASTNode clone0(AST target) {
final FunctionName function = ASTNode.copySubtree(target, getFunctionName());
final FunctionName function = ASTNode.copySubtree(target,
getFunctionName());
final List params = ASTNode.copySubtrees(target, parameters());
final FunctionInvocation result = new FunctionInvocation(getStart(), getEnd(), target, function, params);
PHPArrayDereferenceList newArrayDereferenceList = null;
if (arrayDereferenceList != null) {
newArrayDereferenceList = ASTNode.copySubtree(target,
arrayDereferenceList);
}
final FunctionInvocation result = new FunctionInvocation(getStart(),
getEnd(), target, function, params, newArrayDereferenceList);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersion apiLevel) {
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

/**
* Resolves and returns the binding for this function
* Resolves and returns the binding for this function
*
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
* @return the binding, or <code>null</code> if the binding cannot be
* resolved
*/
public IFunctionBinding resolveFunctionBinding() {
// TODO - Shalom return this.ast.getBindingResolver().resolveFunction(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveFunction(this);
return null;
}
}
@@ -12,8 +12,11 @@

package org2.eclipse.php.internal.core.ast.nodes;

import org2.eclipse.dltk.ast.Modifiers;

import com.aptana.editor.php.core.model.IModelElement;


/**
* A binding represents a named entity in the PHP language. The world of
* bindings provides an integrated picture of the structure of the program as

Large diffs are not rendered by default.

@@ -162,6 +162,8 @@ public final void setName(String value) {
* resolved
*/
public final IBinding resolveBinding() {
// Aptana Mod
// return this.ast.getBindingResolver().resolveName(this);
return getBinding();
}
}
@@ -19,8 +19,6 @@
import org2.eclipse.php.internal.core.ast.match.ASTMatcher;
import org2.eclipse.php.internal.core.ast.visitor.Visitor;

import com.aptana.editor.php.core.typebinding.IBinding;

/**
* Represents include, include_once, require and require_once expressions
* <pre>e.g.<pre> include('myFile.php'),
@@ -245,6 +243,9 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IBinding resolveBinding() {
return (IBinding) getBinding();
// Aptana Mod
// return this.ast.getBindingResolver().resolveInclude(this);
return getBinding();
}

}
@@ -19,16 +19,21 @@
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.TextEdit;
import org2.eclipse.php.internal.core.ast.rewrite.*;
import org2.eclipse.php.internal.core.ast.rewrite.ASTRewriteAnalyzer;
import org2.eclipse.php.internal.core.ast.rewrite.LineInformation;
import org2.eclipse.php.internal.core.ast.rewrite.ListRewriteEvent;
import org2.eclipse.php.internal.core.ast.rewrite.NodeInfoStore;
import org2.eclipse.php.internal.core.ast.rewrite.NodeRewriteEvent;
import org2.eclipse.php.internal.core.ast.rewrite.RewriteEventStore;
import org2.eclipse.php.internal.core.ast.rewrite.RewriteEventStore.CopySourceInfo;
import org2.eclipse.php.internal.core.ast.rewrite.RewriteEventStore.PropertyLocation;
import org2.eclipse.php.internal.core.ast.rewrite.TargetSourceRangeComputer;
import org2.eclipse.php.internal.core.ast.scanner.AstLexer;

/**
* Internal class: not intended to be used by client.
* When AST modifications recording is enabled, all changes are recorded by this class.
* Internal class: not intended to be used by client. When AST modifications
* recording is enabled, all changes are recorded by this class.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
class InternalASTRewrite extends NodeEventHandler {

/** root node for the rewrite: Only nodes under this root are accepted */
@@ -43,7 +48,9 @@ class InternalASTRewrite extends NodeEventHandler {

/**
* Constructor
* @param root root node of the recorded ast.
*
* @param root
* root node of the recorded ast.
*/
public InternalASTRewrite(Program root) {
this.root = root;
@@ -54,11 +61,16 @@ public InternalASTRewrite(Program root) {
}

/**
* Performs the rewrite: The rewrite events are translated to the corresponding in text changes.
* @param document Document which describes the code of the AST that is passed in in the
* constructor. This document is accessed read-only.
* @param options options
* @throws IllegalArgumentException if the rewrite fails
* Performs the rewrite: The rewrite events are translated to the
* corresponding in text changes.
*
* @param document
* Document which describes the code of the AST that is passed in
* in the constructor. This document is accessed read-only.
* @param options
* options
* @throws IllegalArgumentException
* if the rewrite fails
* @return Returns the edit describing the text changes.
*/
public TextEdit rewriteAST(IDocument document, Map options) {
@@ -67,24 +79,30 @@ public TextEdit rewriteAST(IDocument document, Map options) {
final Program rootNode = getRootNode();
if (rootNode != null) {
TargetSourceRangeComputer xsrComputer = new TargetSourceRangeComputer() {
/**
/**
* This implementation of
* {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)}
* is specialized to work in the case of internal AST rewriting, where the
* original AST has been modified from its original form. This means that
* one cannot trust that the root of the given node is the compilation unit.
* is specialized to work in the case of internal AST rewriting,
* where the original AST has been modified from its original
* form. This means that one cannot trust that the root of the
* given node is the compilation unit.
*/
public SourceRange computeSourceRange(ASTNode node) {
int extendedStartPosition = rootNode.getExtendedStartPosition(node);
int extendedStartPosition = rootNode
.getExtendedStartPosition(node);
int extendedLength = rootNode.getExtendedLength(node);
return new SourceRange(extendedStartPosition, extendedLength);
return new SourceRange(extendedStartPosition,
extendedLength);
}
};
LineInformation lineInfo = LineInformation.create(document);
String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
List comments = rootNode.comments();

ASTRewriteAnalyzer visitor = new ASTRewriteAnalyzer(lexer, document, lineInfo, lineDelim, result, this.eventStore, this.nodeStore, comments, options, xsrComputer);
ASTRewriteAnalyzer visitor = new ASTRewriteAnalyzer(lexer,
document, lineInfo, lineDelim, result, this.eventStore,
this.nodeStore, comments, options, xsrComputer);
visitor.setInsertUseStatement(isInsertUseStatement);
rootNode.accept(visitor);
}
return result;
@@ -94,13 +112,19 @@ private void markAsMoveOrCopyTarget(ASTNode node, ASTNode newChild) {
ASTNode source = (ASTNode) this.clonedNodes.get(newChild);
if (source != null) {
if (this.cloneDepth == 0) {
PropertyLocation propertyLocation = this.eventStore.getPropertyLocation(source, RewriteEventStore.ORIGINAL);
CopySourceInfo sourceInfo = this.eventStore.markAsCopySource(propertyLocation.getParent(), propertyLocation.getProperty(), source, false);
PropertyLocation propertyLocation = this.eventStore
.getPropertyLocation(source, RewriteEventStore.ORIGINAL);
CopySourceInfo sourceInfo = this.eventStore.markAsCopySource(
propertyLocation.getParent(),
propertyLocation.getProperty(), source, false);
this.nodeStore.markAsCopyTarget(newChild, sourceInfo);
}
} else if ((newChild.getFlags() & ASTNode.ORIGINAL) != 0) {
PropertyLocation propertyLocation = this.eventStore.getPropertyLocation(newChild, RewriteEventStore.ORIGINAL);
CopySourceInfo sourceInfo = this.eventStore.markAsCopySource(propertyLocation.getParent(), propertyLocation.getProperty(), newChild, true);
PropertyLocation propertyLocation = this.eventStore
.getPropertyLocation(newChild, RewriteEventStore.ORIGINAL);
CopySourceInfo sourceInfo = this.eventStore.markAsCopySource(
propertyLocation.getParent(),
propertyLocation.getProperty(), newChild, true);
this.nodeStore.markAsCopyTarget(newChild, sourceInfo);
}
}
@@ -126,7 +150,8 @@ void postValueChangeEvent(ASTNode node, SimplePropertyDescriptor property) {
event.setNewValue(node.getStructuralProperty(property));
}

void preAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) {
void preAddChildEvent(ASTNode node, ASTNode child,
StructuralPropertyDescriptor property) {
if (property.isChildProperty()) {
NodeRewriteEvent event = this.getNodeEvent(node, property);
event.setNewValue(child);
@@ -139,7 +164,8 @@ void preAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor
}
}

void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) {
void postAddChildEvent(ASTNode node, ASTNode child,
StructuralPropertyDescriptor property) {
if (property.isChildListProperty()) {

ListRewriteEvent event = this.getListEvent(node, property);
@@ -160,7 +186,8 @@ void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor
}
}

void preRemoveChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) {
void preRemoveChildEvent(ASTNode node, ASTNode child,
StructuralPropertyDescriptor property) {
if (property.isChildProperty()) {
NodeRewriteEvent event = getNodeEvent(node, property);
event.setNewValue(null);
@@ -176,7 +203,8 @@ void preRemoveChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescript
}
}

void preReplaceChildEvent(ASTNode node, ASTNode child, ASTNode newChild, StructuralPropertyDescriptor property) {
void preReplaceChildEvent(ASTNode node, ASTNode child, ASTNode newChild,
StructuralPropertyDescriptor property) {
if (property.isChildProperty()) {
NodeRewriteEvent event = getNodeEvent(node, property);
event.setNewValue(newChild);
@@ -213,11 +241,20 @@ void postCloneNodeEvent(ASTNode node, ASTNode clone) {
this.cloneDepth--;
}

private NodeRewriteEvent getNodeEvent(ASTNode node, StructuralPropertyDescriptor property) {
private NodeRewriteEvent getNodeEvent(ASTNode node,
StructuralPropertyDescriptor property) {
return this.eventStore.getNodeEvent(node, property, true);
}

private ListRewriteEvent getListEvent(ASTNode node, StructuralPropertyDescriptor property) {
private ListRewriteEvent getListEvent(ASTNode node,
StructuralPropertyDescriptor property) {
return this.eventStore.getListEvent(node, property, true);
}

private boolean isInsertUseStatement;

public void setInsertUseStatement(boolean isInsertUseStatement) {
// TODO Auto-generated method stub
this.isInsertUseStatement = isInsertUseStatement;
}
}
@@ -29,10 +29,11 @@
*
* @see http://wiki.php.net/rfc/closures
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class LambdaFunctionDeclaration extends Expression {

private boolean isReference;
private boolean isStatic;
private int staticStart;
private final ASTNode.NodeList<FormalParameter> formalParameters = new ASTNode.NodeList<FormalParameter>(
FORMAL_PARAMETERS_PROPERTY);
private final ASTNode.NodeList<Expression> lexicalVariables = new ASTNode.NodeList<Expression>(
@@ -45,6 +46,9 @@ public class LambdaFunctionDeclaration extends Expression {
public static final SimplePropertyDescriptor IS_REFERENCE_PROPERTY = new SimplePropertyDescriptor(
LambdaFunctionDeclaration.class,
"isReference", Boolean.class, OPTIONAL); //$NON-NLS-1$
public static final SimplePropertyDescriptor IS_STATIC = new SimplePropertyDescriptor(
LambdaFunctionDeclaration.class,
"isStatic", Boolean.class, OPTIONAL); //$NON-NLS-1$
public static final ChildListPropertyDescriptor FORMAL_PARAMETERS_PROPERTY = new ChildListPropertyDescriptor(
LambdaFunctionDeclaration.class,
"formalParameters", FormalParameter.class, NO_CYCLE_RISK); //$NON-NLS-1$
@@ -64,6 +68,7 @@ public class LambdaFunctionDeclaration extends Expression {
List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(
4);
propertyList.add(IS_REFERENCE_PROPERTY);
propertyList.add(IS_STATIC);
propertyList.add(FORMAL_PARAMETERS_PROPERTY);
propertyList.add(LEXICAL_VARIABLES_PROPERTY);
propertyList.add(BODY_PROPERTY);
@@ -73,6 +78,13 @@ public class LambdaFunctionDeclaration extends Expression {
public LambdaFunctionDeclaration(int start, int end, AST ast,
List formalParameters, List lexicalVars, Block body,
final boolean isReference) {
this(start, end, ast, formalParameters, lexicalVars, body, isReference,
false, -1);
}

public LambdaFunctionDeclaration(int start, int end, AST ast,
List formalParameters, List lexicalVars, Block body,
final boolean isReference, final boolean isStatic, int staticStart) {
super(start, end, ast);

if (formalParameters == null) {
@@ -94,6 +106,8 @@ public LambdaFunctionDeclaration(int start, int end, AST ast,
if (body != null) {
setBody(body);
}
setStatic(isStatic);
this.staticStart = staticStart;
}

public LambdaFunctionDeclaration(AST ast) {
@@ -149,8 +163,11 @@ public void traverseBottomUp(Visitor visitor) {
public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<LambdaFunctionDeclaration"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(" isReference='").append(isReference).append("'>\n"); //$NON-NLS-1$ //$NON-NLS-2$

buffer.append(" isReference='").append(isReference); //$NON-NLS-1$ //$NON-NLS-2$
if (isStatic) {
buffer.append(" isStatic='").append(isStatic); //$NON-NLS-1$ //$NON-NLS-2$
}
buffer.append("'>\n");
buffer.append(TAB).append(tab).append("<FormalParameters>\n"); //$NON-NLS-1$
for (ASTNode node : this.formalParameters) {
node.toString(buffer, TAB + TAB + tab);
@@ -257,6 +274,16 @@ public final void setIsReference(boolean value) {
postValueChange(IS_REFERENCE_PROPERTY);
}

public boolean isStatic() {
return isStatic;
}

public void setStatic(boolean isStatic) {
preValueChange(IS_STATIC);
this.isStatic = isStatic;
postValueChange(IS_STATIC);
}

/*
* (omit javadoc for this method) Method declared on ASTNode.
*/
@@ -269,6 +296,13 @@ final boolean internalGetSetBooleanProperty(
setIsReference(value);
return false;
}
} else if (property == IS_STATIC) {
if (get) {
return isStatic();
} else {
setStatic(value);
return false;
}
}
// allow default implementation to flag the error
return super.internalGetSetBooleanProperty(property, get, value);
@@ -318,7 +352,7 @@ ASTNode clone0(AST target) {

final LambdaFunctionDeclaration result = new LambdaFunctionDeclaration(
getStart(), getEnd(), target, formalParams, lexicalVars, body,
isRef);
isRef, isStatic(), this.staticStart);
return result;
}

@@ -213,6 +213,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IMethodBinding resolveMethodBinding() {
// Aptana Mod
// return this.ast.getBindingResolver().resolveMethod(this);
return (IMethodBinding) this.getBinding();
}
}
@@ -186,7 +186,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IMethodBinding resolveConstructorBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveConstructor(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveConstructor(this);
return null;
}

@@ -198,7 +199,8 @@ public IMethodBinding resolveConstructorBinding() {
* resolved
*/
public IMethodBinding resolveMethodBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveMethod(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveMethod(this);
return null;
}

@@ -0,0 +1,5 @@
package org2.eclipse.php.internal.core.ast.nodes;

public interface MethodStub {

}
@@ -0,0 +1,10 @@
package org2.eclipse.php.internal.core.ast.nodes;

import java.util.List;

public class ParameterAndDereferenceList {

public List parameterList;
public PHPArrayDereferenceList arrayDereferenceList;

}
@@ -21,7 +21,11 @@

/**
* Represents a scalar
* <pre>e.g.<pre> 'string',
*
* <pre>e.g.
*
* <pre>
* 'string',
* 1,
* 1.3,
* __CLASS__
@@ -38,32 +42,34 @@ public class Scalar extends Expression {
public static final int TYPE_UNKNOWN = 3;
// system scalars (__CLASS__ / ...)
public static final int TYPE_SYSTEM = 4;
// 'binary' starts with "0b",e.g "0b"[01]+
public static final int TYPE_BIN = 5;

private String stringValue;
private int scalarType;

/**
* The structural property of this node type.
*/
public static final SimplePropertyDescriptor VALUE_PROPERTY =
new SimplePropertyDescriptor(Scalar.class, "stringValue", String.class, MANDATORY); //$NON-NLS-1$
public static final SimplePropertyDescriptor TYPE_PROPERTY =
new SimplePropertyDescriptor(Scalar.class, "scalarType", Integer.class, MANDATORY); //$NON-NLS-1$
public static final SimplePropertyDescriptor VALUE_PROPERTY = new SimplePropertyDescriptor(
Scalar.class, "stringValue", String.class, MANDATORY); //$NON-NLS-1$
public static final SimplePropertyDescriptor TYPE_PROPERTY = new SimplePropertyDescriptor(
Scalar.class, "scalarType", Integer.class, MANDATORY); //$NON-NLS-1$

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
* or null if uninitialized.
* 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);
List<StructuralPropertyDescriptor> propertyList = new ArrayList<StructuralPropertyDescriptor>(
2);
propertyList.add(VALUE_PROPERTY);
propertyList.add(TYPE_PROPERTY);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}
}

public Scalar(int start, int end, AST ast, String value, int type) {
super(start, end, ast);

@@ -85,7 +91,7 @@ public void accept0(Visitor visitor) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}
}

public void childrenAccept(Visitor visitor) {
}
@@ -108,18 +114,20 @@ public void toString(StringBuffer buffer, String tab) {

public static String getType(int type) {
switch (type) {
case TYPE_INT:
return "int"; //$NON-NLS-1$
case TYPE_REAL:
return "real"; //$NON-NLS-1$
case TYPE_STRING:
return "string"; //$NON-NLS-1$
case TYPE_UNKNOWN:
return "unknown"; //$NON-NLS-1$
case TYPE_SYSTEM:
return "system"; //$NON-NLS-1$
default:
throw new IllegalArgumentException();
case TYPE_INT:
return "int"; //$NON-NLS-1$
case TYPE_REAL:
return "real"; //$NON-NLS-1$
case TYPE_STRING:
return "string"; //$NON-NLS-1$
case TYPE_UNKNOWN:
return "unknown"; //$NON-NLS-1$
case TYPE_SYSTEM:
return "system"; //$NON-NLS-1$
case TYPE_BIN:
return "bin"; //$NON-NLS-1$
default:
throw new IllegalArgumentException();
}
}

@@ -130,6 +138,7 @@ public int getType() {
/**
* the scalar type - one of {@link #TYPE_INT}, {@link #TYPE_REAL},
* {@link #TYPE_STRING}, {@link #TYPE_SYSTEM} {@link #TYPE_UNKNOWN}
*
* @return scalar type
*/
public int getScalarType() {
@@ -140,24 +149,26 @@ public int getScalarType() {
* Sets the type of this scalar
*
* @param new operator of this unary operation
* @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>
* @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 final void setScalarType(int type) {
if (getType(type) == null) {
throw new IllegalArgumentException();
}

preValueChange(TYPE_PROPERTY);
this.scalarType = type;
postValueChange(TYPE_PROPERTY);
}

final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) {

final int internalGetSetIntProperty(SimplePropertyDescriptor property,
boolean get, int value) {
if (property == TYPE_PROPERTY) {
if (get) {
return getScalarType();
@@ -169,9 +180,10 @@ final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean g
// allow default implementation to flag the error
return super.internalGetSetIntProperty(property, get, value);
}

/**
* the scalar value
*
* @return scalar value
*/
public String getStringValue() {
@@ -182,24 +194,26 @@ public String getStringValue() {
* Sets the value of this scalar
*
* @param new operator of this unary operation
* @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>
* @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 final void setStringValue(String value) {
if (value == null) {
throw new IllegalArgumentException();
}

preValueChange(VALUE_PROPERTY);
this.stringValue = value;
postValueChange(VALUE_PROPERTY);
}

final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) {

final Object internalGetSetObjectProperty(
SimplePropertyDescriptor property, boolean get, Object value) {
if (property == VALUE_PROPERTY) {
if (get) {
return getStringValue();
@@ -210,9 +224,9 @@ final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boo
}
// allow default implementation to flag the error
return super.internalGetSetObjectProperty(property, get, value);
}
/*
}

/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
@@ -222,13 +236,15 @@ public boolean subtreeMatch(ASTMatcher matcher, Object other) {

@Override
ASTNode clone0(AST target) {
final Scalar result = new Scalar(this.getStart(), this.getEnd(), target, getStringValue(), getScalarType());
final Scalar result = new Scalar(this.getStart(), this.getEnd(),
target, getStringValue(), getScalarType());
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersion apiLevel) {
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

}
@@ -190,7 +190,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IVariableBinding resolveFieldBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveField(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveField(this);
return null;
}
}
@@ -185,7 +185,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IVariableBinding resolveFieldBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveField(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveField(this);
return null;
}

@@ -189,7 +189,8 @@ List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(PHPVersio
* resolved
*/
public IMethodBinding resolveMethodBinding() {
// TODO: Shalom - return this.ast.getBindingResolver().resolveMethod(this);
// Aptana Mod
// return this.ast.getBindingResolver().resolveMethod(this);
return null;
}
}
@@ -0,0 +1,228 @@
package org2.eclipse.php.internal.core.ast.nodes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org2.eclipse.php.core.compiler.PHPFlags;
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;

public class TraitAlias extends Expression {

// TODO need modifier start offset,change functionName to scalar
public TraitAlias(int start, int end, AST ast, Expression traitMethod,
int modifier, int modifierOffset, Identifier functionName) {
super(start, end, ast);
setTraitMethod(traitMethod);
setModifier(modifier);
setModifierOffset(modifierOffset);
setFunctionName(functionName);
}

public TraitAlias(AST ast) {
super(ast);
}

private Expression traitMethod;
private int modifier;
private int modifierOffset;

/**
* functionName could be null
*/
private Identifier functionName;

public static final ChildPropertyDescriptor TRAIT_METHOD = new ChildPropertyDescriptor(
TraitAlias.class,
"traitMethod", Expression.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
public static final SimplePropertyDescriptor MODIFIER = new SimplePropertyDescriptor(
TraitAlias.class, "modifier", Integer.class, OPTIONAL); //$NON-NLS-1$
public static final ChildPropertyDescriptor FUNCTION_NAME = new ChildPropertyDescriptor(
TraitAlias.class,
"functionName", Identifier.class, OPTIONAL, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(TRAIT_METHOD);
propertyList.add(MODIFIER);
propertyList.add(FUNCTION_NAME);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public Expression getTraitMethod() {
return traitMethod;
}

public void setTraitMethod(Expression traitMethod) {
if (traitMethod == null) {
throw new IllegalArgumentException();
}
ASTNode oldChild = this.traitMethod;
preReplaceChild(oldChild, traitMethod, TRAIT_METHOD);
this.traitMethod = traitMethod;
postReplaceChild(oldChild, traitMethod, TRAIT_METHOD);
}

public int getModifier() {
return modifier;
}

public void setModifier(int modifier) {
preValueChange(MODIFIER);
this.modifier = modifier;
postValueChange(MODIFIER);
}

public int getModifierOffset() {
return modifierOffset;
}

public void setModifierOffset(int modifierOffset) {
this.modifierOffset = modifierOffset;
}

public Identifier getFunctionName() {
return functionName;
}

public void setFunctionName(Identifier functionName) {
ASTNode oldChild = this.functionName;
preReplaceChild(oldChild, functionName, FUNCTION_NAME);
this.functionName = functionName;
postReplaceChild(oldChild, functionName, FUNCTION_NAME);
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

public void childrenAccept(Visitor visitor) {
traitMethod.accept(visitor);
if (functionName != null) {
functionName.accept(visitor);
}

}

public void traverseTopDown(Visitor visitor) {
accept(visitor);
traitMethod.traverseTopDown(visitor);
if (functionName != null) {
functionName.traverseTopDown(visitor);
}
}

public void traverseBottomUp(Visitor visitor) {
traitMethod.traverseBottomUp(visitor);
if (functionName != null) {
functionName.traverseBottomUp(visitor);
}
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitAlias"); //$NON-NLS-1$
appendInterval(buffer);
if (functionName != null) {
buffer.append(" functionName='").append(functionName.getName()).append("' "); //$NON-NLS-1$
}
buffer.append(" modifier='").append(PHPFlags.toString(modifier)).append("'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
traitMethod.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</TraitAlias>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.FUNCTION_NAME;
}

/*
* 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) {
Expression traitMethod = ASTNode.copySubtree(target, getTraitMethod());
Identifier functionName = ASTNode
.copySubtree(target, getFunctionName());
final TraitAlias result = new TraitAlias(this.getStart(),
this.getEnd(), target, traitMethod, modifier, modifierOffset,
functionName);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

// @Override
// Object internalGetSetObjectProperty(SimplePropertyDescriptor property,
// boolean get, Object value) {
// if (property == FUNCTION_NAME) {
// if (get) {
// return getFunctionName();
// } else {
// setFunctionName((String) value);
// return null;
// }
// }
// return super.internalGetSetObjectProperty(property, get, value);
// }

@Override
int internalGetSetIntProperty(SimplePropertyDescriptor property,
boolean get, int value) {
if (property == MODIFIER) {
if (get) {
return getModifier();
} else {
int oldValue = getModifier();
setModifier(value);
return oldValue;
}
}
return super.internalGetSetIntProperty(property, get, value);
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == TRAIT_METHOD) {
if (get) {
return getTraitMethod();
} else {
setTraitMethod((Expression) child);
return null;
}
} else if (property == FUNCTION_NAME) {
if (get) {
return getFunctionName();
} else {
setFunctionName((Identifier) child);
return null;
}
}

// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

}
@@ -0,0 +1,59 @@
package org2.eclipse.php.internal.core.ast.nodes;

import org2.eclipse.php.internal.core.ast.match.ASTMatcher;
import org2.eclipse.php.internal.core.ast.visitor.Visitor;

public class TraitAliasStatement extends TraitStatement {
private TraitAlias alias;

public TraitAliasStatement(int start, int end, AST ast, TraitAlias alias) {
super(start, end, ast, alias);
this.alias = alias;
}

public TraitAliasStatement(AST ast) {
super(ast);
}

public TraitAlias getAlias() {
return alias;
}

public void setAlias(TraitAlias alias) {
super.setExp(alias);
this.alias = alias;
}

@Override
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
if (!(other instanceof TraitAliasStatement)) {
return false;
}
return super.subtreeMatch(matcher, other);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitAliasStatement"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
alias.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</TraitAliasStatement>"); //$NON-NLS-1$
}

@Override
ASTNode clone0(AST target) {
TraitAlias alias = ASTNode.copySubtree(target, getAlias());
final TraitAliasStatement result = new TraitAliasStatement(
this.getStart(), this.getEnd(), target, alias);
return result;
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,59 @@
package org2.eclipse.php.internal.core.ast.nodes;

import java.util.List;

import org2.eclipse.php.internal.core.ast.match.ASTMatcher;

public class TraitDeclaration extends ClassDeclaration {

public TraitDeclaration(int start, int end, AST ast, int modifier,
Identifier className, Expression superClass, List interfaces,
Block body) {
super(start, end, ast, modifier, className, superClass, interfaces,
body);
}

public TraitDeclaration(AST ast) {
super(ast);
}

/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
if (!(other instanceof TraitDeclaration)) {
return false;
}
return super.subtreeMatch(matcher, other);
}

@Override
ASTNode clone0(AST target) {
final Block body = ASTNode.copySubtree(target, getBody());
final int modifier = getModifier();
final Identifier name = ASTNode.copySubtree(target, getName());

final TraitDeclaration result = new TraitDeclaration(getStart(),
getEnd(), target, modifier, name, getName(), interfaces(), body);
return result;
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitDeclaration"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append("'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append(tab).append(TAB).append("<TraitName>\n"); //$NON-NLS-1$
getName().toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append(TAB).append("</TraitName>\n"); //$NON-NLS-1$

getBody().toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</TraitDeclaration>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.CLASS_DECLARATION;
}

}
@@ -0,0 +1,185 @@
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;

public class TraitPrecedence extends Expression {

public TraitPrecedence(int start, int end, AST ast,
FullyQualifiedTraitMethodReference methodReference,
List<NamespaceName> trList) {
super(start, end, ast);
setMethodReference(methodReference);

if (trList != null) {
this.trList.addAll(trList);
}
}

public TraitPrecedence(AST ast) {
super(ast);
}

private FullyQualifiedTraitMethodReference methodReference;
private ASTNode.NodeList<NamespaceName> trList = new ASTNode.NodeList<NamespaceName>(
TRAIT_REFERENCE_LIST);;

public static final ChildPropertyDescriptor METHOD_REFERENCE = new ChildPropertyDescriptor(
TraitPrecedence.class,
"methodReference", FullyQualifiedTraitMethodReference.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

public static final ChildListPropertyDescriptor TRAIT_REFERENCE_LIST = new ChildListPropertyDescriptor(
TraitPrecedence.class, "trList", NamespaceName.class, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(METHOD_REFERENCE);
propertyList.add(TRAIT_REFERENCE_LIST);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public FullyQualifiedTraitMethodReference getMethodReference() {
return methodReference;
}

public void setMethodReference(
FullyQualifiedTraitMethodReference methodReference) {
if (methodReference == null) {
throw new IllegalArgumentException();
}
ASTNode oldChild = this.methodReference;
preReplaceChild(oldChild, methodReference, METHOD_REFERENCE);
this.methodReference = methodReference;
postReplaceChild(oldChild, methodReference, METHOD_REFERENCE);
}

public List<NamespaceName> getTrList() {
return trList;
}

public void setTrList(List<NamespaceName> trList) {
this.trList.clear();
if (trList != null) {
this.trList.addAll(trList);
}
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

public void childrenAccept(Visitor visitor) {
methodReference.accept(visitor);
if (trList != null) {
for (NamespaceName name : trList) {
name.accept(visitor);
}
}

}

public void traverseTopDown(Visitor visitor) {
accept(visitor);
methodReference.traverseTopDown(visitor);
if (trList != null) {
for (NamespaceName name : trList) {
name.traverseTopDown(visitor);
}
}
}

public void traverseBottomUp(Visitor visitor) {
methodReference.traverseBottomUp(visitor);
if (trList != null) {
for (NamespaceName name : trList) {
name.traverseBottomUp(visitor);
}
}
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitPrecedence"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
methodReference.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
if (trList != null) {
buffer.append(TAB).append(tab).append("<TraitReferenceList>\n"); //$NON-NLS-1$
for (NamespaceName name : trList) {
name.toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab).append("</TraitReferenceList>\n"); //$NON-NLS-1$
}
buffer.append(tab).append("</TraitPrecedence>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.FUNCTION_NAME;
}

/*
* 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) {
FullyQualifiedTraitMethodReference methodReference = ASTNode
.copySubtree(target, getMethodReference());
List<NamespaceName> trList = ASTNode.copySubtrees(target, getTrList());
final TraitPrecedence result = new TraitPrecedence(this.getStart(),
this.getEnd(), target, methodReference, trList);
return result;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == METHOD_REFERENCE) {
if (get) {
return getMethodReference();
} else {
setMethodReference((FullyQualifiedTraitMethodReference) child);
return null;
}
}

// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == TRAIT_REFERENCE_LIST) {
return getTrList();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

}
@@ -0,0 +1,61 @@
package org2.eclipse.php.internal.core.ast.nodes;

import org2.eclipse.php.internal.core.ast.match.ASTMatcher;
import org2.eclipse.php.internal.core.ast.visitor.Visitor;

public class TraitPrecedenceStatement extends TraitStatement {
private TraitPrecedence precedence;

public TraitPrecedenceStatement(int start, int end, AST ast,
TraitPrecedence precedence) {
super(start, end, ast, precedence);
this.precedence = precedence;
}

public TraitPrecedenceStatement(AST ast) {
super(ast);
}

public TraitPrecedence getPrecedence() {
return precedence;
}

public void setPrecedence(TraitPrecedence precedence) {
setExp(precedence);
this.precedence = precedence;
}

@Override
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
if (!(other instanceof TraitPrecedenceStatement)) {
return false;
}
return super.subtreeMatch(matcher, other);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitPrecedenceStatement"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
precedence.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</TraitPrecedenceStatement>"); //$NON-NLS-1$
}

@Override
ASTNode clone0(AST target) {
TraitPrecedence precedence = ASTNode.copySubtree(target,
getPrecedence());
final TraitPrecedenceStatement result = new TraitPrecedenceStatement(
this.getStart(), this.getEnd(), target, precedence);
return result;
}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,121 @@
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;

public abstract class TraitStatement extends Statement {

private Expression exp;

public static final ChildPropertyDescriptor EXP = new ChildPropertyDescriptor(
TraitStatement.class,
"exp", Expression.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(EXP);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public TraitStatement(int start, int end, AST ast, Expression exp) {
super(start, end, ast);
setExp(exp);
}

public TraitStatement(AST ast) {
super(ast);
}

public Expression getExp() {
return exp;
}

public void setExp(Expression exp) {
if (exp == null) {
throw new IllegalArgumentException();
}
ASTNode oldChild = this.exp;
preReplaceChild(oldChild, exp, EXP);
this.exp = exp;
postReplaceChild(oldChild, exp, EXP);

}

public void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

public void childrenAccept(Visitor visitor) {
exp.accept(visitor);

}

public void traverseTopDown(Visitor visitor) {
accept(visitor);
exp.traverseTopDown(visitor);
}

public void traverseBottomUp(Visitor visitor) {
exp.traverseBottomUp(visitor);
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitStatement"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
exp.toString(buffer, TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(tab).append("</TraitStatement>"); //$NON-NLS-1$
}

public int getType() {
return ASTNode.FUNCTION_NAME;
}

/*
* Method declared on ASTNode.
*/
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
// dispatch to correct overloaded match method
return matcher.match(this, other);
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get, ASTNode child) {
if (property == EXP) {
if (get) {
return getExp();
} else {
setExp((Expression) child);
return null;
}
}

// allow default implementation to flag the error
return super.internalGetSetChildProperty(property, get, child);
}

}
@@ -0,0 +1,195 @@
/*******************************************************************************
* 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;

/**
* Represent a 'use' statement.
*
* <pre>e.g.
*
* <pre>
* use A;
* use A as B;
* use \A\B as C;
*/
public class TraitUseStatement extends Statement {

private ASTNode.NodeList<NamespaceName> traitList = new ASTNode.NodeList<NamespaceName>(
TRAIT);
private ASTNode.NodeList<TraitStatement> tsList = new ASTNode.NodeList<TraitStatement>(
TRAIT_STATEMENT);

public static final ChildListPropertyDescriptor TRAIT = new ChildListPropertyDescriptor(
TraitUseStatement.class,
"traitList", NamespaceName.class, CYCLE_RISK); //$NON-NLS-1$
public static final ChildListPropertyDescriptor TRAIT_STATEMENT = new ChildListPropertyDescriptor(
TraitUseStatement.class, "tsList", TraitStatement.class, CYCLE_RISK); //$NON-NLS-1$

/**
* 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>(
1);
propertyList.add(TRAIT);
propertyList.add(TRAIT_STATEMENT);
PROPERTY_DESCRIPTORS = Collections.unmodifiableList(propertyList);
}

public TraitUseStatement(int start, int end, AST ast,
List<NamespaceName> traitList, List<TraitStatement> tsList) {
super(start, end, ast);

if (traitList != null) {
this.traitList.addAll(traitList);
}
if (tsList != null) {
this.tsList.addAll(tsList);
}
}

public TraitUseStatement(AST ast) {
super(ast);
}

public void childrenAccept(Visitor visitor) {
for (ASTNode node : traitList) {
node.accept(visitor);
}
for (ASTNode node : tsList) {
node.accept(visitor);
}

}

public void traverseTopDown(Visitor visitor) {
for (ASTNode node : traitList) {
node.traverseTopDown(visitor);
}
for (ASTNode node : tsList) {
node.traverseTopDown(visitor);
}
}

public void traverseBottomUp(Visitor visitor) {
for (ASTNode node : traitList) {
node.traverseBottomUp(visitor);
}
for (ASTNode node : tsList) {
node.traverseBottomUp(visitor);
}
accept(visitor);
}

public void toString(StringBuffer buffer, String tab) {
buffer.append(tab).append("<TraitUseStatement"); //$NON-NLS-1$
appendInterval(buffer);
buffer.append(">\n"); //$NON-NLS-1$
if (traitList != null && !traitList.isEmpty()) {
buffer.append(TAB).append(tab).append("<TraitNameList>\n"); //$NON-NLS-1$
for (NamespaceName name : traitList) {
name.toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab).append("</TraitNameList>\n"); //$NON-NLS-1$
}
if (tsList != null && !tsList.isEmpty()) {
buffer.append(TAB).append(tab).append("<TraitStatementList>\n"); //$NON-NLS-1$
for (TraitStatement name : tsList) {
name.toString(buffer, TAB + TAB + tab);
buffer.append("\n"); //$NON-NLS-1$
}
buffer.append(TAB).append(tab).append("</TraitStatementList>\n"); //$NON-NLS-1$
}
buffer.append(tab).append("</TraitUseStatement>"); //$NON-NLS-1$
}

@Override
void accept0(Visitor visitor) {
final boolean visit = visitor.visit(this);
if (visit) {
childrenAccept(visitor);
}
visitor.endVisit(this);
}

@Override
public boolean subtreeMatch(ASTMatcher matcher, Object other) {
return matcher.match(this, other);
}

@Override
public int getType() {
return TRAIT_USE_STATEMENT;
}

@Override
List<StructuralPropertyDescriptor> internalStructuralPropertiesForType(
PHPVersion apiLevel) {
return PROPERTY_DESCRIPTORS;
}

@Override
ASTNode clone0(AST target) {
final List<NamespaceName> traitList = ASTNode.copySubtrees(target,
getTraitList());
List<TraitStatement> tsList = ASTNode.copySubtrees(target, getTsList());
final TraitUseStatement result = new TraitUseStatement(this.getStart(),
this.getEnd(), target, traitList, tsList);

return result;
}

public List<NamespaceName> getTraitList() {
return traitList;
}

public void setTraitList(List<NamespaceName> traitList) {
this.traitList.clear();
if (traitList != null) {
this.traitList.addAll(traitList);
}
}

public List<TraitStatement> getTsList() {
return tsList;
}

public void setTsList(List<TraitStatement> tsList) {
this.tsList.clear();
if (tsList != null) {
this.tsList.addAll(tsList);
}
}

final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == TRAIT) {
return getTraitList();
} else if (property == TRAIT_STATEMENT) {
return getTsList();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}

}