package net.sourceforge.phpeclipse;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;

import net.sourceforge.phpdt.internal.core.BatchOperation;
import net.sourceforge.phpeclipse.resourcesview.PHPFile;
import net.sourceforge.phpeclipse.resourcesview.PHPProject;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;

public class PHPCore {

  public static HashSet OptionNames = new HashSet(20);
  /**
   * The plug-in identifier of the Java core support
   * (value <code>"org.phpeclipse.phpdt.core"</code>).
   */
  public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.core"; //$NON-NLS-1$

  /**
     * Possible  configurable option ID.
     * @see #getDefaultOptions
     * @since 2.0
     */
  public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$

  /**
     * Possible  configurable option ID.
     * @see #getDefaultOptions
     * @since 2.0
     */
  public static final String FORMATTER_NEWLINE_OPENING_BRACE = PLUGIN_ID + ".formatter.newline.openingBrace"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_NEWLINE_CONTROL = PLUGIN_ID + ".formatter.newline.controlStatement"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_NEWLINE_ELSE_IF = PLUGIN_ID + ".formatter.newline.elseIf"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_NEWLINE_EMPTY_BLOCK = PLUGIN_ID + ".formatter.newline.emptyBlock"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_CLEAR_BLANK_LINES = PLUGIN_ID + ".formatter.newline.clearAll"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_LINE_SPLIT = PLUGIN_ID + ".formatter.lineSplit"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_COMPACT_ASSIGNMENT = PLUGIN_ID + ".formatter.style.assignment"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_TAB_CHAR = PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$
  /**
   * Possible  configurable option ID.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String FORMATTER_TAB_SIZE = PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String INSERT = "insert"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$

  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String PRESERVE_ONE = "preserve one"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String CLEAR_ALL = "clear all"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String NORMAL = "normal"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String COMPACT = "compact"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String TAB = "tab"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String SPACE = "space"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String ENABLED = "enabled"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.0
   */
  public static final String DISABLED = "disabled"; //$NON-NLS-1$
  /**
   * Possible  configurable option value.
   * @see #getDefaultOptions
   * @since 2.1
   */
  public static final String CLEAN = "clean"; //$NON-NLS-1$

