From 79717fae088bef06c86275fa7e2f819e3398d86e Mon Sep 17 00:00:00 2001 From: kpouer Date: Wed, 29 Oct 2003 13:50:49 +0000 Subject: [PATCH] Some minor changes --- .../phpdt/internal/compiler/ast/AbstractCase.java | 17 +++-- .../internal/compiler/ast/AbstractPHPComment.java | 14 ++-- .../compiler/ast/AbstractSuffixExpression.java | 2 +- .../internal/compiler/ast/AbstractVariable.java | 13 ++-- .../internal/compiler/ast/ArgumentDeclaration.java | 48 ++++++++----- .../internal/compiler/ast/ArrayDeclarator.java | 38 +++++++---- .../internal/compiler/ast/ArrayInitializer.java | 17 ++++- .../compiler/ast/ArrayVariableDeclaration.java | 34 ++++++--- .../phpdt/internal/compiler/ast/AstNode.java | 14 ++-- .../internal/compiler/ast/BinaryExpression.java | 36 +++++++-- .../phpdt/internal/compiler/ast/Block.java | 12 +++- .../internal/compiler/ast/BranchStatement.java | 19 ++++-- .../phpdt/internal/compiler/ast/Break.java | 2 +- .../phpdt/internal/compiler/ast/Case.java | 8 ++- .../internal/compiler/ast/CastExpression.java | 15 +++-- .../phpdt/internal/compiler/ast/ClassAccess.java | 41 +++++++---- .../internal/compiler/ast/ClassDeclaration.java | 39 ++++++----- .../internal/compiler/ast/ClassInstantiation.java | 6 +- .../compiler/ast/ConditionalExpression.java | 32 ++++++--- .../internal/compiler/ast/ConstantIdentifier.java | 19 +++-- .../phpdt/internal/compiler/ast/Continue.java | 2 +- .../phpdt/internal/compiler/ast/DefaultCase.java | 12 +++- .../phpdt/internal/compiler/ast/Define.java | 45 +++++++----- .../phpdt/internal/compiler/ast/DoStatement.java | 32 ++++++-- .../phpdt/internal/compiler/ast/EchoStatement.java | 16 +++- .../phpdt/internal/compiler/ast/Else.java | 14 +++- .../phpdt/internal/compiler/ast/ElseIf.java | 12 +++- .../internal/compiler/ast/EmptyStatement.java | 19 +++-- .../phpdt/internal/compiler/ast/Expression.java | 4 +- .../phpdt/internal/compiler/ast/FalseLiteral.java | 2 +- .../internal/compiler/ast/FieldDeclaration.java | 23 ++++--- .../phpdt/internal/compiler/ast/ForStatement.java | 19 ++++-- .../internal/compiler/ast/ForeachStatement.java | 30 ++++++-- .../phpdt/internal/compiler/ast/FunctionCall.java | 28 +++++-- .../internal/compiler/ast/GlobalStatement.java | 20 +++-- .../phpdt/internal/compiler/ast/HTMLBlock.java | 19 +++-- .../phpdt/internal/compiler/ast/HTMLCode.java | 28 ++++---- .../phpdt/internal/compiler/ast/IfStatement.java | 16 +++-- .../internal/compiler/ast/InclusionStatement.java | 29 +++++--- .../internal/compiler/ast/LabeledStatement.java | 16 +++- .../internal/compiler/ast/ListExpression.java | 15 +++-- .../phpdt/internal/compiler/ast/Literal.java | 17 +++-- .../phpdt/internal/compiler/ast/MagicLiteral.java | 2 +- .../internal/compiler/ast/MethodDeclaration.java | 49 ++++++------- .../phpdt/internal/compiler/ast/NullLiteral.java | 2 +- .../phpdt/internal/compiler/ast/NumberLiteral.java | 4 +- .../internal/compiler/ast/OperatorExpression.java | 6 +- .../phpdt/internal/compiler/ast/OperatorIds.java | 64 ++++++++-------- .../phpdt/internal/compiler/ast/PHPDocument.java | 10 ++-- .../phpdt/internal/compiler/ast/PHPEchoBlock.java | 16 +++-- .../compiler/ast/PostfixedUnaryExpression.java | 6 +- .../compiler/ast/PrefixedUnaryExpression.java | 4 +- .../internal/compiler/ast/PrintExpression.java | 10 ++- .../internal/compiler/ast/ReturnStatement.java | 15 +++-- .../phpdt/internal/compiler/ast/Statement.java | 2 +- .../internal/compiler/ast/StaticStatement.java | 10 ++- .../phpdt/internal/compiler/ast/StringLiteral.java | 6 +- .../internal/compiler/ast/SwitchStatement.java | 12 +++- .../phpdt/internal/compiler/ast/TrueLiteral.java | 4 +- .../phpdt/internal/compiler/ast/Types.java | 20 +++--- .../internal/compiler/ast/UnaryExpression.java | 19 +++-- .../internal/compiler/ast/VarAssignation.java | 10 ++-- .../phpdt/internal/compiler/ast/Variable.java | 26 ++++---- .../internal/compiler/ast/VariableDeclaration.java | 75 +++++++++++-------- .../internal/compiler/ast/WhileStatement.java | 12 +++- .../compiler/ast/declarations/VariableUsage.java | 8 +- net.sourceforge.phpeclipse/src/test/PHPParser.java | 19 +++--- net.sourceforge.phpeclipse/src/test/PHPParser.jj | 22 +++--- .../src/test/PHPParserTokenManager.java | 17 +++++ 69 files changed, 804 insertions(+), 490 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java index 02291c8..4817163 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java @@ -9,26 +9,27 @@ import java.util.List; 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); } @@ -36,6 +37,7 @@ public abstract class AbstractCase extends Statement { /** * 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++) { @@ -45,6 +47,7 @@ public abstract class AbstractCase extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java index 21f63dd..f60ebf0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java @@ -13,28 +13,28 @@ public abstract class AbstractPHPComment extends AstNode { * @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) { } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java index 316d271..d0283b5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java @@ -8,7 +8,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; */ 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); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariable.java index f5ed3d9..9a91e22 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariable.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariable.java @@ -1,16 +1,17 @@ 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(); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java index e2fa5f4..c961dd1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java @@ -3,32 +3,32 @@ package net.sourceforge.phpdt.internal.compiler.ast; /** * 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, @@ -37,22 +37,32 @@ public class ArgumentDeclaration extends VariableDeclaration { 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(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java index ceb04d5..53e5b62 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java @@ -3,19 +3,29 @@ package net.sourceforge.phpdt.internal.compiler.ast; 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; } /** @@ -25,8 +35,8 @@ public class ArrayDeclarator extends AbstractVariable { 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(); @@ -42,27 +52,29 @@ public class ArrayDeclarator extends 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) { 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); } } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java index 317b854..8dca5e1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java @@ -7,10 +7,17 @@ import java.util.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) { @@ -38,12 +45,13 @@ public class ArrayInitializer extends 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++) { @@ -55,6 +63,7 @@ public class ArrayInitializer extends Expression { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java index 5486d9c..215c9ea 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java @@ -5,19 +5,21 @@ import java.util.List; /** * 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) { @@ -28,7 +30,8 @@ public class ArrayVariableDeclaration extends Expression { /** * 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) { @@ -38,27 +41,36 @@ public class ArrayVariableDeclaration extends Expression { /** * 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); @@ -69,6 +81,8 @@ public class ArrayVariableDeclaration extends Expression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { key.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java index e7ed112..4d3aec2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java @@ -12,11 +12,11 @@ public abstract class AstNode { 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; } @@ -52,16 +52,19 @@ public abstract class AstNode { /** * 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); @@ -69,16 +72,15 @@ public abstract class AstNode { * 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; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java index 463c01a..7488cb8 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java @@ -3,13 +3,24 @@ package net.sourceforge.phpdt.internal.compiler.ast; 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) { @@ -19,20 +30,27 @@ public class BinaryExpression extends OperatorExpression { } 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); @@ -41,6 +59,8 @@ public class BinaryExpression extends OperatorExpression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { left.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java index ac3cdb5..1f6c9a0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java @@ -9,10 +9,10 @@ import java.util.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. @@ -44,7 +44,7 @@ public class Block extends Statement { 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$ } @@ -55,6 +55,8 @@ public class Block extends 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++) { @@ -64,6 +66,8 @@ public class Block extends Statement { /** * 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++) { @@ -73,6 +77,8 @@ public class Block extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java index d64a352..3013a50 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java @@ -3,22 +3,25 @@ package net.sourceforge.phpdt.internal.compiler.ast; 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); } @@ -26,8 +29,10 @@ public abstract class BranchStatement extends Statement { /** * 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); } @@ -35,8 +40,10 @@ public abstract class BranchStatement extends Statement { /** * 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); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java index 158cb3d..df40b0f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java @@ -4,7 +4,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; * 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java index 8a623d4..751f223 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java @@ -6,9 +6,9 @@ import java.util.List; * 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, @@ -39,6 +39,8 @@ public class Case extends AbstractCase { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { super.getModifiedVariable(list); @@ -47,6 +49,8 @@ public class Case extends AbstractCase { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { super.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java index 65e8268..8b52822 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java @@ -6,13 +6,13 @@ import java.util.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. @@ -44,12 +44,15 @@ public class CastExpression extends 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); @@ -57,6 +60,8 @@ public class CastExpression extends Expression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { expression.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java index 303b62a..5a0553b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java @@ -6,21 +6,21 @@ import java.util.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. @@ -37,7 +37,7 @@ public class ClassAccess extends AbstractVariable { this.type = type; } - public String toStringOperator() { + private String toStringOperator() { switch (type) { case STATIC : return "::"; //$NON-NLS-1$ case NORMAL : return "->"; //$NON-NLS-1$ @@ -50,16 +50,21 @@ public class ClassAccess extends AbstractVariable { * @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) { @@ -70,18 +75,22 @@ public class ClassAccess extends 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java index 0dbf6dd..adb4332 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java @@ -17,12 +17,12 @@ import org.eclipse.jface.text.Position; * 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; @@ -31,18 +31,18 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr /** 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 */ @@ -59,7 +59,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr } /** - * Create a class giving starting and ending offset + * Create a class giving starting and ending offset. * @param sourceStart starting offset * @param sourceEnd ending offset */ @@ -119,7 +119,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr * @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++) { @@ -142,7 +142,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr * 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$ @@ -190,19 +190,22 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr /** * 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassInstantiation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassInstantiation.java index aec08c9..30ee9a9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassInstantiation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassInstantiation.java @@ -4,9 +4,9 @@ package net.sourceforge.phpdt.internal.compiler.ast; * 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, @@ -19,6 +19,6 @@ public class ClassInstantiation extends PrefixedUnaryExpression { if (!reference) { return super.toStringExpression(); } - return "&"+super.toStringExpression(); + return '&' + super.toStringExpression(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java index 76c486c..04ad606 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java @@ -3,12 +3,14 @@ package net.sourceforge.phpdt.internal.compiler.ast; 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, @@ -20,23 +22,33 @@ public class ConditionalExpression extends OperatorExpression { } 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); @@ -46,6 +58,8 @@ public class ConditionalExpression extends OperatorExpression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { condition.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java index 2ba5bb3..0978c7d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java @@ -7,9 +7,9 @@ import test.Token; /** * @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, @@ -33,19 +33,22 @@ public class ConstantIdentifier extends 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) { - } + 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java index 16c3fcd..bb37d26 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java @@ -4,7 +4,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; * 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java index 758c404..e8c6d12 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java @@ -1,16 +1,26 @@ 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 */ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Define.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Define.java index 9669c82..7351341 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Define.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Define.java @@ -1,25 +1,26 @@ 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, @@ -34,19 +35,25 @@ public class Define extends Statement implements Outlineable { } 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(); } @@ -64,20 +71,24 @@ public class Define extends Statement implements Outlineable { /** * 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java index 7d24015..a6c2934 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java @@ -4,15 +4,16 @@ import java.util.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, @@ -25,24 +26,35 @@ public class DoStatement extends Statement { /** * 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 @@ -51,6 +63,8 @@ public class DoStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { condition.getModifiedVariable(list); @@ -59,6 +73,8 @@ public class DoStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { condition.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java index 916f072..b4677ce 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java @@ -5,14 +5,15 @@ import java.util.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; } @@ -30,18 +31,21 @@ public class EchoStatement extends Statement { /** * 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++) { @@ -51,6 +55,8 @@ public class EchoStatement extends Statement { /** * 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++) { @@ -60,6 +66,8 @@ public class EchoStatement extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java index bf00a5e..47748bc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java @@ -7,10 +7,10 @@ import java.util.List; * 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). @@ -35,8 +35,8 @@ public class Else extends Statement { 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; } /** @@ -57,6 +57,8 @@ public class Else extends 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++) { @@ -66,6 +68,8 @@ public class Else extends Statement { /** * 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++) { @@ -75,6 +79,8 @@ public class Else extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java index 677faf5..b0ff581 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java @@ -6,13 +6,13 @@ import java.util.List; * 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); @@ -39,6 +39,8 @@ public class ElseIf extends 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++) { @@ -48,6 +50,8 @@ public class ElseIf extends Statement { /** * 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++) { @@ -58,6 +62,8 @@ public class ElseIf extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java index a389edf..34f4d4d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java @@ -6,31 +6,34 @@ import java.util.List; * 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java index d935982..aa5841e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java @@ -12,7 +12,7 @@ public abstract class Expression extends Statement { * @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); } @@ -21,7 +21,7 @@ public abstract class Expression extends Statement { * @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(); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java index ec7be4b..161eb67 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java @@ -5,7 +5,7 @@ import test.Token; /** * @author Matthieu Casanova */ -public class FalseLiteral extends MagicLiteral { +public final class FalseLiteral extends MagicLiteral { public FalseLiteral(final Token token) { super(token.sourceStart, token.sourceEnd); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java index 2d3be57..c36e9dd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java @@ -16,13 +16,13 @@ import org.eclipse.jface.text.Position; * 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. @@ -75,19 +75,22 @@ public class FieldDeclaration extends Statement implements Outlineable { /** * 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java index 9ee27d5..b11d6f0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java @@ -7,20 +7,21 @@ import java.util.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 @@ -78,6 +79,8 @@ public class ForStatement extends Statement { /** * 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) { @@ -100,6 +103,8 @@ public class ForStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { if (condition != null) { @@ -122,6 +127,8 @@ public class ForStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { if (condition != null) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java index c15e001..d32038a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java @@ -5,11 +5,11 @@ import java.util.List; /** * @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, @@ -24,23 +24,33 @@ public class ForeachStatement extends Statement { /** * 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); @@ -50,6 +60,8 @@ public class ForeachStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { expression.getModifiedVariable(list); @@ -59,6 +71,8 @@ public class ForeachStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { expression.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java index 721354a..d897240 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java @@ -6,19 +6,26 @@ import java.util.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 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; } @@ -44,12 +51,15 @@ public class FunctionCall extends AbstractSuffixExpression { /** * 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) { @@ -61,6 +71,8 @@ public class FunctionCall extends AbstractSuffixExpression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { functionName.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java index 8dce333..3e97fb4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java @@ -16,14 +16,14 @@ import test.PHPParserSuperclass; * 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, @@ -68,6 +68,8 @@ public class GlobalStatement extends Statement implements Outlineable { /** * 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++) { @@ -77,15 +79,17 @@ public class GlobalStatement extends Statement implements Outlineable { /** * 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. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java index 80e7f40..d276a00 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java @@ -5,9 +5,9 @@ import java.util.List; /** * @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); @@ -31,19 +31,22 @@ public class HTMLBlock extends Statement { /** * 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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLCode.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLCode.java index 7e9d327..ad6ff93 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLCode.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLCode.java @@ -8,10 +8,10 @@ import java.util.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. @@ -19,7 +19,7 @@ public class HTMLCode extends AstNode { * @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); @@ -31,7 +31,7 @@ public class HTMLCode extends AstNode { * @return the text of the block */ public String toString() { - return new String(htmlCode); + return htmlCode; } /** @@ -40,27 +40,27 @@ public class HTMLCode extends AstNode { * @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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java index 824b721..bb2e3a0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java @@ -10,12 +10,12 @@ import java.util.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. @@ -64,6 +64,8 @@ public class IfStatement extends 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 @@ -80,6 +82,8 @@ public class IfStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { condition.getModifiedVariable(list); @@ -96,6 +100,8 @@ public class IfStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { condition.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/InclusionStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/InclusionStatement.java index 1cc212c..37d99c1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/InclusionStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/InclusionStatement.java @@ -11,7 +11,7 @@ import org.eclipse.jface.text.Position; /** * @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; @@ -19,12 +19,12 @@ public class InclusionStatement extends Statement implements Outlineable { 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, @@ -38,7 +38,7 @@ public class InclusionStatement extends Statement implements Outlineable { position = new Position(sourceStart, sourceEnd); } - public String keywordToString() { + private String keywordToString() { switch (keyword) { case INCLUDE: return "include"; //$NON-NLS-1$ @@ -64,13 +64,16 @@ public class InclusionStatement extends Statement implements Outlineable { } 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(); } @@ -92,6 +95,8 @@ public class InclusionStatement extends Statement implements Outlineable { /** * 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); @@ -99,6 +104,8 @@ public class InclusionStatement extends Statement implements Outlineable { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { expression.getModifiedVariable(list); @@ -106,6 +113,8 @@ public class InclusionStatement extends Statement implements Outlineable { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { expression.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/LabeledStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/LabeledStatement.java index d0f38f0..3acad54 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/LabeledStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/LabeledStatement.java @@ -5,11 +5,11 @@ import java.util.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, @@ -23,6 +23,7 @@ public class LabeledStatement extends Statement { /** * Return the object into String. * It should be overriden + * * @return a String */ public String toString() { @@ -31,6 +32,7 @@ public class LabeledStatement extends Statement { /** * Return the object into String. + * * @param tab how many tabs (not used here * @return a String */ @@ -38,8 +40,10 @@ public class LabeledStatement extends Statement { 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); @@ -47,6 +51,8 @@ public class LabeledStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { statement.getModifiedVariable(list); @@ -54,6 +60,8 @@ public class LabeledStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { statement.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ListExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ListExpression.java index 425d0f3..a277078 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ListExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ListExpression.java @@ -7,10 +7,10 @@ import java.util.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, @@ -51,12 +51,15 @@ public class ListExpression extends 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++) { @@ -71,6 +74,8 @@ public class ListExpression extends Expression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { if (expression != null) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Literal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Literal.java index b91f015..125abe7 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Literal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Literal.java @@ -13,25 +13,28 @@ public abstract class Literal extends Expression { * @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) {} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MagicLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MagicLiteral.java index 71b1e01..d1107b1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MagicLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MagicLiteral.java @@ -5,7 +5,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; */ 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); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java index f556cc8..6be74d7 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java @@ -19,28 +19,28 @@ import test.PHPParserSuperclass; * 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, @@ -72,7 +72,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild return buff.toString(); } - public String toStringHeader() { + private String toStringHeader() { return "function " + toString(); } @@ -81,7 +81,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild * @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++) { @@ -132,7 +132,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild 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$ @@ -152,19 +152,16 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild } /** 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); @@ -175,7 +172,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild 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)); } } @@ -203,7 +200,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild } } - 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++) { @@ -228,7 +225,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild 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()); @@ -252,9 +249,9 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild * @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( @@ -270,7 +267,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild } } - 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; @@ -284,10 +281,10 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild * @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( diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NullLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NullLiteral.java index 44c41b7..23f88d3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NullLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NullLiteral.java @@ -5,7 +5,7 @@ import test.Token; /** * @author Matthieu Casanova */ -public class NullLiteral extends MagicLiteral { +public final class NullLiteral extends MagicLiteral { public NullLiteral(final Token token) { super(token.sourceStart, token.sourceEnd); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NumberLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NumberLiteral.java index 774b553..760fa54 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NumberLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/NumberLiteral.java @@ -6,8 +6,8 @@ import test.Token; * 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorExpression.java index fc503ab..d675ef0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorExpression.java @@ -8,14 +8,14 @@ public abstract class OperatorExpression 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$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java index 20b8dc1..09d6c1b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java @@ -6,37 +6,37 @@ package net.sourceforge.phpdt.internal.compiler.ast; * @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; // "=" } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java index 74a6c11..0f81089 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java @@ -16,7 +16,7 @@ import org.eclipse.jface.text.Position; * It will contains html and php * @author Matthieu Casanova */ -public class PHPDocument implements OutlineableWithChildren { +public final class PHPDocument implements OutlineableWithChildren { /** * The nodes. @@ -24,15 +24,15 @@ public class PHPDocument implements OutlineableWithChildren { */ 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 ?) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java index 6f8fae9..abef9c5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java @@ -7,10 +7,10 @@ import java.util.List; * * @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. @@ -45,18 +45,22 @@ public class PHPEchoBlock extends AstNode { /** * 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java index 22e31be..8101890 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java @@ -3,7 +3,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; /** * @author Matthieu Casanova */ -public class PostfixedUnaryExpression extends UnaryExpression { +public final class PostfixedUnaryExpression extends UnaryExpression { public PostfixedUnaryExpression(final Expression expression, final int operator, @@ -12,8 +12,6 @@ public class PostfixedUnaryExpression extends UnaryExpression { } public String toStringExpression() { - final StringBuffer buff = new StringBuffer(expression.toStringExpression()); - buff.append(operatorToString()); - return buff.toString(); + return expression.toStringExpression() + operatorToString(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java index 4c74cc4..5e1ef75 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java @@ -12,8 +12,6 @@ public class PrefixedUnaryExpression extends UnaryExpression { } public String toStringExpression() { - final StringBuffer buff = new StringBuffer(operatorToString()); - buff.append(expression.toStringExpression()); - return buff.toString(); + return operatorToString() + expression.toStringExpression(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java index f67d682..9dca4d1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java @@ -5,9 +5,9 @@ import java.util.List; /** * @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); @@ -24,6 +24,8 @@ public class PrintExpression extends Expression { /** * 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); @@ -31,6 +33,8 @@ public class PrintExpression extends Expression { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { expression.getModifiedVariable(list); @@ -38,6 +42,8 @@ public class PrintExpression extends Expression { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { expression.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java index ff4a838..61e5cec 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java @@ -6,9 +6,9 @@ import java.util.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); @@ -23,14 +23,17 @@ public class ReturnStatement extends Statement { 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) { @@ -40,6 +43,8 @@ public class ReturnStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { if (expression != null) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java index bb6e49f..ff647a4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java @@ -12,7 +12,7 @@ public abstract class Statement extends AstNode { * @param sourceStart starting offset * @param sourceEnd ending offset */ - public Statement(final int sourceStart, + protected Statement(final int sourceStart, final int sourceEnd) { super(sourceStart, sourceEnd); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java index 974c7c0..60d5da9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java @@ -6,10 +6,10 @@ import java.util.List; * 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); @@ -33,6 +33,8 @@ public class StaticStatement extends 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 < variables.length; i++) { @@ -42,12 +44,16 @@ public class StaticStatement extends Statement { /** * 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) { } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java index d268e64..1d19a60 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java @@ -14,10 +14,10 @@ import java.util.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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java index 5de7507..e12e122 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java @@ -5,10 +5,10 @@ import java.util.List; /** * @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, @@ -38,6 +38,8 @@ public class SwitchStatement extends 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 < cases.length; i++) { @@ -47,6 +49,8 @@ public class SwitchStatement extends Statement { /** * 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++) { @@ -57,6 +61,8 @@ public class SwitchStatement extends Statement { /** * 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++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java index d3f13bc..bb63a58 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java @@ -6,9 +6,9 @@ import test.Token; * 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); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java index 1b1de19..4165fb4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java @@ -6,15 +6,15 @@ package net.sourceforge.phpdt.internal.compiler.ast; */ 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'}; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java index 2a1a3c2..09f1cf1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java @@ -7,30 +7,35 @@ import java.util.List; */ 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); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java index 6c1c020..3c8699e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java @@ -7,7 +7,7 @@ import java.util.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; @@ -23,9 +23,9 @@ public class VarAssignation extends Expression { 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. @@ -50,7 +50,7 @@ public class VarAssignation extends Expression { * Return the operator as String. * @return the operator */ - public final String operatorToString() { + public String operatorToString() { switch (operator) { case EQUAL: return "="; //$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java index 2a76db4..3cced48 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java @@ -9,7 +9,7 @@ import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage; * 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; @@ -20,16 +20,16 @@ public class Variable extends AbstractVariable { /** 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, @@ -87,7 +87,7 @@ public class Variable extends AbstractVariable { * @return the expression */ public String toStringExpression() { - return "$" + getName(); + return '$' + getName(); } public String getName() { @@ -97,7 +97,7 @@ public class Variable extends AbstractVariable { if (variable != null) { return variable.toStringExpression(); } - return "{" + expression.toStringExpression() + "}"; + return '{' + expression.toStringExpression() + '}'; } /** diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java index 4adb02d..fc4f236 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java @@ -1,15 +1,15 @@ 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 { @@ -28,13 +28,13 @@ 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; @@ -42,10 +42,11 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * 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, @@ -62,7 +63,8 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * 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, @@ -75,15 +77,16 @@ public class VariableDeclaration extends Expression implements Outlineable { 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, @@ -97,7 +100,8 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * 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, @@ -108,9 +112,10 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * Return the operator as String. + * * @return the operator */ - public final String operatorToString() { + private String operatorToString() { switch (operator) { case EQUAL: return "="; //$NON-NLS-1$ @@ -144,61 +149,67 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * 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); @@ -208,7 +219,7 @@ public class VariableDeclaration extends Expression implements Outlineable { /** * Get the variables used. */ - public void getUsedVariable(final List list) { + public final void getUsedVariable(final List list) { if (initialization != null) { initialization.getUsedVariable(list); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java index 22edcc6..f98367c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java @@ -6,12 +6,12 @@ import java.util.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. @@ -48,6 +48,8 @@ public class WhileStatement extends 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 @@ -58,6 +60,8 @@ public class WhileStatement extends Statement { /** * get the modified variables. + * + * @param list the list where we will put variables */ public void getModifiedVariable(final List list) { condition.getModifiedVariable(list); @@ -68,6 +72,8 @@ public class WhileStatement extends Statement { /** * Get the variables used. + * + * @param list the list where we will put variables */ public void getUsedVariable(final List list) { condition.getUsedVariable(list); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/declarations/VariableUsage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/declarations/VariableUsage.java index 4a5eaf1..7d9b936 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/declarations/VariableUsage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/declarations/VariableUsage.java @@ -5,13 +5,13 @@ package net.sourceforge.phpdt.internal.compiler.ast.declarations; * 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. @@ -24,7 +24,7 @@ public class VariableUsage { } public String toString() { - return name + " " + startOffset; + return name + ' ' + startOffset; } /** diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java index 07c6773..301d62c 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java @@ -209,14 +209,14 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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; } @@ -312,9 +312,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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. */ @@ -953,7 +952,7 @@ Token token; 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: @@ -1266,7 +1265,7 @@ final Expression expr,expr2; ; } variableDeclaration = VariableDeclaratorNoSuffix(); - outlineInfo.addVariable("$"+variableDeclaration.name()); + outlineInfo.addVariable('$'+variableDeclaration.name()); if (token != null) { variableDeclaration.setReference(true); } @@ -1889,7 +1888,7 @@ final Expression expr,expr2; 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; @@ -5109,7 +5108,7 @@ Token token; } try { statement = Statement(); - pos = rparenToken.sourceEnd+1; + pos = statement.sourceEnd+1; } catch (ParseException e) { if (errorMessage != null) {if (true) throw e;} errorMessage = "statement expected"; @@ -5122,7 +5121,7 @@ Token token; variable, statement, foreachToken.sourceStart, - statement.sourceEnd);} + pos);} throw new Error("Missing return statement in function"); } diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index f2cd08d..9d2846a 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -232,14 +232,14 @@ public final class PHPParser extends PHPParserSuperclass { 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; } @@ -335,9 +335,8 @@ public final class PHPParser extends PHPParserSuperclass { 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. */ @@ -1125,7 +1124,7 @@ Variable Var() : | token = { - outlineInfo.addVariable("$" + token.image); + outlineInfo.addVariable('$' + token.image); return new Variable(token.image,token.sourceStart,token.sourceEnd); } } @@ -1333,7 +1332,7 @@ VariableDeclaration FormalParameter() : { [token = ] variableDeclaration = VariableDeclaratorNoSuffix() { - outlineInfo.addVariable("$"+variableDeclaration.name()); + outlineInfo.addVariable('$'+variableDeclaration.name()); if (token != null) { variableDeclaration.setReference(true); } @@ -1643,7 +1642,7 @@ Expression MultiplicativeExpression() : 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; @@ -3238,7 +3237,7 @@ ForeachStatement ForeachStatement() : } try { statement = Statement() - {pos = rparenToken.sourceEnd+1;} + {pos = statement.sourceEnd+1;} } catch (ParseException e) { if (errorMessage != null) throw e; errorMessage = "statement expected"; @@ -3247,11 +3246,12 @@ ForeachStatement ForeachStatement() : errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } - {return new ForeachStatement(expression, + { + return new ForeachStatement(expression, variable, statement, foreachToken.sourceStart, - statement.sourceEnd);} + pos);} } diff --git a/net.sourceforge.phpeclipse/src/test/PHPParserTokenManager.java b/net.sourceforge.phpeclipse/src/test/PHPParserTokenManager.java index bbdad0b..9a4efb3 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParserTokenManager.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParserTokenManager.java @@ -1,5 +1,22 @@ /* 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 { -- 1.7.1