package test; /** * A Variable usage. It could be a first use, an in code use of an already declared var. * In fact I'm not sure for the moment I will keep this * @author Matthieu Casanova */ public class PHPVar { /** The name of the variable. It couldn't be changed. */ private final String name; /** The value. It could change. */ private String value; /** * Tell if the variable is a reference or not (given in function by &$varname, * or comming from a 'global' keyword. */ private boolean reference; /** * Does the variable have a value or not. * If we don't know if it was initialized it should be set on true. * (when we have a global keyword for example) */ private boolean initialized; /** This variable indicate if it is used or not in the code. */ private boolean used; /** * We initialize the name and the value of the variable. * @param name the name of the variable * @param value the value of the variable */ public PHPVar(String name, String value) { this.name = name; this.value = value; initialized = value != null; } /** * We initialize the name of the variable. The value will be null * @param name the name of the variable */ public PHPVar(String name) { this.name = name; } /** * Initialize the variable name and set the initialization status. * @param name the name of the variable * @param initialized the initialization status (it should be true or it's unuseful) */ public PHPVar(String name, boolean initialized) { this(name); this.initialized = initialized; } /** * Give a reference to the variable. * @param reference a reference */ public void setReference(boolean reference) { this.reference = reference; if (reference) {// a reference variable status is unknown so is initialized for me //example : global initialized = true; } } /** * Tell if the variable is reference. * @return a boolean */ public boolean isReference() { return reference; } public void setUsed(boolean used) { this.used = used; } public void setInitialized(boolean initialized) { this.initialized = initialized; } /** * Get the name of the variable. * @return a string containing the name of the variable */ public String getName() { return name; } /** * Tell if the variable was used. * @return a boolean telling if the variable is used */ public boolean isUsed() { return used; } /** * Return a human readable variable (: * @return a string representation of the object. */ public String toString() { if (value == null) { if (reference) { return "&$" + name; } return "$" + name; } if (reference) { return "&$" + name + "=" + value; } return "$" + name + "=" + value; } }