  /**
   * Returns a table of all known configurable options with their default values.
   * These options allow to configure the behaviour of the underlying components.
   * The client may safely use the result as a template that they can modify and
   * then pass to <code>setOptions</code>.
   * 
   * Helper constants have been defined on JavaCore for each of the option ID and 
   * their possible constant values.
   * 
   * Note: more options might be added in further releases.
   * <pre>
   * RECOGNIZED OPTIONS:
   * COMPILER / Generating Local Variable Debug Attribute
   *    When generated, this attribute will enable local variable names 
   *    to be displayed in debugger, only in place where variables are 
   *    definitely assigned (.class file is then bigger)
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.localVariable"
   *     - possible values:   { "generate", "do not generate" }
   *     - default:           "generate"
   *
   * COMPILER / Generating Line Number Debug Attribute 
   *    When generated, this attribute will enable source code highlighting in debugger 
   *    (.class file is then bigger).
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.lineNumber"
   *     - possible values:   { "generate", "do not generate" }
   *     - default:           "generate"
   *    
   * COMPILER / Generating Source Debug Attribute 
   *    When generated, this attribute will enable the debugger to present the 
   *    corresponding source code.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.sourceFile"
   *     - possible values:   { "generate", "do not generate" }
   *     - default:           "generate"
   *    
   * COMPILER / Preserving Unused Local Variables
   *    Unless requested to preserve unused local variables (i.e. never read), the 
   *    compiler will optimize them out, potentially altering debugging
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.unusedLocal"
   *     - possible values:   { "preserve", "optimize out" }
   *     - default:           "preserve"
   * 
   * COMPILER / Defining Target Java Platform
   *    For binary compatibility reason, .class files can be tagged to with certain VM versions and later.
   *    Note that "1.4" target require to toggle compliance mode to "1.4" too.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.targetPlatform"
   *     - possible values:   { "1.1", "1.2", "1.3", "1.4" }
   *     - default:           "1.1"
   *
   * COMPILER / Reporting Unreachable Code
   *    Unreachable code can optionally be reported as an error, warning or simply 
   *    ignored. The bytecode generation will always optimized it out.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unreachableCode"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "error"
   *
   * COMPILER / Reporting Invalid Import
   *    An import statement that cannot be resolved might optionally be reported 
   *    as an error, as a warning or ignored.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.invalidImport"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "error"
   *
   * COMPILER / Reporting Attempt to Override Package-Default Method
   *    A package default method is not visible in a different package, and thus 
   *    cannot be overridden. When enabling this option, the compiler will signal 
   *    such scenarii either as an error or a warning.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.overridingPackageDefaultMethod"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   *
   * COMPILER / Reporting Method With Constructor Name
   *    Naming a method with a constructor name is generally considered poor 
   *    style programming. When enabling this option, the compiler will signal such 
   *    scenarii either as an error or a warning.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.methodWithConstructorName"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   *
   * COMPILER / Reporting Deprecation
   *    When enabled, the compiler will signal use of deprecated API either as an 
   *    error or a warning.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecation"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   *
   * COMPILER / Reporting Deprecation Inside Deprecated Code
   *    When enabled, the compiler will signal use of deprecated API inside deprecated code.
   *    The severity of the problem is controlled with option "org.phpeclipse.phpdt.core.compiler.problem.deprecation".
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecationInDeprecatedCode"
   *     - possible values:   { "enabled", "disabled" }
   *     - default:           "disabled"
   *
   * COMPILER / Reporting Hidden Catch Block
   *    Locally to a try statement, some catch blocks may hide others , e.g.
   *      try {  throw new java.io.CharConversionException();
   *      } catch (java.io.CharConversionException e) {
   *      } catch (java.io.IOException e) {}. 
   *    When enabling this option, the compiler will issue an error or a warning for hidden 
   *    catch blocks corresponding to checked exceptions
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.hiddenCatchBlock"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   *
   * COMPILER / Reporting Unused Local
   *    When enabled, the compiler will issue an error or a warning for unused local 
   *    variables (i.e. variables never read from)
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedLocal"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "ignore"
   *
   * COMPILER / Reporting Unused Parameter
   *    When enabled, the compiler will issue an error or a warning for unused method 
   *    parameters (i.e. parameters never read from)
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedParameter"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "ignore"
   *
   * COMPILER / Reporting Unused Import
   *    When enabled, the compiler will issue an error or a warning for unused import 
   *    reference 
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedImport"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   *
   * COMPILER / Reporting Synthetic Access Emulation
   *    When enabled, the compiler will issue an error or a warning whenever it emulates 
   *    access to a non-accessible member of an enclosing type. Such access can have
   *    performance implications.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.syntheticAccessEmulation"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "ignore"
   *
   * COMPILER / Reporting Non-Externalized String Literal
   *    When enabled, the compiler will issue an error or a warning for non externalized 
   *    String literal (i.e. non tagged with //$NON-NLS-<n>$). 
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.nonExternalizedStringLiteral"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "ignore"
   * 
   * COMPILER / Reporting Usage of 'assert' Identifier
   *    When enabled, the compiler will issue an error or a warning whenever 'assert' is 
   *    used as an identifier (reserved keyword in 1.4)
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.assertIdentifier"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "ignore"
   * 
   * COMPILER / Reporting Usage of expression receiver on static invocation/field access
   *    When enabled, the compiler will issue an error or a warning whenever a static field
   *    or method is accessed with an expression receiver.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.staticAccessReceiver"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   * 
   * COMPILER / Reporting Assignment with no effect
   *    When enabled, the compiler will issue an error or a warning whenever an assignment
   *    has no effect (e.g 'x = x').
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.noEffectAssignment"
   *     - possible values:   { "error", "warning", "ignore" }
   *     - default:           "warning"
   * 
   * COMPILER / Setting Source Compatibility Mode
   *    Specify whether source is 1.3 or 1.4 compatible. From 1.4 on, 'assert' is a keyword
   *    reserved for assertion support. Also note, than when toggling to 1.4 mode, the target VM
   *   level should be set to "1.4" and the compliance mode should be "1.4".
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.source"
   *     - possible values:   { "1.3", "1.4" }
   *     - default:           "1.3"
   * 
   * COMPILER / Setting Compliance Level
   *    Select the compliance level for the compiler. In "1.3" mode, source and target settings
   *    should not go beyond "1.3" level.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.compliance"
   *     - possible values:   { "1.3", "1.4" }
   *     - default:           "1.3"
   * 
   * COMPILER / Maximum number of problems reported per compilation unit
   *    Specify the maximum number of problems reported on each compilation unit.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.maxProblemPerUnit"
   *     - possible values:	"<n>" where <n> is zero or a positive integer (if zero then all problems are reported).
   *     - default:           "100"
   * 
   * COMPILER / Define the Automatic Task Tags
   *    When the tag is non empty, the compiler will issue a task marker whenever it encounters
   *    one of the corresponding tag inside any comment in Java source code.
   *    Generated task messages will include the tag, and range until the next line separator or comment ending, and will be trimmed.
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskTags"
   *     - possible values:   { "<tag>[,<tag>]*" } where <tag> is a String without any wild-card 
   *     - default:           ""
   * 
   * COMPILER / Define the Automatic Task Priorities
   *    In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low)
   *    of the task markers issued by the compiler.
   *    If the default is specified, the priority of each task marker is "NORMAL".
   *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskPriorities"
   *     - possible values:   { "<priority>[,<priority>]*" } where <priority> is one of "HIGH", "NORMAL" or "LOW"
   *     - default:           ""
   * 
   * BUILDER / Specifying Filters for Resource Copying Control
   *    Allow to specify some filters to control the resource copy process.
   *     - option id:         "org.phpeclipse.phpdt.core.builder.resourceCopyExclusionFilter"
   *     - possible values:   { "<name>[,<name>]* } where <name> is a file name pattern (* and ? wild-cards allowed)
   *       or the name of a folder which ends with '/'
   *     - default:           ""
   * 
   * BUILDER / Abort if Invalid Classpath
   *    Allow to toggle the builder to abort if the classpath is invalid
   *     - option id:         "org.phpeclipse.phpdt.core.builder.invalidClasspath"
   *     - possible values:   { "abort", "ignore" }
   *     - default:           "ignore"
   * 
   * BUILDER / Cleaning Output Folder(s)
   *    Indicate whether the JavaBuilder is allowed to clean the output folders
   *    when performing full build operations.
   *     - option id:         "org.phpeclipse.phpdt.core.builder.cleanOutputFolder"
   *     - possible values:   { "clean", "ignore" }
   *     - default:           "clean"
   * 
   * JAVACORE / Computing Project Build Order
   *    Indicate whether JavaCore should enforce the project build order to be based on
   *    the classpath prerequisite chain. When requesting to compute, this takes over
   *    the platform default order (based on project references).
   *     - option id:         "org.phpeclipse.phpdt.core.computeJavaBuildOrder"
   *     - possible values:   { "compute", "ignore" }
   *     - default:           "ignore"	 
   * 
   * JAVACORE / Specify Default Source Encoding Format
   *    Get the encoding format for compiled sources. This setting is read-only, it is equivalent
   *    to 'ResourcesPlugin.getEncoding()'.
   *     - option id:         "org.phpeclipse.phpdt.core.encoding"
   *     - possible values:   { any of the supported encoding name}.
   *     - default:           <platform default>
   * 
   * JAVACORE / Reporting Incomplete Classpath
   *    An entry on the classpath doesn't exist or is not visible (e.g. a referenced project is closed).
   *     - option id:         "org.phpeclipse.phpdt.core.incompleteClasspath"
   *     - possible values:   { "error", "warning"}
   *     - default:           "error"
   * 
   * JAVACORE / Reporting Classpath Cycle
   *    A project is involved in a cycle.
   *     - option id:         "org.phpeclipse.phpdt.core.circularClasspath"
   *     - possible values:   { "error", "warning" }
   *     - default:           "error"
   * 
   *	FORMATTER / Inserting New Line Before Opening Brace
   *    When Insert, a new line is inserted before an opening brace, otherwise nothing
   *    is inserted
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.openingBrace"
   *     - possible values:   { "insert", "do not insert" }
   *     - default:           "do not insert"
   * 
   *	FORMATTER / Inserting New Line Inside Control Statement
   *    When Insert, a new line is inserted between } and following else, catch, finally
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.controlStatement"
   *     - possible values:   { "insert", "do not insert" }
   *     - default:           "do not insert"
   * 
   *	FORMATTER / Clearing Blank Lines
   *    When Clear all, all blank lines are removed. When Preserve one, only one is kept
   *    and all others removed.
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.clearAll"
   *     - possible values:   { "clear all", "preserve one" }
   *     - default:           "preserve one"
   * 
   *	FORMATTER / Inserting New Line Between Else/If 
   *    When Insert, a blank line is inserted between an else and an if when they are 
   *    contiguous. When choosing to not insert, else-if will be kept on the same
   *    line when possible.
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.elseIf"
   *     - possible values:   { "insert", "do not insert" }
   *     - default:           "do not insert"
   * 
   *	FORMATTER / Inserting New Line In Empty Block
   *    When insert, a line break is inserted between contiguous { and }, if } is not followed
   *    by a keyword.
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.emptyBlock"
   *     - possible values:   { "insert", "do not insert" }
   *     - default:           "insert"
   * 
   *	FORMATTER / Splitting Lines Exceeding Length
   *    Enable splitting of long lines (exceeding the configurable length). Length of 0 will
   *    disable line splitting
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.lineSplit"
   *     - possible values:	"<n>", where n is zero or a positive integer
   *     - default:           "80"
   * 
   *	FORMATTER / Compacting Assignment
   *    Assignments can be formatted asymmetrically, e.g. 'int x= 2;', when Normal, a space
   *    is inserted before the assignment operator
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.style.assignment"
   *     - possible values:   { "compact", "normal" }
   *     - default:           "normal"
   * 
   *	FORMATTER / Defining Indentation Character
   *    Either choose to indent with tab characters or spaces
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.char"
   *     - possible values:   { "tab", "space" }
   *     - default:           "tab"
   * 
   *	FORMATTER / Defining Space Indentation Length
   *    When using spaces, set the amount of space characters to use for each 
   *    indentation mark.
   *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.size"
   *     - possible values:	"<n>", where n is a positive integer
   *     - default:           "4"
   * 
   *	CODEASSIST / Activate Visibility Sensitive Completion
   *    When active, completion doesn't show that you can not see
   *    (e.g. you can not see private methods of a super class).
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.visibilityCheck"
   *     - possible values:   { "enabled", "disabled" }
   *     - default:           "disabled"
   * 
   *	CODEASSIST / Automatic Qualification of Implicit Members
   *    When active, completion automatically qualifies completion on implicit
   *    field references and message expressions.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.forceImplicitQualification"
   *     - possible values:   { "enabled", "disabled" }
   *     - default:           "disabled"
   * 
   *  CODEASSIST / Define the Prefixes for Field Name
   *    When the prefixes is non empty, completion for field name will begin with
   *    one of the proposed prefixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldPrefixes"
   *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Prefixes for Static Field Name
   *    When the prefixes is non empty, completion for static field name will begin with
   *    one of the proposed prefixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldPrefixes"
   *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Prefixes for Local Variable Name
   *    When the prefixes is non empty, completion for local variable name will begin with
   *    one of the proposed prefixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localPrefixes"
   *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Prefixes for Argument Name
   *    When the prefixes is non empty, completion for argument name will begin with
   *    one of the proposed prefixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentPrefixes"
   *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Suffixes for Field Name
   *    When the suffixes is non empty, completion for field name will end with
   *    one of the proposed suffixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldSuffixes"
   *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Suffixes for Static Field Name
   *    When the suffixes is non empty, completion for static field name will end with
   *    one of the proposed suffixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldSuffixes"
   *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Suffixes for Local Variable Name
   *    When the suffixes is non empty, completion for local variable name will end with
   *    one of the proposed suffixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localSuffixes"
   *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
   *     - default:           ""
   * 
   *  CODEASSIST / Define the Suffixes for Argument Name
   *    When the suffixes is non empty, completion for argument name will end with
   *    one of the proposed suffixes.
   *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentSuffixes"
   *     - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String without any wild-card 
   *     - default:           ""
   * </pre>
   * 
   * @return a mutable table containing the default settings of all known options
   *   (key type: <code>String</code>; value type: <code>String</code>)
   * @see #setOptions
   */
  public static Hashtable getDefaultOptions() {

    Hashtable defaultOptions = new Hashtable(10);

    // see #initializeDefaultPluginPreferences() for changing default settings
    Preferences preferences = getPlugin().getPluginPreferences();
    HashSet optionNames = OptionNames;

    // get preferences set to their default
    String[] defaultPropertyNames = preferences.defaultPropertyNames();
    for (int i = 0; i < defaultPropertyNames.length; i++) {
      String propertyName = defaultPropertyNames[i];
      if (optionNames.contains(propertyName)) {
        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
      }
    }
    // get preferences not set to their default
    String[] propertyNames = preferences.propertyNames();
    for (int i = 0; i < propertyNames.length; i++) {
      String propertyName = propertyNames[i];
      if (optionNames.contains(propertyName)) {
        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
      }
    }
    // get encoding through resource plugin
    defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());

