Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPCore.java
1 package net.sourceforge.phpeclipse;
2
3 import java.util.ArrayList;
4 import java.util.Enumeration;
5 import java.util.HashSet;
6 import java.util.Hashtable;
7 import java.util.List;
8
9 import net.sourceforge.phpdt.internal.core.BatchOperation;
10 import net.sourceforge.phpeclipse.resourcesview.PHPFile;
11 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IProjectDescription;
16 import org.eclipse.core.resources.IWorkspace;
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.Plugin;
22 import org.eclipse.core.runtime.Preferences;
23
24 public class PHPCore {
25
26   public static HashSet OptionNames = new HashSet(20);
27   /**
28    * The plug-in identifier of the Java core support
29    * (value <code>"org.phpeclipse.phpdt.core"</code>).
30    */
31   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.core"; //$NON-NLS-1$
32
33   /**
34      * Possible  configurable option ID.
35      * @see #getDefaultOptions
36      * @since 2.0
37      */
38   public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$
39
40   /**
41      * Possible  configurable option ID.
42      * @see #getDefaultOptions
43      * @since 2.0
44      */
45   public static final String FORMATTER_NEWLINE_OPENING_BRACE = PLUGIN_ID + ".formatter.newline.openingBrace"; //$NON-NLS-1$
46   /**
47    * Possible  configurable option ID.
48    * @see #getDefaultOptions
49    * @since 2.0
50    */
51   public static final String FORMATTER_NEWLINE_CONTROL = PLUGIN_ID + ".formatter.newline.controlStatement"; //$NON-NLS-1$
52   /**
53    * Possible  configurable option ID.
54    * @see #getDefaultOptions
55    * @since 2.0
56    */
57   public static final String FORMATTER_NEWLINE_ELSE_IF = PLUGIN_ID + ".formatter.newline.elseIf"; //$NON-NLS-1$
58   /**
59    * Possible  configurable option ID.
60    * @see #getDefaultOptions
61    * @since 2.0
62    */
63   public static final String FORMATTER_NEWLINE_EMPTY_BLOCK = PLUGIN_ID + ".formatter.newline.emptyBlock"; //$NON-NLS-1$
64   /**
65    * Possible  configurable option ID.
66    * @see #getDefaultOptions
67    * @since 2.0
68    */
69   public static final String FORMATTER_CLEAR_BLANK_LINES = PLUGIN_ID + ".formatter.newline.clearAll"; //$NON-NLS-1$
70   /**
71    * Possible  configurable option ID.
72    * @see #getDefaultOptions
73    * @since 2.0
74    */
75   public static final String FORMATTER_LINE_SPLIT = PLUGIN_ID + ".formatter.lineSplit"; //$NON-NLS-1$
76   /**
77    * Possible  configurable option ID.
78    * @see #getDefaultOptions
79    * @since 2.0
80    */
81   public static final String FORMATTER_COMPACT_ASSIGNMENT = PLUGIN_ID + ".formatter.style.assignment"; //$NON-NLS-1$
82   /**
83    * Possible  configurable option ID.
84    * @see #getDefaultOptions
85    * @since 2.0
86    */
87   public static final String FORMATTER_TAB_CHAR = PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$
88   /**
89    * Possible  configurable option ID.
90    * @see #getDefaultOptions
91    * @since 2.0
92    */
93   public static final String FORMATTER_TAB_SIZE = PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$
94   /**
95    * Possible  configurable option value.
96    * @see #getDefaultOptions
97    * @since 2.0
98    */
99   public static final String INSERT = "insert"; //$NON-NLS-1$
100   /**
101    * Possible  configurable option value.
102    * @see #getDefaultOptions
103    * @since 2.0
104    */
105   public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$
106
107   /**
108    * Possible  configurable option value.
109    * @see #getDefaultOptions
110    * @since 2.0
111    */
112   public static final String PRESERVE_ONE = "preserve one"; //$NON-NLS-1$
113   /**
114    * Possible  configurable option value.
115    * @see #getDefaultOptions
116    * @since 2.0
117    */
118   public static final String CLEAR_ALL = "clear all"; //$NON-NLS-1$
119   /**
120    * Possible  configurable option value.
121    * @see #getDefaultOptions
122    * @since 2.0
123    */
124   public static final String NORMAL = "normal"; //$NON-NLS-1$
125   /**
126    * Possible  configurable option value.
127    * @see #getDefaultOptions
128    * @since 2.0
129    */
130   public static final String COMPACT = "compact"; //$NON-NLS-1$
131   /**
132    * Possible  configurable option value.
133    * @see #getDefaultOptions
134    * @since 2.0
135    */
136   public static final String TAB = "tab"; //$NON-NLS-1$
137   /**
138    * Possible  configurable option value.
139    * @see #getDefaultOptions
140    * @since 2.0
141    */
142   public static final String SPACE = "space"; //$NON-NLS-1$
143   /**
144    * Possible  configurable option value.
145    * @see #getDefaultOptions
146    * @since 2.0
147    */
148   public static final String ENABLED = "enabled"; //$NON-NLS-1$
149   /**
150    * Possible  configurable option value.
151    * @see #getDefaultOptions
152    * @since 2.0
153    */
154   public static final String DISABLED = "disabled"; //$NON-NLS-1$
155   /**
156    * Possible  configurable option value.
157    * @see #getDefaultOptions
158    * @since 2.1
159    */
160   public static final String CLEAN = "clean"; //$NON-NLS-1$
161
162   /**
163    * Returns a table of all known configurable options with their default values.
164    * These options allow to configure the behaviour of the underlying components.
165    * The client may safely use the result as a template that they can modify and
166    * then pass to <code>setOptions</code>.
167    * 
168    * Helper constants have been defined on JavaCore for each of the option ID and 
169    * their possible constant values.
170    * 
171    * Note: more options might be added in further releases.
172    * <pre>
173    * RECOGNIZED OPTIONS:
174    * COMPILER / Generating Local Variable Debug Attribute
175    *    When generated, this attribute will enable local variable names 
176    *    to be displayed in debugger, only in place where variables are 
177    *    definitely assigned (.class file is then bigger)
178    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.localVariable"
179    *     - possible values:   { "generate", "do not generate" }
180    *     - default:           "generate"
181    *
182    * COMPILER / Generating Line Number Debug Attribute 
183    *    When generated, this attribute will enable source code highlighting in debugger 
184    *    (.class file is then bigger).
185    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.lineNumber"
186    *     - possible values:   { "generate", "do not generate" }
187    *     - default:           "generate"
188    *    
189    * COMPILER / Generating Source Debug Attribute 
190    *    When generated, this attribute will enable the debugger to present the 
191    *    corresponding source code.
192    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.sourceFile"
193    *     - possible values:   { "generate", "do not generate" }
194    *     - default:           "generate"
195    *    
196    * COMPILER / Preserving Unused Local Variables
197    *    Unless requested to preserve unused local variables (i.e. never read), the 
198    *    compiler will optimize them out, potentially altering debugging
199    *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.unusedLocal"
200    *     - possible values:   { "preserve", "optimize out" }
201    *     - default:           "preserve"
202    * 
203    * COMPILER / Defining Target Java Platform
204    *    For binary compatibility reason, .class files can be tagged to with certain VM versions and later.
205    *    Note that "1.4" target require to toggle compliance mode to "1.4" too.
206    *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.targetPlatform"
207    *     - possible values:   { "1.1", "1.2", "1.3", "1.4" }
208    *     - default:           "1.1"
209    *
210    * COMPILER / Reporting Unreachable Code
211    *    Unreachable code can optionally be reported as an error, warning or simply 
212    *    ignored. The bytecode generation will always optimized it out.
213    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unreachableCode"
214    *     - possible values:   { "error", "warning", "ignore" }
215    *     - default:           "error"
216    *
217    * COMPILER / Reporting Invalid Import
218    *    An import statement that cannot be resolved might optionally be reported 
219    *    as an error, as a warning or ignored.
220    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.invalidImport"
221    *     - possible values:   { "error", "warning", "ignore" }
222    *     - default:           "error"
223    *
224    * COMPILER / Reporting Attempt to Override Package-Default Method
225    *    A package default method is not visible in a different package, and thus 
226    *    cannot be overridden. When enabling this option, the compiler will signal 
227    *    such scenarii either as an error or a warning.
228    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.overridingPackageDefaultMethod"
229    *     - possible values:   { "error", "warning", "ignore" }
230    *     - default:           "warning"
231    *
232    * COMPILER / Reporting Method With Constructor Name
233    *    Naming a method with a constructor name is generally considered poor 
234    *    style programming. When enabling this option, the compiler will signal such 
235    *    scenarii either as an error or a warning.
236    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.methodWithConstructorName"
237    *     - possible values:   { "error", "warning", "ignore" }
238    *     - default:           "warning"
239    *
240    * COMPILER / Reporting Deprecation
241    *    When enabled, the compiler will signal use of deprecated API either as an 
242    *    error or a warning.
243    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecation"
244    *     - possible values:   { "error", "warning", "ignore" }
245    *     - default:           "warning"
246    *
247    * COMPILER / Reporting Deprecation Inside Deprecated Code
248    *    When enabled, the compiler will signal use of deprecated API inside deprecated code.
249    *    The severity of the problem is controlled with option "org.phpeclipse.phpdt.core.compiler.problem.deprecation".
250    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecationInDeprecatedCode"
251    *     - possible values:   { "enabled", "disabled" }
252    *     - default:           "disabled"
253    *
254    * COMPILER / Reporting Hidden Catch Block
255    *    Locally to a try statement, some catch blocks may hide others , e.g.
256    *      try {  throw new java.io.CharConversionException();
257    *      } catch (java.io.CharConversionException e) {
258    *      } catch (java.io.IOException e) {}. 
259    *    When enabling this option, the compiler will issue an error or a warning for hidden 
260    *    catch blocks corresponding to checked exceptions
261    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.hiddenCatchBlock"
262    *     - possible values:   { "error", "warning", "ignore" }
263    *     - default:           "warning"
264    *
265    * COMPILER / Reporting Unused Local
266    *    When enabled, the compiler will issue an error or a warning for unused local 
267    *    variables (i.e. variables never read from)
268    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedLocal"
269    *     - possible values:   { "error", "warning", "ignore" }
270    *     - default:           "ignore"
271    *
272    * COMPILER / Reporting Unused Parameter
273    *    When enabled, the compiler will issue an error or a warning for unused method 
274    *    parameters (i.e. parameters never read from)
275    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedParameter"
276    *     - possible values:   { "error", "warning", "ignore" }
277    *     - default:           "ignore"
278    *
279    * COMPILER / Reporting Unused Import
280    *    When enabled, the compiler will issue an error or a warning for unused import 
281    *    reference 
282    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedImport"
283    *     - possible values:   { "error", "warning", "ignore" }
284    *     - default:           "warning"
285    *
286    * COMPILER / Reporting Synthetic Access Emulation
287    *    When enabled, the compiler will issue an error or a warning whenever it emulates 
288    *    access to a non-accessible member of an enclosing type. Such access can have
289    *    performance implications.
290    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.syntheticAccessEmulation"
291    *     - possible values:   { "error", "warning", "ignore" }
292    *     - default:           "ignore"
293    *
294    * COMPILER / Reporting Non-Externalized String Literal
295    *    When enabled, the compiler will issue an error or a warning for non externalized 
296    *    String literal (i.e. non tagged with //$NON-NLS-<n>$). 
297    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.nonExternalizedStringLiteral"
298    *     - possible values:   { "error", "warning", "ignore" }
299    *     - default:           "ignore"
300    * 
301    * COMPILER / Reporting Usage of 'assert' Identifier
302    *    When enabled, the compiler will issue an error or a warning whenever 'assert' is 
303    *    used as an identifier (reserved keyword in 1.4)
304    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.assertIdentifier"
305    *     - possible values:   { "error", "warning", "ignore" }
306    *     - default:           "ignore"
307    * 
308    * COMPILER / Reporting Usage of expression receiver on static invocation/field access
309    *    When enabled, the compiler will issue an error or a warning whenever a static field
310    *    or method is accessed with an expression receiver.
311    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.staticAccessReceiver"
312    *     - possible values:   { "error", "warning", "ignore" }
313    *     - default:           "warning"
314    * 
315    * COMPILER / Reporting Assignment with no effect
316    *    When enabled, the compiler will issue an error or a warning whenever an assignment
317    *    has no effect (e.g 'x = x').
318    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.noEffectAssignment"
319    *     - possible values:   { "error", "warning", "ignore" }
320    *     - default:           "warning"
321    * 
322    * COMPILER / Setting Source Compatibility Mode
323    *    Specify whether source is 1.3 or 1.4 compatible. From 1.4 on, 'assert' is a keyword
324    *    reserved for assertion support. Also note, than when toggling to 1.4 mode, the target VM
325    *   level should be set to "1.4" and the compliance mode should be "1.4".
326    *     - option id:         "org.phpeclipse.phpdt.core.compiler.source"
327    *     - possible values:   { "1.3", "1.4" }
328    *     - default:           "1.3"
329    * 
330    * COMPILER / Setting Compliance Level
331    *    Select the compliance level for the compiler. In "1.3" mode, source and target settings
332    *    should not go beyond "1.3" level.
333    *     - option id:         "org.phpeclipse.phpdt.core.compiler.compliance"
334    *     - possible values:   { "1.3", "1.4" }
335    *     - default:           "1.3"
336    * 
337    * COMPILER / Maximum number of problems reported per compilation unit
338    *    Specify the maximum number of problems reported on each compilation unit.
339    *     - option id:         "org.phpeclipse.phpdt.core.compiler.maxProblemPerUnit"
340    *     - possible values:     "<n>" where <n> is zero or a positive integer (if zero then all problems are reported).
341    *     - default:           "100"
342    * 
343    * COMPILER / Define the Automatic Task Tags
344    *    When the tag is non empty, the compiler will issue a task marker whenever it encounters
345    *    one of the corresponding tag inside any comment in Java source code.
346    *    Generated task messages will include the tag, and range until the next line separator or comment ending, and will be trimmed.
347    *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskTags"
348    *     - possible values:   { "<tag>[,<tag>]*" } where <tag> is a String without any wild-card 
349    *     - default:           ""
350    * 
351    * COMPILER / Define the Automatic Task Priorities
352    *    In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low)
353    *    of the task markers issued by the compiler.
354    *    If the default is specified, the priority of each task marker is "NORMAL".
355    *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskPriorities"
356    *     - possible values:   { "<priority>[,<priority>]*" } where <priority> is one of "HIGH", "NORMAL" or "LOW"
357    *     - default:           ""
358    * 
359    * BUILDER / Specifying Filters for Resource Copying Control
360    *    Allow to specify some filters to control the resource copy process.
361    *     - option id:         "org.phpeclipse.phpdt.core.builder.resourceCopyExclusionFilter"
362    *     - possible values:   { "<name>[,<name>]* } where <name> is a file name pattern (* and ? wild-cards allowed)
363    *       or the name of a folder which ends with '/'
364    *     - default:           ""
365    * 
366    * BUILDER / Abort if Invalid Classpath
367    *    Allow to toggle the builder to abort if the classpath is invalid
368    *     - option id:         "org.phpeclipse.phpdt.core.builder.invalidClasspath"
369    *     - possible values:   { "abort", "ignore" }
370    *     - default:           "ignore"
371    * 
372    * BUILDER / Cleaning Output Folder(s)
373    *    Indicate whether the JavaBuilder is allowed to clean the output folders
374    *    when performing full build operations.
375    *     - option id:         "org.phpeclipse.phpdt.core.builder.cleanOutputFolder"
376    *     - possible values:   { "clean", "ignore" }
377    *     - default:           "clean"
378    * 
379    * JAVACORE / Computing Project Build Order
380    *    Indicate whether JavaCore should enforce the project build order to be based on
381    *    the classpath prerequisite chain. When requesting to compute, this takes over
382    *    the platform default order (based on project references).
383    *     - option id:         "org.phpeclipse.phpdt.core.computeJavaBuildOrder"
384    *     - possible values:   { "compute", "ignore" }
385    *     - default:           "ignore"   
386    * 
387    * JAVACORE / Specify Default Source Encoding Format
388    *    Get the encoding format for compiled sources. This setting is read-only, it is equivalent
389    *    to 'ResourcesPlugin.getEncoding()'.
390    *     - option id:         "org.phpeclipse.phpdt.core.encoding"
391    *     - possible values:   { any of the supported encoding name}.
392    *     - default:           <platform default>
393    * 
394    * JAVACORE / Reporting Incomplete Classpath
395    *    An entry on the classpath doesn't exist or is not visible (e.g. a referenced project is closed).
396    *     - option id:         "org.phpeclipse.phpdt.core.incompleteClasspath"
397    *     - possible values:   { "error", "warning"}
398    *     - default:           "error"
399    * 
400    * JAVACORE / Reporting Classpath Cycle
401    *    A project is involved in a cycle.
402    *     - option id:         "org.phpeclipse.phpdt.core.circularClasspath"
403    *     - possible values:   { "error", "warning" }
404    *     - default:           "error"
405    * 
406    *    FORMATTER / Inserting New Line Before Opening Brace
407    *    When Insert, a new line is inserted before an opening brace, otherwise nothing
408    *    is inserted
409    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.openingBrace"
410    *     - possible values:   { "insert", "do not insert" }
411    *     - default:           "do not insert"
412    * 
413    *    FORMATTER / Inserting New Line Inside Control Statement
414    *    When Insert, a new line is inserted between } and following else, catch, finally
415    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.controlStatement"
416    *     - possible values:   { "insert", "do not insert" }
417    *     - default:           "do not insert"
418    * 
419    *    FORMATTER / Clearing Blank Lines
420    *    When Clear all, all blank lines are removed. When Preserve one, only one is kept
421    *    and all others removed.
422    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.clearAll"
423    *     - possible values:   { "clear all", "preserve one" }
424    *     - default:           "preserve one"
425    * 
426    *    FORMATTER / Inserting New Line Between Else/If 
427    *    When Insert, a blank line is inserted between an else and an if when they are 
428    *    contiguous. When choosing to not insert, else-if will be kept on the same
429    *    line when possible.
430    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.elseIf"
431    *     - possible values:   { "insert", "do not insert" }
432    *     - default:           "do not insert"
433    * 
434    *    FORMATTER / Inserting New Line In Empty Block
435    *    When insert, a line break is inserted between contiguous { and }, if } is not followed
436    *    by a keyword.
437    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.emptyBlock"
438    *     - possible values:   { "insert", "do not insert" }
439    *     - default:           "insert"
440    * 
441    *    FORMATTER / Splitting Lines Exceeding Length
442    *    Enable splitting of long lines (exceeding the configurable length). Length of 0 will
443    *    disable line splitting
444    *     - option id:         "org.phpeclipse.phpdt.core.formatter.lineSplit"
445    *     - possible values:     "<n>", where n is zero or a positive integer
446    *     - default:           "80"
447    * 
448    *    FORMATTER / Compacting Assignment
449    *    Assignments can be formatted asymmetrically, e.g. 'int x= 2;', when Normal, a space
450    *    is inserted before the assignment operator
451    *     - option id:         "org.phpeclipse.phpdt.core.formatter.style.assignment"
452    *     - possible values:   { "compact", "normal" }
453    *     - default:           "normal"
454    * 
455    *    FORMATTER / Defining Indentation Character
456    *    Either choose to indent with tab characters or spaces
457    *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.char"
458    *     - possible values:   { "tab", "space" }
459    *     - default:           "tab"
460    * 
461    *    FORMATTER / Defining Space Indentation Length
462    *    When using spaces, set the amount of space characters to use for each 
463    *    indentation mark.
464    *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.size"
465    *     - possible values:     "<n>", where n is a positive integer
466    *     - default:           "4"
467    * 
468    *    CODEASSIST / Activate Visibility Sensitive Completion
469    *    When active, completion doesn't show that you can not see
470    *    (e.g. you can not see private methods of a super class).
471    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.visibilityCheck"
472    *     - possible values:   { "enabled", "disabled" }
473    *     - default:           "disabled"
474    * 
475    *    CODEASSIST / Automatic Qualification of Implicit Members
476    *    When active, completion automatically qualifies completion on implicit
477    *    field references and message expressions.
478    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.forceImplicitQualification"
479    *     - possible values:   { "enabled", "disabled" }
480    *     - default:           "disabled"
481    * 
482    *  CODEASSIST / Define the Prefixes for Field Name
483    *    When the prefixes is non empty, completion for field name will begin with
484    *    one of the proposed prefixes.
485    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldPrefixes"
486    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
487    *     - default:           ""
488    * 
489    *  CODEASSIST / Define the Prefixes for Static Field Name
490    *    When the prefixes is non empty, completion for static field name will begin with
491    *    one of the proposed prefixes.
492    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldPrefixes"
493    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
494    *     - default:           ""
495    * 
496    *  CODEASSIST / Define the Prefixes for Local Variable Name
497    *    When the prefixes is non empty, completion for local variable name will begin with
498    *    one of the proposed prefixes.
499    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localPrefixes"
500    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
501    *     - default:           ""
502    * 
503    *  CODEASSIST / Define the Prefixes for Argument Name
504    *    When the prefixes is non empty, completion for argument name will begin with
505    *    one of the proposed prefixes.
506    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentPrefixes"
507    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
508    *     - default:           ""
509    * 
510    *  CODEASSIST / Define the Suffixes for Field Name
511    *    When the suffixes is non empty, completion for field name will end with
512    *    one of the proposed suffixes.
513    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldSuffixes"
514    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
515    *     - default:           ""
516    * 
517    *  CODEASSIST / Define the Suffixes for Static Field Name
518    *    When the suffixes is non empty, completion for static field name will end with
519    *    one of the proposed suffixes.
520    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldSuffixes"
521    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
522    *     - default:           ""
523    * 
524    *  CODEASSIST / Define the Suffixes for Local Variable Name
525    *    When the suffixes is non empty, completion for local variable name will end with
526    *    one of the proposed suffixes.
527    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localSuffixes"
528    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
529    *     - default:           ""
530    * 
531    *  CODEASSIST / Define the Suffixes for Argument Name
532    *    When the suffixes is non empty, completion for argument name will end with
533    *    one of the proposed suffixes.
534    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentSuffixes"
535    *     - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String without any wild-card 
536    *     - default:           ""
537    * </pre>
538    * 
539    * @return a mutable table containing the default settings of all known options
540    *   (key type: <code>String</code>; value type: <code>String</code>)
541    * @see #setOptions
542    */
543   public static Hashtable getDefaultOptions() {
544
545     Hashtable defaultOptions = new Hashtable(10);
546
547     // see #initializeDefaultPluginPreferences() for changing default settings
548     Preferences preferences = getPlugin().getPluginPreferences();
549     HashSet optionNames = OptionNames;
550
551     // get preferences set to their default
552     String[] defaultPropertyNames = preferences.defaultPropertyNames();
553     for (int i = 0; i < defaultPropertyNames.length; i++) {
554       String propertyName = defaultPropertyNames[i];
555       if (optionNames.contains(propertyName)) {
556         defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
557       }
558     }
559     // get preferences not set to their default
560     String[] propertyNames = preferences.propertyNames();
561     for (int i = 0; i < propertyNames.length; i++) {
562       String propertyName = propertyNames[i];
563       if (optionNames.contains(propertyName)) {
564         defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
565       }
566     }
567     // get encoding through resource plugin
568     defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
569
570     return defaultOptions;
571   }
572   /**
573    * Helper method for returning one option value only. Equivalent to <code>(String)JavaCore.getOptions().get(optionName)</code>
574    * Note that it may answer <code>null</code> if this option does not exist.
575    * <p>
576    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
577    * </p>
578    * 
579    * @param optionName the name of an option
580    * @return the String value of a given option
581    * @see JavaCore#getDefaultOptions
582    * @since 2.0
583    */
584   public static String getOption(String optionName) {
585
586     if (CORE_ENCODING.equals(optionName)) {
587       return ResourcesPlugin.getEncoding();
588     }
589     if (OptionNames.contains(optionName)) {
590       Preferences preferences = getPlugin().getPluginPreferences();
591       return preferences.getString(optionName).trim();
592     }
593     return null;
594   }
595
596   /**
597    * Returns the table of the current options. Initially, all options have their default values,
598    * and this method returns a table that includes all known options.
599    * <p>
600    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
601    * </p>
602    * 
603    * @return table of current settings of all options 
604    *   (key type: <code>String</code>; value type: <code>String</code>)
605    * @see JavaCore#getDefaultOptions
606    */
607   public static Hashtable getOptions() {
608
609     Hashtable options = new Hashtable(10);
610
611     // see #initializeDefaultPluginPreferences() for changing default settings
612     Plugin plugin = getPlugin();
613     if (plugin != null) {
614       Preferences preferences = getPlugin().getPluginPreferences();
615       HashSet optionNames = OptionNames;
616
617       // get preferences set to their default
618       String[] defaultPropertyNames = preferences.defaultPropertyNames();
619       for (int i = 0; i < defaultPropertyNames.length; i++) {
620         String propertyName = defaultPropertyNames[i];
621         if (optionNames.contains(propertyName)) {
622           options.put(propertyName, preferences.getDefaultString(propertyName));
623         }
624       }
625       // get preferences not set to their default
626       String[] propertyNames = preferences.propertyNames();
627       for (int i = 0; i < propertyNames.length; i++) {
628         String propertyName = propertyNames[i];
629         if (optionNames.contains(propertyName)) {
630           options.put(propertyName, preferences.getString(propertyName).trim());
631         }
632       }
633       // get encoding through resource plugin
634       options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
635     }
636     return options;
637   }
638   /**
639    * Sets the current table of options. All and only the options explicitly included in the given table 
640    * are remembered; all previous option settings are forgotten, including ones not explicitly
641    * mentioned.
642    * <p>
643    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
644    * </p>
645    * 
646    * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
647    *   or <code>null</code> to reset all options to their default values
648    * @see JavaCore#getDefaultOptions
649    */
650   public static void setOptions(Hashtable newOptions) {
651
652     // see #initializeDefaultPluginPreferences() for changing default settings
653     Preferences preferences = getPlugin().getPluginPreferences();
654
655     if (newOptions == null) {
656       newOptions = getDefaultOptions();
657     }
658     Enumeration keys = newOptions.keys();
659     while (keys.hasMoreElements()) {
660       String key = (String) keys.nextElement();
661       if (!OptionNames.contains(key))
662         continue; // unrecognized option
663       if (key.equals(CORE_ENCODING))
664         continue; // skipped, contributed by resource prefs
665       String value = (String) newOptions.get(key);
666       preferences.setValue(key, value);
667     }
668
669     // persist options
670     getPlugin().savePluginPreferences();
671   }
672   public static IProject[] getPHPProjects() {
673     List phpProjectsList = new ArrayList();
674     IProject[] workspaceProjects = PHPeclipsePlugin.getWorkspace().getRoot().getProjects();
675
676     for (int i = 0; i < workspaceProjects.length; i++) {
677       IProject iProject = workspaceProjects[i];
678       if (isPHPProject(iProject))
679         phpProjectsList.add(iProject);
680     }
681
682     IProject[] phpProjects = new IProject[phpProjectsList.size()];
683     return (IProject[]) phpProjectsList.toArray(phpProjects);
684   }
685
686   public static PHPProject getPHPProject(String name) {
687     IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
688     if (isPHPProject(aProject)) {
689       PHPProject thePHPProject = new PHPProject();
690       thePHPProject.setProject(aProject);
691       return thePHPProject;
692     }
693     return null;
694   }
695
696   public static boolean isPHPProject(IProject aProject) {
697     try {
698       return aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
699     } catch (CoreException e) {
700     }
701
702     return false;
703   }
704
705   public static PHPFile create(IFile aFile) {
706     if (PHPFile.EXTENSION.equalsIgnoreCase(aFile.getFileExtension()))
707       return new PHPFile(aFile);
708     if (PHPFile.EXTENSION1.equalsIgnoreCase(aFile.getFileExtension()))
709       return new PHPFile(aFile);
710     if (PHPFile.EXTENSION2.equalsIgnoreCase(aFile.getFileExtension()))
711       return new PHPFile(aFile);
712     if (PHPFile.EXTENSION3.equalsIgnoreCase(aFile.getFileExtension()))
713       return new PHPFile(aFile);
714     if (PHPFile.EXTENSION4.equalsIgnoreCase(aFile.getFileExtension()))
715       return new PHPFile(aFile);
716     if (PHPFile.EXTENSION5.equalsIgnoreCase(aFile.getFileExtension()))
717       return new PHPFile(aFile);
718
719     return null;
720   }
721
722   public static PHPProject create(IProject aProject) {
723     try {
724       if (aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
725         PHPProject project = new PHPProject();
726         project.setProject(aProject);
727         return project;
728       }
729     } catch (CoreException e) {
730       System.err.println("Exception occurred in PHPCore#create(IProject): " + e.toString());
731     }
732
733     return null;
734   }
735
736   public static void addPHPNature(IProject project, IProgressMonitor monitor) throws CoreException {
737     if (!project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
738       IProjectDescription description = project.getDescription();
739       String[] prevNatures = description.getNatureIds();
740       String[] newNatures = new String[prevNatures.length + 1];
741       System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
742       newNatures[prevNatures.length] = PHPeclipsePlugin.PHP_NATURE_ID;
743       description.setNatureIds(newNatures);
744       project.setDescription(description, monitor);
745     }
746   }
747
748   /**
749    * Returns the single instance of the PHP core plug-in runtime class.
750    * 
751    * @return the single instance of the PHP core plug-in runtime class
752    */
753   public static Plugin getPlugin() {
754     return PHPeclipsePlugin.getDefault();
755   }
756
757   /**
758      * Initializes the default preferences settings for this plug-in.
759      */
760   protected static void initializeDefaultPluginPreferences() {
761
762     Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
763     HashSet optionNames = OptionNames;
764
765     //    // Compiler settings
766     //    preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
767     //    optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
768     //
769     //    preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE); 
770     //    optionNames.add(COMPILER_LINE_NUMBER_ATTR);
771     //
772     //    preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE); 
773     //    optionNames.add(COMPILER_SOURCE_FILE_ATTR);
774     //
775     //    preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); 
776     //    optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
777     //
778     //    preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1); 
779     //    optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
780     //
781     //    preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); 
782     //    optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
783     //
784     //    preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR); 
785     //    optionNames.add(COMPILER_PB_INVALID_IMPORT);
786     //
787     //    preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING); 
788     //    optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
789     //
790     //    preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING); 
791     //    optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
792     //
793     //    preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
794     //    optionNames.add(COMPILER_PB_DEPRECATION);
795     //
796     //    preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
797     //    optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
798     //
799     //    preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING); 
800     //    optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
801     //
802     //    preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE); 
803     //    optionNames.add(COMPILER_PB_UNUSED_LOCAL);
804     //
805     //    preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE); 
806     //    optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
807     //
808     //    preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING); 
809     //    optionNames.add(COMPILER_PB_UNUSED_IMPORT);
810     //
811     //    preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE); 
812     //    optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
813     //
814     //    preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE); 
815     //    optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
816     //
817     //    preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE); 
818     //    optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
819     //
820     //    preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING); 
821     //    optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
822     //
823     //    preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING); 
824     //    optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
825     //
826     //    preferences.setDefault(COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
827     //    optionNames.add(COMPILER_TASK_TAGS);
828     //
829     //    preferences.setDefault(COMPILER_TASK_PRIORITIES, ""); //$NON-NLS-1$
830     //    optionNames.add(COMPILER_TASK_PRIORITIES);
831     //
832     //    preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
833     //    optionNames.add(COMPILER_SOURCE);
834     //
835     //    preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3); 
836     //    optionNames.add(COMPILER_COMPLIANCE);
837     //
838     //    preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
839     //    optionNames.add(COMPILER_PB_MAX_PER_UNIT);
840     //          
841     //    // Builder settings
842     //    preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
843     //    optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
844     //
845     //    preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
846     //    optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
847     //  
848     //    preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
849     //    optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
850     //          
851     //    preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
852     //    optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
853     //
854     //    // JavaCore settings
855     //    preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
856     //    optionNames.add(CORE_JAVA_BUILD_ORDER);
857     //  
858     //    preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
859     //    optionNames.add(CORE_CIRCULAR_CLASSPATH);
860     //          
861     //    preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
862     //    optionNames.add(CORE_INCOMPLETE_CLASSPATH);
863
864     // encoding setting comes from resource plug-in
865     optionNames.add(CORE_ENCODING);
866
867     // Formatter settings
868     preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT);
869     optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
870
871     preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
872     optionNames.add(FORMATTER_NEWLINE_CONTROL);
873
874     preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE);
875     optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
876
877     preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
878     optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
879
880     preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT);
881     optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
882
883     preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
884     optionNames.add(FORMATTER_LINE_SPLIT);
885
886     preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL);
887     optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
888
889     preferences.setDefault(FORMATTER_TAB_CHAR, TAB);
890     optionNames.add(FORMATTER_TAB_CHAR);
891
892     preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
893     optionNames.add(FORMATTER_TAB_SIZE);
894
895     // CodeAssist settings
896     //    preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
897     //    optionNames.add(CODEASSIST_VISIBILITY_CHECK);
898     //
899     //    preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
900     //    optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
901     //          
902     //    preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
903     //    optionNames.add(CODEASSIST_FIELD_PREFIXES);
904     //          
905     //    preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
906     //    optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
907     //          
908     //    preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
909     //    optionNames.add(CODEASSIST_LOCAL_PREFIXES);
910     //          
911     //    preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
912     //    optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
913     //          
914     //    preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
915     //    optionNames.add(CODEASSIST_FIELD_SUFFIXES);
916     //          
917     //    preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
918     //    optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
919     //          
920     //    preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
921     //    optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
922     //          
923     //    preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
924     //    optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
925
926   }
927   /**
928          * Runs the given action as an atomic Java model operation.
929          * <p>
930          * After running a method that modifies Java elements,
931          * registered listeners receive after-the-fact notification of
932          * what just transpired, in the form of a element changed event.
933          * This method allows clients to call a number of
934          * methods that modify java elements and only have element
935          * changed event notifications reported at the end of the entire
936          * batch.
937          * </p>
938          * <p>
939          * If this method is called outside the dynamic scope of another such
940          * call, this method runs the action and then reports a single
941          * element changed event describing the net effect of all changes
942          * done to java elements by the action.
943          * </p>
944          * <p>
945          * If this method is called in the dynamic scope of another such
946          * call, this method simply runs the action.
947          * </p>
948          *
949          * @param action the action to perform
950          * @param monitor a progress monitor, or <code>null</code> if progress
951          *    reporting and cancellation are not desired
952          * @exception CoreException if the operation failed.
953          * @since 2.1
954          */
955   public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
956     IWorkspace workspace = ResourcesPlugin.getWorkspace();
957     if (workspace.isTreeLocked()) {
958       new BatchOperation(action).run(monitor);
959     } else {
960       // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode
961       workspace.run(new BatchOperation(action), monitor);
962     }
963   }
964 }