From: kpouer Date: Thu, 30 Oct 2003 16:17:04 +0000 (+0000) Subject: the unknown variables should be reported only once X-Git-Url: http://secure.phpeclipse.com the unknown variables should be reported only once --- 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 6be74d7..f1220ab 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,22 +1,22 @@ package net.sourceforge.phpdt.internal.compiler.ast; -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 test.PHPParserSuperclass; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + /** * A Method declaration. + * * @author Matthieu Casanova */ public final class MethodDeclaration extends Statement implements OutlineableWithChildren { @@ -62,6 +62,7 @@ public final class MethodDeclaration extends Statement implements OutlineableWit /** * Return method into String, with a number of tabs + * * @param tab the number of tabs * @return the String containing the method */ @@ -78,6 +79,7 @@ public final class MethodDeclaration extends Statement implements OutlineableWit /** * Return the statements of the method into Strings + * * @param tab the number of tabs * @return the String containing the statements */ @@ -97,6 +99,7 @@ public final class MethodDeclaration extends Statement implements OutlineableWit /** * Get the image of a class. + * * @return the image that represents a php class */ public ImageDescriptor getImage() { @@ -132,7 +135,7 @@ public final class MethodDeclaration extends Statement implements OutlineableWit if (arguments != null) { for (int i = 0; i < arguments.size(); i++) { - final 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$ @@ -151,11 +154,25 @@ public final class MethodDeclaration extends Statement implements OutlineableWit return children; } - /** no outside variables. */ + /** + * 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) {} + /** + * This method will analyze the code. + * + * @param list the list where we will put variables + */ public void getUsedVariable(final List list) {} /** @@ -212,7 +229,9 @@ public final class MethodDeclaration extends Statement implements OutlineableWit return false; } - /** This method will analyze the code. */ + /** + * This method will analyze the code. + */ public void analyzeCode() { if (statements != null) { for (int i = 0; i < statements.length; i++) { @@ -246,7 +265,8 @@ public final class MethodDeclaration extends Statement implements OutlineableWit /** * This method will add a warning on all unused parameters. - * @param vars the used variable list + * + * @param vars the used variable list * @param parameters the declared variable list */ private static void findUnusedParameters(final List vars, final List parameters) { @@ -267,6 +287,13 @@ public final class MethodDeclaration extends Statement implements OutlineableWit } } + /** + * Tell if the list of VariableUsage contains a variable named by the name given. + * + * @param name the variable name + * @param list the list of VariableUsage + * @return true if the variable is in the list false otherwise + */ 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)) { @@ -278,14 +305,17 @@ public final class MethodDeclaration extends Statement implements OutlineableWit /** * This method will add a warning on all used variables in a method that aren't declared before. - * @param usedVars the used variable list + * + * @param usedVars the used variable list * @param declaredVars the declared variable list */ private static void findUnknownUsedVars(final List usedVars, final List declaredVars) { + final HashSet list = new HashSet(usedVars.size()); for (int i = 0; i < usedVars.size(); i++) { final VariableUsage variableUsage = (VariableUsage) usedVars.get(i); if ("this".equals(variableUsage.getName())) continue; // this is a special variable - if (!isVariableDeclaredBefore(declaredVars, variableUsage)) { + if (!list.contains(variableUsage.getName()) && !isVariableDeclaredBefore(declaredVars, variableUsage)) { + list.add(variableUsage.getName()); try { PHPParserSuperclass.setMarker( "warning, usage of a variable that seems to be unassigned yet : " + variableUsage.getName(),