public abstract class AbstractCase extends Statement {
/** The statements in the case. */
- public Statement[] statements;
+ public final Statement[] statements;
/**
- * Create a case statement
+ * 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) {
+ protected AbstractCase(final Statement[] statements,
+ final int sourceStart,
+ final int sourceEnd) {
super(sourceStart, sourceEnd);
this.statements = statements;
}
/**
- * Get the variables from outside (parameters, globals ...)
+ * Get the variables from outside (parameters, globals ...).
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
+ public final void getOutsideVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
statements[i].getOutsideVariable(list);
}
/**
* get the modified variables.
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* Get the variables used.
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public AbstractPHPComment(final int sourceStart, final int sourceEnd) {
+ protected AbstractPHPComment(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
/**
* Get the variables from outside (parameters, globals ...)
- * @return an empty list
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
+ public final void getOutsideVariable(final List list) {
}
/**
* get the modified variables.
- * @return an empty list
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
+ public final void getModifiedVariable(final List list) {
}
/**
* Get the variables used.
- * @return an empty list
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
+ public final void getUsedVariable(final List list) {
}
}
*/
public abstract class AbstractSuffixExpression extends Expression {
- public AbstractSuffixExpression(final int sourceStart, final int sourceEnd) {
+ protected AbstractSuffixExpression(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
}
package net.sourceforge.phpdt.internal.compiler.ast;
/**
- * Created by IntelliJ IDEA.
- * User: Administrateur
- * Date: 9 août 2003
- * Time: 15:57:05
- * To change this template use Options | File Templates.
+ * The variable superclass.
+ * @author Matthieu Casanova
*/
public abstract class AbstractVariable extends Expression {
- public AbstractVariable(final int sourceStart, final int sourceEnd) {
+ protected AbstractVariable(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
+ /**
+ * This method will return the name of the variable.
+ * @return a string containing the name of the variable.
+ */
public abstract String getName();
}
/**
* An argument declaration.
+ *
* @author Matthieu Casanova
*/
-public class ArgumentDeclaration extends VariableDeclaration {
-
- /** The argument is a reference or not. */
- public boolean reference;
+public final class ArgumentDeclaration extends VariableDeclaration {
/**
* Create an argument.
- * @param name the name
- * @param reference the variable is a reference ?
+ *
+ * @param name the name
+ * @param reference the variable is a reference ?
* @param initialization the initialization
- * @param sourceStart the start point
+ * @param sourceStart the start point
*/
public ArgumentDeclaration(final Variable name,
final boolean reference,
final Expression initialization,
final int sourceStart) {
- super(name, initialization,VariableDeclaration.EQUAL, sourceStart);
+ super(name, initialization, VariableDeclaration.EQUAL, sourceStart);
this.reference = reference;
}
/**
* Create an argument.
- * @param name the name
- * @param reference the variable is a reference ?
+ *
+ * @param name the name
+ * @param reference the variable is a reference ?
* @param sourceStart the start point
*/
public ArgumentDeclaration(final Variable name,
super(name, sourceStart);
this.reference = reference;
}
+
/**
* Return the expression as String.
+ *
* @return the expression
*/
public String toStringExpression() {
- final StringBuffer buff;
- if (reference) {
- buff = new StringBuffer("&");
+ if (initialization == null) {
+ if (reference) {
+ return '&' + variable.toStringExpression();
+ } else {
+ return variable.toStringExpression();
+ }
} else {
- buff = new StringBuffer();
- }
- buff.append(variable.toStringExpression());
- if (initialization != null) {
+ final String variableString = variable.toStringExpression();
+ final String initializationString = initialization.toStringExpression();
+ final StringBuffer buff = new StringBuffer(4 +
+ variableString.length() +
+ initializationString.length());
+ if (reference) {
+ buff.append('&');
+ }
+ buff.append(variableString);
buff.append(" = ");
- buff.append(initialization.toStringExpression());
+ buff.append(initializationString);
+ return buff.toString();
}
- return buff.toString();
}
}
import java.util.List;
/**
+ * An access to a key of an array.
* @author Matthieu Casanova
*/
-public class ArrayDeclarator extends AbstractVariable {
+public final class ArrayDeclarator extends AbstractVariable {
- public AbstractVariable prefix;
- public Expression var;
+ /** The name of the array. */
+ private final AbstractVariable prefix;
+ /** The key. */
+ private final Expression key;
+
+ /**
+ * Create an ArrayDeclarator.
+ * @param prefix the prefix, it could be a variable.
+ * @param key the key
+ * @param sourceEnd the end of the expression
+ */
public ArrayDeclarator(final AbstractVariable prefix,
- final Expression vars,
+ final Expression key,
final int sourceEnd) {
super(prefix.sourceStart, sourceEnd);
this.prefix = prefix;
- this.var = vars;
+ this.key = key;
}
/**
public String toStringExpression() {
final StringBuffer buff = new StringBuffer(prefix.toStringExpression());
buff.append('[');
- if (var != null) {
- buff.append(var.toStringExpression());
+ if (key != null) {
+ buff.append(key.toStringExpression());
}
buff.append(']');
return buff.toString();
/**
* Get the variables from outside (parameters, globals ...)
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
prefix.getModifiedVariable(list);
- if (var != null) {
- var.getModifiedVariable(list);
+ if (key != null) {
+ key.getModifiedVariable(list);
}
}
/**
* Get the variables used.
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
prefix.getUsedVariable(list);
- if (var != null) {
- var.getUsedVariable(list);
+ if (key != null) {
+ key.getUsedVariable(list);
}
}
}
* array('a','b','c') or array('a' => 2,'b' = '3');
* @author Matthieu Casanova
*/
-public class ArrayInitializer extends Expression {
+public final class ArrayInitializer extends Expression {
- public ArrayVariableDeclaration[] vars;
+ /** the key and values. */
+ private final ArrayVariableDeclaration[] vars;
+ /**
+ * Create a new array initializer.
+ * @param vars the keys and values of the array
+ * @param sourceStart the starting offset
+ * @param sourceEnd the ending offset
+ */
public ArrayInitializer(final ArrayVariableDeclaration[] vars,
final int sourceStart,
final int sourceEnd) {
/**
* Get the variables from outside (parameters, globals ...)
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < vars.length; i++) {
/**
* Get the variables used.
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < vars.length; i++) {
/**
* a variable declaration in an array().
* it could take Expression as key.
+ *
* @author Matthieu Casanova
*/
-public class ArrayVariableDeclaration extends Expression {
+public final class ArrayVariableDeclaration extends Expression {
/** the array key. */
- public Expression key;
+ private final Expression key;
/** the array value. */
- public Expression value;
+ private Expression value;
/**
* Create a new array variable declaration.
- * @param key the key
+ *
+ * @param key the key
* @param value the value
*/
public ArrayVariableDeclaration(final Expression key, final Expression value) {
/**
* Create a new array variable declaration.
- * @param key the key
+ *
+ * @param key the key
* @param sourceEnd the end position
*/
public ArrayVariableDeclaration(final Expression key, final int sourceEnd) {
/**
* Return the expression as String.
+ *
* @return the expression
*/
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer();
- buff.append(key.toStringExpression());
- if (value != null) {
+ if (value == null) {
+ return key.toStringExpression();
+ } else {
+ final String keyString = key.toStringExpression();
+ final String valueString = value.toStringExpression();
+ final StringBuffer buff = new StringBuffer(keyString.length() + valueString.length() + 3);
+ buff.append(keyString);
buff.append(" => ");
- buff.append(value.toStringExpression());
+ buff.append(valueString);
+ return buff.toString();
}
- return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
key.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
key.getUsedVariable(list);
public int sourceStart, sourceEnd;
/**
- * 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 AstNode(final int sourceStart, final int sourceEnd) {
+ protected AstNode(final int sourceStart, final int sourceEnd) {
this.sourceStart = sourceStart;
this.sourceEnd = sourceEnd;
}
/**
* Get the variables from outside (parameters, globals ...)
+ * @param list the list where we will put variables
*/
public abstract void getOutsideVariable(List list);
/**
* get the modified variables.
+ * @param list the list where we will put variables
*/
public abstract void getModifiedVariable(List list);
/**
* Get the variables used.
+ * @param list the list where we will put variables
*/
public abstract void getUsedVariable(List list);
* This method will analyze the code.
* by default it will do nothing
*/
- public void analyzeCode() {
- }
+ public void analyzeCode() {}
/**
- * Check if the array array contains the object o
+ * Check if the array array contains the object o.
* @param array an array
* @param o an obejct
* @return true if the array contained the object o
*/
- public boolean arrayContains(Object[] array, Object o) {
+ public final boolean arrayContains(final Object[] array, final Object o) {
for (int i = 0; i < array.length; i++) {
if (array[i].equals(o)) {
return true;
import java.util.List;
/**
+ * a binary expression is a combination of two expressions with an operator.
+ *
* @author Matthieu Casanova
*/
-public class BinaryExpression extends OperatorExpression {
+public final class BinaryExpression extends OperatorExpression {
- /** The two expressions. */
- public Expression left,right;
+ /** The left expression. */
+ private final Expression left;
+ /** The right expression. */
+ private final Expression right;
+ /**
+ * Create a binary expression.
+ *
+ * @param left the left expression
+ * @param right the right expression
+ * @param operator an operator taken in the {@link OperatorExpression} interface
+ */
public BinaryExpression(final Expression left,
final Expression right,
final int operator) {
}
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer(left.toStringExpression());
- buff.append(operatorToString());
- buff.append(right.toStringExpression());
+ final String leftString = left.toStringExpression();
+ final String operatorString = operatorToString();
+ final String rightString = right.toStringExpression();
+ final StringBuffer buff = new StringBuffer(leftString.length() + operatorString.length() + rightString.length());
+ buff.append(leftString);
+ buff.append(operatorString);
+ buff.append(rightString);
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
left.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
left.getUsedVariable(list);
* }.
* @author Matthieu Casanova
*/
-public class Block extends Statement {
+public final class Block extends Statement {
/** An array of statements inside the block. */
- public Statement[] statements;
+ public final Statement[] statements;
/**
* Create a block.
final String s = AstNode.tabString(tab);
final StringBuffer buff = new StringBuffer(s);
buff.append("{\n"); //$NON-NLS-1$
- if (this.statements != null) {
+ if (statements != null) {
for (int i = 0; i < statements.length; i++) {
buff.append(statements[i].toString(tab + 1)).append(";\n");//$NON-NLS-1$
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
import java.util.List;
/**
- * Here is a branchstatement : break or continue
+ * Here is a branchstatement : break or continue.
* @author Matthieu Casanova
*/
public abstract class BranchStatement extends Statement {
- public Expression expression;
+ /** The label (if there is one). */
+ protected final Expression expression;
- public BranchStatement(final Expression expression, final int sourceStart, final int sourceEnd) {
+ protected BranchStatement(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expression = expression;
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
+ public final void getOutsideVariable(final List list) {
if (expression != null) {
expression.getOutsideVariable(list);
}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
+ public final void getModifiedVariable(final List list) {
if (expression != null) {
expression.getModifiedVariable(list);
}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
+ public final void getUsedVariable(final List list) {
if (expression != null) {
expression.getUsedVariable(list);
}
* A break statement.
* @author Matthieu Casanova
*/
-public class Break extends BranchStatement {
+public final class Break extends BranchStatement {
public Break(final Expression expression, final int sourceStart, final int sourceEnd) {
super(expression, sourceStart, sourceEnd);
* A Case statement for a Switch.
* @author Matthieu Casanova
*/
-public class Case extends AbstractCase {
+public final class Case extends AbstractCase {
- public Expression value;
+ private final Expression value;
public Case(final Expression value,
final Statement[] statements,
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
super.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
super.getUsedVariable(list);
* This is a cast expression.
* @author Matthieu Casanova
*/
-public class CastExpression extends Expression {
+public final class CastExpression extends Expression {
/** The type in which we cast the expression. */
- public ConstantIdentifier type;
+ private final ConstantIdentifier type;
/** The expression to be casted. */
- public Expression expression;
+ private final Expression expression;
/**
* Create a cast expression.
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
expression.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
expression.getUsedVariable(list);
* Any class access.
* @author Matthieu Casanova
*/
-public class ClassAccess extends AbstractVariable {
+public final class ClassAccess extends AbstractVariable {
- /** a static class access : "::" */
+ /** a static class access : "::". */
public static final int STATIC = 0;
- /** a normal class access : "->" */
+ /** a normal class access : "->". */
public static final int NORMAL = 1;
- public Expression prefix;
+ private final Expression prefix;
/** the suffix. */
- public Expression suffix;
+ private final Expression suffix;
/** the type of access. */
- public int type;
+ private final int type;
/**
* Create a new class access.
this.type = type;
}
- public String toStringOperator() {
+ private String toStringOperator() {
switch (type) {
case STATIC : return "::"; //$NON-NLS-1$
case NORMAL : return "->"; //$NON-NLS-1$
* @return the expression
*/
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer();
- buff.append(prefix.toStringExpression());
- buff.append(toStringOperator());
- buff.append(suffix.toStringExpression());
+ final String prefixString = prefix.toStringExpression();
+ final String operatorString = toStringOperator();
+ final String suffixString = suffix.toStringExpression();
+ final StringBuffer buff = new StringBuffer(prefixString.length() +
+ operatorString.length() +
+ suffixString.length());
+ buff.append(prefixString);
+ buff.append(operatorString);
+ buff.append(suffixString);
return buff.toString();
}
/**
* todo: find a better way to handle this
- * @return
+ * @return the name of the variable
*/
public String getName() {
if (prefix instanceof AbstractVariable) {
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
prefix.getUsedVariable(list);
* It directly extends AstNode because a class cannot appear anywhere in php
* @author Matthieu Casanova
*/
-public class ClassDeclaration extends Statement implements OutlineableWithChildren {
+public final class ClassDeclaration extends Statement implements OutlineableWithChildren {
/** The name of the class. */
- public String name;
+ private final String name;
/** The superclass. */
- public String superclass;
+ private String superclass;
public int declarationSourceStart;
public int declarationSourceEnd;
/** The methods of the class. */
private final ArrayList methods = new ArrayList();
/** The constructor of the class. */
- public MethodDeclaration constructor;
+ private MethodDeclaration constructor;
/** The fields of the class. */
- private ArrayList fields = new ArrayList();
+ private final ArrayList fields = new ArrayList();
- private Object parent;
+ private final Object parent;
/** The outlineable children (those will be in the node array too. */
- private ArrayList children = new ArrayList();
+ private final ArrayList children = new ArrayList();
- private Position position;
+ private final Position position;
/**
- * Create a class giving starting and ending offset
+ * Create a class giving starting and ending offset.
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
}
/**
- * Create a class giving starting and ending offset
+ * Create a class giving starting and ending offset.
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
* @param tab how many tabs before the body of the class
* @return the body as String
*/
- public String toStringBody(final int tab) {
+ private String toStringBody(final int tab) {
final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
if (fields != null) {
for (int i = 0; i < fields.size(); i++) {
* Return the header of the class as String.
* @return the header of the class
*/
- public String toStringHeader() {
+ private String toStringHeader() {
final StringBuffer buff = new StringBuffer("class ").append(name);//$NON-NLS-1$
if (superclass != null) {
buff.append(" extends "); //$NON-NLS-1$
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* a class instantiation.
* @author Matthieu Casanova
*/
-public class ClassInstantiation extends PrefixedUnaryExpression {
+public final class ClassInstantiation extends PrefixedUnaryExpression {
- private boolean reference;
+ private final boolean reference;
public ClassInstantiation(final Expression expression,
final boolean reference,
if (!reference) {
return super.toStringExpression();
}
- return "&"+super.toStringExpression();
+ return '&' + super.toStringExpression();
}
}
import java.util.List;
/**
- * A ConditionalExpression is like that : booleanExpression ? trueValue : falseValue;
+ * A ConditionalExpression is like that : booleanExpression ? trueValue : falseValue;.
* @author Matthieu Casanova
*/
-public class ConditionalExpression extends OperatorExpression {
+public final class ConditionalExpression extends OperatorExpression {
- public Expression condition, valueIfTrue, valueIfFalse;
+ private final Expression condition;
+ private final Expression valueIfTrue;
+ private final Expression valueIfFalse;
public ConditionalExpression(final Expression condition,
final Expression valueIfTrue,
}
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer("(");
- buff.append(condition.toStringExpression());
+ final String conditionString = condition.toStringExpression();
+ final String valueIfTrueString = valueIfTrue.toStringExpression();
+ final String valueIfFalse = this.valueIfFalse.toStringExpression();
+ final StringBuffer buff = new StringBuffer(8 +
+ conditionString.length() +
+ valueIfTrueString.length() +
+ valueIfFalse.length());
+ buff.append("(");
+ buff.append(conditionString);
buff.append(") ? ");
- buff.append(valueIfTrue.toStringExpression());
+ buff.append(valueIfTrueString);
buff.append(" : ");
- buff.append(valueIfFalse.toStringExpression());
+ buff.append(valueIfFalse);
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
condition.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
condition.getUsedVariable(list);
/**
* @author Matthieu Casanova
*/
-public class ConstantIdentifier extends Expression {
+public final class ConstantIdentifier extends Expression {
- public String name;
+ private final String name;
public ConstantIdentifier(final String name,
final int sourceStart,
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* A continue statement.
* @author Matthieu Casanova
*/
-public class Continue extends BranchStatement {
+public final class Continue extends BranchStatement {
public Continue(final Expression expression, final int sourceStart, final int sourceEnd) {
super(expression, sourceStart, sourceEnd);
package net.sourceforge.phpdt.internal.compiler.ast;
/**
+ * A default case for a switch.
+ * it's default : .....;
* @author Matthieu Casanova
*/
-public class DefaultCase extends AbstractCase {
+public final class DefaultCase extends AbstractCase {
+ /**
+ * Create a default case.
+ *
+ * @param statements the statements
+ * @param sourceStart the starting offset
+ * @param sourceEnd the ending offset
+ */
public DefaultCase(final Statement[] statements, final int sourceStart, final int sourceEnd) {
super(statements, sourceStart, sourceEnd);
}
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
package net.sourceforge.phpdt.internal.compiler.ast;
-import java.util.List;
-
import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
-
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import java.util.List;
+
/**
* a Define.
* define(expression,expression)
+ *
* @author Matthieu Casanova
*/
-public class Define extends Statement implements Outlineable {
+public final class Define extends Statement implements Outlineable {
- public Expression defineName,defineValue;
+ private final Expression defineName;
+ private final Expression defineValue;
- private Object parent;
- private Position position;
+ private final Object parent;
+ private final Position position;
public Define(final Object parent,
final Expression defineName,
}
public String toString(final int tab) {
- final StringBuffer buff = new StringBuffer(tabString(tab));
+ final String nameString = defineName.toStringExpression();
+ final String valueString = defineValue.toStringExpression();
+ final StringBuffer buff = new StringBuffer(tab + 10 + nameString.length() + valueString.length());
+ buff.append(tabString(tab));
buff.append("define(");
- buff.append(defineName.toStringExpression());
+ buff.append(nameString);
buff.append(", ");
- buff.append(defineValue.toStringExpression());
+ buff.append(valueString);
buff.append(")");
return buff.toString();
}
public String toString() {
- final StringBuffer buff = new StringBuffer(defineName.toStringExpression());
+ final String nameString = defineName.toStringExpression();
+ final String valueString = defineValue.toStringExpression();
+ final StringBuffer buff = new StringBuffer(nameString.length() + valueString.length() + 3);
+ buff.append(nameString);
buff.append(" = ");
- buff.append(defineValue.toStringExpression());
+ buff.append(valueString);
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
- list.add(new VariableUsage(defineName.toStringExpression(),sourceStart));//todo: someday : evaluate the defineName
+ list.add(new VariableUsage(defineName.toStringExpression(), sourceStart));//todo: someday : evaluate the defineName
}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
/**
* A do statement.
+ *
* @author Matthieu Casanova
*/
-public class DoStatement extends Statement {
+public final class DoStatement extends Statement {
/** The condition expression. */
- public Expression condition;
+ private final Expression condition;
/** The action of the while. (it could be a block) */
- public Statement action;
+ private final Statement action;
public DoStatement(final Expression condition,
final Statement action,
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
public String toString(final int tab) {
- final String s = tabString(tab);
- final StringBuffer buff = new StringBuffer("do ");//$NON-NLS-1$
+ final String conditionString = condition.toStringExpression();
+ final StringBuffer buff;
if (action == null) {
+ buff = new StringBuffer(17 + tab + conditionString.length());
+ buff.append("do ");//$NON-NLS-1$
buff.append(" {} ;"); //$NON-NLS-1$
} else {
- buff.append("\n").append(action.toString(tab + 1));//$NON-NLS-1$
+ final String actionString = action.toString(tab + 1);
+ buff = new StringBuffer(13 + conditionString.length() + actionString.length());
+ buff.append("do ");//$NON-NLS-1$
+ buff.append("\n");//$NON-NLS-1$
+ buff.append(actionString);
}
- buff.append(s).append(" while (");//$NON-NLS-1$
- buff.append(condition.toStringExpression()).append(")");//$NON-NLS-1$
+ buff.append(tabString(tab));
+ buff.append(" while (");//$NON-NLS-1$
+ buff.append(conditionString);
+ buff.append(")");//$NON-NLS-1$
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
condition.getOutsideVariable(list); // todo: check if unuseful
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
condition.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
condition.getUsedVariable(list);
/**
* an echo statement.
* echo something;
+ *
* @author Matthieu Casanova
*/
-public class EchoStatement extends Statement {
+public final class EchoStatement extends Statement {
/** An array of expressions in this echo statement. */
- public Expression[] expressions;
+ private final Expression[] expressions;
- public EchoStatement (final Expression[] expressions, final int sourceStart, final int sourceEnd) {
+ public EchoStatement(final Expression[] expressions, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.expressions = expressions;
}
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
public String toString(final int tab) {
final String tabs = tabString(tab);
final String str = toString();
- final StringBuffer buff = new StringBuffer(tabs.length()+str.length());
+ final StringBuffer buff = new StringBuffer(tabs.length() + str.length());
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < expressions.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < expressions.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < expressions.length; i++) {
* it's else
* @author Matthieu Casanova
*/
-public class Else extends Statement {
+public final class Else extends Statement {
/** the statements. */
- public Statement[] statements;
+ private final Statement[] statements;
/**
* An else statement bad version ( : endif).
final int sourceStart,
final int sourceEnd) {
super(sourceStart, sourceEnd);
- this.statements = new Statement[1];
- this.statements[0] = statement;
+ statements = new Statement[1];
+ statements[0] = statement;
}
/**
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
* An elseif statement.
* @author Matthieu Casanova
*/
-public class ElseIf extends Statement {
+public final class ElseIf extends Statement {
/** The condition. */
- public Expression condition;
+ private final Expression condition;
/** The statements. */
- public Statement[] statements;
+ private final Statement[] statements;
public ElseIf(final Expression condition, final Statement[] statements, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < statements.length; i++) {
* An empty statement.
* @author Matthieu Casanova
*/
-public class EmptyStatement extends Statement {
+public final class EmptyStatement extends Statement {
public EmptyStatement(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
public String toString(final int tab) {
- return tabString(tab) + ";"; //$NON-NLS-1$
+ return tabString(tab) + ';'; //$NON-NLS-1$
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Expression(final int sourceStart, final int sourceEnd) {
+ protected 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(final int tab) {
+ public final String toString(final int tab) {
return tabString(tab) + toStringExpression();
}
/**
* @author Matthieu Casanova
*/
-public class FalseLiteral extends MagicLiteral {
+public final class FalseLiteral extends MagicLiteral {
public FalseLiteral(final Token token) {
super(token.sourceStart, token.sourceEnd);
* var $toto,$tata;
* @author Matthieu Casanova
*/
-public class FieldDeclaration extends Statement implements Outlineable {
+public final class FieldDeclaration extends Statement implements Outlineable {
/** The variables. */
- public VariableDeclaration[] vars;
+ public final VariableDeclaration[] vars;
- private Object parent;
- private Position position;
+ private final Object parent;
+ private final Position position;
/**
* Create a new field.
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* for(initializations;condition;increments) action
* @author Matthieu Casanova
*/
-public class ForStatement extends Statement {
+public final class ForStatement extends Statement {
/** the initializations. */
- public Expression[] initializations;
+ private final Expression[] initializations;
/** the condition. */
- public Expression condition;
+ private final Expression condition;
/** the increments. */
- public Expression[] increments;
+ private final Expression[] increments;
- public Statement action;
+ private final Statement action;
/**
- * a for statement
+ * a for statement.
+ *
* @param initializations the initializations expressions
* @param condition the condition when the for get out
* @param increments the increments statements
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
if (condition != null) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
if (condition != null) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
if (condition != null) {
/**
* @author Matthieu Casanova
*/
-public class ForeachStatement extends Statement {
+public final class ForeachStatement extends Statement {
- public Expression expression;
- public Expression variable;
- public Statement statement;
+ private final Expression expression;
+ private final Expression variable;
+ private final Statement statement;
public ForeachStatement(final Expression expression,
final Expression variable,
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
public String toString(final int tab) {
- final StringBuffer buff = new StringBuffer(tabString(tab));
+ final String expressionString = expression.toStringExpression();
+ final String variableString = variable.toStringExpression();
+ final String statementString = statement.toString(tab + 1);
+ final StringBuffer buff = new StringBuffer(tab +
+ expressionString.length() +
+ variableString.length() +
+ statementString.length() + 18);
+ buff.append(tabString(tab));
buff.append("foreach (");
- buff.append(expression.toStringExpression());
+ buff.append(expressionString);
buff.append(" as ");
- buff.append(variable.toStringExpression());
+ buff.append(variableString);
buff.append(" {\n");
- buff.append(statement.toString(tab+1));
+ buff.append(statementString);
buff.append("\n}");
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
expression.getOutsideVariable(list);
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
expression.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
expression.getUsedVariable(list);
* A Function call.
* @author Matthieu Casanova
*/
-public class FunctionCall extends AbstractSuffixExpression {
+public final class FunctionCall extends AbstractSuffixExpression {
/** the function name. */
- public Expression functionName;
+ private final Expression functionName;
/** the arguments. */
- public Expression[] args;
+ private final Expression[] args;
- public FunctionCall(final Expression prefix,
+ /**
+ * a function call.
+ * it's <code>functionName(args ...)
+ * @param functionName the function name
+ * @param args the arguments
+ * @param sourceEnd the source end
+ */
+ public FunctionCall(final Expression functionName,
final Expression[] args,
final int sourceEnd) {
- super(prefix.sourceStart, sourceEnd);
- this.functionName = prefix;
+ super(functionName.sourceStart, sourceEnd);
+ this.functionName = functionName;
this.args = args;
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
if (args != null) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
functionName.getUsedVariable(list);
* A GlobalStatement statement in php.
* @author Matthieu Casanova
*/
-public class GlobalStatement extends Statement implements Outlineable {
+public final class GlobalStatement extends Statement implements Outlineable {
/** An array of the variables called by this global statement. */
- public AbstractVariable[] variables;
+ private final AbstractVariable[] variables;
- private Object parent;
+ private final Object parent;
- private Position position;
+ private final Position position;
public GlobalStatement(final Object parent,
final AbstractVariable[] variables,
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < variables.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
/**
* We will analyse the code.
/**
* @author Matthieu Casanova
*/
-public class HTMLBlock extends Statement {
+public final class HTMLBlock extends Statement {
- public AstNode[] nodes;
+ private final AstNode[] nodes;
public HTMLBlock(final AstNode[] nodes) {
super(nodes[0].sourceStart, nodes[(nodes.length > 0) ? nodes.length - 1 : 0].sourceEnd);
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* It will contains some html, javascript, css ...
* @author Matthieu Casanova
*/
-public class HTMLCode extends AstNode {
+public final class HTMLCode extends AstNode {
/** The html Code. */
- public char[] htmlCode;
+ private final String htmlCode;
/**
* Create an html Block.
* @param sourceStart the starting offset
* @param sourceEnd the ending offset
*/
- public HTMLCode(final char[] htmlCode,
+ public HTMLCode(final String htmlCode,
final int sourceStart,
final int sourceEnd) {
super(sourceStart, sourceEnd);
* @return the text of the block
*/
public String toString() {
- return new String(htmlCode);
+ return htmlCode;
}
/**
* @return the text of the block
*/
public String toString(final int tab) {
- return new String(htmlCode) + " ";//$NON-NLS-1$
+ return htmlCode + ' ';
}
/**
* Get the variables from outside (parameters, globals ...)
- * @return an empty list
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
- * @return an empty list
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
- * @return an empty list
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
* else statement
* @author Matthieu Casanova
*/
-public class IfStatement extends Statement {
+public final class IfStatement extends Statement {
- public Expression condition;
- public Statement statement;
- public ElseIf[] elseifs;
- public Else els;
+ private final Expression condition;
+ private final Statement statement;
+ private final ElseIf[] elseifs;
+ private final Else els;
/**
* Create a new If statement.
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
condition.getOutsideVariable(list); // todo: check if unuseful
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
condition.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
condition.getUsedVariable(list);
/**
* @author Matthieu Casanova
*/
-public class InclusionStatement extends Statement implements Outlineable {
+public final class InclusionStatement extends Statement implements Outlineable {
public static final int INCLUDE = 0;
public static final int INCLUDE_ONCE = 1;
public static final int REQUIRE_ONCE = 3;
public boolean silent;
/** The kind of include. */
- public int keyword;
- public Expression expression;
+ private final int keyword;
+ private final Expression expression;
- private Object parent;
+ private final Object parent;
- private Position position;
+ private final Position position;
public InclusionStatement(final Object parent,
final int keyword,
position = new Position(sourceStart, sourceEnd);
}
- public String keywordToString() {
+ private String keywordToString() {
switch (keyword) {
case INCLUDE:
return "include"; //$NON-NLS-1$
}
public String toString() {
- final StringBuffer buffer = new StringBuffer();
+ final String keyword = keywordToString();
+ final String expressionString = expression.toStringExpression();
+ final StringBuffer buffer = new StringBuffer(keyword.length() +
+ expressionString.length() + 2);
if (silent) {
buffer.append('@');
}
- buffer.append(keywordToString());
- buffer.append(" ");
- buffer.append(expression.toStringExpression());
+ buffer.append(keyword);
+ buffer.append(' ');
+ buffer.append(expressionString);
return buffer.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
expression.getOutsideVariable(list);
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
expression.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
expression.getUsedVariable(list);
/**
* @author Matthieu Casanova
*/
-public class LabeledStatement extends Statement {
+public final class LabeledStatement extends Statement {
- public String label;
+ private final String label;
- public Statement statement;
+ private final Statement statement;
public LabeledStatement(final String label,
final Statement statement,
/**
* Return the object into String.
* It should be overriden
+ *
* @return a String
*/
public String toString() {
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
return tabString(tab) + toString();
}
- /**
+ /**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
statement.getOutsideVariable(list);
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
statement.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
statement.getUsedVariable(list);
* it could be list($v1,$v2), list(,$v2) ...
* @author Matthieu Casanova
*/
-public class ListExpression extends Expression {
+public final class ListExpression extends Expression {
- public Expression[] vars;
- public Expression expression;
+ private final Expression[] vars;
+ private Expression expression;
public ListExpression(final Expression[] vars,
final Expression expression,
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < vars.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
if (expression != null) {
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Literal(final int sourceStart, final int sourceEnd) {
+ protected Literal(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public final void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public final void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
}
*/
public abstract class MagicLiteral extends Literal {
- public MagicLiteral(final int sourceStart, final int sourceEnd) {
+ protected MagicLiteral(final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
}
}
* A Method declaration.
* @author Matthieu Casanova
*/
-public class MethodDeclaration extends Statement implements OutlineableWithChildren {
+public final class MethodDeclaration extends Statement implements OutlineableWithChildren {
/** The name of the method. */
- public String name;
- public ArrayList arguments;
+ public final String name;
+ private final ArrayList arguments;
public Statement[] statements;
- public int bodyStart;
- public int bodyEnd = -1;
+ private final int bodyStart;
+ private int bodyEnd = -1;
/** Tell if the method is a class constructor. */
public boolean isConstructor;
/** The parent object. */
private Object parent;
/** The outlineable children (those will be in the node array too. */
- private ArrayList children = new ArrayList();
+ private final ArrayList children = new ArrayList();
/** Tell if the method returns a reference. */
- public boolean reference;
+ private final boolean reference;
- private Position position;
+ private final Position position;
public MethodDeclaration(final Object parent,
final String name,
return buff.toString();
}
- public String toStringHeader() {
+ private String toStringHeader() {
return "function " + toString();
}
* @param tab the number of tabs
* @return the String containing the statements
*/
- public String toStringStatements(final int tab) {
+ private String toStringStatements(final int tab) {
final StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
if (arguments != null) {
for (int i = 0; i < arguments.size(); i++) {
- VariableDeclaration o = (VariableDeclaration) arguments.get(i);
+ final VariableDeclaration o = (VariableDeclaration) arguments.get(i);
buff.append(o.toStringExpression());
if (i != (arguments.size() - 1)) {
buff.append(", "); //$NON-NLS-1$
}
/** no outside variables. */
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
/**
* Get global variables (not parameters).
*/
- public void getGlobalVariable(final List list) {
+ private void getGlobalVariable(final List list) {
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
statements[i].getOutsideVariable(list);
private void getParameters(final List list) {
if (arguments != null) {
for (int i = 0; i < arguments.size(); i++) {
- VariableDeclaration variable = (VariableDeclaration) arguments.get(i);
+ final VariableDeclaration variable = (VariableDeclaration) arguments.get(i);
list.add(new VariableUsage(variable.name(), variable.sourceStart));
}
}
}
}
- private boolean isVariableDeclaredBefore(final List list, final VariableUsage var) {
+ private static boolean isVariableDeclaredBefore(final List list, final VariableUsage var) {
final String name = var.getName();
final int pos = var.getStartOffset();
for (int i = 0; i < list.size(); i++) {
getGlobalVariable(globalsVars);
final List modifiedVars = new ArrayList();
getAssignedVariableInCode(modifiedVars);
- final List parameters = new ArrayList();
+ final List parameters = new ArrayList(arguments.size());
getParameters(parameters);
final List declaredVars = new ArrayList(globalsVars.size() + modifiedVars.size());
* @param vars the used variable list
* @param parameters the declared variable list
*/
- private void findUnusedParameters(final List vars, final List parameters) {
+ private static void findUnusedParameters(final List vars, final List parameters) {
for (int i = 0; i < parameters.size(); i++) {
- final VariableUsage param = ((VariableUsage) parameters.get(i));
+ final VariableUsage param = (VariableUsage) parameters.get(i);
if (!isVariableInList(param.getName(), vars)) {
try {
PHPParserSuperclass.setMarker(
}
}
- private boolean isVariableInList(final String name, final List list) {
+ private static boolean isVariableInList(final String name, final List list) {
for (int i = 0; i < list.size(); i++) {
if (((VariableUsage) list.get(i)).getName().equals(name)) {
return true;
* @param usedVars the used variable list
* @param declaredVars the declared variable list
*/
- private void findUnknownUsedVars(final List usedVars, final List declaredVars) {
+ private static void findUnknownUsedVars(final List usedVars, final List declaredVars) {
for (int i = 0; i < usedVars.size(); i++) {
final VariableUsage variableUsage = (VariableUsage) usedVars.get(i);
- if (variableUsage.getName().equals("this")) continue; // this is a special variable
+ if ("this".equals(variableUsage.getName())) continue; // this is a special variable
if (!isVariableDeclaredBefore(declaredVars, variableUsage)) {
try {
PHPParserSuperclass.setMarker(
/**
* @author Matthieu Casanova
*/
-public class NullLiteral extends MagicLiteral {
+public final class NullLiteral extends MagicLiteral {
public NullLiteral(final Token token) {
super(token.sourceStart, token.sourceEnd);
* Literal for numbers.
* @author Matthieu Casanova
*/
-public class NumberLiteral extends Literal {
- public String source;
+public final class NumberLiteral extends Literal {
+ private final String source;
public NumberLiteral(final Token token) {
super(token.sourceStart, token.sourceEnd);
extends Expression
implements OperatorIds {
- public int operator;
+ private final int operator;
- public OperatorExpression(final int operator, final int sourceStart, final int sourceEnd) {
+ protected OperatorExpression(final int operator, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
this.operator = operator;
}
- public String operatorToString() {
+ public final String operatorToString() {
switch (operator) {
case EQUAL_EQUAL:
return "=="; //$NON-NLS-1$
* @author Matthieu Casanova
*/
public interface OperatorIds {
- static final int AND_AND = 0; // "&&"
- static final int OR_OR = 1; // "||"
- static final int AND = 2; // "&"
- static final int OR = 3; // "|"
- static final int LESS = 4; // "<"
- static final int LESS_EQUAL = 5; // "<="
- static final int GREATER = 6; // ">"
- static final int GREATER_EQUAL = 7; // ">="
- static final int XOR = 8; // "^"
- static final int DIVIDE = 9; // "/"
- static final int LEFT_SHIFT = 10; // "<<"
- static final int NOT = 11; // "!"
- static final int TWIDDLE = 12; // "~"
- static final int MINUS = 13; // "-"
- static final int PLUS = 14; // "+"
- static final int MULTIPLY = 15; // "*"
- static final int REMAINDER = 16; // "%"
- static final int RIGHT_SHIFT = 17; // ">>"
- static final int EQUAL_EQUAL = 18; // "=="
- static final int UNSIGNED_RIGHT_SHIFT= 19; // ">>>"
- static final int ORL = 20; // "OR"
- static final int ANDL = 21; // "AND"
- static final int DOT = 22; // "."
- static final int DIF = 23; // "<>"
- static final int BANG_EQUAL_EQUAL = 24; // "!=="
- static final int EQUAL_EQUAL_EQUAL = 25; // "==="
- static final int AT = 26; // "@"
+ int AND_AND = 0; // "&&"
+ int OR_OR = 1; // "||"
+ int AND = 2; // "&"
+ int OR = 3; // "|"
+ int LESS = 4; // "<"
+ int LESS_EQUAL = 5; // "<="
+ int GREATER = 6; // ">"
+ int GREATER_EQUAL = 7; // ">="
+ int XOR = 8; // "^"
+ int DIVIDE = 9; // "/"
+ int LEFT_SHIFT = 10; // "<<"
+ int NOT = 11; // "!"
+ int TWIDDLE = 12; // "~"
+ int MINUS = 13; // "-"
+ int PLUS = 14; // "+"
+ int MULTIPLY = 15; // "*"
+ int REMAINDER = 16; // "%"
+ int RIGHT_SHIFT = 17; // ">>"
+ int EQUAL_EQUAL = 18; // "=="
+ int UNSIGNED_RIGHT_SHIFT= 19; // ">>>"
+ int ORL = 20; // "OR"
+ int ANDL = 21; // "AND"
+ int DOT = 22; // "."
+ int DIF = 23; // "<>"
+ int BANG_EQUAL_EQUAL = 24; // "!=="
+ int EQUAL_EQUAL_EQUAL = 25; // "==="
+ int AT = 26; // "@"
- static final int NOT_EQUAL = 29; // "!="
- static final int PLUS_PLUS = 32; // "++"
- static final int MINUS_MINUS = 33; // "--"
- static final int NEW = 34; // "new "
- static final int EQUAL = 35; // "="
+ int NOT_EQUAL = 29; // "!="
+ int PLUS_PLUS = 32; // "++"
+ int MINUS_MINUS = 33; // "--"
+ int NEW = 34; // "new "
+ int EQUAL = 35; // "="
}
* It will contains html and php
* @author Matthieu Casanova
*/
-public class PHPDocument implements OutlineableWithChildren {
+public final class PHPDocument implements OutlineableWithChildren {
/**
* The nodes.
*/
public AstNode[] nodes;
- public char[] name;
+ private final char[] name;
/** The parent of the object. */
- public Object parent;
+ private final Object parent;
/** The outlineable children (those will be in the node array too. */
- private ArrayList children = new ArrayList();
+ private final ArrayList children = new ArrayList();
- private Position position;
+ private final Position position;
/**
* Create the PHPDocument.
* @param parent the parent object (it should be null isn't it ?)
* <?= someexpression ?>
* @author Matthieu Casanova
*/
-public class PHPEchoBlock extends AstNode {
+public final class PHPEchoBlock extends AstNode {
/** the expression. */
- public Expression expr;
+ private final Expression expr;
/**
* Create a new php echo block.
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
expr.getUsedVariable(list);
/**
* @author Matthieu Casanova
*/
-public class PostfixedUnaryExpression extends UnaryExpression {
+public final class PostfixedUnaryExpression extends UnaryExpression {
public PostfixedUnaryExpression(final Expression expression,
final int operator,
}
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer(expression.toStringExpression());
- buff.append(operatorToString());
- return buff.toString();
+ return expression.toStringExpression() + operatorToString();
}
}
}
public String toStringExpression() {
- final StringBuffer buff = new StringBuffer(operatorToString());
- buff.append(expression.toStringExpression());
- return buff.toString();
+ return operatorToString() + expression.toStringExpression();
}
}
/**
* @author Matthieu Casanova
*/
-public class PrintExpression extends Expression {
+public final class PrintExpression extends Expression {
- public Expression expression;
+ private final Expression expression;
public PrintExpression(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
expression.getOutsideVariable(list);
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
expression.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
expression.getUsedVariable(list);
* A return statement.
* @author Matthieu Casanova
*/
-public class ReturnStatement extends Statement {
+public final class ReturnStatement extends Statement {
- public Expression expression;
+ private final Expression expression;
public ReturnStatement(final Expression expression, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
return s + "return " + expression.toStringExpression();//$NON-NLS-1$
}
- /**
+ /**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
if (expression != null) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
if (expression != null) {
* @param sourceStart starting offset
* @param sourceEnd ending offset
*/
- public Statement(final int sourceStart,
+ protected Statement(final int sourceStart,
final int sourceEnd) {
super(sourceStart, sourceEnd);
}
* A GlobalStatement statement in php.
* @author Matthieu Casanova
*/
-public class StaticStatement extends Statement {
+public final class StaticStatement extends Statement {
/** An array of the variables called by this global statement. */
- public VariableDeclaration[] variables;
+ private final VariableDeclaration[] variables;
public StaticStatement(final VariableDeclaration[] variables, final int sourceStart, final int sourceEnd) {
super(sourceStart, sourceEnd);
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < variables.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
}
import test.Token;
-public class StringLiteral extends Literal {
- String source;
+public final class StringLiteral extends Literal {
+ private String source;
- AbstractVariable[] variablesInside;
+ private AbstractVariable[] variablesInside;
public StringLiteral(final Token token) {
super(token.sourceStart,token.sourceEnd);
/**
* @author Matthieu Casanova
*/
-public class SwitchStatement extends Statement {
+public final class SwitchStatement extends Statement {
- public Expression variable;
- public AbstractCase[] cases;
+ private final Expression variable;
+ private final AbstractCase[] cases;
public SwitchStatement(final Expression variable,
final AbstractCase[] cases,
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
for (int i = 0; i < cases.length; i++) {
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
for (int i = 0; i < cases.length; i++) {
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
for (int i = 0; i < cases.length; i++) {
* the true literal.
* @author Matthieu Casanova
*/
-public class TrueLiteral extends MagicLiteral {
+public final class TrueLiteral extends MagicLiteral {
- public TrueLiteral(Token token) {
+ public TrueLiteral(final Token token) {
super(token.sourceStart, token.sourceEnd);
}
*/
public interface Types {
- static final char[] STRING = {'s', 't', 'r', 'i', 'n', 'g'};
- static final char[] BOOL = {'b', 'o', 'o', 'l'};
- static final char[] BOOLEAN = {'b', 'o', 'o', 'l', 'e', 'a', 'n'};
- static final char[] REAL = {'r', 'e', 'a', 'l'};
- static final char[] DOUBLE = {'d', 'o', 'u', 'b', 'l', 'e'};
- static final char[] FLOAT = {'f', 'l', 'o', 'a', 't'};
- static final char[] INT = {'i', 'n', 't'};
- static final char[] INTEGER = {'i', 'n', 't', 'e', 'g', 'e', 'r'};
- static final char[] OBJECT = {'o', 'b', 'j', 'e', 'c', 't'};
- static final char[] ARRAY = {'a', 'r', 'r', 'a', 'y'};
+ char[] STRING = {'s', 't', 'r', 'i', 'n', 'g'};
+ char[] BOOL = {'b', 'o', 'o', 'l'};
+ char[] BOOLEAN = {'b', 'o', 'o', 'l', 'e', 'a', 'n'};
+ char[] REAL = {'r', 'e', 'a', 'l'};
+ char[] DOUBLE = {'d', 'o', 'u', 'b', 'l', 'e'};
+ char[] FLOAT = {'f', 'l', 'o', 'a', 't'};
+ char[] INT = {'i', 'n', 't'};
+ char[] INTEGER = {'i', 'n', 't', 'e', 'g', 'e', 'r'};
+ char[] OBJECT = {'o', 'b', 'j', 'e', 'c', 't'};
+ char[] ARRAY = {'a', 'r', 'r', 'a', 'y'};
}
*/
public abstract class UnaryExpression extends OperatorExpression {
- public Expression expression;
+ public final Expression expression;
- public UnaryExpression(final Expression expression, final int operator, final int sourceStart, final int sourceEnd) {
+ protected UnaryExpression(final Expression expression, final int operator, final int sourceStart, final int sourceEnd) {
super(operator, sourceStart, sourceEnd);
this.expression = expression;
}
- /**
+ /**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
- public void getOutsideVariable(final List list) {
- }
+ public final void getOutsideVariable(final List list) {}
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
- public void getModifiedVariable(final List list) {
+ public final void getModifiedVariable(final List list) {
expression.getModifiedVariable(list);
}
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
- public void getUsedVariable(final List list) {
+ public final void getUsedVariable(final List list) {
expression.getUsedVariable(list);
}
}
* $varname = initializer
* @author Matthieu Casanova
*/
-public class VarAssignation extends Expression {
+public final class VarAssignation extends Expression {
public static final int EQUAL = 0;
public static final int PLUS_EQUAL = 1;
public static final int LSHIFT_EQUAL = 11;
public static final int RSIGNEDSHIFT_EQUAL = 12;
- public Expression variableName;
- public Expression initializer;
- public int operator;
+ public final Expression variableName;
+ public final Expression initializer;
+ public final int operator;
/**
* Create a new variable assignation.
* Return the operator as String.
* @return the operator
*/
- public final String operatorToString() {
+ public String operatorToString() {
switch (operator) {
case EQUAL:
return "="; //$NON-NLS-1$
* It could be a simple variable, or contains another variable.
* @author Matthieu Casanova
*/
-public class Variable extends AbstractVariable {
+public final class Variable extends AbstractVariable {
/** The name of the variable. */
private String name;
/** the variable is defined like this ${expression} */
private Expression expression;
- public static final String _GET = "_GET";
- public static final String _POST = "_POST";
- public static final String _REQUEST = "_REQUEST";
- public static final String _SERVER = "_SERVER";
- public static final String _SESSION = "_SESSION";
- public static final String _this = "this";
- public static final String GLOBALS = "GLOBALS";
- public static final String _COOKIE = "_COOKIE";
- public static final String _FILES = "_FILES";
- public static final String _ENV = "_ENV";
+ private static final String _GET = "_GET";
+ private static final String _POST = "_POST";
+ private static final String _REQUEST = "_REQUEST";
+ private static final String _SERVER = "_SERVER";
+ private static final String _SESSION = "_SESSION";
+ private static final String _this = "this";
+ private static final String GLOBALS = "GLOBALS";
+ private static final String _COOKIE = "_COOKIE";
+ private static final String _FILES = "_FILES";
+ private static final String _ENV = "_ENV";
/** Here is an array of all superglobals variables and the special "this". */
public static final String[] SPECIAL_VARS = {_GET,
* @return the expression
*/
public String toStringExpression() {
- return "$" + getName();
+ return '$' + getName();
}
public String getName() {
if (variable != null) {
return variable.toStringExpression();
}
- return "{" + expression.toStringExpression() + "}";
+ return '{' + expression.toStringExpression() + '}';
}
/**
package net.sourceforge.phpdt.internal.compiler.ast;
-import java.util.List;
-
import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
-
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.Position;
+import java.util.List;
+
/**
* A variable declaration.
+ *
* @author Matthieu Casanova
*/
public class VariableDeclaration extends Expression implements Outlineable {
public static final int LSHIFT_EQUAL = 11;
public static final int RSIGNEDSHIFT_EQUAL = 12;
- protected AbstractVariable variable;
+ protected final AbstractVariable variable;
/** The value for variable initialization. */
public Expression initialization;
private Object parent;
- private boolean reference;
+ protected boolean reference;
private Position position;
/**
* Create a variable.
- * @param variable the name of the variable
+ *
+ * @param variable the name of the variable
* @param initialization the initialization
- * @param operator the assign operator
- * @param sourceStart the start point
+ * @param operator the assign operator
+ * @param sourceStart the start point
*/
public VariableDeclaration(final Object parent,
final AbstractVariable variable,
/**
* Create a variable.
- * @param variable a variable (in case of $$variablename)
+ *
+ * @param variable a variable (in case of $$variablename)
* @param sourceStart the start point
*/
public VariableDeclaration(final Object parent,
position = new Position(sourceStart, sourceEnd);
}
- public void setReference(final boolean reference) {
+ public final void setReference(final boolean reference) {
this.reference = reference;
}
/**
* Create a variable.
+ *
* @param initialization the initialization
- * @param variable a variable (in case of $$variablename)
- * @param sourceStart the start point
+ * @param variable a variable (in case of $$variablename)
+ * @param sourceStart the start point
*/
public VariableDeclaration(final AbstractVariable variable,
final Expression initialization,
/**
* Create a variable.
- * @param variable a variable (in case of $$variablename)
+ *
+ * @param variable a variable (in case of $$variablename)
* @param sourceStart the start point
*/
public VariableDeclaration(final AbstractVariable variable,
/**
* Return the operator as String.
+ *
* @return the operator
*/
- public final String operatorToString() {
+ private String operatorToString() {
switch (operator) {
case EQUAL:
return "="; //$NON-NLS-1$
/**
* Return the variable into String.
+ *
* @return a String
*/
public String toStringExpression() {
- final StringBuffer buff;
- if (reference) {
- buff = new StringBuffer("&"); //$NON-NLS-1$
+ final String variableString = variable.toStringExpression();
+ if (initialization == null) {
+ if (reference) return '&' + variableString; else return variableString;
} else {
- buff = new StringBuffer();//$NON-NLS-1$
- }
- buff.append(variable.toStringExpression());
- if (initialization != null) {
- buff.append(operatorToString()); //$NON-NLS-1$
- buff.append(initialization.toStringExpression());
+ final String operatorString = operatorToString();
+ final String initString = initialization.toStringExpression();
+ final StringBuffer buff = new StringBuffer(variableString.length() +
+ operatorString.length() +
+ initString.length() +
+ 1);
+ buff.append(variableString);
+ buff.append(operatorString); //$NON-NLS-1$
+ buff.append(initString);
+ return buff.toString();
}
- return buff.toString();
}
- public Object getParent() {
+ public final Object getParent() {
return parent;
}
- public String toString() {
+ public final String toString() {
return toStringExpression();
}
/**
* Get the image of a variable.
+ *
* @return the image that represents a php variable
*/
- public ImageDescriptor getImage() {
+ public final ImageDescriptor getImage() {
return PHPUiImages.DESC_VAR;
}
- public Position getPosition() {
+ public final Position getPosition() {
return position;
}
/**
* Get the name of the field as String.
+ *
* @return the name of the String
*/
- public String name() {
+ public final String name() {
return variable.getName();
}
/**
* Get the variables from outside (parameters, globals ...)
*/
- public void getOutsideVariable(final List list) {
+ public final void getOutsideVariable(final List list) {
}
/**
* get the modified variables.
*/
- public void getModifiedVariable(final List list) {
+ public final void getModifiedVariable(final List list) {
variable.getUsedVariable(list);
if (initialization != null) {
initialization.getModifiedVariable(list);
/**
* Get the variables used.
*/
- public void getUsedVariable(final List list) {
+ public final void getUsedVariable(final List list) {
if (initialization != null) {
initialization.getUsedVariable(list);
}
* A While statement.
* @author Matthieu Casanova
*/
-public class WhileStatement extends Statement {
+public final class WhileStatement extends Statement {
/** The condition expression. */
- public Expression condition;
+ private final Expression condition;
/** The action of the while. (it could be a block) */
- public Statement action;
+ private final Statement action;
/**
* Create a While statement.
/**
* Get the variables from outside (parameters, globals ...)
+ *
+ * @param list the list where we will put variables
*/
public void getOutsideVariable(final List list) {
condition.getOutsideVariable(list); // todo: check if unuseful
/**
* get the modified variables.
+ *
+ * @param list the list where we will put variables
*/
public void getModifiedVariable(final List list) {
condition.getModifiedVariable(list);
/**
* Get the variables used.
+ *
+ * @param list the list where we will put variables
*/
public void getUsedVariable(final List list) {
condition.getUsedVariable(list);
* This describe a variable declaration in a php document and his starting offset
* @author Matthieu Casanova
*/
-public class VariableUsage {
+public final class VariableUsage {
/** the variable name. */
- private String name;
+ private final String name;
/** where the variable is declared. */
- private int startOffset;
+ private final int startOffset;
/**
* create a VariableUsage.
}
public String toString() {
- return name + " " + startOffset;
+ return name + ' ' + startOffset;
}
/**
e.currentToken.sourceStart,
e.currentToken.sourceEnd,
errorLevel,
- "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
+ "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+':'+e.currentToken.sourceEnd);
} else {
setMarker(fileToParse,
errorMessage,
errorStart,
errorEnd,
errorLevel,
- "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
+ "Line " + e.currentToken.beginLine+", "+errorStart+':'+errorEnd);
errorStart = -1;
errorEnd = -1;
}
currentPosition > SimpleCharStream.currentBuffer.length()) {
return;
}
- final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,
- currentPosition).toCharArray();
- pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
+ final String html = SimpleCharStream.currentBuffer.substring(htmlStart, currentPosition);
+ pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition));
}
/** Create a new task. */
break;
case IDENTIFIER:
token = jj_consume_token(IDENTIFIER);
- outlineInfo.addVariable("$" + token.image);
+ outlineInfo.addVariable('$' + token.image);
{if (true) return new Variable(token.image,token.sourceStart,token.sourceEnd);}
break;
default:
;
}
variableDeclaration = VariableDeclaratorNoSuffix();
- outlineInfo.addVariable("$"+variableDeclaration.name());
+ outlineInfo.addVariable('$'+variableDeclaration.name());
if (token != null) {
variableDeclaration.setReference(true);
}
expr = UnaryExpression();
} catch (ParseException e) {
if (errorMessage != null) {if (true) throw e;}
- errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
+ errorMessage = "unexpected token '"+e.currentToken.next.image+'\'';
errorLevel = ERROR;
errorStart = PHPParser.token.sourceStart;
errorEnd = PHPParser.token.sourceEnd;
}
try {
statement = Statement();
- pos = rparenToken.sourceEnd+1;
+ pos = statement.sourceEnd+1;
} catch (ParseException e) {
if (errorMessage != null) {if (true) throw e;}
errorMessage = "statement expected";
variable,
statement,
foreachToken.sourceStart,
- statement.sourceEnd);}
+ pos);}
throw new Error("Missing return statement in function");
}
e.currentToken.sourceStart,
e.currentToken.sourceEnd,
errorLevel,
- "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
+ "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+':'+e.currentToken.sourceEnd);
} else {
setMarker(fileToParse,
errorMessage,
errorStart,
errorEnd,
errorLevel,
- "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
+ "Line " + e.currentToken.beginLine+", "+errorStart+':'+errorEnd);
errorStart = -1;
errorEnd = -1;
}
currentPosition > SimpleCharStream.currentBuffer.length()) {
return;
}
- final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,
- currentPosition).toCharArray();
- pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
+ final String html = SimpleCharStream.currentBuffer.substring(htmlStart, currentPosition);
+ pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition));
}
/** Create a new task. */
|
token = <IDENTIFIER>
{
- outlineInfo.addVariable("$" + token.image);
+ outlineInfo.addVariable('$' + token.image);
return new Variable(token.image,token.sourceStart,token.sourceEnd);
}
}
{
[token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
{
- outlineInfo.addVariable("$"+variableDeclaration.name());
+ outlineInfo.addVariable('$'+variableDeclaration.name());
if (token != null) {
variableDeclaration.setReference(true);
}
expr = UnaryExpression()
} catch (ParseException e) {
if (errorMessage != null) throw e;
- errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
+ errorMessage = "unexpected token '"+e.currentToken.next.image+'\'';
errorLevel = ERROR;
errorStart = PHPParser.token.sourceStart;
errorEnd = PHPParser.token.sourceEnd;
}
try {
statement = Statement()
- {pos = rparenToken.sourceEnd+1;}
+ {pos = statement.sourceEnd+1;}
} catch (ParseException e) {
if (errorMessage != null) throw e;
errorMessage = "statement expected";
errorEnd = e.currentToken.sourceEnd;
processParseExceptionDebug(e);
}
- {return new ForeachStatement(expression,
+ {
+ return new ForeachStatement(expression,
variable,
statement,
foreachToken.sourceStart,
- statement.sourceEnd);}
+ pos);}
}
/* Generated By:JavaCC: Do not edit this line. PHPParserTokenManager.java */
package test;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.texteditor.MarkerUtilities;
+import org.eclipse.jface.preference.IPreferenceStore;
+import java.util.Hashtable;
+import java.util.ArrayList;
+import java.io.StringReader;
+import java.io.*;
+import java.text.MessageFormat;
+import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpdt.internal.compiler.ast.*;
+import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
+import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
+import net.sourceforge.phpdt.internal.corext.Assert;
public class PHPParserTokenManager implements PHPParserConstants
{