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 424ca3b..b61470f 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 @@ -155,11 +155,24 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild return children; } + /** no outside variables. */ + public List getOutsideVariable() { + return new ArrayList(1); + } + + public List getModifiedVariable() { + return new ArrayList(1); + } + + public List getUsedVariable() { + return new ArrayList(1); + } + /** - * Get global variables (not parameters) + * Get global variables (not parameters). * @return the variables from outside */ - public List getOutsideVariable() { + public List getGlobalVariable() { final ArrayList list = new ArrayList(); if (statements != null) { @@ -172,9 +185,10 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild private List getParameters(final List list) { if (arguments != null) { - final Enumeration vars = arguments.keys(); + final Enumeration vars = arguments.elements(); while (vars.hasMoreElements()) { - list.add(new VariableUsage((String) vars.nextElement(), sourceStart)); + final VariableDeclaration variable = (VariableDeclaration) vars.nextElement(); + list.add(new VariableUsage(variable.name(), variable.sourceStart)); } } return list; @@ -184,7 +198,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild * get the modified variables. * @return the variables from we change value */ - public List getModifiedVariable() { + private List getAssignedVariableInCode() { final ArrayList list = new ArrayList(); if (statements != null) { for (int i = 0; i < statements.length; i++) { @@ -198,7 +212,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild * Get the variables used. * @return the variables used */ - public List getUsedVariable() { + private List getUsedVariableInCode() { final ArrayList list = new ArrayList(); if (statements != null) { for (int i = 0; i < statements.length; i++) { @@ -208,11 +222,11 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild return list; } - private boolean isVariableDeclaredBefore(List list, VariableUsage var) { + private 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++) { - VariableUsage variableUsage = (VariableUsage) list.get(i); + final VariableUsage variableUsage = (VariableUsage) list.get(i); if (variableUsage.getName().equals(name) && variableUsage.getStartOffset() < pos) { return true; } @@ -220,22 +234,17 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild return false; } - private void dumpList(List list, String name) { - StringBuffer buff = new StringBuffer(name).append("\n"); - for (int i = 0; i < list.size(); i++) { - buff.append(list.get(i).toString()).append("\n"); - } - if (PHPeclipsePlugin.DEBUG) { - PHPeclipsePlugin.log(1, buff.toString()); + /** This method will analyze the code. */ + public void analyzeCode() { + if (statements != null) { + for (int i = 0; i < statements.length; i++) { + statements[i].analyzeCode(); + + } } - } - /** - * This method will analyze the code. - */ - public void analyzeCode() { - final List globalsVars = getOutsideVariable(); - final List modifiedVars = getModifiedVariable(); + final List globalsVars = getGlobalVariable(); + final List modifiedVars = getAssignedVariableInCode(); final List parameters = getParameters(new ArrayList()); final List declaredVars = new ArrayList(globalsVars.size() + modifiedVars.size()); @@ -243,14 +252,10 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild declaredVars.addAll(modifiedVars); declaredVars.addAll(parameters); - final List usedVars = getUsedVariable(); + final List usedVars = getUsedVariableInCode(); final List readOrWriteVars = new ArrayList(modifiedVars.size()+usedVars.size()); readOrWriteVars.addAll(modifiedVars); readOrWriteVars.addAll(usedVars); -/* dumpList(globalsVars, "outside"); - dumpList(modifiedVars, "modified"); - dumpList(usedVars, "used"); */ - //look for used variables that were not declared before findUnusedParameters(readOrWriteVars,parameters); @@ -264,7 +269,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild */ private void findUnusedParameters(final List vars, final List parameters) { for (int i = 0; i < parameters.size(); i++) { - VariableUsage param = ((VariableUsage)parameters.get(i)); + final VariableUsage param = ((VariableUsage)parameters.get(i)); if (!isVariableInList(param.getName(),vars)) { try { PHPParserSuperclass.setMarker("warning, the parameter "+param.getName() +" seems to be never used in your method", @@ -295,7 +300,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild */ private void findUnknownUsedVars(final List usedVars, final List declaredVars) { for (int i = 0; i < usedVars.size(); i++) { - VariableUsage variableUsage = (VariableUsage) usedVars.get(i); + final VariableUsage variableUsage = (VariableUsage) usedVars.get(i); if (variableUsage.getName().equals("this")) continue; // this is a special variable if (!isVariableDeclaredBefore(declaredVars, variableUsage)) { try {