* A Method declaration.
* @author Matthieu Casanova
*/
-public class MethodDeclaration extends Statement implements OutlineableWithChildren {
+public final class MethodDeclaration extends Statement implements OutlineableWithChildren {
/** The name of the method. */
- public String name;
- public ArrayList arguments;
+ public final String name;
+ private final ArrayList arguments;
public Statement[] statements;
- public int bodyStart;
- public int bodyEnd = -1;
+ private final int bodyStart;
+ private int bodyEnd = -1;
/** Tell if the method is a class constructor. */
public boolean isConstructor;
/** The parent object. */
private Object parent;
/** The outlineable children (those will be in the node array too. */
- private ArrayList children = new ArrayList();
+ private final ArrayList children = new ArrayList();
/** Tell if the method returns a reference. */
- public boolean reference;
+ private final boolean reference;
- private Position position;
+ private final Position position;
public MethodDeclaration(final Object parent,
final String name,
return buff.toString();
}
- public String toStringHeader() {
+ private String toStringHeader() {
return "function " + toString();
}
* @param tab the number of tabs
* @return the String containing the statements
*/
- public String toStringStatements(final int tab) {
+ private String toStringStatements(final int tab) {
final StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
if (arguments != null) {
for (int i = 0; i < arguments.size(); i++) {
- VariableDeclaration o = (VariableDeclaration) arguments.get(i);
+ final VariableDeclaration o = (VariableDeclaration) arguments.get(i);
buff.append(o.toStringExpression());
if (i != (arguments.size() - 1)) {
buff.append(", "); //$NON-NLS-1$
}
/** no outside variables. */
- public void getOutsideVariable(final List list) {
- }
+ public void getOutsideVariable(final List list) {}
- public void getModifiedVariable(final List list) {
- }
+ public void getModifiedVariable(final List list) {}
- public void getUsedVariable(final List list) {
- }
+ public void getUsedVariable(final List list) {}
/**
* Get global variables (not parameters).
*/
- public void getGlobalVariable(final List list) {
+ private void getGlobalVariable(final List list) {
if (statements != null) {
for (int i = 0; i < statements.length; i++) {
statements[i].getOutsideVariable(list);
private void getParameters(final List list) {
if (arguments != null) {
for (int i = 0; i < arguments.size(); i++) {
- VariableDeclaration variable = (VariableDeclaration) arguments.get(i);
+ final VariableDeclaration variable = (VariableDeclaration) arguments.get(i);
list.add(new VariableUsage(variable.name(), variable.sourceStart));
}
}
}
}
- private boolean isVariableDeclaredBefore(final List list, final VariableUsage var) {
+ private static boolean isVariableDeclaredBefore(final List list, final VariableUsage var) {
final String name = var.getName();
final int pos = var.getStartOffset();
for (int i = 0; i < list.size(); i++) {
getGlobalVariable(globalsVars);
final List modifiedVars = new ArrayList();
getAssignedVariableInCode(modifiedVars);
- final List parameters = new ArrayList();
+ final List parameters = new ArrayList(arguments.size());
getParameters(parameters);
final List declaredVars = new ArrayList(globalsVars.size() + modifiedVars.size());
* @param vars the used variable list
* @param parameters the declared variable list
*/
- private void findUnusedParameters(final List vars, final List parameters) {
+ private static void findUnusedParameters(final List vars, final List parameters) {
for (int i = 0; i < parameters.size(); i++) {
- final VariableUsage param = ((VariableUsage) parameters.get(i));
+ final VariableUsage param = (VariableUsage) parameters.get(i);
if (!isVariableInList(param.getName(), vars)) {
try {
PHPParserSuperclass.setMarker(
}
}
- private boolean isVariableInList(final String name, final List list) {
+ private static boolean isVariableInList(final String name, final List list) {
for (int i = 0; i < list.size(); i++) {
if (((VariableUsage) list.get(i)).getName().equals(name)) {
return true;
* @param usedVars the used variable list
* @param declaredVars the declared variable list
*/
- private void findUnknownUsedVars(final List usedVars, final List declaredVars) {
+ private static void findUnknownUsedVars(final List usedVars, final List declaredVars) {
for (int i = 0; i < usedVars.size(); i++) {
final VariableUsage variableUsage = (VariableUsage) usedVars.get(i);
- if (variableUsage.getName().equals("this")) continue; // this is a special variable
+ if ("this".equals(variableUsage.getName())) continue; // this is a special variable
if (!isVariableDeclaredBefore(declaredVars, variableUsage)) {
try {
PHPParserSuperclass.setMarker(