X-Git-Url: http://git.phpeclipse.com 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 6934c07..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 @@ -1,18 +1,17 @@ package net.sourceforge.phpdt.internal.compiler.ast; -import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; -import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import java.util.ArrayList; +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.compiler.parser.OutlineableWithChildren; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpeclipse.PHPeclipsePlugin; + +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Position; -import org.eclipse.core.runtime.CoreException; - -import java.util.Hashtable; -import java.util.Enumeration; -import java.util.ArrayList; -import java.util.List; import test.PHPParserSuperclass; @@ -20,32 +19,32 @@ 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 Hashtable 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, - final Hashtable arguments, + final ArrayList arguments, final boolean reference, final int sourceStart, final int sourceEnd, @@ -73,7 +72,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild return buff.toString(); } - public String toStringHeader() { + private String toStringHeader() { return "function " + toString(); } @@ -82,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,15 +131,12 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild buff.append(name).append("(");//$NON-NLS-1$ if (arguments != null) { - final Enumeration values = arguments.elements(); - int i = 0; - while (values.hasMoreElements()) { - final VariableDeclaration o = (VariableDeclaration) values.nextElement(); + for (int i = 0; i < arguments.size(); i++) { + final VariableDeclaration o = (VariableDeclaration) arguments.get(i); buff.append(o.toStringExpression()); if (i != (arguments.size() - 1)) { buff.append(", "); //$NON-NLS-1$ } - i++; } } buff.append(")"); //$NON-NLS-1$ @@ -156,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); @@ -178,9 +171,8 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild private void getParameters(final List list) { if (arguments != null) { - final Enumeration vars = arguments.elements(); - while (vars.hasMoreElements()) { - final VariableDeclaration variable = (VariableDeclaration) vars.nextElement(); + for (int i = 0; i < arguments.size(); i++) { + final VariableDeclaration variable = (VariableDeclaration) arguments.get(i); list.add(new VariableUsage(variable.name(), variable.sourceStart)); } } @@ -208,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++) { @@ -233,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()); @@ -257,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( @@ -275,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; @@ -289,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(