package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
+ * Superclass of case statement that we can find in a switch.
* @author Matthieu Casanova
*/
public abstract class AbstractCase extends Statement {
+
+ /** The statements in the case. */
public Statement[] statements;
- public AbstractCase(Statement[] statements, int sourceStart, int sourceEnd) {
+ /**
+ * Create a case statement
+ * @param statements the statements array
+ * @param sourceStart the beginning source offset
+ * @param sourceEnd the ending offset
+ */
+ public AbstractCase(final Statement[] statements,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.statements = statements;
}
+
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* Here are php comment.
* @author Matthieu Casanova
public abstract class AbstractPHPComment extends AstNode {
/**
- * Create a comment giving starting and ending offset
+ * Create a comment giving starting and ending offset.
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public AbstractPHPComment(int sourceStart, int sourceEnd) {
+ public AbstractPHPComment(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return an empty list
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
*/
public abstract class AbstractSuffixExpression extends Expression {
- public AbstractSuffixExpression(int sourceStart, int sourceEnd) {
+ public AbstractSuffixExpression(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* An abstract variable declaration.
* @param sourceEnd ending offset
* @param name the name of the variable
*/
- public AbstractVariableDeclaration(char[] name, int sourceStart, int sourceEnd) {
+ public AbstractVariableDeclaration(final char[] name, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.name = name;
}
- /**
- * Get the name of the field as String.
- * @return the name of the String
- */
- public String name() {
- return new String(name);
- }
+
}
* @param initialization the initialization
* @param sourceStart the start point
*/
- public ArgumentDeclaration(char[] name,
- boolean reference,
- Expression initialization,
- int sourceStart) {
- super(name, initialization, sourceStart);
+ public ArgumentDeclaration(final char[] name,
+ final boolean reference,
+ final Expression initialization,
+ final int sourceStart) {
+ super(name, initialization,VariableDeclaration.EQUAL, sourceStart);
this.reference = reference;
}
* @param reference the variable is a reference ?
* @param sourceStart the start point
*/
- public ArgumentDeclaration(char[] name,
- boolean reference,
- int sourceStart) {
+ public ArgumentDeclaration(final char[] name,
+ final boolean reference,
+ final int sourceStart) {
super(name, sourceStart);
this.reference = reference;
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public Expression prefix;
public Expression vars;
- public ArrayDeclarator(Expression prefix,
- Expression vars,
- int sourceEnd) {
+ public ArrayDeclarator(final Expression prefix,
+ final Expression vars,
+ final int sourceEnd) {
super(prefix.sourceStart, sourceEnd);
this.prefix = prefix;
this.vars = vars;
buff.append(']');
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(prefix.getModifiedVariable());
+ list.addAll(vars.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(prefix.getUsedVariable());
+ list.addAll(vars.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public ArrayVariableDeclaration[] vars;
- public ArrayInitializer(ArrayVariableDeclaration[] vars,
- int sourceStart,
- int sourceEnd) {
+ public ArrayInitializer(final ArrayVariableDeclaration[] vars,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.vars = vars;
}
public String toStringExpression() {
final StringBuffer buff = new StringBuffer("array(");
for (int i = 0; i < vars.length; i++) {
- ArrayVariableDeclaration var = vars[i];
+ final ArrayVariableDeclaration var = vars[i];
if (i != 0) {
buff.append(",");
}
buff.append(")");
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < vars.length; i++) {
+ list.addAll(vars[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < vars.length; i++) {
+ list.addAll(vars[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* This variable declaration do not extend AbstractVariableDeclaration because
* it could take Expression as key.
public Expression key,value;
- public ArrayVariableDeclaration(Expression key,Expression value) {
+ public ArrayVariableDeclaration(final Expression key,final Expression value) {
super(key.sourceStart, value.sourceEnd);
this.key = key;
this.value = value;
}
- public ArrayVariableDeclaration(Expression key,int sourceEnd) {
+ public ArrayVariableDeclaration(final Expression key,final int sourceEnd) {
super(key.sourceStart, sourceEnd);
this.key = key;
}
}
return buff.toString();
}
+
+
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(key.getModifiedVariable());
+ list.addAll(value.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(value.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+
/**
* It will be the mother of our own ast tree for php just like the ast tree of Eclipse.
* @author Matthieu Casanova
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public AstNode(int sourceStart, int sourceEnd) {
+ public AstNode(final int sourceStart, final int sourceEnd) {
this.sourceStart = sourceStart;
this.sourceEnd = sourceEnd;
}
* @param tab the number of tabulations
* @return a String containing some spaces
*/
- public static String tabString(int tab) {
- StringBuffer s = new StringBuffer();
- for (int i = tab; i > 0; i--)
+ public static String tabString(final int tab) {
+ final StringBuffer s = new StringBuffer(2 * tab);
+ for (int i = tab; i > 0; i--) {
s.append(" "); //$NON-NLS-1$
+ }
return s.toString();
}
* @return a String
*/
public abstract String toString(int tab);
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public abstract List getOutsideVariable();
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public abstract List getModifiedVariable();
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public abstract List getUsedVariable();
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
/** The two expressions. */
public Expression left,right;
- public BinaryExpression(Expression left,
- Expression right,
- int operator) {
+ public BinaryExpression(final Expression left,
+ final Expression right,
+ final int operator) {
super(operator, left.sourceStart, right.sourceEnd);
this.left = left;
this.right = right;
buff.append(right.toStringExpression());
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(left.getModifiedVariable());
+ list.addAll(right.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(left.getUsedVariable());
+ list.addAll(right.getUsedVariable());
+ return list;
+ }
+
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
- * A Block is
+ * A Block.
* {
* statements
* }.
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Block(Statement[] statements,int sourceStart, int sourceEnd) {
+ public Block(final Statement[] statements,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.statements = statements;
}
+ /**
+ * tell if the block is empty.
+ * @return the block is empty if there are no statements in it
+ */
public boolean isEmptyBlock() {
return statements == null;
}
/**
* Return the block as String.
- * @param tab how many tabs
+ * @param tab how many tabs
* @return the string representation of the block
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final String s = AstNode.tabString(tab);
final StringBuffer buff = new StringBuffer(s);
buff.append("{\n"); //$NON-NLS-1$
if (this.statements != null) {
for (int i = 0; i < statements.length; i++) {
- buff.append(statements[i].toString(tab+1)).append(";\n");//$NON-NLS-1$
+ buff.append(statements[i].toString(tab + 1)).append(";\n");//$NON-NLS-1$
}
}
buff.append("}\n"); //$NON-NLS-1$
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* Here is a branchstatement : break or continue
* @author Matthieu Casanova
public Expression expression;
- public BranchStatement(Expression expression,int sourceStart, int sourceEnd) {
+ public BranchStatement(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expression = expression;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ if (expression == null) {
+ return new ArrayList();
+ }
+ return expression.getOutsideVariable();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ if (expression == null) {
+ return new ArrayList();
+ }
+ return expression.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ if (expression == null) {
+ return new ArrayList();
+ }
+ return expression.getUsedVariable();
+ }
}
*/
public class Break extends BranchStatement {
- public Break(Expression expression, int sourceStart, int sourceEnd) {
+ public Break(final Expression expression, final int sourceStart, final int sourceEnd) {
super(expression, sourceStart, sourceEnd);
}
- public String toString(int tab) {
- String s = tabString(tab);
+ public String toString(final int tab) {
+ final String s = tabString(tab);
if (expression != null) {
return s + "break " + expression.toString();//$NON-NLS-1$
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+
/**
* A Case statement for a Switch.
* @author Matthieu Casanova
public class Case extends AbstractCase {
public Expression value;
- public Statement[] statements;
- public Case(Expression value,
- Statement[] statements,
- int sourceStart,
- int sourceEnd) {
+ public Case(final Expression value,
+ final Statement[] statements,
+ final int sourceStart,
+ final int sourceEnd) {
super(statements, sourceStart, sourceEnd);
this.value = value;
}
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("case ");
buff.append(value.toStringExpression());
buff.append(" :\n");
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
- Statement statement = statements[i];
+ final Statement statement = statements[i];
buff.append(statement.toString(tab + 1));
}
}
return buff.toString();
}
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final List list = super.getModifiedVariable();
+ list.addAll(value.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final List list = super.getUsedVariable();
+ list.addAll(value.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* This is a cast expression.
* @author Matthieu Casanova
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public CastExpression(ConstantIdentifier type,
- Expression expression,
- int sourceStart,
- int sourceEnd) {
+ public CastExpression(final ConstantIdentifier type,
+ final Expression expression,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.type = type;
this.expression = expression;
buff.append(expression.toStringExpression());
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return expression.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return expression.getUsedVariable();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* Any class access.
* @author Matthieu Casanova
public Expression suffix;
public int type;
- public ClassAccess(Expression prefix,
- Expression suffix,
- int type) {
+ public ClassAccess(final Expression prefix,
+ final Expression suffix,
+ final int type) {
super(prefix.sourceStart, suffix.sourceEnd);
this.prefix = prefix;
this.suffix = suffix;
buff.append(suffix.toStringExpression());
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return prefix.getUsedVariable();
+ }
}
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
import java.util.ArrayList;
import java.util.List;
+import java.util.Enumeration;
/**
private ArrayList children = new ArrayList();
private Position position;
+
/**
* Create a class giving starting and ending offset
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public ClassDeclaration(Object parent,
- char[] name,
- char[] superclass,
- int sourceStart,
- int sourceEnd) {
+ public ClassDeclaration(final Object parent,
+ final char[] name,
+ final char[] superclass,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.parent = parent;
this.name = name;
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public ClassDeclaration(Object parent,
- char[] name,
- int sourceStart,
- int sourceEnd) {
+ public ClassDeclaration(final Object parent,
+ final char[] name,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.parent = parent;
this.name = name;
position = new Position(sourceStart, name.length);
}
- public void addMethod(MethodDeclaration method) {
+ public void addMethod(final MethodDeclaration method) {
methods.add(method);
add(method);
if (method.name.equals(name)) {
}
}
- public void addField(FieldDeclaration var) {
+ public void addField(final FieldDeclaration var) {
for (int i = 0; i < var.vars.length; i++) {
- VariableDeclaration c = var.vars[i];
+ final VariableDeclaration c = var.vars[i];
children.add(c);
}
fields.add(var);
}
- public boolean add(Outlineable o) {
+ public boolean add(final Outlineable o) {
return children.add(o);
}
* @param tab how many tabs before the class
* @return the code of this class into String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + toStringHeader() + toStringBody(tab);
}
* @param tab how many tabs before the body of the class
* @return the body as String
*/
- public String toStringBody(int tab) {
+ public String toStringBody(final int tab) {
final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
if (fields != null) {
for (int i = 0; i < fields.size(); i++) {
- FieldDeclaration field = (FieldDeclaration) fields.get(i);
+ final FieldDeclaration field = (FieldDeclaration) fields.get(i);
buff.append("\n"); //$NON-NLS-1$
buff.append(field.toString(tab + 1));
buff.append(";");//$NON-NLS-1$
}
}
for (int i = 0; i < methods.size(); i++) {
- MethodDeclaration o = (MethodDeclaration) methods.get(i);
+ final MethodDeclaration o = (MethodDeclaration) methods.get(i);
buff.append("\n");//$NON-NLS-1$
buff.append(o.toString(tab + 1));
}
return parent;
}
- public Outlineable get(int index) {
+ public Outlineable get(final int index) {
return (Outlineable) children.get(index);
}
public List getList() {
return children;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A ConditionalExpression is like that : booleanExpression ? trueValue : falseValue;
* @author Matthieu Casanova
public Expression condition, valueIfTrue, valueIfFalse;
- public ConditionalExpression(Expression condition,
- Expression valueIfTrue,
- Expression valueIfFalse) {
+ public ConditionalExpression(final Expression condition,
+ final Expression valueIfTrue,
+ final Expression valueIfFalse) {
super(-1, condition.sourceStart, valueIfFalse.sourceEnd);
this.condition = condition;
this.valueIfTrue = valueIfTrue;
buff.append(valueIfFalse.toStringExpression());
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getModifiedVariable());
+ list.addAll(valueIfTrue.getModifiedVariable());
+ list.addAll(valueIfFalse.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getUsedVariable());
+ list.addAll(valueIfTrue.getUsedVariable());
+ list.addAll(valueIfFalse.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public char[] name;
- public ConstantIdentifier(char[] name,
- int sourceStart,
- int sourceEnd) {
+ public ConstantIdentifier(final char[] name,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.name = name;
}
public String toStringExpression() {
return new String(name);
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
*/
public class Continue extends BranchStatement {
- public Continue(Expression expression, int sourceStart, int sourceEnd) {
+ public Continue(final Expression expression, final int sourceStart, final int sourceEnd) {
super(expression, sourceStart, sourceEnd);
}
- public String toString(int tab) {
- String s = tabString(tab);
+ public String toString(final int tab) {
+ final String s = tabString(tab);
if (expression == null) {
return s + "continue";//$NON-NLS-1$
}
*/
public class DefaultCase extends AbstractCase {
- public DefaultCase(Statement[] statements, int sourceStart, int sourceEnd) {
+ public DefaultCase(final Statement[] statements, final int sourceStart, final int sourceEnd) {
super(statements, sourceStart, sourceEnd);
}
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("default : \n"); //$NON-NLS-1$
for (int i = 0; i < statements.length; i++) {
- Statement statement = statements[i];
+ final Statement statement = statements[i];
buff.append(statement.toString(tab + 9));
}
return buff.toString();
import org.eclipse.jface.text.Position;
import org.eclipse.jface.resource.ImageDescriptor;
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* a Define.
* define(expression,expression)
public Position getPosition() {
return position;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList(1);
+ list.add(new VariableUsage(defineName.toStringExpression(),sourceStart));//todo: someday : evaluate the defineName
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
+ * A do statement.
* @author Matthieu Casanova
*/
public class DoStatement extends Statement {
/** The action of the while. (it could be a block) */
public Statement action;
- public DoStatement(Expression condition,
- Statement action,
- int sourceStart,
- int sourceEnd) {
+ public DoStatement(final Expression condition,
+ final Statement action,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.condition = condition;
this.action = action;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final String s = tabString(tab);
- final StringBuffer buff = new StringBuffer("do "); //$NON-NLS-1$
+ final StringBuffer buff = new StringBuffer("do ");//$NON-NLS-1$
if (action == null) {
buff.append(" {} ;"); //$NON-NLS-1$
} else {
- buff.append("\n").append(action.toString(tab + 1)); //$NON-NLS-1$
+ buff.append("\n").append(action.toString(tab + 1));//$NON-NLS-1$
}
- buff.append(s).append(" while (");
- buff.append(condition.toStringExpression()).append(")"); //$NON-NLS-1$
+ buff.append(s).append(" while (");//$NON-NLS-1$
+ buff.append(condition.toStringExpression()).append(")");//$NON-NLS-1$
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
+ list.addAll(action.getOutsideVariable());
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getModifiedVariable());
+ list.addAll(action.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getUsedVariable());
+ list.addAll(action.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
+ * an echo statement.
+ * echo something;
* @author Matthieu Casanova
*/
public class EchoStatement extends Statement {
/** An array of expressions in this echo statement. */
public Expression[] expressions;
- public EchoStatement (Expression[] expressions, int sourceStart) {
+ public EchoStatement (final Expression[] expressions, final int sourceStart) {
super(sourceStart, expressions[expressions.length-1].sourceEnd);
this.expressions = expressions;
}
public String toString() {
- StringBuffer buff = new StringBuffer("echo ");
+ final StringBuffer buff = new StringBuffer("echo ");//$NON-NLS-1$
for (int i = 0; i < expressions.length; i++) {
if (i != 0) {
- buff.append(", ");
+ buff.append(", ");//$NON-NLS-1$
}
buff.append(expressions[i].toStringExpression());
}
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
- return tabString(tab) + toString();
+ public String toString(final int tab) {
+ final String tabs = tabString(tab);
+ final String str = toString();
+ final StringBuffer buff = new StringBuffer(tabs.length()+str.length());
+ return buff.toString();
+ }
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < expressions.length; i++) {
+ list.addAll(expressions[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < expressions.length; i++) {
+ list.addAll(expressions[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < expressions.length; i++) {
+ list.addAll(expressions[i].getUsedVariable());
+ }
+ return list;
}
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.ArrayList;
+import java.util.List;
+
/**
+ * an else statement.
+ * it's else
* @author Matthieu Casanova
*/
public class Else extends Statement {
+ /** the statements. */
public Statement[] statements;
- public Else(Statement[] statements, int sourceStart, int sourceEnd) {
+ /**
+ * An else statement bad version ( : endif).
+ * @param statements the statements
+ * @param sourceStart the starting offset
+ * @param sourceEnd the ending offset
+ */
+ public Else(final Statement[] statements,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.statements = statements;
}
- public Else(Statement statement, int sourceStart, int sourceEnd) {
+ /**
+ * An else statement good version
+ * @param statement the statement (it could be a block)
+ * @param sourceStart the starting offset
+ * @param sourceEnd the ending offset
+ */
+ public Else(final Statement statement,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.statements = new Statement[1];
this.statements[0] = statement;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
- buff.append("else \n");
+ buff.append("else \n");//$NON-NLS-1$
+ Statement statement;
for (int i = 0; i < statements.length; i++) {
- Statement statement = statements[i];
- buff.append(statement.toString(tab + 1)).append('\n');
+ statement = statements[i];
+ buff.append(statement.toString(tab + 1)).append("\n");//$NON-NLS-1$
}
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from outside
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables from outside
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* An elseif statement.
* @author Matthieu Casanova
/** The statements. */
public Statement[] statements;
- public ElseIf(Expression condition, Statement[] statements, int sourceStart, int sourceEnd) {
+ public ElseIf(final Expression condition, final Statement[] statements, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.condition = condition;
this.statements = statements;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("elseif (");
buff.append(condition.toStringExpression());
buff.append(") \n");
for (int i = 0; i < statements.length; i++) {
- Statement statement = statements[i];
- buff.append(statement.toString(tab+1)).append('\n');
+ final Statement statement = statements[i];
+ buff.append(statement.toString(tab + 1)).append('\n');
}
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ list.addAll(condition.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getUsedVariable());
+ }
+ list.addAll(condition.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* An empty statement.
* @author Matthieu Casanova
*/
public class EmptyStatement extends Statement {
- public EmptyStatement(int sourceStart, int sourceEnd) {
+ public EmptyStatement(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + ";"; //$NON-NLS-1$
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return an empty list
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Expression(int sourceStart, int sourceEnd) {
+ public Expression(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
* @param tab how many spaces before the expression
* @return a string representing the expression
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + toStringExpression();
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public static final char[] source = {'f', 'a', 'l', 's', 'e'};
- public FalseLiteral(int sourceStart, int sourceEnd) {
+ public FalseLiteral(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
* @return the expression
*/
public String toStringExpression() {
- return "false";
+ return "false";//$NON-NLS-1$
}
public char[] source() {
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A Field declaration.
* This is a variable declaration for a php class
- * In fact it's an array of VariableDeclaration, since a field could contains
+ * In fact it's an array of VariableUsage, since a field could contains
* several vars :
* var $toto,$tata;
* @author Matthieu Casanova
* @param sourceStart the starting offset
* @param sourceEnd the ending offset
*/
- public FieldDeclaration(VariableDeclaration[] vars, int sourceStart, int sourceEnd, Object parent) {
+ public FieldDeclaration(final VariableDeclaration[] vars,
+ final int sourceStart,
+ final int sourceEnd,
+ final Object parent) {
super(sourceStart, sourceEnd);
this.vars = vars;
this.parent = parent;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("var ");//$NON-NLS-1$
for (int i = 0; i < vars.length; i++) {
- VariableDeclaration var = vars[i];
if (i != 0) {
- buff.append(',');//$NON-NLS-1$
+ buff.append(",");//$NON-NLS-1$
}
- buff.append(var.toStringExpression());
+ buff.append(vars[i].toStringExpression());
}
return buff.toString();
}
public Position getPosition() {
return position;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A For statement.
* for(initializations;condition;increments) action
public Statement action;
- public ForStatement(Expression[] initializations,
- Expression condition,
- Expression[] increments,
- Statement action,
- int sourceStart,
- int sourceEnd) {
+ public ForStatement(final Expression[] initializations,
+ final Expression condition,
+ final Expression[] increments,
+ final Statement action,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.initializations = initializations;
this.condition = condition;
this.action = action;
}
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("for ("); //$NON-NLS-1$
//inits
buff.append(" , "); //$NON-NLS-1$
}
}
- buff.append( "; "); //$NON-NLS-1$
+ buff.append("; "); //$NON-NLS-1$
//cond
- if (condition != null) {
+ if (condition != null) {
buff.append(condition.toStringExpression());
}
- buff.append( "; "); //$NON-NLS-1$
+ buff.append("; "); //$NON-NLS-1$
//updates
if (increments != null) {
for (int i = 0; i < increments.length; i++) {
buff.append(action.toString(tab + 1)); //$NON-NLS-1$
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getOutsideVariable());
+ list.addAll(action.getOutsideVariable());
+ for (int i = 0; i < initializations.length; i++) {
+ list.addAll(initializations[i].getOutsideVariable());
+ }
+ for (int i = 0; i < increments.length; i++) {
+ list.addAll(increments[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getModifiedVariable());
+ list.addAll(action.getModifiedVariable());
+ for (int i = 0; i < initializations.length; i++) {
+ list.addAll(initializations[i].getModifiedVariable());
+ }
+ for (int i = 0; i < increments.length; i++) {
+ list.addAll(increments[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getUsedVariable());
+ list.addAll(action.getUsedVariable());
+ for (int i = 0; i < initializations.length; i++) {
+ list.addAll(initializations[i].getUsedVariable());
+ }
+ for (int i = 0; i < increments.length; i++) {
+ list.addAll(increments[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public Expression variable;
public Statement statement;
- public ForeachStatement(Expression expression,
- Expression variable,
- Statement statement,
- int sourceStart,
- int sourceEnd) {
+ public ForeachStatement(final Expression expression,
+ final Expression variable,
+ final Statement statement,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expression = expression;
this.variable = variable;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("foreach (");
buff.append(expression.toStringExpression());
buff.append("\n}");
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(expression.getOutsideVariable());
+ list.addAll(variable.getOutsideVariable());
+ list.addAll(statement.getOutsideVariable());
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(expression.getModifiedVariable());
+ list.addAll(variable.getModifiedVariable());
+ list.addAll(statement.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(expression.getUsedVariable());
+ list.addAll(statement.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public Expression prefix;
public Expression[] args;
- public FunctionCall(Expression prefix,
- Expression[] args,
- int sourceEnd) {
+ public FunctionCall(final Expression prefix,
+ final Expression[] args,
+ final int sourceEnd) {
super(prefix.sourceStart, sourceEnd);
this.prefix = prefix;
this.args = args;
buff.append('(');
if (args != null) {
for (int i = 0; i < args.length; i++) {
- Expression arg = args[i];
+ final Expression arg = args[i];
if (i != 0) {
buff.append(',');
}
buff.append(')');
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < args.length; i++) {
+ list.addAll(args[i].getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(prefix.getUsedVariable());
+ for (int i = 0; i < args.length; i++) {
+ list.addAll(args[i].getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A GlobalStatement statement in php.
* @author Matthieu Casanova
private Position position;
- public GlobalStatement(Object parent, String[] variables, int sourceStart, int sourceEnd) {
+ public GlobalStatement(final Object parent,
+ final String[] variables,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.variables = variables;
this.parent = parent;
}
public String toString() {
- StringBuffer buff = new StringBuffer("global ");
+ final StringBuffer buff = new StringBuffer("global ");//$NON-NLS-1$
for (int i = 0; i < variables.length; i++) {
if (i != 0) {
- buff.append(", ");
+ buff.append(", ");//$NON-NLS-1$
}
buff.append(variables[i]);
}
return buff.toString();
}
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + toString();
}
public Position getPosition() {
return position;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList(variables.length);
+ for (int i = 0; i < variables.length; i++) {
+ list.add(new VariableUsage(variables[i],sourceStart));
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public AstNode[] nodes;
- public HTMLBlock(AstNode[] nodes) {
+ public HTMLBlock(final AstNode[] nodes) {
super(nodes[0].sourceStart, nodes[nodes.length-1].sourceEnd);
this.nodes = nodes;
}
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("?>");
for (int i = 0; i < nodes.length; i++) {
- AstNode node = nodes[i];
- buff.append(node.toString(tab +1));
+ buff.append(nodes[i].toString(tab +1));
}
buff.append("<?php\n");
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return an empty list
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* It's html code.
* @param sourceStart the starting offset
* @param sourceEnd the ending offset
*/
- public HTMLCode(char[] htmlCode, int sourceStart, int sourceEnd) {
+ public HTMLCode(final char[] htmlCode,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.htmlCode = htmlCode;
}
* @param tab how many tabs before this html
* @return the text of the block
*/
- public String toString(int tab) {
- return new String(htmlCode)+" ";
+ public String toString(final int tab) {
+ return new String(htmlCode) + " ";//$NON-NLS-1$
+ }
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return an empty list
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
}
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* This is a if statement.
* if (condition)
* @param sourceStart the starting position
* @param sourceEnd the ending offset
*/
- public IfStatement(Expression condition,
- Statement statement,
- ElseIf[] elseifs,
- Else els,
- int sourceStart,
- int sourceEnd) {
+ public IfStatement(final Expression condition,
+ final Statement statement,
+ final ElseIf[] elseifs,
+ final Else els,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.condition = condition;
this.statement = statement;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
- buff.append("if (");
- buff.append(condition.toStringExpression()).append(") ");
- buff.append(statement.toString(tab+1));
+ buff.append("if (");//$NON-NLS-1$
+ buff.append(condition.toStringExpression()).append(") ");//$NON-NLS-1$
+ buff.append(statement.toString(tab + 1));
for (int i = 0; i < elseifs.length; i++) {
- buff.append(elseifs[i].toString(tab+1));
- buff.append("\n");
+ buff.append(elseifs[i].toString(tab + 1));
+ buff.append("\n");//$NON-NLS-1$
}
if (els != null) {
- buff.append(els.toString(tab+1));
- buff.append('\n');
+ buff.append(els.toString(tab + 1));
+ buff.append("\n");//$NON-NLS-1$
}
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
+ list.addAll(statement.getOutsideVariable());
+ for (int i = 0; i < elseifs.length; i++) {
+ list.addAll(elseifs[i].getOutsideVariable());
+ }
+ if (els != null) {
+ list.addAll(els.getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getModifiedVariable());
+ list.addAll(statement.getModifiedVariable());
+ for (int i = 0; i < elseifs.length; i++) {
+ list.addAll(elseifs[i].getModifiedVariable());
+ }
+ if (els != null) {
+ list.addAll(els.getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ list.addAll(condition.getUsedVariable());
+ list.addAll(statement.getUsedVariable());
+ for (int i = 0; i < elseifs.length; i++) {
+ list.addAll(elseifs[i].getUsedVariable());
+ }
+ if (els != null) {
+ list.addAll(els.getUsedVariable());
+ }
+ return list;
+ }
}
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
private Object parent;
private Position position;
- public InclusionStatement(Object parent,
- int keyword,
- Expression expression,
- int sourceStart) {
+
+ public InclusionStatement(final Object parent,
+ final int keyword,
+ final Expression expression,
+ final int sourceStart) {
super(sourceStart, expression.sourceEnd);
this.keyword = keyword;
this.expression = expression;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buffer = new StringBuffer(tabString(tab));
buffer.append(toString());
return buffer.toString();
public Position getPosition() {
return position;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return expression.getOutsideVariable();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return expression.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return expression.getUsedVariable();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+
/**
* @author Matthieu Casanova
*/
public Statement statement;
- public LabeledStatement(char[] label, Statement statement, int sourceStart, int sourceEnd) {
+ public LabeledStatement(final char[] label, final Statement statement, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.label = label;
this.statement = statement;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return statement.getOutsideVariable();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ return statement.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return statement.getUsedVariable();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A list expression.
* it could be list($v1,$v2), list(,$v2) ...
public String[] vars;
public Expression expression;
- public ListExpression(String[] vars,
- Expression expression,
- int sourceStart,
- int sourceEnd) {
+ public ListExpression(final String[] vars,
+ final Expression expression,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.vars = vars;
this.expression = expression;
}
- public ListExpression(String[] vars,
- int sourceStart,
- int sourceEnd) {
+ public ListExpression(final String[] vars,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.vars = vars;
}
public String toStringExpression() {
final StringBuffer buff = new StringBuffer("list(");
for (int i = 0; i < vars.length; i++) {
- String var = vars[i];
+ final String var = vars[i];
if (i != 0) {
buff.append(", ");
}
}
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < vars.length; i++) {
+ list.add(new VariableUsage(vars[i],sourceStart));
+ }
+ if (expression != null) {
+ list.addAll(expression.getModifiedVariable());
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ if (expression != null) {
+ list.addAll(expression.getUsedVariable());
+ }
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* Here is the Superclass of the Literal expressions.
* @author Matthieu Casanova
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Literal(int sourceStart, int sourceEnd) {
+ public Literal(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
public abstract char[] source();
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return an empty list
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
*/
public abstract class MagicLiteral extends Literal {
- public MagicLiteral(int sourceStart, int sourceEnd) {
+ public MagicLiteral(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
}
import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import org.eclipse.core.runtime.CoreException;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.ArrayList;
import java.util.List;
+import test.PHPParserSuperclass;
+
/**
* A Method declaration.
* @author Matthieu Casanova
private Position position;
- public MethodDeclaration(Object parent,
- char[] name,
- Hashtable arguments,
- boolean reference,
- int sourceStart,
- int sourceEnd) {
+ public MethodDeclaration(final Object parent,
+ final char[] name,
+ final Hashtable arguments,
+ final boolean reference,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.name = name;
this.arguments = arguments;
* @param tab the number of tabs
* @return the String containing the method
*/
- public String toString(int tab) {
- StringBuffer buff = new StringBuffer(tabString(tab));
+ public String toString(final int tab) {
+ final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append(toStringHeader());
buff.append(toStringStatements(tab + 1));
return buff.toString();
* @param tab the number of tabs
* @return the String containing the statements
*/
- public String toStringStatements(int tab) {
- StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
+ public String toStringStatements(final int tab) {
+ final StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
return PHPUiImages.DESC_FUN;
}
- public void setParent(Object parent) {
+ public void setParent(final Object parent) {
this.parent = parent;
}
return parent;
}
- public boolean add(Outlineable o) {
+ public boolean add(final Outlineable o) {
return children.add(o);
}
- public Outlineable get(int index) {
+ public Outlineable get(final int index) {
return (Outlineable) children.get(index);
}
}
public String toString() {
- StringBuffer buff = new StringBuffer();
+ final StringBuffer buff = new StringBuffer();
if (reference) {
buff.append("&");//$NON-NLS-1$
}
buff.append(name).append("(");//$NON-NLS-1$
if (arguments != null) {
- Enumeration values = arguments.elements();
+ final Enumeration values = arguments.elements();
int i = 0;
while (values.hasMoreElements()) {
- VariableDeclaration o = (VariableDeclaration) values.nextElement();
+ final VariableDeclaration o = (VariableDeclaration) values.nextElement();
buff.append(o.toStringExpression());
if (i != (arguments.size() - 1)) {
buff.append(", "); //$NON-NLS-1$
public List getList() {
return children;
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ if (arguments != null) {
+ final Enumeration vars = arguments.keys();
+ while (vars.hasMoreElements()) {
+ list.add(new VariableUsage((String) vars.nextElement(), sourceStart));
+ }
+ }
+
+ if (statements != null) {
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getOutsideVariable());
+ }
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ if (statements != null) {
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getModifiedVariable());
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ if (statements != null) {
+ for (int i = 0; i < statements.length; i++) {
+ list.addAll(statements[i].getUsedVariable());
+ }
+ }
+ return list;
+ }
+
+ private boolean isVariableDeclaredBefore(List list, VariableUsage var) {
+ final String name = var.getName();
+ final int pos = var.getStartOffset();
+ for (int i = 0; i < list.size(); i++) {
+ VariableUsage variableUsage = (VariableUsage) list.get(i);
+ if (variableUsage.getName().equals(name) && variableUsage.getStartOffset() < pos) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void dumpList(List list, String name) {
+ StringBuffer buff = new StringBuffer(name).append("\n");
+ for (int i = 0; i < list.size(); i++) {
+ buff.append(list.get(i).toString()).append("\n");
+ }
+ if (PHPeclipsePlugin.DEBUG) {
+ PHPeclipsePlugin.log(1, buff.toString());
+ }
+ }
+
+ /**
+ * This method will analyze the code.
+ */
+ public void analyzeCode() {
+ final List outsideVars = getOutsideVariable();
+ final List modifiedVars = getModifiedVariable();
+
+ final List declaredVars = new ArrayList(outsideVars.size() + modifiedVars.size());
+ declaredVars.addAll(outsideVars);
+ declaredVars.addAll(modifiedVars);
+
+ final List usedVars = getUsedVariable();
+
+/* dumpList(outsideVars, "outside");
+ dumpList(modifiedVars, "modified");
+ dumpList(usedVars, "used"); */
+
+
+ //look for used variables that were not declared before
+ for (int i = 0; i < usedVars.size(); i++) {
+ VariableUsage variableUsage = (VariableUsage) usedVars.get(i);
+ if (!isVariableDeclaredBefore(declaredVars, variableUsage)) {
+ try {
+ PHPParserSuperclass.setMarker("warning, usage of an unknown : " + variableUsage.getName(),
+ variableUsage.getStartOffset(),
+ variableUsage.getStartOffset() + variableUsage.getName().length(),
+ PHPParserSuperclass.WARNING,
+ "");
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+
+ }
+ }
}
public static final char[] source = {'n' , 'u' , 'l' , 'l'};
- public NullLiteral(int sourceStart, int sourceEnd) {
+ public NullLiteral(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
public class NumberLiteral extends Literal {
public char[] source;
- public NumberLiteral(char[] token, int sourceStart, int sourceEnd) {
+ public NumberLiteral(final char[] token,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
source = token;
}
public int operator;
- public OperatorExpression(int operator, int sourceStart, int sourceEnd) {
+ public OperatorExpression(final int operator, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.operator = operator;
}
* Create the PHPDocument.
* @param parent the parent object (it should be null isn't it ?)
*/
- public PHPDocument(Object parent, char[] name) {
+ public PHPDocument(final Object parent,
+ final char[] name) {
this.parent = parent;
this.name = name;
position = new Position(1,name.length);
}
buff.append(node.toString(0));
if (node instanceof HTMLCode) {
- buff.append("\n");
+ buff.append("\n");//$NON-NLS-1$
} else {
- buff.append(";\n");
+ buff.append(";\n");//$NON-NLS-1$
}
}
}
* @param o the new outlineable
* @return does the addition worked ?
*/
- public boolean add(Outlineable o) {
+ public boolean add(final Outlineable o) {
return children.add(o);
}
* @param index the index
* @return an outlineable object
*/
- public Outlineable get(int index) {
+ public Outlineable get(final int index) {
return (Outlineable) children.get(index);
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
+ * a php echo block.
+ * <?= someexpression ?>
* @author Matthieu Casanova
*/
public class PHPEchoBlock extends AstNode {
+ /** the expression. */
public Expression expr;
- public PHPEchoBlock(Expression expr,int sourceStart, int sourceEnd) {
+ /**
+ * Create a new php echo block.
+ * @param expr the expression
+ * @param sourceStart the starting offset
+ * @param sourceEnd the ending offset
+ */
+ public PHPEchoBlock(final Expression expr,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expr = expr;
}
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
- final StringBuffer buff = new StringBuffer(tabString(tab));
- buff.append("<?=");
- buff.append(expr.toStringExpression());
- buff.append("?>");
+ public String toString(final int tab) {
+ final String tabs = tabString(tab);
+ final String expression = expr.toStringExpression();
+ final StringBuffer buff = new StringBuffer(tabs.length() +
+ expression.length() +
+ 5);
+ buff.append(tabs);
+ buff.append("<?=");//$NON-NLS-1$
+ buff.append(expression);
+ buff.append("?>");//$NON-NLS-1$
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return an empty list
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return an empty list
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the used variables are the used variables from the expression
+ */
+ public List getUsedVariable() {
+ return expr.getUsedVariable();
+ }
}
*/
public class PostfixedUnaryExpression extends UnaryExpression {
- public PostfixedUnaryExpression(Expression expression, int operator, int sourceEnd) {
+ public PostfixedUnaryExpression(final Expression expression, final int operator, final int sourceEnd) {
super(expression, operator, expression.sourceStart, sourceEnd);
}
public String toStringExpression() {
- StringBuffer buff = new StringBuffer(expression.toStringExpression());
+ final StringBuffer buff = new StringBuffer(expression.toStringExpression());
buff.append(operatorToString());
return buff.toString();
}
*/
public class PrefixedUnaryExpression extends UnaryExpression {
- public PrefixedUnaryExpression(Expression expression, int operator, int sourceStart) {
+ public PrefixedUnaryExpression(final Expression expression, final int operator, final int sourceStart) {
super(expression, operator, sourceStart, expression.sourceEnd);
}
public String toStringExpression() {
- StringBuffer buff = new StringBuffer(operatorToString());
+ final StringBuffer buff = new StringBuffer(operatorToString());
buff.append(expression.toStringExpression());
return buff.toString();
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public Expression expression;
- public PrintExpression(Expression expression, int sourceStart, int sourceEnd) {
+ public PrintExpression(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expression = expression;
}
public String toStringExpression() {
return "print " + expression.toStringExpression();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return expression.getOutsideVariable();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables from we change value
+ */
+ public List getModifiedVariable() {
+ return expression.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return expression.getUsedVariable();
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A return statement.
* @author Matthieu Casanova
public Expression expression;
- public ReturnStatement(Expression expression, int sourceStart, int sourceEnd) {
+ public ReturnStatement(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expression = expression;
}
- public String toString(int tab) {
+ public String toString(final int tab) {
final String s = tabString(tab);
if (expression == null) {
return s + "return";//$NON-NLS-1$
}
return s + "return " + expression.toStringExpression();//$NON-NLS-1$
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ return expression.getModifiedVariable();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return expression.getUsedVariable();
+ }
}
public abstract class Statement extends AstNode {
/**
- * Create a node giving starting and ending offset
+ * Create a node giving starting and ending offset.
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Statement(int sourceStart, int sourceEnd) {
+ public Statement(final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
}
+ /**
+ * Tell if the block is empty.
+ * @return a statement is not empty by default
+ */
public boolean isEmptyBlock() {
return false;
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* A GlobalStatement statement in php.
* @author Matthieu Casanova
/** An array of the variables called by this global statement. */
public String[] variables;
- public StaticStatement(String[] variables, int sourceStart, int sourceEnd) {
+ public StaticStatement(final String[] variables, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.variables = variables;
}
public String toString() {
- StringBuffer buff = new StringBuffer("static ");
+ final StringBuffer buff = new StringBuffer("static ");
for (int i = 0; i < variables.length; i++) {
if (i != 0) {
buff.append(", ");
return buff.toString();
}
- public String toString(int tab) {
+ public String toString(final int tab) {
return tabString(tab) + toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList(variables.length);
+ for (int i = 0; i < variables.length; i++) {
+ list.add(new VariableUsage(variables[i], sourceStart));
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ return new ArrayList();
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList();
+ }
}
******************************************************************************/
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
//import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
//import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
//import net.sourceforge.phpdt.internal.compiler.impl.Constant;
public class StringLiteral extends Literal {
char[] source;
- public StringLiteral(char[] token, int s) {
+ public StringLiteral(final char[] token, final int s) {
super(s, s + token.length);
source = token;
}
* @param e sourceend
* @deprecated
*/
- public StringLiteral(char[] token, int s, int e) {
+ public StringLiteral(final char[] token, final int s, final int e) {
super(s, e);
source = token;
}
- public StringLiteral(int s, int e) {
+ public StringLiteral(final int s, final int e) {
super(s, e);
}
* Return the expression as String.
* @return the expression
*/
- /* public String toStringExpression() {
- // handle some special char.....
- StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
- for (int i = 0; i < source.length; i++) {
- switch (source[i]) {
- case '\b':
- result.append("\\b"); //$NON-NLS-1$
- break;
- case '\t':
- result.append("\\t"); //$NON-NLS-1$
- break;
- case '\n':
- result.append("\\n"); //$NON-NLS-1$
- break;
- case '\f':
- result.append("\\f"); //$NON-NLS-1$
- break;
- case '\r':
- result.append("\\r"); //$NON-NLS-1$
- break;
- case '\"':
- result.append("\\\""); //$NON-NLS-1$
- break;
- case '\'':
- result.append("\\'"); //$NON-NLS-1$
- break;
- case '\\': //take care not to display the escape as a potential real char
- result.append("\\\\"); //$NON-NLS-1$
- break;
- default :
- result.append(source[i]);
- }
- }
- result.append("\""); //$NON-NLS-1$
- return result.toString();
- } */
+ /* public String toStringExpression() {
+ // handle some special char.....
+ StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
+ for (int i = 0; i < source.length; i++) {
+ switch (source[i]) {
+ case '\b':
+ result.append("\\b"); //$NON-NLS-1$
+ break;
+ case '\t':
+ result.append("\\t"); //$NON-NLS-1$
+ break;
+ case '\n':
+ result.append("\\n"); //$NON-NLS-1$
+ break;
+ case '\f':
+ result.append("\\f"); //$NON-NLS-1$
+ break;
+ case '\r':
+ result.append("\\r"); //$NON-NLS-1$
+ break;
+ case '\"':
+ result.append("\\\""); //$NON-NLS-1$
+ break;
+ case '\'':
+ result.append("\\'"); //$NON-NLS-1$
+ break;
+ case '\\': //take care not to display the escape as a potential real char
+ result.append("\\\\"); //$NON-NLS-1$
+ break;
+ default :
+ result.append(source[i]);
+ }
+ }
+ result.append("\""); //$NON-NLS-1$
+ return result.toString();
+ } */
/**
* Return the expression as String.
package net.sourceforge.phpdt.internal.compiler.ast;
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
/**
* @author Matthieu Casanova
*/
public Expression variable;
public AbstractCase[] cases;
- public SwitchStatement(Expression variable,
- AbstractCase[] cases,
- int sourceStart,
- int sourceEnd) {
+ public SwitchStatement(final Expression variable,
+ final AbstractCase[] cases,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.variable = variable;
this.cases = cases;
* @param tab how many tabs (not used here
* @return a String
*/
- public String toString(int tab) {
+ public String toString(final int tab) {
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("switch (").append(variable.toStringExpression()).append(") {\n");
for (int i = 0; i < cases.length; i++) {
- AbstractCase cas = cases[i];
- buff.append(cas.toString(tab +1));
+ final AbstractCase cas = cases[i];
+ buff.append(cas.toString(tab + 1));
buff.append('\n');
}
buff.append('}');
return buff.toString();
}
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < cases.length; i++) {
+ list.addAll(cases[i].getOutsideVariable());
+ }
+ return list;
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < cases.length; i++) {
+ list.addAll(cases[i].getModifiedVariable());
+ }
+ list.addAll(variable.getModifiedVariable());
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ final ArrayList list = new ArrayList();
+ for (int i = 0; i < cases.length; i++) {
+ list.addAll(cases[i].getUsedVariable());
+ }
+ list.addAll(variable.getUsedVariable());
+ return list;
+ }
}
package net.sourceforge.phpdt.internal.compiler.ast;
+import java.util.List;
+import java.util.ArrayList;
+
/**
+ * the true literal.
* @author Matthieu Casanova
*/
public class TrueLiteral extends MagicLiteral {
public static final char[] source = {'t', 'r', 'u', 'e'};
- public TrueLiteral(int sourceStart, int sourceEnd) {
+ public TrueLiteral(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
public String toStringExpression() {
return "true";//$NON-NLS-1$
}
+
+ public String toString() {
+ return "true";//$NON-NLS-1$
+ }
}