    return defaultOptions;
  }
  /**
   * Helper method for returning one option value only. Equivalent to <code>(String)JavaCore.getOptions().get(optionName)</code>
   * Note that it may answer <code>null</code> if this option does not exist.
   * <p>
   * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
   * </p>
   * 
   * @param optionName the name of an option
   * @return the String value of a given option
   * @see JavaCore#getDefaultOptions
   * @since 2.0
   */
  public static String getOption(String optionName) {

    if (CORE_ENCODING.equals(optionName)) {
      return ResourcesPlugin.getEncoding();
    }
    if (OptionNames.contains(optionName)) {
      Preferences preferences = getPlugin().getPluginPreferences();
      return preferences.getString(optionName).trim();
    }
    return null;
  }

  /**
   * Returns the table of the current options. Initially, all options have their default values,
   * and this method returns a table that includes all known options.
   * <p>
   * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
   * </p>
   * 
   * @return table of current settings of all options 
   *   (key type: <code>String</code>; value type: <code>String</code>)
   * @see JavaCore#getDefaultOptions
   */
  public static Hashtable getOptions() {

    Hashtable options = new Hashtable(10);

    // see #initializeDefaultPluginPreferences() for changing default settings
    Plugin plugin = getPlugin();
    if (plugin != null) {
      Preferences preferences = getPlugin().getPluginPreferences();
      HashSet optionNames = OptionNames;

      // get preferences set to their default
      String[] defaultPropertyNames = preferences.defaultPropertyNames();
      for (int i = 0; i < defaultPropertyNames.length; i++) {
        String propertyName = defaultPropertyNames[i];
        if (optionNames.contains(propertyName)) {
          options.put(propertyName, preferences.getDefaultString(propertyName));
        }
      }
      // get preferences not set to their default
      String[] propertyNames = preferences.propertyNames();
      for (int i = 0; i < propertyNames.length; i++) {
        String propertyName = propertyNames[i];
        if (optionNames.contains(propertyName)) {
          options.put(propertyName, preferences.getString(propertyName).trim());
        }
      }
      // get encoding through resource plugin
      options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
    }
    return options;
  }
  /**
   * Sets the current table of options. All and only the options explicitly included in the given table 
   * are remembered; all previous option settings are forgotten, including ones not explicitly
   * mentioned.
   * <p>
   * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
   * </p>
   * 
   * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
   *   or <code>null</code> to reset all options to their default values
   * @see JavaCore#getDefaultOptions
   */
  public static void setOptions(Hashtable newOptions) {

    // see #initializeDefaultPluginPreferences() for changing default settings
    Preferences preferences = getPlugin().getPluginPreferences();

    if (newOptions == null) {
      newOptions = getDefaultOptions();
    }
    Enumeration keys = newOptions.keys();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      if (!OptionNames.contains(key))
        continue; // unrecognized option
      if (key.equals(CORE_ENCODING))
        continue; // skipped, contributed by resource prefs
      String value = (String) newOptions.get(key);
      preferences.setValue(key, value);
    }

    // persist options
    getPlugin().savePluginPreferences();
  }
  public static IProject[] getPHPProjects() {
    List phpProjectsList = new ArrayList();
    IProject[] workspaceProjects = PHPeclipsePlugin.getWorkspace().getRoot().getProjects();

    for (int i = 0; i < workspaceProjects.length; i++) {
      IProject iProject = workspaceProjects[i];
      if (isPHPProject(iProject))
        phpProjectsList.add(iProject);
    }

    IProject[] phpProjects = new IProject[phpProjectsList.size()];
    return (IProject[]) phpProjectsList.toArray(phpProjects);
  }

  public static PHPProject getPHPProject(String name) {
    IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
    if (isPHPProject(aProject)) {
      PHPProject thePHPProject = new PHPProject();
      thePHPProject.setProject(aProject);
      return thePHPProject;
    }
    return null;
  }

  public static boolean isPHPProject(IProject aProject) {
    try {
      return aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
    } catch (CoreException e) {
    }

    return false;
  }

  public static PHPFile create(IFile aFile) {
    if (PHPFile.EXTENSION.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);
    if (PHPFile.EXTENSION1.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);
    if (PHPFile.EXTENSION2.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);
    if (PHPFile.EXTENSION3.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);
    if (PHPFile.EXTENSION4.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);
    if (PHPFile.EXTENSION5.equalsIgnoreCase(aFile.getFileExtension()))
      return new PHPFile(aFile);

    return null;
  }

  public static PHPProject create(IProject aProject) {
    try {
      if (aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
        PHPProject project = new PHPProject();
        project.setProject(aProject);
        return project;
      }
    } catch (CoreException e) {
      System.err.println("Exception occurred in PHPCore#create(IProject): " + e.toString());
    }

    return null;
  }

  public static void addPHPNature(IProject project, IProgressMonitor monitor) throws CoreException {
    if (!project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
      IProjectDescription description = project.getDescription();
      String[] prevNatures = description.getNatureIds();
      String[] newNatures = new String[prevNatures.length + 1];
      System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
      newNatures[prevNatures.length] = PHPeclipsePlugin.PHP_NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, monitor);
    }
  }

  /**
   * Returns the single instance of the PHP core plug-in runtime class.
   * 
   * @return the single instance of the PHP core plug-in runtime class
   */
  public static Plugin getPlugin() {
    return PHPeclipsePlugin.getDefault();
  }

  /**
     * Initializes the default preferences settings for this plug-in.
     */
  protected static void initializeDefaultPluginPreferences() {

    Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
    HashSet optionNames = OptionNames;

    //    // Compiler settings
    //    preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
    //    optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
    //
    //    preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE); 
    //    optionNames.add(COMPILER_LINE_NUMBER_ATTR);
    //
    //    preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE); 
    //    optionNames.add(COMPILER_SOURCE_FILE_ATTR);
    //
    //    preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); 
    //    optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
    //
    //    preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1); 
    //    optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
    //
    //    preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); 
    //    optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
    //
    //    preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR); 
    //    optionNames.add(COMPILER_PB_INVALID_IMPORT);
    //
    //    preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING); 
    //    optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
    //
    //    preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING); 
    //    optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
    //
    //    preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
    //    optionNames.add(COMPILER_PB_DEPRECATION);
    //
    //    preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
    //    optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
    //
    //    preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING); 
    //    optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
    //
    //    preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE); 
    //    optionNames.add(COMPILER_PB_UNUSED_LOCAL);
    //
    //    preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE); 
    //    optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
    //
    //    preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING); 
    //    optionNames.add(COMPILER_PB_UNUSED_IMPORT);
    //
    //    preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE); 
    //    optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
    //
    //    preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE); 
    //    optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
    //
    //    preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE); 
    //    optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
    //
    //    preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING); 
    //    optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
    //
    //    preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING); 
    //    optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
    //
    //    preferences.setDefault(COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
    //    optionNames.add(COMPILER_TASK_TAGS);
    //
    //    preferences.setDefault(COMPILER_TASK_PRIORITIES, ""); //$NON-NLS-1$
    //    optionNames.add(COMPILER_TASK_PRIORITIES);
    //
    //    preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
    //    optionNames.add(COMPILER_SOURCE);
    //
    //    preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3); 
    //    optionNames.add(COMPILER_COMPLIANCE);
    //
    //    preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
    //    optionNames.add(COMPILER_PB_MAX_PER_UNIT);
    //		
    //    // Builder settings
    //    preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
    //    optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
    //
    //    preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
    //    optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
    //	
    //    preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
    //    optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
    //		
    //    preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
    //    optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
    //
    //    // JavaCore settings
    //    preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
    //    optionNames.add(CORE_JAVA_BUILD_ORDER);
    //	
    //    preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
    //    optionNames.add(CORE_CIRCULAR_CLASSPATH);
    //		
    //    preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
    //    optionNames.add(CORE_INCOMPLETE_CLASSPATH);

    // encoding setting comes from resource plug-in
    optionNames.add(CORE_ENCODING);

    // Formatter settings
    preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT);
    optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);

    preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
    optionNames.add(FORMATTER_NEWLINE_CONTROL);

    preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE);
    optionNames.add(FORMATTER_CLEAR_BLANK_LINES);

    preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
    optionNames.add(FORMATTER_NEWLINE_ELSE_IF);

    preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT);
    optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);

    preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
    optionNames.add(FORMATTER_LINE_SPLIT);

    preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL);
    optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);

    preferences.setDefault(FORMATTER_TAB_CHAR, TAB);
    optionNames.add(FORMATTER_TAB_CHAR);

    preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
    optionNames.add(FORMATTER_TAB_SIZE);

    // CodeAssist settings
    //    preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_VISIBILITY_CHECK);
    //
    //    preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
    //		
    //    preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_FIELD_PREFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_LOCAL_PREFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_FIELD_SUFFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
    //		
    //    preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
    //    optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);

  }
  /**
  	 * Runs the given action as an atomic Java model operation.
  	 * <p>
  	 * After running a method that modifies Java elements,
  	 * registered listeners receive after-the-fact notification of
  	 * what just transpired, in the form of a element changed event.
  	 * This method allows clients to call a number of
  	 * methods that modify java elements and only have element
  	 * changed event notifications reported at the end of the entire
  	 * batch.
  	 * </p>
  	 * <p>
  	 * If this method is called outside the dynamic scope of another such
  	 * call, this method runs the action and then reports a single
  	 * element changed event describing the net effect of all changes
  	 * done to java elements by the action.
  	 * </p>
  	 * <p>
  	 * If this method is called in the dynamic scope of another such
  	 * call, this method simply runs the action.
  	 * </p>
  	 *
  	 * @param action the action to perform
  	 * @param monitor a progress monitor, or <code>null</code> if progress
  	 *    reporting and cancellation are not desired
  	 * @exception CoreException if the operation failed.
  	 * @since 2.1
  	 */
  public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (workspace.isTreeLocked()) {
      new BatchOperation(action).run(monitor);
    } else {
      // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode
      workspace.run(new BatchOperation(action), monitor);
    }
  }
}