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 {
/**
* Return method into String, with a number of tabs
+ *
* @param tab the number of tabs
* @return the String containing the method
*/
/**
* Return the statements of the method into Strings
+ *
* @param tab the number of tabs
* @return the String containing the statements
*/
/**
* Get the image of a class.
+ *
* @return the image that represents a php class
*/
public ImageDescriptor getImage() {
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$
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) {}
/**
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++) {
/**
* 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) {
}
}
+ /**
+ * 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)) {
/**
* 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(),