new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPCore.java
1 package net.sourceforge.phpeclipse;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.Enumeration;
7 import java.util.HashSet;
8 import java.util.Hashtable;
9 import java.util.List;
10 import java.util.Map;
11
12 import net.sourceforge.phpdt.core.ClasspathVariableInitializer;
13 import net.sourceforge.phpdt.core.ElementChangedEvent;
14 import net.sourceforge.phpdt.core.IBufferFactory;
15 import net.sourceforge.phpdt.core.IClasspathEntry;
16 import net.sourceforge.phpdt.core.ICompilationUnit;
17 import net.sourceforge.phpdt.core.IElementChangedListener;
18 import net.sourceforge.phpdt.core.IJavaElement;
19 import net.sourceforge.phpdt.core.IJavaModel;
20 import net.sourceforge.phpdt.core.IJavaProject;
21 import net.sourceforge.phpdt.core.IMember;
22 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
23 import net.sourceforge.phpdt.core.IRegion;
24 import net.sourceforge.phpdt.core.IWorkingCopy;
25 import net.sourceforge.phpdt.core.JavaModelException;
26 import net.sourceforge.phpdt.internal.core.BatchOperation;
27 import net.sourceforge.phpdt.internal.core.BufferManager;
28 import net.sourceforge.phpdt.internal.core.ClasspathEntry;
29 import net.sourceforge.phpdt.internal.core.JavaModel;
30 import net.sourceforge.phpdt.internal.core.JavaModelManager;
31 import net.sourceforge.phpdt.internal.core.Region;
32 import net.sourceforge.phpdt.internal.corext.Assert;
33
34 import org.eclipse.core.resources.IFile;
35 import org.eclipse.core.resources.IFolder;
36 import org.eclipse.core.resources.IMarker;
37 import org.eclipse.core.resources.IMarkerDelta;
38 import org.eclipse.core.resources.IProject;
39 import org.eclipse.core.resources.IProjectDescription;
40 import org.eclipse.core.resources.IResource;
41 import org.eclipse.core.resources.IResourceChangeEvent;
42 import org.eclipse.core.resources.IWorkspace;
43 import org.eclipse.core.resources.IWorkspaceRoot;
44 import org.eclipse.core.resources.IWorkspaceRunnable;
45 import org.eclipse.core.resources.ResourcesPlugin;
46 import org.eclipse.core.runtime.CoreException;
47 import org.eclipse.core.runtime.IConfigurationElement;
48 import org.eclipse.core.runtime.IPath;
49 import org.eclipse.core.runtime.IProgressMonitor;
50 import org.eclipse.core.runtime.Plugin;
51 import org.eclipse.core.runtime.Preferences;
52
53 public class PHPCore {
54
55 //  public static HashSet OptionNames = new HashSet(20);
56   /**
57    * The plug-in identifier of the Java core support
58    * (value <code>"org.phpeclipse.phpdt.core"</code>).
59    */
60 //  public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.core"; //$NON-NLS-1$
61         public static final String PLUGIN_ID = PHPeclipsePlugin.PLUGIN_ID;
62   /**
63      * Possible  configurable option ID.
64      * @see #getDefaultOptions
65      * @since 2.0
66      */
67   public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$
68
69   /**
70      * Possible  configurable option ID.
71      * @see #getDefaultOptions
72      * @since 2.0
73      */
74   public static final String FORMATTER_NEWLINE_OPENING_BRACE = PLUGIN_ID + ".formatter.newline.openingBrace"; //$NON-NLS-1$
75   /**
76    * Possible  configurable option ID.
77    * @see #getDefaultOptions
78    * @since 2.0
79    */
80   public static final String FORMATTER_NEWLINE_CONTROL = PLUGIN_ID + ".formatter.newline.controlStatement"; //$NON-NLS-1$
81   /**
82    * Possible  configurable option ID.
83    * @see #getDefaultOptions
84    * @since 2.0
85    */
86   public static final String FORMATTER_NEWLINE_ELSE_IF = PLUGIN_ID + ".formatter.newline.elseIf"; //$NON-NLS-1$
87   /**
88    * Possible  configurable option ID.
89    * @see #getDefaultOptions
90    * @since 2.0
91    */
92   public static final String FORMATTER_NEWLINE_EMPTY_BLOCK = PLUGIN_ID + ".formatter.newline.emptyBlock"; //$NON-NLS-1$
93   /**
94    * Possible  configurable option ID.
95    * @see #getDefaultOptions
96    * @since 2.0
97    */
98   public static final String FORMATTER_CLEAR_BLANK_LINES = PLUGIN_ID + ".formatter.newline.clearAll"; //$NON-NLS-1$
99   /**
100    * Possible  configurable option ID.
101    * @see #getDefaultOptions
102    * @since 2.0
103    */
104   public static final String FORMATTER_LINE_SPLIT = PLUGIN_ID + ".formatter.lineSplit"; //$NON-NLS-1$
105   /**
106    * Possible  configurable option ID.
107    * @see #getDefaultOptions
108    * @since 2.0
109    */
110   public static final String FORMATTER_COMPACT_ASSIGNMENT = PLUGIN_ID + ".formatter.style.assignment"; //$NON-NLS-1$
111   /**
112    * Possible  configurable option ID.
113    * @see #getDefaultOptions
114    * @since 2.0
115    */
116   public static final String FORMATTER_TAB_CHAR = PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$
117   /**
118    * Possible  configurable option ID.
119    * @see #getDefaultOptions
120    * @since 2.0
121    */
122   public static final String FORMATTER_TAB_SIZE = PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$
123   /**
124    * Possible  configurable option value.
125    * @see #getDefaultOptions
126    * @since 2.0
127    */
128   public static final String INSERT = "insert"; //$NON-NLS-1$
129   /**
130    * Possible  configurable option value.
131    * @see #getDefaultOptions
132    * @since 2.0
133    */
134   public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$
135
136   /**
137    * Possible  configurable option value.
138    * @see #getDefaultOptions
139    * @since 2.0
140    */
141   public static final String PRESERVE_ONE = "preserve one"; //$NON-NLS-1$
142   /**
143    * Possible  configurable option value.
144    * @see #getDefaultOptions
145    * @since 2.0
146    */
147   public static final String CLEAR_ALL = "clear all"; //$NON-NLS-1$
148   /**
149    * Possible  configurable option value.
150    * @see #getDefaultOptions
151    * @since 2.0
152    */
153   public static final String NORMAL = "normal"; //$NON-NLS-1$
154   /**
155    * Possible  configurable option value.
156    * @see #getDefaultOptions
157    * @since 2.0
158    */
159   public static final String COMPACT = "compact"; //$NON-NLS-1$
160   /**
161    * Possible  configurable option value.
162    * @see #getDefaultOptions
163    * @since 2.0
164    */
165   public static final String TAB = "tab"; //$NON-NLS-1$
166   /**
167    * Possible  configurable option value.
168    * @see #getDefaultOptions
169    * @since 2.0
170    */
171   public static final String SPACE = "space"; //$NON-NLS-1$
172   /**
173    * Possible  configurable option value.
174    * @see #getDefaultOptions
175    * @since 2.0
176    */
177   public static final String ENABLED = "enabled"; //$NON-NLS-1$
178   /**
179    * Possible  configurable option value.
180    * @see #getDefaultOptions
181    * @since 2.0
182    */
183   public static final String DISABLED = "disabled"; //$NON-NLS-1$
184   /**
185    * Possible  configurable option value.
186    * @see #getDefaultOptions
187    * @since 2.1
188    */
189   public static final String CLEAN = "clean"; //$NON-NLS-1$
190
191   /**
192          * Possible  configurable option ID.
193          * @see #getDefaultOptions
194          * @since 2.1
195          */
196   public static final String COMPILER_TASK_TAGS = PLUGIN_ID + ".compiler.taskTags"; //$NON-NLS-1$
197
198         /**
199                  * Name of the handle id attribute in a Java marker.
200                  */
201                 protected static final String ATT_HANDLE_ID =
202                         "net.sourceforge.phpdt.internal.core.JavaModelManager.handleId" ; //$NON-NLS-1$
203
204                 // *************** Possible IDs for configurable options. ********************
205
206                 /**
207                  * Possible  configurable option ID.
208                  * @see #getDefaultOptions()
209                  */
210                 public static final String COMPILER_LOCAL_VARIABLE_ATTR = PLUGIN_ID + ".compiler.debug.localVariable"; //$NON-NLS-1$
211                 /**
212                  * Possible  configurable option ID.
213                  * @see #getDefaultOptions()
214                  */
215                 public static final String COMPILER_LINE_NUMBER_ATTR = PLUGIN_ID + ".compiler.debug.lineNumber"; //$NON-NLS-1$
216                 /**
217                  * Possible  configurable option ID.
218                  * @see #getDefaultOptions
219                  */
220                 public static final String COMPILER_SOURCE_FILE_ATTR = PLUGIN_ID + ".compiler.debug.sourceFile"; //$NON-NLS-1$
221                 /**
222                  * Possible  configurable option ID.
223                  * @see #getDefaultOptions
224                  */
225                 public static final String COMPILER_CODEGEN_UNUSED_LOCAL = PLUGIN_ID + ".compiler.codegen.unusedLocal"; //$NON-NLS-1$
226                 /**
227                  * Possible  configurable option ID.
228                  * @see #getDefaultOptions
229                  */
230                 public static final String COMPILER_CODEGEN_TARGET_PLATFORM = PLUGIN_ID + ".compiler.codegen.targetPlatform"; //$NON-NLS-1$
231                 /**
232                  * Possible  configurable option ID.
233                  * @see #getDefaultOptions
234                  */
235                 public static final String COMPILER_PB_UNREACHABLE_CODE = PLUGIN_ID + ".compiler.problem.unreachableCode"; //$NON-NLS-1$
236                 /**
237                  * Possible  configurable option ID.
238                  * @see #getDefaultOptions
239                  */
240                 public static final String COMPILER_PB_INVALID_IMPORT = PLUGIN_ID + ".compiler.problem.invalidImport"; //$NON-NLS-1$
241                 /**
242                  * Possible  configurable option ID.
243                  * @see #getDefaultOptions
244                  */
245                 public static final String COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD = PLUGIN_ID + ".compiler.problem.overridingPackageDefaultMethod"; //$NON-NLS-1$
246                 /**
247                  * Possible  configurable option ID.
248                  * @see #getDefaultOptions
249                  */
250                 public static final String COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME = PLUGIN_ID + ".compiler.problem.methodWithConstructorName"; //$NON-NLS-1$
251                 /**
252                  * Possible  configurable option ID.
253                  * @see #getDefaultOptions
254                  */
255                 public static final String COMPILER_PB_DEPRECATION = PLUGIN_ID + ".compiler.problem.deprecation"; //$NON-NLS-1$
256                 /**
257                  * Possible  configurable option ID.
258                  * @see #getDefaultOptions
259                  * @since 2.1
260                  */
261                 public static final String COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE = PLUGIN_ID + ".compiler.problem.deprecationInDeprecatedCode"; //$NON-NLS-1$
262                 /**
263                  * Possible  configurable option ID.
264                  * @see #getDefaultOptions
265                  */
266                 public static final String COMPILER_PB_HIDDEN_CATCH_BLOCK = PLUGIN_ID + ".compiler.problem.hiddenCatchBlock"; //$NON-NLS-1$
267                 /**
268                  * Possible  configurable option ID.
269                  * @see #getDefaultOptions
270                  */
271                 public static final String COMPILER_PB_UNUSED_LOCAL = PLUGIN_ID + ".compiler.problem.unusedLocal"; //$NON-NLS-1$
272                 /**
273                  * Possible  configurable option ID.
274                  * @see #getDefaultOptions
275                  */
276                 public static final String COMPILER_PB_UNUSED_PARAMETER = PLUGIN_ID + ".compiler.problem.unusedParameter"; //$NON-NLS-1$
277                 /**
278                  * Possible  configurable option ID.
279                  * @see #getDefaultOptions
280                  * @since 2.1
281                  */
282                 public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT = PLUGIN_ID + ".compiler.problem.unusedParameterWhenImplementingAbstract"; //$NON-NLS-1$
283                 /**
284                  * Possible  configurable option ID.
285                  * @see #getDefaultOptions
286                  * @since 2.1
287                  */
288                 public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE = PLUGIN_ID + ".compiler.problem.unusedParameterWhenOverridingConcrete"; //$NON-NLS-1$
289                 /**
290                  * Possible  configurable option ID.
291                  * @see #getDefaultOptions
292                  * @since 2.0
293                  */
294                 public static final String COMPILER_PB_UNUSED_IMPORT = PLUGIN_ID + ".compiler.problem.unusedImport"; //$NON-NLS-1$
295                 /**
296                  * Possible  configurable option ID.
297                  * @see #getDefaultOptions
298                  */
299                 public static final String COMPILER_PB_SYNTHETIC_ACCESS_EMULATION = PLUGIN_ID + ".compiler.problem.syntheticAccessEmulation"; //$NON-NLS-1$
300                 /**
301                  * Possible  configurable option ID.
302                  * @see #getDefaultOptions
303                  * @since 2.0
304                  */
305                 public static final String COMPILER_PB_NON_NLS_STRING_LITERAL = PLUGIN_ID + ".compiler.problem.nonExternalizedStringLiteral"; //$NON-NLS-1$
306                 /**
307                  * Possible  configurable option ID.
308                  * @see #getDefaultOptions
309                  * @since 2.0
310                  */
311                 public static final String COMPILER_PB_ASSERT_IDENTIFIER = PLUGIN_ID + ".compiler.problem.assertIdentifier"; //$NON-NLS-1$
312                 /**
313                  * Possible  configurable option ID.
314                  * @see #getDefaultOptions
315                  * @since 2.1
316                  */
317                 public static final String COMPILER_PB_STATIC_ACCESS_RECEIVER = PLUGIN_ID + ".compiler.problem.staticAccessReceiver"; //$NON-NLS-1$
318                 /**
319                  * Possible  configurable option ID.
320                  * @see #getDefaultOptions
321                  * @since 2.1
322                  */
323                 public static final String COMPILER_PB_NO_EFFECT_ASSIGNMENT = PLUGIN_ID + ".compiler.problem.noEffectAssignment"; //$NON-NLS-1$
324                 /**
325                  * Possible  configurable option ID.
326                  * @see #getDefaultOptions
327                  * @since 2.1
328                  */
329                 public static final String COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD = PLUGIN_ID + ".compiler.problem.incompatibleNonInheritedInterfaceMethod"; //$NON-NLS-1$
330                 /**
331                  * Possible  configurable option ID.
332                  * @see #getDefaultOptions
333                  * @since 2.1
334                  */
335                 public static final String COMPILER_PB_UNUSED_PRIVATE_MEMBER = PLUGIN_ID + ".compiler.problem.unusedPrivateMember"; //$NON-NLS-1$
336                 /**
337                  * Possible  configurable option ID.
338                  * @see #getDefaultOptions
339                  * @since 2.1
340                  */
341                 public static final String COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION = PLUGIN_ID + ".compiler.problem.noImplicitStringConversion"; //$NON-NLS-1$
342                 /**
343                  * Possible  configurable option ID.
344                  * @see #getDefaultOptions
345                  * @since 2.0
346                  */
347                 public static final String COMPILER_PB_MAX_PER_UNIT = PLUGIN_ID + ".compiler.maxProblemPerUnit"; //$NON-NLS-1$
348                 /**
349                  * Possible  configurable option ID.
350                  * @see #getDefaultOptions
351                  * @since 2.0
352                  */
353                 public static final String COMPILER_SOURCE = PLUGIN_ID + ".compiler.source"; //$NON-NLS-1$
354                 /**
355                  * Possible  configurable option ID.
356                  * @see #getDefaultOptions
357                  * @since 2.0
358                  */
359                 public static final String COMPILER_COMPLIANCE = PLUGIN_ID + ".compiler.compliance"; //$NON-NLS-1$
360                 /**
361                  * Possible  configurable option ID.
362                  * @see #getDefaultOptions
363                  * @since 2.1
364                  */
365                 public static final String COMPILER_TASK_PRIORITIES = PLUGIN_ID + ".compiler.taskPriorities"; //$NON-NLS-1$
366                 /**
367                  * Possible  configurable option value for COMPILER_TASK_PRIORITIES.
368                  * @see #getDefaultOptions
369                  * @since 2.1
370                  */
371                 public static final String COMPILER_TASK_PRIORITY_HIGH = "HIGH"; //$NON-NLS-1$
372                 /**
373                  * Possible  configurable option value for COMPILER_TASK_PRIORITIES.
374                  * @see #getDefaultOptions
375                  * @since 2.1
376                  */
377                 public static final String COMPILER_TASK_PRIORITY_LOW = "LOW"; //$NON-NLS-1$
378                 /**
379                  * Possible  configurable option value for COMPILER_TASK_PRIORITIES.
380                  * @see #getDefaultOptions
381                  * @since 2.1
382                  */
383                 public static final String COMPILER_TASK_PRIORITY_NORMAL = "NORMAL"; //$NON-NLS-1$
384                                 /**
385                  * Possible  configurable option ID.
386                  * @see #getDefaultOptions
387                  */
388                 public static final String CORE_JAVA_BUILD_ORDER = PLUGIN_ID + ".computeJavaBuildOrder"; //$NON-NLS-1$
389                 /**
390                  * Possible  configurable option ID.
391                  * @see #getDefaultOptions
392                  * @since 2.0
393                  */
394                 public static final String CORE_JAVA_BUILD_RESOURCE_COPY_FILTER = PLUGIN_ID + ".builder.resourceCopyExclusionFilter"; //$NON-NLS-1$
395                 /**
396                  * Possible  configurable option ID.
397                  * @see #getDefaultOptions
398                  * @since 2.1
399                  */
400                 public static final String CORE_JAVA_BUILD_DUPLICATE_RESOURCE = PLUGIN_ID + ".builder.duplicateResourceTask"; //$NON-NLS-1$
401                 /**
402                  * Possible  configurable option ID.
403                  * @see #getDefaultOptions
404                  * @since 2.1
405                  */
406                 public static final String CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER = PLUGIN_ID + ".builder.cleanOutputFolder"; //$NON-NLS-1$                
407                 /**
408                  * Possible  configurable option ID.
409                  * @see #getDefaultOptions
410                  * @since 2.1
411                  */
412                 public static final String CORE_INCOMPLETE_CLASSPATH = PLUGIN_ID + ".incompleteClasspath"; //$NON-NLS-1$
413                 /**
414                  * Possible  configurable option ID.
415                  * @see #getDefaultOptions
416                  * @since 2.1
417                  */
418                 public static final String CORE_CIRCULAR_CLASSPATH = PLUGIN_ID + ".circularClasspath"; //$NON-NLS-1$
419                 /**
420                  * Possible  configurable option ID.
421                  * @see #getDefaultOptions
422                  * @since 2.0
423                  */
424                 public static final String CORE_JAVA_BUILD_INVALID_CLASSPATH = PLUGIN_ID + ".builder.invalidClasspath"; //$NON-NLS-1$
425                         /**
426                  * Possible  configurable option ID.
427                  * @see #getDefaultOptions
428                  * @since 2.1 
429                  */
430                 public static final String CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS = PLUGIN_ID + ".classpath.exclusionPatterns"; //$NON-NLS-1$
431                 /**
432                  * Possible  configurable option ID.
433                  * @see #getDefaultOptions
434                  * @since 2.1
435                  */
436                 public static final String CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS = PLUGIN_ID + ".classpath.multipleOutputLocations"; //$NON-NLS-1$
437                 /**
438                  * Default task tag
439                  * @since 2.1
440                  */
441                 public static final String DEFAULT_TASK_TAG = "TODO"; //$NON-NLS-1$
442                 /**
443                  * Default task priority
444                  * @since 2.1
445                  */
446                 public static final String DEFAULT_TASK_PRIORITY = "NORMAL"; //$NON-NLS-1$
447                 /**
448                  * Possible configurable option ID
449                  * @see #getDefaultOptions
450                  * @since 2.1
451                  */
452                 public static final String FORMATTER_SPACE_CASTEXPRESSION = PLUGIN_ID + ".formatter.space.castexpression"; //$NON-NLS-1$
453                 /**
454                  * Possible  configurable option ID.
455                  * @see #getDefaultOptions
456                  * @since 2.0
457                  */
458                 public static final String CODEASSIST_VISIBILITY_CHECK = PLUGIN_ID + ".codeComplete.visibilityCheck"; //$NON-NLS-1$
459                 /**
460                  * Possible  configurable option ID.
461                  * @see #getDefaultOptions
462                  * @since 2.0
463                  */
464                 public static final String CODEASSIST_IMPLICIT_QUALIFICATION = PLUGIN_ID + ".codeComplete.forceImplicitQualification"; //$NON-NLS-1$
465                 /**
466                  * Possible  configurable option ID.
467                  * @see #getDefaultOptions
468                  * @since 2.1
469                  */
470                 public static final String CODEASSIST_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.fieldPrefixes"; //$NON-NLS-1$
471                 /**
472                  * Possible  configurable option ID.
473                  * @see #getDefaultOptions
474                  * @since 2.1
475                  */
476                 public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
477                 /**
478                  * Possible  configurable option ID.
479                  * @see #getDefaultOptions
480                  * @since 2.1
481                  */
482                 public static final String CODEASSIST_LOCAL_PREFIXES = PLUGIN_ID + ".codeComplete.localPrefixes"; //$NON-NLS-1$
483                 /**
484                  * Possible  configurable option ID.
485                  * @see #getDefaultOptions
486                  * @since 2.1
487                  */
488                 public static final String CODEASSIST_ARGUMENT_PREFIXES = PLUGIN_ID + ".codeComplete.argumentPrefixes"; //$NON-NLS-1$
489                 /**
490                  * Possible  configurable option ID.
491                  * @see #getDefaultOptions
492                  * @since 2.1
493                  */
494                 public static final String CODEASSIST_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.fieldSuffixes"; //$NON-NLS-1$
495                 /**
496                  * Possible  configurable option ID.
497                  * @see #getDefaultOptions
498                  * @since 2.1
499                  */
500                 public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
501                 /**
502                  * Possible  configurable option ID.
503                  * @see #getDefaultOptions
504                  * @since 2.1
505                  */
506                 public static final String CODEASSIST_LOCAL_SUFFIXES = PLUGIN_ID + ".codeComplete.localSuffixes"; //$NON-NLS-1$
507                 /**
508                  * Possible  configurable option ID.
509                  * @see #getDefaultOptions
510                  * @since 2.1
511                  */
512                 public static final String CODEASSIST_ARGUMENT_SUFFIXES = PLUGIN_ID + ".codeComplete.argumentSuffixes"; //$NON-NLS-1$
513
514                 // *************** Possible values for configurable options. ********************
515         
516                 /**
517                  * Possible  configurable option value.
518                  * @see #getDefaultOptions
519                  */
520                 public static final String GENERATE = "generate"; //$NON-NLS-1$
521                 /**
522                  * Possible  configurable option value.
523                  * @see #getDefaultOptions
524                  */
525                 public static final String DO_NOT_GENERATE = "do not generate"; //$NON-NLS-1$
526                 /**
527                  * Possible  configurable option value.
528                  * @see #getDefaultOptions
529                  */
530                 public static final String PRESERVE = "preserve"; //$NON-NLS-1$
531                 /**
532                  * Possible  configurable option value.
533                  * @see #getDefaultOptions
534                  */
535                 public static final String OPTIMIZE_OUT = "optimize out"; //$NON-NLS-1$
536                 /**
537                  * Possible  configurable option value.
538                  * @see #getDefaultOptions
539                  */
540                 public static final String VERSION_1_1 = "1.1"; //$NON-NLS-1$
541                 /**
542                  * Possible  configurable option value.
543                  * @see #getDefaultOptions
544                  */
545                 public static final String VERSION_1_2 = "1.2"; //$NON-NLS-1$
546                 /**
547                  * Possible  configurable option value.
548                  * @see #getDefaultOptions
549                  * @since 2.0
550                  */
551                 public static final String VERSION_1_3 = "1.3"; //$NON-NLS-1$
552                 /**
553                  * Possible  configurable option value.
554                  * @see #getDefaultOptions
555                  * @since 2.0
556                  */
557                 public static final String VERSION_1_4 = "1.4"; //$NON-NLS-1$
558                 /**
559                  * Possible  configurable option value.
560                  * @see #getDefaultOptions
561                  * @since 2.0
562                  */
563                 public static final String ABORT = "abort"; //$NON-NLS-1$
564                 /**
565                  * Possible  configurable option value.
566                  * @see #getDefaultOptions
567                  */
568                 public static final String ERROR = "error"; //$NON-NLS-1$
569                 /**
570                  * Possible  configurable option value.
571                  * @see #getDefaultOptions
572                  */
573                 public static final String WARNING = "warning"; //$NON-NLS-1$
574                 /**
575                  * Possible  configurable option value.
576                  * @see #getDefaultOptions
577                  */
578                 public static final String IGNORE = "ignore"; //$NON-NLS-1$
579                 /**
580                  * Possible  configurable option value.
581                  * @see #getDefaultOptions
582                  */
583                 public static final String COMPUTE = "compute"; //$NON-NLS-1$
584                 /**
585                  * Possible  configurable option value.
586                  * @see #getDefaultOptions
587                  * @since 2.0
588                  */
589
590         
591   /**
592    * Returns a table of all known configurable options with their default values.
593    * These options allow to configure the behaviour of the underlying components.
594    * The client may safely use the result as a template that they can modify and
595    * then pass to <code>setOptions</code>.
596    * 
597    * Helper constants have been defined on JavaCore for each of the option ID and 
598    * their possible constant values.
599    * 
600    * Note: more options might be added in further releases.
601    * <pre>
602    * RECOGNIZED OPTIONS:
603    * COMPILER / Generating Local Variable Debug Attribute
604    *    When generated, this attribute will enable local variable names 
605    *    to be displayed in debugger, only in place where variables are 
606    *    definitely assigned (.class file is then bigger)
607    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.localVariable"
608    *     - possible values:   { "generate", "do not generate" }
609    *     - default:           "generate"
610    *
611    * COMPILER / Generating Line Number Debug Attribute 
612    *    When generated, this attribute will enable source code highlighting in debugger 
613    *    (.class file is then bigger).
614    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.lineNumber"
615    *     - possible values:   { "generate", "do not generate" }
616    *     - default:           "generate"
617    *    
618    * COMPILER / Generating Source Debug Attribute 
619    *    When generated, this attribute will enable the debugger to present the 
620    *    corresponding source code.
621    *     - option id:         "org.phpeclipse.phpdt.core.compiler.debug.sourceFile"
622    *     - possible values:   { "generate", "do not generate" }
623    *     - default:           "generate"
624    *    
625    * COMPILER / Preserving Unused Local Variables
626    *    Unless requested to preserve unused local variables (i.e. never read), the 
627    *    compiler will optimize them out, potentially altering debugging
628    *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.unusedLocal"
629    *     - possible values:   { "preserve", "optimize out" }
630    *     - default:           "preserve"
631    * 
632    * COMPILER / Defining Target Java Platform
633    *    For binary compatibility reason, .class files can be tagged to with certain VM versions and later.
634    *    Note that "1.4" target require to toggle compliance mode to "1.4" too.
635    *     - option id:         "org.phpeclipse.phpdt.core.compiler.codegen.targetPlatform"
636    *     - possible values:   { "1.1", "1.2", "1.3", "1.4" }
637    *     - default:           "1.1"
638    *
639    * COMPILER / Reporting Unreachable Code
640    *    Unreachable code can optionally be reported as an error, warning or simply 
641    *    ignored. The bytecode generation will always optimized it out.
642    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unreachableCode"
643    *     - possible values:   { "error", "warning", "ignore" }
644    *     - default:           "error"
645    *
646    * COMPILER / Reporting Invalid Import
647    *    An import statement that cannot be resolved might optionally be reported 
648    *    as an error, as a warning or ignored.
649    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.invalidImport"
650    *     - possible values:   { "error", "warning", "ignore" }
651    *     - default:           "error"
652    *
653    * COMPILER / Reporting Attempt to Override Package-Default Method
654    *    A package default method is not visible in a different package, and thus 
655    *    cannot be overridden. When enabling this option, the compiler will signal 
656    *    such scenarii either as an error or a warning.
657    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.overridingPackageDefaultMethod"
658    *     - possible values:   { "error", "warning", "ignore" }
659    *     - default:           "warning"
660    *
661    * COMPILER / Reporting Method With Constructor Name
662    *    Naming a method with a constructor name is generally considered poor 
663    *    style programming. When enabling this option, the compiler will signal such 
664    *    scenarii either as an error or a warning.
665    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.methodWithConstructorName"
666    *     - possible values:   { "error", "warning", "ignore" }
667    *     - default:           "warning"
668    *
669    * COMPILER / Reporting Deprecation
670    *    When enabled, the compiler will signal use of deprecated API either as an 
671    *    error or a warning.
672    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecation"
673    *     - possible values:   { "error", "warning", "ignore" }
674    *     - default:           "warning"
675    *
676    * COMPILER / Reporting Deprecation Inside Deprecated Code
677    *    When enabled, the compiler will signal use of deprecated API inside deprecated code.
678    *    The severity of the problem is controlled with option "org.phpeclipse.phpdt.core.compiler.problem.deprecation".
679    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.deprecationInDeprecatedCode"
680    *     - possible values:   { "enabled", "disabled" }
681    *     - default:           "disabled"
682    *
683    * COMPILER / Reporting Hidden Catch Block
684    *    Locally to a try statement, some catch blocks may hide others , e.g.
685    *      try {  throw new java.io.CharConversionException();
686    *      } catch (java.io.CharConversionException e) {
687    *      } catch (java.io.IOException e) {}. 
688    *    When enabling this option, the compiler will issue an error or a warning for hidden 
689    *    catch blocks corresponding to checked exceptions
690    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.hiddenCatchBlock"
691    *     - possible values:   { "error", "warning", "ignore" }
692    *     - default:           "warning"
693    *
694    * COMPILER / Reporting Unused Local
695    *    When enabled, the compiler will issue an error or a warning for unused local 
696    *    variables (i.e. variables never read from)
697    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedLocal"
698    *     - possible values:   { "error", "warning", "ignore" }
699    *     - default:           "ignore"
700    *
701    * COMPILER / Reporting Unused Parameter
702    *    When enabled, the compiler will issue an error or a warning for unused method 
703    *    parameters (i.e. parameters never read from)
704    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedParameter"
705    *     - possible values:   { "error", "warning", "ignore" }
706    *     - default:           "ignore"
707    *
708    * COMPILER / Reporting Unused Import
709    *    When enabled, the compiler will issue an error or a warning for unused import 
710    *    reference 
711    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.unusedImport"
712    *     - possible values:   { "error", "warning", "ignore" }
713    *     - default:           "warning"
714    *
715    * COMPILER / Reporting Synthetic Access Emulation
716    *    When enabled, the compiler will issue an error or a warning whenever it emulates 
717    *    access to a non-accessible member of an enclosing type. Such access can have
718    *    performance implications.
719    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.syntheticAccessEmulation"
720    *     - possible values:   { "error", "warning", "ignore" }
721    *     - default:           "ignore"
722    *
723    * COMPILER / Reporting Non-Externalized String Literal
724    *    When enabled, the compiler will issue an error or a warning for non externalized 
725    *    String literal (i.e. non tagged with //$NON-NLS-<n>$). 
726    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.nonExternalizedStringLiteral"
727    *     - possible values:   { "error", "warning", "ignore" }
728    *     - default:           "ignore"
729    * 
730    * COMPILER / Reporting Usage of 'assert' Identifier
731    *    When enabled, the compiler will issue an error or a warning whenever 'assert' is 
732    *    used as an identifier (reserved keyword in 1.4)
733    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.assertIdentifier"
734    *     - possible values:   { "error", "warning", "ignore" }
735    *     - default:           "ignore"
736    * 
737    * COMPILER / Reporting Usage of expression receiver on static invocation/field access
738    *    When enabled, the compiler will issue an error or a warning whenever a static field
739    *    or method is accessed with an expression receiver.
740    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.staticAccessReceiver"
741    *     - possible values:   { "error", "warning", "ignore" }
742    *     - default:           "warning"
743    * 
744    * COMPILER / Reporting Assignment with no effect
745    *    When enabled, the compiler will issue an error or a warning whenever an assignment
746    *    has no effect (e.g 'x = x').
747    *     - option id:         "org.phpeclipse.phpdt.core.compiler.problem.noEffectAssignment"
748    *     - possible values:   { "error", "warning", "ignore" }
749    *     - default:           "warning"
750    * 
751    * COMPILER / Setting Source Compatibility Mode
752    *    Specify whether source is 1.3 or 1.4 compatible. From 1.4 on, 'assert' is a keyword
753    *    reserved for assertion support. Also note, than when toggling to 1.4 mode, the target VM
754    *   level should be set to "1.4" and the compliance mode should be "1.4".
755    *     - option id:         "org.phpeclipse.phpdt.core.compiler.source"
756    *     - possible values:   { "1.3", "1.4" }
757    *     - default:           "1.3"
758    * 
759    * COMPILER / Setting Compliance Level
760    *    Select the compliance level for the compiler. In "1.3" mode, source and target settings
761    *    should not go beyond "1.3" level.
762    *     - option id:         "org.phpeclipse.phpdt.core.compiler.compliance"
763    *     - possible values:   { "1.3", "1.4" }
764    *     - default:           "1.3"
765    * 
766    * COMPILER / Maximum number of problems reported per compilation unit
767    *    Specify the maximum number of problems reported on each compilation unit.
768    *     - option id:         "org.phpeclipse.phpdt.core.compiler.maxProblemPerUnit"
769    *     - possible values:     "<n>" where <n> is zero or a positive integer (if zero then all problems are reported).
770    *     - default:           "100"
771    * 
772    * COMPILER / Define the Automatic Task Tags
773    *    When the tag is non empty, the compiler will issue a task marker whenever it encounters
774    *    one of the corresponding tag inside any comment in Java source code.
775    *    Generated task messages will include the tag, and range until the next line separator or comment ending, and will be trimmed.
776    *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskTags"
777    *     - possible values:   { "<tag>[,<tag>]*" } where <tag> is a String without any wild-card 
778    *     - default:           ""
779    * COMPILER / Define the Automatic Task Priorities
780    *    In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low)
781    *    of the task markers issued by the compiler.
782    *    If the default is specified, the priority of each task marker is "NORMAL".
783    *     - option id:         "org.phpeclipse.phpdt.core.compiler.taskPriorities"
784    *     - possible values:   { "<priority>[,<priority>]*" } where <priority> is one of "HIGH", "NORMAL" or "LOW"
785    *     - default:           ""
786    * 
787    * BUILDER / Specifying Filters for Resource Copying Control
788    *    Allow to specify some filters to control the resource copy process.
789    *     - option id:         "org.phpeclipse.phpdt.core.builder.resourceCopyExclusionFilter"
790    *     - possible values:   { "<name>[,<name>]* } where <name> is a file name pattern (* and ? wild-cards allowed)
791    *       or the name of a folder which ends with '/'
792    *     - default:           ""
793    * 
794    * BUILDER / Abort if Invalid Classpath
795    *    Allow to toggle the builder to abort if the classpath is invalid
796    *     - option id:         "org.phpeclipse.phpdt.core.builder.invalidClasspath"
797    *     - possible values:   { "abort", "ignore" }
798    *     - default:           "ignore"
799    * 
800    * BUILDER / Cleaning Output Folder(s)
801    *    Indicate whether the JavaBuilder is allowed to clean the output folders
802    *    when performing full build operations.
803    *     - option id:         "org.phpeclipse.phpdt.core.builder.cleanOutputFolder"
804    *     - possible values:   { "clean", "ignore" }
805    *     - default:           "clean"
806    * 
807    * JAVACORE / Computing Project Build Order
808    *    Indicate whether JavaCore should enforce the project build order to be based on
809    *    the classpath prerequisite chain. When requesting to compute, this takes over
810    *    the platform default order (based on project references).
811    *     - option id:         "org.phpeclipse.phpdt.core.computeJavaBuildOrder"
812    *     - possible values:   { "compute", "ignore" }
813    *     - default:           "ignore"   
814    * 
815    * JAVACORE / Specify Default Source Encoding Format
816    *    Get the encoding format for compiled sources. This setting is read-only, it is equivalent
817    *    to 'ResourcesPlugin.getEncoding()'.
818    *     - option id:         "org.phpeclipse.phpdt.core.encoding"
819    *     - possible values:   { any of the supported encoding name}.
820    *     - default:           <platform default>
821    * 
822    * JAVACORE / Reporting Incomplete Classpath
823    *    An entry on the classpath doesn't exist or is not visible (e.g. a referenced project is closed).
824    *     - option id:         "org.phpeclipse.phpdt.core.incompleteClasspath"
825    *     - possible values:   { "error", "warning"}
826    *     - default:           "error"
827    * 
828    * JAVACORE / Reporting Classpath Cycle
829    *    A project is involved in a cycle.
830    *     - option id:         "org.phpeclipse.phpdt.core.circularClasspath"
831    *     - possible values:   { "error", "warning" }
832    *     - default:           "error"
833    * 
834    *    FORMATTER / Inserting New Line Before Opening Brace
835    *    When Insert, a new line is inserted before an opening brace, otherwise nothing
836    *    is inserted
837    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.openingBrace"
838    *     - possible values:   { "insert", "do not insert" }
839    *     - default:           "do not insert"
840    * 
841    *    FORMATTER / Inserting New Line Inside Control Statement
842    *    When Insert, a new line is inserted between } and following else, catch, finally
843    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.controlStatement"
844    *     - possible values:   { "insert", "do not insert" }
845    *     - default:           "do not insert"
846    * 
847    *    FORMATTER / Clearing Blank Lines
848    *    When Clear all, all blank lines are removed. When Preserve one, only one is kept
849    *    and all others removed.
850    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.clearAll"
851    *     - possible values:   { "clear all", "preserve one" }
852    *     - default:           "preserve one"
853    * 
854    *    FORMATTER / Inserting New Line Between Else/If 
855    *    When Insert, a blank line is inserted between an else and an if when they are 
856    *    contiguous. When choosing to not insert, else-if will be kept on the same
857    *    line when possible.
858    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.elseIf"
859    *     - possible values:   { "insert", "do not insert" }
860    *     - default:           "do not insert"
861    * 
862    *    FORMATTER / Inserting New Line In Empty Block
863    *    When insert, a line break is inserted between contiguous { and }, if } is not followed
864    *    by a keyword.
865    *     - option id:         "org.phpeclipse.phpdt.core.formatter.newline.emptyBlock"
866    *     - possible values:   { "insert", "do not insert" }
867    *     - default:           "insert"
868    * 
869    *    FORMATTER / Splitting Lines Exceeding Length
870    *    Enable splitting of long lines (exceeding the configurable length). Length of 0 will
871    *    disable line splitting
872    *     - option id:         "org.phpeclipse.phpdt.core.formatter.lineSplit"
873    *     - possible values:     "<n>", where n is zero or a positive integer
874    *     - default:           "80"
875    * 
876    *    FORMATTER / Compacting Assignment
877    *    Assignments can be formatted asymmetrically, e.g. 'int x= 2;', when Normal, a space
878    *    is inserted before the assignment operator
879    *     - option id:         "org.phpeclipse.phpdt.core.formatter.style.assignment"
880    *     - possible values:   { "compact", "normal" }
881    *     - default:           "normal"
882    * 
883    *    FORMATTER / Defining Indentation Character
884    *    Either choose to indent with tab characters or spaces
885    *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.char"
886    *     - possible values:   { "tab", "space" }
887    *     - default:           "tab"
888    * 
889    *    FORMATTER / Defining Space Indentation Length
890    *    When using spaces, set the amount of space characters to use for each 
891    *    indentation mark.
892    *     - option id:         "org.phpeclipse.phpdt.core.formatter.tabulation.size"
893    *     - possible values:     "<n>", where n is a positive integer
894    *     - default:           "4"
895    * 
896    *    CODEASSIST / Activate Visibility Sensitive Completion
897    *    When active, completion doesn't show that you can not see
898    *    (e.g. you can not see private methods of a super class).
899    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.visibilityCheck"
900    *     - possible values:   { "enabled", "disabled" }
901    *     - default:           "disabled"
902    * 
903    *    CODEASSIST / Automatic Qualification of Implicit Members
904    *    When active, completion automatically qualifies completion on implicit
905    *    field references and message expressions.
906    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.forceImplicitQualification"
907    *     - possible values:   { "enabled", "disabled" }
908    *     - default:           "disabled"
909    * 
910    *  CODEASSIST / Define the Prefixes for Field Name
911    *    When the prefixes is non empty, completion for field name will begin with
912    *    one of the proposed prefixes.
913    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldPrefixes"
914    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
915    *     - default:           ""
916    * 
917    *  CODEASSIST / Define the Prefixes for Static Field Name
918    *    When the prefixes is non empty, completion for static field name will begin with
919    *    one of the proposed prefixes.
920    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldPrefixes"
921    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
922    *     - default:           ""
923    * 
924    *  CODEASSIST / Define the Prefixes for Local Variable Name
925    *    When the prefixes is non empty, completion for local variable name will begin with
926    *    one of the proposed prefixes.
927    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localPrefixes"
928    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
929    *     - default:           ""
930    * 
931    *  CODEASSIST / Define the Prefixes for Argument Name
932    *    When the prefixes is non empty, completion for argument name will begin with
933    *    one of the proposed prefixes.
934    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentPrefixes"
935    *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
936    *     - default:           ""
937    * 
938    *  CODEASSIST / Define the Suffixes for Field Name
939    *    When the suffixes is non empty, completion for field name will end with
940    *    one of the proposed suffixes.
941    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.fieldSuffixes"
942    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
943    *     - default:           ""
944    * 
945    *  CODEASSIST / Define the Suffixes for Static Field Name
946    *    When the suffixes is non empty, completion for static field name will end with
947    *    one of the proposed suffixes.
948    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.staticFieldSuffixes"
949    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
950    *     - default:           ""
951    * 
952    *  CODEASSIST / Define the Suffixes for Local Variable Name
953    *    When the suffixes is non empty, completion for local variable name will end with
954    *    one of the proposed suffixes.
955    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.localSuffixes"
956    *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
957    *     - default:           ""
958    * 
959    *  CODEASSIST / Define the Suffixes for Argument Name
960    *    When the suffixes is non empty, completion for argument name will end with
961    *    one of the proposed suffixes.
962    *     - option id:         "org.phpeclipse.phpdt.core.codeComplete.argumentSuffixes"
963    *     - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String without any wild-card 
964    *     - default:           ""
965    * </pre>
966    * 
967    * @return a mutable table containing the default settings of all known options
968    *   (key type: <code>String</code>; value type: <code>String</code>)
969    * @see #setOptions
970    */
971 //  public static Hashtable getDefaultOptions() {
972 //
973 //    Hashtable defaultOptions = new Hashtable(10);
974 //
975 //    // see #initializeDefaultPluginPreferences() for changing default settings
976 //    Preferences preferences = getPlugin().getPluginPreferences();
977 //    HashSet optionNames = OptionNames;
978 //
979 //    // get preferences set to their default
980 //    String[] defaultPropertyNames = preferences.defaultPropertyNames();
981 //    for (int i = 0; i < defaultPropertyNames.length; i++) {
982 //      String propertyName = defaultPropertyNames[i];
983 //      if (optionNames.contains(propertyName)) {
984 //        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
985 //      }
986 //    }
987 //    // get preferences not set to their default
988 //    String[] propertyNames = preferences.propertyNames();
989 //    for (int i = 0; i < propertyNames.length; i++) {
990 //      String propertyName = propertyNames[i];
991 //      if (optionNames.contains(propertyName)) {
992 //        defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
993 //      }
994 //    }
995 //    // get encoding through resource plugin
996 //    defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
997 //
998 //    return defaultOptions;
999 //  }
1000   /**
1001    * Helper method for returning one option value only. Equivalent to <code>(String)JavaCore.getOptions().get(optionName)</code>
1002    * Note that it may answer <code>null</code> if this option does not exist.
1003    * <p>
1004    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
1005    * </p>
1006    * 
1007    * @param optionName the name of an option
1008    * @return the String value of a given option
1009    * @see JavaCore#getDefaultOptions
1010    * @since 2.0
1011    */
1012 //  public static String getOption(String optionName) {
1013 //
1014 //    if (CORE_ENCODING.equals(optionName)) {
1015 //      return ResourcesPlugin.getEncoding();
1016 //    }
1017 //    if (OptionNames.contains(optionName)) {
1018 //      Preferences preferences = getPlugin().getPluginPreferences();
1019 //      return preferences.getString(optionName).trim();
1020 //    }
1021 //    return null;
1022 //  }
1023
1024   /**
1025    * Returns the table of the current options. Initially, all options have their default values,
1026    * and this method returns a table that includes all known options.
1027    * <p>
1028    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
1029    * </p>
1030    * 
1031    * @return table of current settings of all options 
1032    *   (key type: <code>String</code>; value type: <code>String</code>)
1033    * @see JavaCore#getDefaultOptions
1034    */
1035 //  public static Hashtable getOptions() {
1036 //
1037 //    Hashtable options = new Hashtable(10);
1038 //
1039 //    // see #initializeDefaultPluginPreferences() for changing default settings
1040 //    Plugin plugin = getPlugin();
1041 //    if (plugin != null) {
1042 //      Preferences preferences = getPlugin().getPluginPreferences();
1043 //      HashSet optionNames = OptionNames;
1044 //
1045 //      // get preferences set to their default
1046 //      String[] defaultPropertyNames = preferences.defaultPropertyNames();
1047 //      for (int i = 0; i < defaultPropertyNames.length; i++) {
1048 //        String propertyName = defaultPropertyNames[i];
1049 //        if (optionNames.contains(propertyName)) {
1050 //          options.put(propertyName, preferences.getDefaultString(propertyName));
1051 //        }
1052 //      }
1053 //      // get preferences not set to their default
1054 //      String[] propertyNames = preferences.propertyNames();
1055 //      for (int i = 0; i < propertyNames.length; i++) {
1056 //        String propertyName = propertyNames[i];
1057 //        if (optionNames.contains(propertyName)) {
1058 //          options.put(propertyName, preferences.getString(propertyName).trim());
1059 //        }
1060 //      }
1061 //      // get encoding through resource plugin
1062 //      options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
1063 //    }
1064 //    return options;
1065 //  }
1066   /**
1067    * Sets the current table of options. All and only the options explicitly included in the given table 
1068    * are remembered; all previous option settings are forgotten, including ones not explicitly
1069    * mentioned.
1070    * <p>
1071    * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
1072    * </p>
1073    * 
1074    * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
1075    *   or <code>null</code> to reset all options to their default values
1076    * @see JavaCore#getDefaultOptions
1077    */
1078 //  public static void setOptions(Hashtable newOptions) {
1079 //
1080 //    // see #initializeDefaultPluginPreferences() for changing default settings
1081 //    Preferences preferences = getPlugin().getPluginPreferences();
1082 //
1083 //    if (newOptions == null) {
1084 //      newOptions = getDefaultOptions();
1085 //    }
1086 //    Enumeration keys = newOptions.keys();
1087 //    while (keys.hasMoreElements()) {
1088 //      String key = (String) keys.nextElement();
1089 //      if (!OptionNames.contains(key))
1090 //        continue; // unrecognized option
1091 //      if (key.equals(CORE_ENCODING))
1092 //        continue; // skipped, contributed by resource prefs
1093 //      String value = (String) newOptions.get(key);
1094 //      preferences.setValue(key, value);
1095 //    }
1096 //
1097 //    // persist options
1098 //    getPlugin().savePluginPreferences();
1099 //  }
1100   public static IProject[] getPHPProjects() {
1101     List phpProjectsList = new ArrayList();
1102     IProject[] workspaceProjects = PHPeclipsePlugin.getWorkspace().getRoot().getProjects();
1103
1104     for (int i = 0; i < workspaceProjects.length; i++) {
1105       IProject iProject = workspaceProjects[i];
1106       if (isPHPProject(iProject))
1107         phpProjectsList.add(iProject);
1108     }
1109
1110     IProject[] phpProjects = new IProject[phpProjectsList.size()];
1111     return (IProject[]) phpProjectsList.toArray(phpProjects);
1112   }
1113
1114 //  public static PHPProject getPHPProject(String name) {
1115 //    IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
1116 //    if (isPHPProject(aProject)) {
1117 //      PHPProject thePHPProject = new PHPProject();
1118 //      thePHPProject.setProject(aProject);
1119 //      return thePHPProject;
1120 //    }
1121 //    return null;
1122 //  }
1123
1124   public static boolean isPHPProject(IProject aProject) {
1125     try {
1126       return aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
1127     } catch (CoreException e) {
1128     }
1129
1130     return false;
1131   }
1132
1133 //  public static PHPFile create(IFile aFile) {
1134 //    if (PHPFile.EXTENSION.equalsIgnoreCase(aFile.getFileExtension()))
1135 //      return new PHPFile(aFile);
1136 //    if (PHPFile.EXTENSION1.equalsIgnoreCase(aFile.getFileExtension()))
1137 //      return new PHPFile(aFile);
1138 //    if (PHPFile.EXTENSION2.equalsIgnoreCase(aFile.getFileExtension()))
1139 //      return new PHPFile(aFile);
1140 //    if (PHPFile.EXTENSION3.equalsIgnoreCase(aFile.getFileExtension()))
1141 //      return new PHPFile(aFile);
1142 //    if (PHPFile.EXTENSION4.equalsIgnoreCase(aFile.getFileExtension()))
1143 //      return new PHPFile(aFile);
1144 //    if (PHPFile.EXTENSION5.equalsIgnoreCase(aFile.getFileExtension()))
1145 //      return new PHPFile(aFile);
1146 //
1147 //    return null;
1148 //  }
1149
1150 //  public static PHPProject create(IProject aProject) {
1151 //      
1152 //    try {
1153 //      if (aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
1154 //        PHPProject project = new PHPProject();
1155 //        project.setProject(aProject);
1156 //        return project;
1157 //      }
1158 //    } catch (CoreException e) {
1159 //      System.err.println("Exception occurred in PHPCore#create(IProject): " + e.toString());
1160 //    }
1161 //
1162 //    return null;
1163 //  }
1164
1165   public static void addPHPNature(IProject project, IProgressMonitor monitor) throws CoreException {
1166     if (!project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
1167       IProjectDescription description = project.getDescription();
1168       String[] prevNatures = description.getNatureIds();
1169       String[] newNatures = new String[prevNatures.length + 1];
1170       System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
1171       newNatures[prevNatures.length] = PHPeclipsePlugin.PHP_NATURE_ID;
1172       description.setNatureIds(newNatures);
1173       project.setDescription(description, monitor);
1174     }
1175   }
1176
1177   /**
1178    * Returns the single instance of the PHP core plug-in runtime class.
1179    * 
1180    * @return the single instance of the PHP core plug-in runtime class
1181    */
1182   public static Plugin getPlugin() {
1183     return PHPeclipsePlugin.getDefault();
1184   }
1185
1186   /**
1187      * Initializes the default preferences settings for this plug-in.
1188      */
1189  
1190   /**
1191          * Runs the given action as an atomic Java model operation.
1192          * <p>
1193          * After running a method that modifies Java elements,
1194          * registered listeners receive after-the-fact notification of
1195          * what just transpired, in the form of a element changed event.
1196          * This method allows clients to call a number of
1197          * methods that modify java elements and only have element
1198          * changed event notifications reported at the end of the entire
1199          * batch.
1200          * </p>
1201          * <p>
1202          * If this method is called outside the dynamic scope of another such
1203          * call, this method runs the action and then reports a single
1204          * element changed event describing the net effect of all changes
1205          * done to java elements by the action.
1206          * </p>
1207          * <p>
1208          * If this method is called in the dynamic scope of another such
1209          * call, this method simply runs the action.
1210          * </p>
1211          *
1212          * @param action the action to perform
1213          * @param monitor a progress monitor, or <code>null</code> if progress
1214          *    reporting and cancellation are not desired
1215          * @exception CoreException if the operation failed.
1216          * @since 2.1
1217          */
1218   public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
1219     IWorkspace workspace = ResourcesPlugin.getWorkspace();
1220     if (workspace.isTreeLocked()) {
1221       new BatchOperation(action).run(monitor);
1222     } else {
1223       // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode
1224       workspace.run(new BatchOperation(action), monitor);
1225     }
1226   }
1227   
1228 /**
1229  * Adds the given listener for changes to Java elements.
1230  * Has no effect if an identical listener is already registered.
1231  *
1232  * This listener will only be notified during the POST_CHANGE resource change notification
1233  * and any reconcile operation (POST_RECONCILE).
1234  * For finer control of the notification, use <code>addElementChangedListener(IElementChangedListener,int)</code>,
1235  * which allows to specify a different eventMask.
1236  * 
1237  * @see ElementChangedEvent
1238  * @param listener the listener
1239  */
1240 public static void addElementChangedListener(IElementChangedListener listener) {
1241         addElementChangedListener(listener, ElementChangedEvent.POST_CHANGE | ElementChangedEvent.POST_RECONCILE);
1242 }
1243
1244 /**
1245  * Adds the given listener for changes to Java elements.
1246  * Has no effect if an identical listener is already registered.
1247  * After completion of this method, the given listener will be registered for exactly
1248  * the specified events.  If they were previously registered for other events, they
1249  * will be deregistered.  
1250  * <p>
1251  * Once registered, a listener starts receiving notification of changes to
1252  * java elements in the model. The listener continues to receive 
1253  * notifications until it is replaced or removed. 
1254  * </p>
1255  * <p>
1256  * Listeners can listen for several types of event as defined in <code>ElementChangeEvent</code>.
1257  * Clients are free to register for any number of event types however if they register
1258  * for more than one, it is their responsibility to ensure they correctly handle the
1259  * case where the same java element change shows up in multiple notifications.  
1260  * Clients are guaranteed to receive only the events for which they are registered.
1261  * </p>
1262  * 
1263  * @param listener the listener
1264  * @param eventMask the bit-wise OR of all event types of interest to the listener
1265  * @see IElementChangedListener
1266  * @see ElementChangedEvent
1267  * @see #removeElementChangedListener(IElementChangedListener)
1268  * @since 2.0
1269  */
1270 public static void addElementChangedListener(IElementChangedListener listener, int eventMask) {
1271         JavaModelManager.getJavaModelManager().addElementChangedListener(listener, eventMask);
1272 }
1273
1274 /**
1275  * Configures the given marker attribute map for the given Java element.
1276  * Used for markers, which denote a Java element rather than a resource.
1277  *
1278  * @param attributes the mutable marker attribute map (key type: <code>String</code>,
1279  *   value type: <code>String</code>)
1280  * @param element the Java element for which the marker needs to be configured
1281  */
1282 public static void addJavaElementMarkerAttributes(
1283         Map attributes,
1284         IJavaElement element) {
1285 //      if (element instanceof IMember)
1286 //              element = ((IMember) element).getClassFile();
1287         if (attributes != null && element != null)
1288                 attributes.put(ATT_HANDLE_ID, element.getHandleIdentifier());
1289 }
1290         
1291 /**
1292  * Configures the given marker for the given Java element.
1293  * Used for markers, which denote a Java element rather than a resource.
1294  *
1295  * @param marker the marker to be configured
1296  * @param element the Java element for which the marker needs to be configured
1297  * @exception CoreException if the <code>IMarker.setAttribute</code> on the marker fails
1298  */
1299 public void configureJavaElementMarker(IMarker marker, IJavaElement element)
1300         throws CoreException {
1301 //      if (element instanceof IMember)
1302 //              element = ((IMember) element).getClassFile();
1303         if (marker != null && element != null)
1304                 marker.setAttribute(ATT_HANDLE_ID, element.getHandleIdentifier());
1305 }
1306         
1307 /**
1308  * Returns the Java model element corresponding to the given handle identifier
1309  * generated by <code>IJavaElement.getHandleIdentifier()</code>, or
1310  * <code>null</code> if unable to create the associated element.
1311  */
1312 public static IJavaElement create(String handleIdentifier) {
1313         if (handleIdentifier == null) {
1314                 return null;
1315         }
1316         try {
1317                 return JavaModelManager.getJavaModelManager().getHandleFromMemento(handleIdentifier);
1318         } catch (JavaModelException e) {
1319                 return null;
1320         }
1321 }
1322 /**
1323  * Returns the Java element corresponding to the given file, or
1324  * <code>null</code> if unable to associate the given file
1325  * with a Java element.
1326  *
1327  * <p>The file must be one of:<ul>
1328  *      <li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
1329  *      <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
1330  *      <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
1331  *      </ul>
1332  * <p>
1333  * Creating a Java element has the side effect of creating and opening all of the
1334  * element's parents if they are not yet open.
1335  * 
1336  * @param the given file
1337  * @return the Java element corresponding to the given file, or
1338  * <code>null</code> if unable to associate the given file
1339  * with a Java element
1340  */
1341 public static IJavaElement create(IFile file) {
1342         return JavaModelManager.create(file, null);
1343 }
1344 /**
1345  * Returns the package fragment or package fragment root corresponding to the given folder, or
1346  * <code>null</code> if unable to associate the given folder with a Java element.
1347  * <p>
1348  * Note that a package fragment root is returned rather than a default package.
1349  * <p>
1350  * Creating a Java element has the side effect of creating and opening all of the
1351  * element's parents if they are not yet open.
1352  * 
1353  * @param the given folder
1354  * @return the package fragment or package fragment root corresponding to the given folder, or
1355  * <code>null</code> if unable to associate the given folder with a Java element
1356  */
1357 public static IJavaElement create(IFolder folder) {
1358         return JavaModelManager.create(folder, null);
1359 }
1360 /**
1361  * Returns the Java project corresponding to the given project.
1362  * <p>
1363  * Creating a Java Project has the side effect of creating and opening all of the
1364  * project's parents if they are not yet open.
1365  * <p>
1366  * Note that no check is done at this time on the existence or the java nature of this project.
1367  * 
1368  * @param project the given project
1369  * @return the Java project corresponding to the given project, null if the given project is null
1370  */
1371 public static IJavaProject create(IProject project) {
1372         if (project == null) {
1373                 return null;
1374         }
1375         JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
1376         return javaModel.getJavaProject(project);
1377 }
1378 /**
1379  * Returns the Java element corresponding to the given resource, or
1380  * <code>null</code> if unable to associate the given resource
1381  * with a Java element.
1382  * <p>
1383  * The resource must be one of:<ul>
1384  *      <li>a project - the element returned is the corresponding <code>IJavaProject</code></li>
1385  *      <li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
1386  *      <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
1387  *      <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
1388  *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
1389  *      or <code>IPackageFragment</code></li>
1390  *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
1391  *      </ul>
1392  * <p>
1393  * Creating a Java element has the side effect of creating and opening all of the
1394  * element's parents if they are not yet open.
1395  * 
1396  * @param resource the given resource
1397  * @return the Java element corresponding to the given resource, or
1398  * <code>null</code> if unable to associate the given resource
1399  * with a Java element
1400  */
1401 public static IJavaElement create(IResource resource) {
1402         return JavaModelManager.create(resource, null);
1403 }
1404 /**
1405  * Returns the Java model.
1406  * 
1407  * @param root the given root
1408  * @return the Java model, or <code>null</code> if the root is null
1409  */
1410 public static IJavaModel create(IWorkspaceRoot root) {
1411         if (root == null) {
1412                 return null;
1413         }
1414         return JavaModelManager.getJavaModelManager().getJavaModel();
1415 }
1416 /**
1417  * Creates and returns a class file element for
1418  * the given <code>.class</code> file. Returns <code>null</code> if unable
1419  * to recognize the class file.
1420  * 
1421  * @param file the given <code>.class</code> file
1422  * @return a class file element for the given <code>.class</code> file, or <code>null</code> if unable
1423  * to recognize the class file
1424  */
1425 //public static IClassFile createClassFileFrom(IFile file) {
1426 //      return JavaModelManager.createClassFileFrom(file, null);
1427 //}
1428 /**
1429  * Creates and returns a compilation unit element for
1430  * the given <code>.java</code> file. Returns <code>null</code> if unable
1431  * to recognize the compilation unit.
1432  * 
1433  * @param file the given <code>.java</code> file
1434  * @return a compilation unit element for the given <code>.java</code> file, or <code>null</code> if unable
1435  * to recognize the compilation unit
1436  */
1437 public static ICompilationUnit createCompilationUnitFrom(IFile file) {
1438         return JavaModelManager.createCompilationUnitFrom(file, null);
1439 }
1440 /**
1441  * Creates and returns a handle for the given JAR file.
1442  * The Java model associated with the JAR's project may be
1443  * created as a side effect. 
1444  * 
1445  * @param file the given JAR file
1446  * @return a handle for the given JAR file, or <code>null</code> if unable to create a JAR package fragment root.
1447  * (for example, if the JAR file represents a non-Java resource)
1448  */
1449 //public static IPackageFragmentRoot createJarPackageFragmentRootFrom(IFile file) {
1450 //      return JavaModelManager.createJarPackageFragmentRootFrom(file, null);
1451 //}
1452
1453 /** 
1454  * Answers the project specific value for a given classpath container.
1455  * In case this container path could not be resolved, then will answer <code>null</code>.
1456  * Both the container path and the project context are supposed to be non-null.
1457  * <p>
1458  * The containerPath is a formed by a first ID segment followed with extra segments, which can be 
1459  * used as additional hints for resolution. If no container was ever recorded for this container path 
1460  * onto this project (using <code>setClasspathContainer</code>, then a 
1461  * <code>ClasspathContainerInitializer</code> will be activated if any was registered for this container 
1462  * ID onto the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
1463  * <p>
1464  * There is no assumption that the returned container must answer the exact same containerPath
1465  * when requested <code>IClasspathContainer#getPath</code>. 
1466  * Indeed, the containerPath is just an indication for resolving it to an actual container object.
1467  * <p>
1468  * Classpath container values are persisted locally to the workspace, but 
1469  * are not preserved from a session to another. It is thus highly recommended to register a 
1470  * <code>ClasspathContainerInitializer</code> for each referenced container 
1471  * (through the extension point "org.eclipse.jdt.core.ClasspathContainerInitializer").
1472  * <p>
1473  * @param containerPath the name of the container, which needs to be resolved
1474  * @param project a specific project in which the container is being resolved
1475  * @return the corresponding classpath container or <code>null</code> if unable to find one.
1476  * 
1477  * @exception JavaModelException if an exception occurred while resolving the container, or if the resolved container
1478  *   contains illegal entries (contains CPE_CONTAINER entries or null entries).  
1479  * 
1480  * @see ClasspathContainerInitializer
1481  * @see IClasspathContainer
1482  * @see #setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)
1483  * @since 2.0
1484  */
1485 //public static IClasspathContainer getClasspathContainer(final IPath containerPath, final IJavaProject project) throws JavaModelException {
1486 //
1487 //      IClasspathContainer container = JavaModelManager.containerGet(project, containerPath);
1488 //      if (container == JavaModelManager.ContainerInitializationInProgress) return null; // break cycle
1489 //
1490 //      if (container == null){
1491 //              final ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
1492 //              if (initializer != null){
1493 //                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
1494 //                              System.out.println("CPContainer INIT - triggering initialization of: ["+project.getElementName()+"] " + containerPath + " using initializer: "+ initializer); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
1495 //                              new Exception("FAKE exception for dumping current CPContainer (["+project.getElementName()+"] "+ containerPath+ ")INIT invocation stack trace").printStackTrace(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
1496 //                      }
1497 //                      JavaModelManager.containerPut(project, containerPath, JavaModelManager.ContainerInitializationInProgress); // avoid initialization cycles
1498 //                      boolean ok = false;
1499 //                      try {
1500 //                              // wrap initializer call with Safe runnable in case initializer would be causing some grief
1501 //                              Platform.run(new ISafeRunnable() {
1502 //                                      public void handleException(Throwable exception) {
1503 //                                              Util.log(exception, "Exception occurred in classpath container initializer: "+initializer); //$NON-NLS-1$
1504 //                                      }
1505 //                                      public void run() throws Exception {
1506 //                                              initializer.initialize(containerPath, project);
1507 //                                      }
1508 //                              });
1509 //                                      
1510 //                              // retrieve value (if initialization was successful)
1511 //                              container = JavaModelManager.containerGet(project, containerPath);
1512 //                              if (container == JavaModelManager.ContainerInitializationInProgress) return null; // break cycle
1513 //                              ok = true;
1514 //                      } finally {
1515 //                              if (!ok) JavaModelManager.containerPut(project, containerPath, null); // flush cache
1516 //                      }
1517 //                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
1518 //                              System.out.print("CPContainer INIT - after resolution: ["+project.getElementName()+"] " + containerPath + " --> "); //$NON-NLS-2$//$NON-NLS-1$//$NON-NLS-3$
1519 //                              if (container != null){
1520 //                                      System.out.print("container: "+container.getDescription()+" {"); //$NON-NLS-2$//$NON-NLS-1$
1521 //                                      IClasspathEntry[] entries = container.getClasspathEntries();
1522 //                                      if (entries != null){
1523 //                                              for (int i = 0; i < entries.length; i++){
1524 //                                                      if (i > 0) System.out.println(", ");//$NON-NLS-1$
1525 //                                                      System.out.println(entries[i]);
1526 //                                              }
1527 //                                      }
1528 //                                      System.out.println("}");//$NON-NLS-1$
1529 //                              } else {
1530 //                                      System.out.println("{unbound}");//$NON-NLS-1$
1531 //                              }
1532 //                      }
1533 //              } else {
1534 //                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
1535 //                              System.out.println("CPContainer INIT - no initializer found for: "+project.getElementName()+"] " + containerPath); //$NON-NLS-1$ //$NON-NLS-2$
1536 //                      }
1537 //              }
1538 //      }
1539 //      return container;                       
1540 //}
1541
1542 /**
1543  * Helper method finding the classpath container initializer registered for a given classpath container ID 
1544  * or <code>null</code> if none was found while iterating over the contributions to extension point to
1545  * the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
1546  * <p>
1547  * A containerID is the first segment of any container path, used to identify the registered container initializer.
1548  * <p>
1549  * @param String - a containerID identifying a registered initializer
1550  * @return ClasspathContainerInitializer - the registered classpath container initializer or <code>null</code> if 
1551  * none was found.
1552  * @since 2.1
1553  */
1554 //public static ClasspathContainerInitializer getClasspathContainerInitializer(String containerID){
1555 //              
1556 //      Plugin jdtCorePlugin = JavaCore.getPlugin();
1557 //      if (jdtCorePlugin == null) return null;
1558 //
1559 //      IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.CPCONTAINER_INITIALIZER_EXTPOINT_ID);
1560 //      if (extension != null) {
1561 //              IExtension[] extensions =  extension.getExtensions();
1562 //              for(int i = 0; i < extensions.length; i++){
1563 //                      IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
1564 //                      for(int j = 0; j < configElements.length; j++){
1565 //                              String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$
1566 //                              if (initializerID != null && initializerID.equals(containerID)){
1567 //                                      if (JavaModelManager.CP_RESOLVE_VERBOSE) {
1568 //                                              System.out.println("CPContainer INIT - found initializer: "+containerID +" --> " + configElements[j].getAttribute("class"));//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
1569 //                                      }                                               
1570 //                                      try {
1571 //                                              Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
1572 //                                              if (execExt instanceof ClasspathContainerInitializer){
1573 //                                                      return (ClasspathContainerInitializer)execExt;
1574 //                                              }
1575 //                                      } catch(CoreException e) {
1576 //                                      }
1577 //                              }
1578 //                      }
1579 //              }       
1580 //      }
1581 //      return null;
1582 //}
1583
1584 /**
1585  * Returns the path held in the given classpath variable.
1586  * Returns <node>null</code> if unable to bind.
1587  * <p>
1588  * Classpath variable values are persisted locally to the workspace, and 
1589  * are preserved from session to session.
1590  * <p>
1591  * Note that classpath variables can be contributed registered initializers for,
1592  * using the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
1593  * If an initializer is registered for a variable, its persisted value will be ignored:
1594  * its initializer will thus get the opportunity to rebind the variable differently on
1595  * each session.
1596  *
1597  * @param variableName the name of the classpath variable
1598  * @return the path, or <code>null</code> if none 
1599  * @see #setClasspathVariable
1600  */
1601 public static IPath getClasspathVariable(final String variableName) {
1602         
1603         IPath variablePath = JavaModelManager.variableGet(variableName);
1604         if (variablePath == JavaModelManager.VariableInitializationInProgress) return null; // break cycle
1605                 
1606         if (variablePath != null) {
1607                 return variablePath;
1608         }
1609
1610         // even if persisted value exists, initializer is given priority, only if no initializer is found the persisted value is reused
1611 //      final ClasspathVariableInitializer initializer = PHPCore.getClasspathVariableInitializer(variableName);
1612 //      if (initializer != null){ 
1613 //              if (JavaModelManager.CP_RESOLVE_VERBOSE){
1614 //                      System.out.println("CPVariable INIT - triggering initialization of: " + variableName+ " using initializer: "+ initializer); //$NON-NLS-1$ //$NON-NLS-2$
1615 //                      new Exception("FAKE exception for dumping current CPVariable ("+variableName+ ")INIT invocation stack trace").printStackTrace(); //$NON-NLS-1$//$NON-NLS-2$
1616 //              }
1617 //              JavaModelManager.variablePut(variableName, JavaModelManager.VariableInitializationInProgress); // avoid initialization cycles
1618 //              boolean ok = false;
1619 //              try {
1620 //                      // wrap initializer call with Safe runnable in case initializer would be causing some grief
1621 //                      Platform.run(new ISafeRunnable() {
1622 //                              public void handleException(Throwable exception) {
1623 //                                      Util.log(exception, "Exception occurred in classpath variable initializer: "+initializer+" while initializing variable: "+variableName); //$NON-NLS-1$ //$NON-NLS-2$
1624 //                              }
1625 //                              public void run() throws Exception {
1626 //                                      initializer.initialize(variableName);
1627 //                              }
1628 //                      });
1629 //                      variablePath = (IPath) JavaModelManager.variableGet(variableName); // initializer should have performed side-effect
1630 //                      if (variablePath == JavaModelManager.VariableInitializationInProgress) return null; // break cycle (initializer did not init or reentering call)
1631 //                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
1632 //                              System.out.println("CPVariable INIT - after initialization: " + variableName + " --> " + variablePath); //$NON-NLS-2$//$NON-NLS-1$
1633 //                      }
1634 //                      ok = true;
1635 //              } finally {
1636 //                      if (!ok) JavaModelManager.variablePut(variableName, null); // flush cache
1637 //              }
1638 //      } else {
1639 //              if (JavaModelManager.CP_RESOLVE_VERBOSE){
1640 //                      System.out.println("CPVariable INIT - no initializer found for: " + variableName); //$NON-NLS-1$
1641 //              }
1642 //      }
1643         return variablePath;
1644 }
1645
1646 /**
1647  * Helper method finding the classpath variable initializer registered for a given classpath variable name 
1648  * or <code>null</code> if none was found while iterating over the contributions to extension point to
1649  * the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
1650  * <p>
1651  * @param the given variable
1652  * @return ClasspathVariableInitializer - the registered classpath variable initializer or <code>null</code> if 
1653  * none was found.
1654  * @since 2.1
1655  */
1656 public static ClasspathVariableInitializer getClasspathVariableInitializer(String variable){
1657                 
1658         Plugin jdtCorePlugin = PHPCore.getPlugin();
1659         if (jdtCorePlugin == null) return null;
1660
1661 //      IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID);
1662 //      if (extension != null) {
1663 //              IExtension[] extensions =  extension.getExtensions();
1664 //              for(int i = 0; i < extensions.length; i++){
1665 //                      IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
1666 //                      for(int j = 0; j < configElements.length; j++){
1667 //                              try {
1668 //                                      String varAttribute = configElements[j].getAttribute("variable"); //$NON-NLS-1$
1669 //                                      if (variable.equals(varAttribute)) {
1670 //                                              if (JavaModelManager.CP_RESOLVE_VERBOSE) {
1671 //                                                      System.out.println("CPVariable INIT - found initializer: "+variable+" --> " + configElements[j].getAttribute("class"));//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
1672 //                                              }                                               
1673 //                                              Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
1674 //                                              if (execExt instanceof ClasspathVariableInitializer){
1675 //                                                      return (ClasspathVariableInitializer)execExt;
1676 //                                              }
1677 //                                      }
1678 //                              } catch(CoreException e){
1679 //                              }
1680 //                              }
1681 //              }       
1682 //      }
1683         return null;
1684 }       
1685         
1686 /**
1687  * Returns the names of all known classpath variables.
1688  * <p>
1689  * Classpath variable values are persisted locally to the workspace, and 
1690  * are preserved from session to session.
1691  * <p>
1692  *
1693  * @return the list of classpath variable names
1694  * @see #setClasspathVariable
1695  */
1696 //public static String[] getClasspathVariableNames() {
1697 //      return JavaModelManager.variableNames();
1698 //}
1699
1700 /**
1701  * Returns a table of all known configurable options with their default values.
1702  * These options allow to configure the behaviour of the underlying components.
1703  * The client may safely use the result as a template that they can modify and
1704  * then pass to <code>setOptions</code>.
1705  * 
1706  * Helper constants have been defined on JavaCore for each of the option ID and 
1707  * their possible constant values.
1708  * 
1709  * Note: more options might be added in further releases.
1710  * <pre>
1711  * RECOGNIZED OPTIONS:
1712  * COMPILER / Generating Local Variable Debug Attribute
1713  *    When generated, this attribute will enable local variable names 
1714  *    to be displayed in debugger, only in place where variables are 
1715  *    definitely assigned (.class file is then bigger)
1716  *     - option id:         "org.eclipse.jdt.core.compiler.debug.localVariable"
1717  *     - possible values:   { "generate", "do not generate" }
1718  *     - default:           "generate"
1719  *
1720  * COMPILER / Generating Line Number Debug Attribute 
1721  *    When generated, this attribute will enable source code highlighting in debugger 
1722  *    (.class file is then bigger).
1723  *     - option id:         "org.eclipse.jdt.core.compiler.debug.lineNumber"
1724  *     - possible values:   { "generate", "do not generate" }
1725  *     - default:           "generate"
1726  *    
1727  * COMPILER / Generating Source Debug Attribute 
1728  *    When generated, this attribute will enable the debugger to present the 
1729  *    corresponding source code.
1730  *     - option id:         "org.eclipse.jdt.core.compiler.debug.sourceFile"
1731  *     - possible values:   { "generate", "do not generate" }
1732  *     - default:           "generate"
1733  *    
1734  * COMPILER / Preserving Unused Local Variables
1735  *    Unless requested to preserve unused local variables (that is, never read), the 
1736  *    compiler will optimize them out, potentially altering debugging
1737  *     - option id:         "org.eclipse.jdt.core.compiler.codegen.unusedLocal"
1738  *     - possible values:   { "preserve", "optimize out" }
1739  *     - default:           "preserve"
1740  * 
1741  * COMPILER / Defining Target Java Platform
1742  *    For binary compatibility reason, .class files can be tagged to with certain VM versions and later.
1743  *    Note that "1.4" target require to toggle compliance mode to "1.4" too.
1744  *     - option id:         "org.eclipse.jdt.core.compiler.codegen.targetPlatform"
1745  *     - possible values:   { "1.1", "1.2", "1.3", "1.4" }
1746  *     - default:           "1.1"
1747  *
1748  * COMPILER / Reporting Unreachable Code
1749  *    Unreachable code can optionally be reported as an error, warning or simply 
1750  *    ignored. The bytecode generation will always optimized it out.
1751  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unreachableCode"
1752  *     - possible values:   { "error", "warning", "ignore" }
1753  *     - default:           "error"
1754  *
1755  * COMPILER / Reporting Invalid Import
1756  *    An import statement that cannot be resolved might optionally be reported 
1757  *    as an error, as a warning or ignored.
1758  *     - option id:         "org.eclipse.jdt.core.compiler.problem.invalidImport"
1759  *     - possible values:   { "error", "warning", "ignore" }
1760  *     - default:           "error"
1761  *
1762  * COMPILER / Reporting Attempt to Override Package-Default Method
1763  *    A package default method is not visible in a different package, and thus 
1764  *    cannot be overridden. When enabling this option, the compiler will signal 
1765  *    such scenarii either as an error or a warning.
1766  *     - option id:         "org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod"
1767  *     - possible values:   { "error", "warning", "ignore" }
1768  *     - default:           "warning"
1769  *
1770  * COMPILER / Reporting Method With Constructor Name
1771  *    Naming a method with a constructor name is generally considered poor 
1772  *    style programming. When enabling this option, the compiler will signal such 
1773  *    scenarii either as an error or a warning.
1774  *     - option id:         "org.eclipse.jdt.core.compiler.problem.methodWithConstructorName"
1775  *     - possible values:   { "error", "warning", "ignore" }
1776  *     - default:           "warning"
1777  *
1778  * COMPILER / Reporting Deprecation
1779  *    When enabled, the compiler will signal use of deprecated API either as an 
1780  *    error or a warning.
1781  *     - option id:         "org.eclipse.jdt.core.compiler.problem.deprecation"
1782  *     - possible values:   { "error", "warning", "ignore" }
1783  *     - default:           "warning"
1784  *
1785  * COMPILER / Reporting Deprecation Inside Deprecated Code
1786  *    When enabled, the compiler will signal use of deprecated API inside deprecated code.
1787  *    The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.deprecation".
1788  *     - option id:         "org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode"
1789  *     - possible values:   { "enabled", "disabled" }
1790  *     - default:           "disabled"
1791  *
1792  * COMPILER / Reporting Hidden Catch Block
1793  *    Locally to a try statement, some catch blocks may hide others . For example,
1794  *      try {  throw new java.io.CharConversionException();
1795  *      } catch (java.io.CharConversionException e) {
1796  *      } catch (java.io.IOException e) {}. 
1797  *    When enabling this option, the compiler will issue an error or a warning for hidden 
1798  *    catch blocks corresponding to checked exceptions
1799  *     - option id:         "org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock"
1800  *     - possible values:   { "error", "warning", "ignore" }
1801  *     - default:           "warning"
1802  *
1803  * COMPILER / Reporting Unused Local
1804  *    When enabled, the compiler will issue an error or a warning for unused local 
1805  *    variables (that is, variables never read from)
1806  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedLocal"
1807  *     - possible values:   { "error", "warning", "ignore" }
1808  *     - default:           "ignore"
1809  *
1810  * COMPILER / Reporting Unused Parameter
1811  *    When enabled, the compiler will issue an error or a warning for unused method 
1812  *    parameters (that is, parameters never read from)
1813  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedParameter"
1814  *     - possible values:   { "error", "warning", "ignore" }
1815  *     - default:           "ignore"
1816  *
1817  * COMPILER / Reporting Unused Parameter if Implementing Abstract Method
1818  *    When enabled, the compiler will signal unused parameters in abstract method implementations.
1819  *    The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.unusedParameter".
1820  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract"
1821  *     - possible values:   { "enabled", "disabled" }
1822  *     - default:           "disabled"
1823  *
1824  * COMPILER / Reporting Unused Parameter if Overriding Concrete Method
1825  *    When enabled, the compiler will signal unused parameters in methods overriding concrete ones.
1826  *    The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.unusedParameter".
1827  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete"
1828  *     - possible values:   { "enabled", "disabled" }
1829  *     - default:           "disabled"
1830  *
1831  * COMPILER / Reporting Unused Import
1832  *    When enabled, the compiler will issue an error or a warning for unused import 
1833  *    reference 
1834  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedImport"
1835  *     - possible values:   { "error", "warning", "ignore" }
1836  *     - default:           "warning"
1837  *
1838  * COMPILER / Reporting Unused Private Members
1839  *    When enabled, the compiler will issue an error or a warning whenever a private 
1840  *    method or field is declared but never used within the same unit.
1841  *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedPrivateMember"
1842  *     - possible values:   { "error", "warning", "ignore" }
1843  *     - default:           "ignore"
1844  *
1845  * COMPILER / Reporting Synthetic Access Emulation
1846  *    When enabled, the compiler will issue an error or a warning whenever it emulates 
1847  *    access to a non-accessible member of an enclosing type. Such access can have
1848  *    performance implications.
1849  *     - option id:         "org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation"
1850  *     - possible values:   { "error", "warning", "ignore" }
1851  *     - default:           "ignore"
1852  *
1853  * COMPILER / Reporting Non-Externalized String Literal
1854  *    When enabled, the compiler will issue an error or a warning for non externalized 
1855  *    String literal (that is, not tagged with //$NON-NLS-<n>$). 
1856  *     - option id:         "org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral"
1857  *     - possible values:   { "error", "warning", "ignore" }
1858  *     - default:           "ignore"
1859  * 
1860  * COMPILER / Reporting Usage of 'assert' Identifier
1861  *    When enabled, the compiler will issue an error or a warning whenever 'assert' is 
1862  *    used as an identifier (reserved keyword in 1.4)
1863  *     - option id:         "org.eclipse.jdt.core.compiler.problem.assertIdentifier"
1864  *     - possible values:   { "error", "warning", "ignore" }
1865  *     - default:           "ignore"
1866  * 
1867  * COMPILER / Reporting Non-Static Reference to a Static Member
1868  *    When enabled, the compiler will issue an error or a warning whenever a static field
1869  *    or method is accessed with an expression receiver. A reference to a static member should
1870  *    be qualified with a type name.
1871  *     - option id:         "org.eclipse.jdt.core.compiler.problem.staticAccessReceiver"
1872  *     - possible values:   { "error", "warning", "ignore" }
1873  *     - default:           "warning"
1874  * 
1875  * COMPILER / Reporting Assignment with no Effect
1876  *    When enabled, the compiler will issue an error or a warning whenever an assignment
1877  *    has no effect (e.g 'x = x').
1878  *     - option id:         "org.eclipse.jdt.core.compiler.problem.noEffectAssignment"
1879  *     - possible values:   { "error", "warning", "ignore" }
1880  *     - default:           "warning"
1881  * 
1882  * COMPILER / Reporting Interface Method not Compatible with non-Inherited Methods
1883  *    When enabled, the compiler will issue an error or a warning whenever an interface
1884  *    defines a method incompatible with a non-inherited Object method. Until this conflict
1885  *    is resolved, such an interface cannot be implemented, For example, 
1886  *      interface I { 
1887  *         int clone();
1888  *      } 
1889  *     - option id:         "org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod"
1890  *     - possible values:   { "error", "warning", "ignore" }
1891  *     - default:           "warning"
1892  * 
1893  * COMPILER / Reporting Usage of char[] Expressions in String Concatenations
1894  *    When enabled, the compiler will issue an error or a warning whenever a char[] expression
1895  *    is used in String concatenations (for example, "hello" + new char[]{'w','o','r','l','d'}).
1896  *     - option id:         "org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion"
1897  *     - possible values:   { "error", "warning", "ignore" }
1898  *     - default:           "warning"
1899  *
1900  * COMPILER / Setting Source Compatibility Mode
1901  *    Specify whether source is 1.3 or 1.4 compatible. From 1.4 on, 'assert' is a keyword
1902  *    reserved for assertion support. Also note, than when toggling to 1.4 mode, the target VM
1903  *   level should be set to "1.4" and the compliance mode should be "1.4".
1904  *     - option id:         "org.eclipse.jdt.core.compiler.source"
1905  *     - possible values:   { "1.3", "1.4" }
1906  *     - default:           "1.3"
1907  * 
1908  * COMPILER / Setting Compliance Level
1909  *    Select the compliance level for the compiler. In "1.3" mode, source and target settings
1910  *    should not go beyond "1.3" level.
1911  *     - option id:         "org.eclipse.jdt.core.compiler.compliance"
1912  *     - possible values:   { "1.3", "1.4" }
1913  *     - default:           "1.3"
1914  * 
1915  * COMPILER / Maximum number of problems reported per compilation unit
1916  *    Specify the maximum number of problems reported on each compilation unit.
1917  *     - option id:         "org.eclipse.jdt.core.compiler.maxProblemPerUnit"
1918  *     - possible values:       "<n>" where <n> is zero or a positive integer (if zero then all problems are reported).
1919  *     - default:           "100"
1920  * 
1921  * COMPILER / Define the Automatic Task Tags
1922  *    When the tag list is not empty, the compiler will issue a task marker whenever it encounters
1923  *    one of the corresponding tag inside any comment in Java source code.
1924  *    Generated task messages will include the tag, and range until the next line separator or comment ending.
1925  *    Note that tasks messages are trimmed.
1926  *     - option id:         "org.eclipse.jdt.core.compiler.taskTags"
1927  *     - possible values:   { "<tag>[,<tag>]*" } where <tag> is a String without any wild-card or leading/trailing spaces 
1928  *     - default:           ""
1929  * 
1930  * COMPILER / Define the Automatic Task Priorities
1931  *    In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low)
1932  *    of the task markers issued by the compiler.
1933  *    If the default is specified, the priority of each task marker is "NORMAL".
1934  *     - option id:         "org.eclipse.jdt.core.compiler.taskPriorities"
1935  *     - possible values:   { "<priority>[,<priority>]*" } where <priority> is one of "HIGH", "NORMAL" or "LOW"
1936  *     - default:           ""
1937  *
1938  * BUILDER / Specifying Filters for Resource Copying Control
1939  *    Allow to specify some filters to control the resource copy process.
1940  *     - option id:         "org.eclipse.jdt.core.builder.resourceCopyExclusionFilter"
1941  *     - possible values:   { "<name>[,<name>]* } where <name> is a file name pattern (* and ? wild-cards allowed)
1942  *       or the name of a folder which ends with '/'
1943  *     - default:           ""
1944  * 
1945  * BUILDER / Abort if Invalid Classpath
1946  *    Allow to toggle the builder to abort if the classpath is invalid
1947  *     - option id:         "org.eclipse.jdt.core.builder.invalidClasspath"
1948  *     - possible values:   { "abort", "ignore" }
1949  *     - default:           "abort"
1950  * 
1951  * BUILDER / Cleaning Output Folder(s)
1952  *    Indicate whether the JavaBuilder is allowed to clean the output folders
1953  *    when performing full build operations.
1954  *     - option id:         "org.eclipse.jdt.core.builder.cleanOutputFolder"
1955  *     - possible values:   { "clean", "ignore" }
1956  *     - default:           "clean"
1957  * 
1958  * BUILDER / Reporting Duplicate Resources
1959  *    Indicate the severity of the problem reported when more than one occurrence
1960  *    of a resource is to be copied into the output location.
1961  *     - option id:         "org.eclipse.jdt.core.builder.duplicateResourceTask"
1962  *     - possible values:   { "error", "warning" }
1963  *     - default:           "warning"
1964  * 
1965  * JAVACORE / Computing Project Build Order
1966  *    Indicate whether JavaCore should enforce the project build order to be based on
1967  *    the classpath prerequisite chain. When requesting to compute, this takes over
1968  *    the platform default order (based on project references).
1969  *     - option id:         "org.eclipse.jdt.core.computeJavaBuildOrder"
1970  *     - possible values:   { "compute", "ignore" }
1971  *     - default:           "ignore"     
1972  * 
1973  * JAVACORE / Specify Default Source Encoding Format
1974  *    Get the encoding format for compiled sources. This setting is read-only, it is equivalent
1975  *    to 'ResourcesPlugin.getEncoding()'.
1976  *     - option id:         "org.eclipse.jdt.core.encoding"
1977  *     - possible values:   { any of the supported encoding name}.
1978  *     - default:           <platform default>
1979  * 
1980  * JAVACORE / Reporting Incomplete Classpath
1981  *    Indicate the severity of the problem reported when an entry on the classpath does not exist, 
1982  *    is not legite or is not visible (for example, a referenced project is closed).
1983  *     - option id:         "org.eclipse.jdt.core.incompleteClasspath"
1984  *     - possible values:   { "error", "warning"}
1985  *     - default:           "error"
1986  * 
1987  * JAVACORE / Reporting Classpath Cycle
1988  *    Indicate the severity of the problem reported when a project is involved in a cycle.
1989  *     - option id:         "org.eclipse.jdt.core.circularClasspath"
1990  *     - possible values:   { "error", "warning" }
1991  *     - default:           "error"
1992  * 
1993  * JAVACORE / Enabling Usage of Classpath Exclusion Patterns
1994  *    When disabled, no entry on a project classpath can be associated with
1995  *    an exclusion pattern.
1996  *     - option id:         "org.eclipse.jdt.core.classpath.exclusionPatterns"
1997  *     - possible values:   { "enabled", "disabled" }
1998  *     - default:           "enabled"
1999  * 
2000  * JAVACORE / Enabling Usage of Classpath Multiple Output Locations
2001  *    When disabled, no entry on a project classpath can be associated with
2002  *    a specific output location, preventing thus usage of multiple output locations.
2003  *     - option id:         "org.eclipse.jdt.core.classpath.multipleOutputLocations"
2004  *     - possible values:   { "enabled", "disabled" }
2005  *     - default:           "enabled"
2006  * 
2007  *      FORMATTER / Inserting New Line Before Opening Brace
2008  *    When Insert, a new line is inserted before an opening brace, otherwise nothing
2009  *    is inserted
2010  *     - option id:         "org.eclipse.jdt.core.formatter.newline.openingBrace"
2011  *     - possible values:   { "insert", "do not insert" }
2012  *     - default:           "do not insert"
2013  * 
2014  *      FORMATTER / Inserting New Line Inside Control Statement
2015  *    When Insert, a new line is inserted between } and following else, catch, finally
2016  *     - option id:         "org.eclipse.jdt.core.formatter.newline.controlStatement"
2017  *     - possible values:   { "insert", "do not insert" }
2018  *     - default:           "do not insert"
2019  * 
2020  *      FORMATTER / Clearing Blank Lines
2021  *    When Clear all, all blank lines are removed. When Preserve one, only one is kept
2022  *    and all others removed.
2023  *     - option id:         "org.eclipse.jdt.core.formatter.newline.clearAll"
2024  *     - possible values:   { "clear all", "preserve one" }
2025  *     - default:           "preserve one"
2026  * 
2027  *      FORMATTER / Inserting New Line Between Else/If 
2028  *    When Insert, a blank line is inserted between an else and an if when they are 
2029  *    contiguous. When choosing to not insert, else-if will be kept on the same
2030  *    line when possible.
2031  *     - option id:         "org.eclipse.jdt.core.formatter.newline.elseIf"
2032  *     - possible values:   { "insert", "do not insert" }
2033  *     - default:           "do not insert"
2034  * 
2035  *      FORMATTER / Inserting New Line In Empty Block
2036  *    When insert, a line break is inserted between contiguous { and }, if } is not followed
2037  *    by a keyword.
2038  *     - option id:         "org.eclipse.jdt.core.formatter.newline.emptyBlock"
2039  *     - possible values:   { "insert", "do not insert" }
2040  *     - default:           "insert"
2041  * 
2042  *      FORMATTER / Splitting Lines Exceeding Length
2043  *    Enable splitting of long lines (exceeding the configurable length). Length of 0 will
2044  *    disable line splitting
2045  *     - option id:         "org.eclipse.jdt.core.formatter.lineSplit"
2046  *     - possible values:       "<n>", where n is zero or a positive integer
2047  *     - default:           "80"
2048  * 
2049  *      FORMATTER / Compacting Assignment
2050  *    Assignments can be formatted asymmetrically, for example 'int x= 2;', when Normal, a space
2051  *    is inserted before the assignment operator
2052  *     - option id:         "org.eclipse.jdt.core.formatter.style.assignment"
2053  *     - possible values:   { "compact", "normal" }
2054  *     - default:           "normal"
2055  * 
2056  *      FORMATTER / Defining Indentation Character
2057  *    Either choose to indent with tab characters or spaces
2058  *     - option id:         "org.eclipse.jdt.core.formatter.tabulation.char"
2059  *     - possible values:   { "tab", "space" }
2060  *     - default:           "tab"
2061  * 
2062  *      FORMATTER / Defining Space Indentation Length
2063  *    When using spaces, set the amount of space characters to use for each 
2064  *    indentation mark.
2065  *     - option id:         "org.eclipse.jdt.core.formatter.tabulation.size"
2066  *     - possible values:       "<n>", where n is a positive integer
2067  *     - default:           "4"
2068  * 
2069  *      FORMATTER / Inserting space in cast expression
2070  *    When Insert, a space is added between the type and the expression in a cast expression.
2071  *     - option id:         "org.eclipse.jdt.core.formatter.space.castexpression"
2072  *     - possible values:   { "insert", "do not insert" }
2073  *     - default:           "insert"
2074  * 
2075  *      CODEASSIST / Activate Visibility Sensitive Completion
2076  *    When active, completion doesn't show that you can not see
2077  *    (for example, you can not see private methods of a super class).
2078  *     - option id:         "org.eclipse.jdt.core.codeComplete.visibilityCheck"
2079  *     - possible values:   { "enabled", "disabled" }
2080  *     - default:           "disabled"
2081  * 
2082  *      CODEASSIST / Automatic Qualification of Implicit Members
2083  *    When active, completion automatically qualifies completion on implicit
2084  *    field references and message expressions.
2085  *     - option id:         "org.eclipse.jdt.core.codeComplete.forceImplicitQualification"
2086  *     - possible values:   { "enabled", "disabled" }
2087  *     - default:           "disabled"
2088  * 
2089  *  CODEASSIST / Define the Prefixes for Field Name
2090  *    When the prefixes is non empty, completion for field name will begin with
2091  *    one of the proposed prefixes.
2092  *     - option id:         "org.eclipse.jdt.core.codeComplete.fieldPrefixes"
2093  *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
2094  *     - default:           ""
2095  * 
2096  *  CODEASSIST / Define the Prefixes for Static Field Name
2097  *    When the prefixes is non empty, completion for static field name will begin with
2098  *    one of the proposed prefixes.
2099  *     - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"
2100  *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
2101  *     - default:           ""
2102  * 
2103  *  CODEASSIST / Define the Prefixes for Local Variable Name
2104  *    When the prefixes is non empty, completion for local variable name will begin with
2105  *    one of the proposed prefixes.
2106  *     - option id:         "org.eclipse.jdt.core.codeComplete.localPrefixes"
2107  *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
2108  *     - default:           ""
2109  * 
2110  *  CODEASSIST / Define the Prefixes for Argument Name
2111  *    When the prefixes is non empty, completion for argument name will begin with
2112  *    one of the proposed prefixes.
2113  *     - option id:         "org.eclipse.jdt.core.codeComplete.argumentPrefixes"
2114  *     - possible values:   { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card 
2115  *     - default:           ""
2116  * 
2117  *  CODEASSIST / Define the Suffixes for Field Name
2118  *    When the suffixes is non empty, completion for field name will end with
2119  *    one of the proposed suffixes.
2120  *     - option id:         "org.eclipse.jdt.core.codeComplete.fieldSuffixes"
2121  *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
2122  *     - default:           ""
2123  * 
2124  *  CODEASSIST / Define the Suffixes for Static Field Name
2125  *    When the suffixes is non empty, completion for static field name will end with
2126  *    one of the proposed suffixes.
2127  *     - option id:         "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"
2128  *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
2129  *     - default:           ""
2130  * 
2131  *  CODEASSIST / Define the Suffixes for Local Variable Name
2132  *    When the suffixes is non empty, completion for local variable name will end with
2133  *    one of the proposed suffixes.
2134  *     - option id:         "org.eclipse.jdt.core.codeComplete.localSuffixes"
2135  *     - possible values:   { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card 
2136  *     - default:           ""
2137  * 
2138  *  CODEASSIST / Define the Suffixes for Argument Name
2139  *    When the suffixes is non empty, completion for argument name will end with
2140  *    one of the proposed suffixes.
2141  *     - option id:         "org.eclipse.jdt.core.codeComplete.argumentSuffixes"
2142  *     - possible values:   { "<suffix>[,<suffix>]*" } where <prefix> is a String without any wild-card 
2143  *     - default:           ""
2144  * </pre>
2145  * 
2146  * @return a mutable table containing the default settings of all known options
2147  *   (key type: <code>String</code>; value type: <code>String</code>)
2148  * @see #setOptions
2149  */
2150 public static Hashtable getDefaultOptions(){
2151         
2152         Hashtable defaultOptions = new Hashtable(10);
2153
2154         // see #initializeDefaultPluginPreferences() for changing default settings
2155         Preferences preferences = getPlugin().getPluginPreferences();
2156         HashSet optionNames = JavaModelManager.OptionNames;
2157                 
2158         // get preferences set to their default
2159         String[] defaultPropertyNames = preferences.defaultPropertyNames();
2160         for (int i = 0; i < defaultPropertyNames.length; i++){
2161                 String propertyName = defaultPropertyNames[i];
2162                 if (optionNames.contains(propertyName)) {
2163                         defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
2164                 }
2165         }               
2166         // get preferences not set to their default
2167         String[] propertyNames = preferences.propertyNames();
2168         for (int i = 0; i < propertyNames.length; i++){
2169                 String propertyName = propertyNames[i];
2170                 if (optionNames.contains(propertyName)) {
2171                         defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
2172                 }
2173         }               
2174         // get encoding through resource plugin
2175         defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding()); 
2176                 
2177         return defaultOptions;
2178 }
2179
2180 /**
2181  * Returns the single instance of the Java core plug-in runtime class.
2182  * Equivalent to <code>(JavaCore) getPlugin()</code>.
2183  * 
2184  * @return the single instance of the Java core plug-in runtime class
2185  */
2186 public static PHPeclipsePlugin getJavaCore() {
2187         return (PHPeclipsePlugin) getPlugin();
2188 }
2189         
2190 /**
2191  * Helper method for returning one option value only. Equivalent to <code>(String)JavaCore.getOptions().get(optionName)</code>
2192  * Note that it may answer <code>null</code> if this option does not exist.
2193  * <p>
2194  * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
2195  * </p>
2196  * 
2197  * @param optionName the name of an option
2198  * @return the String value of a given option
2199  * @see JavaCore#getDefaultOptions
2200  * @since 2.0
2201  */
2202 public static String getOption(String optionName) {
2203                 
2204         if (CORE_ENCODING.equals(optionName)){
2205                 return ResourcesPlugin.getEncoding();
2206         }
2207         if (JavaModelManager.OptionNames.contains(optionName)){
2208                 Preferences preferences = getPlugin().getPluginPreferences();
2209                 return preferences.getString(optionName).trim();
2210         }
2211         return null;
2212 }
2213         
2214 /**
2215  * Returns the table of the current options. Initially, all options have their default values,
2216  * and this method returns a table that includes all known options.
2217  * <p>
2218  * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
2219  * </p>
2220  * 
2221  * @return table of current settings of all options 
2222  *   (key type: <code>String</code>; value type: <code>String</code>)
2223  * @see JavaCore#getDefaultOptions
2224  */
2225 public static Hashtable getOptions() {
2226                 
2227         Hashtable options = new Hashtable(10);
2228
2229         // see #initializeDefaultPluginPreferences() for changing default settings
2230         Plugin plugin = getPlugin();
2231         if (plugin != null) {
2232                 Preferences preferences = getPlugin().getPluginPreferences();
2233                 HashSet optionNames = JavaModelManager.OptionNames;
2234                         
2235                 // get preferences set to their default
2236                 String[] defaultPropertyNames = preferences.defaultPropertyNames();
2237                 for (int i = 0; i < defaultPropertyNames.length; i++){
2238                         String propertyName = defaultPropertyNames[i];
2239                         if (optionNames.contains(propertyName)){
2240                                 options.put(propertyName, preferences.getDefaultString(propertyName));
2241                         }
2242                 }               
2243                 // get preferences not set to their default
2244                 String[] propertyNames = preferences.propertyNames();
2245                 for (int i = 0; i < propertyNames.length; i++){
2246                         String propertyName = propertyNames[i];
2247                         if (optionNames.contains(propertyName)){
2248                                 options.put(propertyName, preferences.getString(propertyName).trim());
2249                         }
2250                 }               
2251                 // get encoding through resource plugin
2252                 options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
2253         }
2254         return options;
2255 }
2256                 
2257 /**
2258  * This is a helper method, which returns the resolved classpath entry denoted 
2259  * by a given entry (if it is a variable entry). It is obtained by resolving the variable 
2260  * reference in the first segment. Returns <node>null</code> if unable to resolve using 
2261  * the following algorithm:
2262  * <ul>
2263  * <li> if variable segment cannot be resolved, returns <code>null</code></li>
2264  * <li> finds a project, JAR or binary folder in the workspace at the resolved path location</li>
2265  * <li> if none finds an external JAR file or folder outside the workspace at the resolved path location </li>
2266  * <li> if none returns <code>null</code></li>
2267  * </ul>
2268  * <p>
2269  * Variable source attachment path and root path are also resolved and recorded in the resulting classpath entry.
2270  * <p>
2271  * NOTE: This helper method does not handle classpath containers, for which should rather be used
2272  * <code>JavaCore#getClasspathContainer(IPath, IJavaProject)</code>.
2273  * <p>
2274  * 
2275  * @param entry the given variable entry
2276  * @return the resolved library or project classpath entry, or <code>null</code>
2277  *   if the given variable entry could not be resolved to a valid classpath entry
2278  */
2279 public static IClasspathEntry getResolvedClasspathEntry(IClasspathEntry entry) {
2280         
2281         if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
2282                 return entry;
2283         
2284         IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
2285         IPath resolvedPath = PHPCore.getResolvedVariablePath(entry.getPath());
2286         if (resolvedPath == null)
2287                 return null;
2288         
2289         Object target = JavaModel.getTarget(workspaceRoot, resolvedPath, false);
2290         if (target == null)
2291                 return null;
2292         
2293         // inside the workspace
2294         if (target instanceof IResource) {
2295                 IResource resolvedResource = (IResource) target;
2296                 if (resolvedResource != null) {
2297                         switch (resolvedResource.getType()) {
2298                                         
2299                                 case IResource.PROJECT :  
2300                                         // internal project
2301                                         return PHPCore.newProjectEntry(resolvedPath, entry.isExported());
2302                                                 
2303                                 case IResource.FILE : 
2304 //                                      if (Util.isArchiveFileName(resolvedResource.getName())) {
2305 //                                              // internal binary archive
2306 //                                              return JavaCore.newLibraryEntry(
2307 //                                                              resolvedPath,
2308 //                                                              getResolvedVariablePath(entry.getSourceAttachmentPath()),
2309 //                                                              getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
2310 //                                                              entry.isExported());
2311 //                                      }
2312                                         break;
2313                                                 
2314                                 case IResource.FOLDER : 
2315                                         // internal binary folder
2316 //                                      return JavaCore.newLibraryEntry(
2317 //                                                      resolvedPath,
2318 //                                                      getResolvedVariablePath(entry.getSourceAttachmentPath()),
2319 //                                                      getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
2320 //                                                      entry.isExported());
2321           break;
2322                         }
2323                 }
2324         }
2325         // outside the workspace
2326         if (target instanceof File) {
2327                 File externalFile = (File) target;
2328                 if (externalFile.isFile()) {
2329                         String fileName = externalFile.getName().toLowerCase();
2330 //                      if (fileName.endsWith(".jar"  //$NON-NLS-1$
2331 //                              ) || fileName.endsWith(".zip"  //$NON-NLS-1$
2332 //                              )) { // external binary archive
2333 //                              return JavaCore.newLibraryEntry(
2334 //                                              resolvedPath,
2335 //                                              getResolvedVariablePath(entry.getSourceAttachmentPath()),
2336 //                                              getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
2337 //                                              entry.isExported());
2338 //                      }
2339                 } else { // external binary folder
2340                         if (resolvedPath.isAbsolute()){
2341 //                              return JavaCore.newLibraryEntry(
2342 //                                              resolvedPath,
2343 //                                              getResolvedVariablePath(entry.getSourceAttachmentPath()),
2344 //                                              getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
2345 //                                              entry.isExported());
2346                         }
2347                 }
2348         }
2349         return null;
2350 }
2351
2352
2353 /**
2354  * Resolve a variable path (helper method).
2355  * 
2356  * @param variablePath the given variable path
2357  * @return the resolved variable path or <code>null</code> if none
2358  */
2359 public static IPath getResolvedVariablePath(IPath variablePath) {
2360         
2361         if (variablePath == null)
2362                 return null;
2363         int count = variablePath.segmentCount();
2364         if (count == 0)
2365                 return null;
2366         
2367         // lookup variable      
2368         String variableName = variablePath.segment(0);
2369         IPath resolvedPath = PHPCore.getClasspathVariable(variableName);
2370         if (resolvedPath == null)
2371                 return null;
2372         
2373         // append path suffix
2374         if (count > 1) {
2375                 resolvedPath = resolvedPath.append(variablePath.removeFirstSegments(1));
2376         }
2377         return resolvedPath; 
2378 }
2379
2380 /**
2381  * Answers the shared working copies currently registered for this buffer factory. 
2382  * Working copies can be shared by several clients using the same buffer factory,see 
2383  * <code>IWorkingCopy.getSharedWorkingCopy</code>.
2384  * 
2385  * @param factory the given buffer factory
2386  * @return the list of shared working copies for a given buffer factory
2387  * @see IWorkingCopy
2388  * @since 2.0
2389  */
2390 public static IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory){
2391                 
2392         // if factory is null, default factory must be used
2393         if (factory == null) factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
2394         Map sharedWorkingCopies = JavaModelManager.getJavaModelManager().sharedWorkingCopies;
2395                 
2396         Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
2397         if (perFactoryWorkingCopies == null) return JavaModelManager.NoWorkingCopy;
2398         Collection copies = perFactoryWorkingCopies.values();
2399         IWorkingCopy[] result = new IWorkingCopy[copies.size()];
2400         copies.toArray(result);
2401         return result;
2402 }
2403         
2404 /**
2405  * Initializes the default preferences settings for this plug-in.
2406  */
2407 protected static void initializeDefaultPluginPreferences() {
2408                 
2409         Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
2410         HashSet optionNames = JavaModelManager.OptionNames;
2411                 
2412         // Compiler settings
2413         preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
2414         optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
2415
2416         preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE); 
2417         optionNames.add(COMPILER_LINE_NUMBER_ATTR);
2418
2419         preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE); 
2420         optionNames.add(COMPILER_SOURCE_FILE_ATTR);
2421
2422         preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); 
2423         optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
2424
2425         preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1); 
2426         optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
2427
2428         preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); 
2429         optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
2430
2431         preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR); 
2432         optionNames.add(COMPILER_PB_INVALID_IMPORT);
2433
2434         preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING); 
2435         optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
2436
2437         preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING); 
2438         optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
2439
2440         preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
2441         optionNames.add(COMPILER_PB_DEPRECATION);
2442
2443         preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
2444         optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
2445
2446         preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING); 
2447         optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
2448
2449         preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE); 
2450         optionNames.add(COMPILER_PB_UNUSED_LOCAL);
2451
2452         preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE); 
2453         optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
2454
2455         preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT, DISABLED); 
2456         optionNames.add(COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT);
2457
2458         preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE, DISABLED); 
2459         optionNames.add(COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE);
2460
2461         preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING); 
2462         optionNames.add(COMPILER_PB_UNUSED_IMPORT);
2463
2464         preferences.setDefault(COMPILER_PB_UNUSED_PRIVATE_MEMBER, IGNORE); 
2465         optionNames.add(COMPILER_PB_UNUSED_PRIVATE_MEMBER);
2466
2467         preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE); 
2468         optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
2469
2470         preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE); 
2471         optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
2472
2473         preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE); 
2474         optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
2475
2476         preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING); 
2477         optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
2478
2479         preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING); 
2480         optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
2481
2482         preferences.setDefault(COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD, WARNING); 
2483         optionNames.add(COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD);
2484
2485         preferences.setDefault(COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION, WARNING); 
2486         optionNames.add(COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION);
2487
2488         preferences.setDefault(COMPILER_TASK_TAGS, DEFAULT_TASK_TAG); //$NON-NLS-1$
2489         optionNames.add(COMPILER_TASK_TAGS);
2490
2491         preferences.setDefault(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITY); //$NON-NLS-1$
2492         optionNames.add(COMPILER_TASK_PRIORITIES);
2493
2494         preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
2495         optionNames.add(COMPILER_SOURCE);
2496
2497         preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3); 
2498         optionNames.add(COMPILER_COMPLIANCE);
2499
2500         preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
2501         optionNames.add(COMPILER_PB_MAX_PER_UNIT);
2502                 
2503         // Builder settings
2504         preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
2505         optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
2506
2507         preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
2508         optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
2509         
2510         preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
2511         optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
2512                 
2513         preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
2514         optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
2515
2516         // JavaCore settings
2517         preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
2518         optionNames.add(CORE_JAVA_BUILD_ORDER);
2519         
2520         preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
2521         optionNames.add(CORE_CIRCULAR_CLASSPATH);
2522                 
2523         preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
2524         optionNames.add(CORE_INCOMPLETE_CLASSPATH);
2525                 
2526         preferences.setDefault(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED); 
2527         optionNames.add(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
2528
2529         preferences.setDefault(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED); 
2530         optionNames.add(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
2531
2532         // encoding setting comes from resource plug-in
2533         optionNames.add(CORE_ENCODING);
2534                 
2535         // Formatter settings
2536         preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); 
2537         optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
2538
2539         preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
2540         optionNames.add(FORMATTER_NEWLINE_CONTROL);
2541
2542         preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); 
2543         optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
2544
2545         preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
2546         optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
2547
2548         preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); 
2549         optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
2550
2551         preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
2552         optionNames.add(FORMATTER_LINE_SPLIT);
2553
2554         preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); 
2555         optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
2556
2557         preferences.setDefault(FORMATTER_TAB_CHAR, TAB); 
2558         optionNames.add(FORMATTER_TAB_CHAR);
2559
2560         preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
2561         optionNames.add(FORMATTER_TAB_SIZE);
2562                 
2563         preferences.setDefault(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$ 
2564         optionNames.add(FORMATTER_SPACE_CASTEXPRESSION);
2565
2566         // CodeAssist settings
2567         preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
2568         optionNames.add(CODEASSIST_VISIBILITY_CHECK);
2569
2570         preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
2571         optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
2572                 
2573         preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
2574         optionNames.add(CODEASSIST_FIELD_PREFIXES);
2575                 
2576         preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
2577         optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
2578                 
2579         preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
2580         optionNames.add(CODEASSIST_LOCAL_PREFIXES);
2581                 
2582         preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
2583         optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
2584                 
2585         preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2586         optionNames.add(CODEASSIST_FIELD_SUFFIXES);
2587                 
2588         preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2589         optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
2590                 
2591         preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
2592         optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
2593                 
2594         preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
2595         optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
2596 }
2597         
2598 /**
2599  * Returns whether the given marker references the given Java element.
2600  * Used for markers, which denote a Java element rather than a resource.
2601  *
2602  * @param element the element
2603  * @param marker the marker
2604  * @return <code>true</code> if the marker references the element, false otherwise
2605  * @exception CoreException if the <code>IMarker.getAttribute</code> on the marker fails         
2606  */
2607 public static boolean isReferencedBy(IJavaElement element, IMarker marker) throws CoreException {
2608                 
2609         // only match units or classfiles
2610         if (element instanceof IMember){
2611                 IMember member = (IMember) element;
2612                 if (member.isBinary()){
2613                         element = null; //member.getClassFile();
2614                 } else {
2615                         element = member.getCompilationUnit();
2616                 }
2617         }
2618         if (element == null) return false;                      
2619         if (marker == null) return false;
2620
2621         String markerHandleId = (String)marker.getAttribute(ATT_HANDLE_ID);
2622         if (markerHandleId == null) return false;
2623                 
2624         IJavaElement markerElement = PHPCore.create(markerHandleId);
2625 //      while (true){
2626                 if (element.equals(markerElement)) return true; // external elements may still be equal with different handleIDs.
2627                         
2628                 // cycle through enclosing types in case marker is associated with a classfile (15568)
2629 //              if (markerElement instanceof IClassFile){
2630 //                      IType enclosingType = ((IClassFile)markerElement).getType().getDeclaringType();
2631 //                      if (enclosingType != null){
2632 //                              markerElement = enclosingType.getClassFile(); // retry with immediate enclosing classfile
2633 //                              continue;
2634 //                      }
2635 //              }
2636 //              break;
2637 //      }
2638         return false;
2639 }
2640
2641 /**
2642  * Returns whether the given marker delta references the given Java element.
2643  * Used for markers deltas, which denote a Java element rather than a resource.
2644  *
2645  * @param element the element
2646  * @param markerDelta the marker delta
2647  * @return <code>true</code> if the marker delta references the element
2648  * @exception CoreException if the  <code>IMarkerDelta.getAttribute</code> on the marker delta fails     
2649  */
2650 public static boolean isReferencedBy(IJavaElement element, IMarkerDelta markerDelta) throws CoreException {
2651                 
2652         // only match units or classfiles
2653         if (element instanceof IMember){
2654                 IMember member = (IMember) element;
2655                 if (member.isBinary()){
2656                         element = null; //member.getClassFile();
2657                 } else {
2658                         element = member.getCompilationUnit();
2659                 }
2660         }
2661         if (element == null) return false;                      
2662         if (markerDelta == null) return false;
2663
2664         String markerDeltarHandleId = (String)markerDelta.getAttribute(ATT_HANDLE_ID);
2665         if (markerDeltarHandleId == null) return false;
2666                 
2667         IJavaElement markerElement = PHPCore.create(markerDeltarHandleId);
2668 //      while (true){
2669                 if (element.equals(markerElement)) return true; // external elements may still be equal with different handleIDs.
2670                         
2671                 // cycle through enclosing types in case marker is associated with a classfile (15568)
2672 //              if (markerElement instanceof IClassFile){
2673 //                      IType enclosingType = ((IClassFile)markerElement).getType().getDeclaringType();
2674 //                      if (enclosingType != null){
2675 //                              markerElement = enclosingType.getClassFile(); // retry with immediate enclosing classfile
2676 //                              continue;
2677 //                      }
2678 //              }
2679 //              break;
2680 //      }
2681         return false;
2682 }
2683
2684 /**
2685  * Creates and returns a new classpath entry of kind <code>CPE_CONTAINER</code>
2686  * for the given path. The path of the container will be used during resolution so as to map this
2687  * container entry to a set of other classpath entries the container is acting for.
2688  * <p>
2689  * A container entry allows to express indirect references to a set of libraries, projects and variable entries,
2690  * which can be interpreted differently for each Java project where it is used.
2691  * A classpath container entry can be resolved using <code>JavaCore.getResolvedClasspathContainer</code>,
2692  * and updated with <code>JavaCore.classpathContainerChanged</code>
2693  * <p>
2694  * A container is exclusively resolved by a <code>ClasspathContainerInitializer</code> registered onto the
2695  * extension point "org.eclipse.jdt.core.classpathContainerInitializer".
2696  * <p>
2697  * A container path must be formed of at least one segment, where: <ul>
2698  * <li> the first segment is a unique ID identifying the target container, there must be a container initializer registered
2699  *      onto this ID through the extension point  "org.eclipse.jdt.core.classpathContainerInitializer". </li>
2700  * <li> the remaining segments will be passed onto the initializer, and can be used as additional
2701  *      hints during the initialization phase. </li>
2702  * </ul>
2703  * <p>
2704  * Example of an ClasspathContainerInitializer for a classpath container denoting a default JDK container:
2705  * 
2706  * containerEntry = JavaCore.newContainerEntry(new Path("MyProvidedJDK/default"));
2707  * 
2708  * <extension
2709  *    point="org.eclipse.jdt.core.classpathContainerInitializer">
2710  *    <containerInitializer
2711  *       id="MyProvidedJDK"
2712  *       class="com.example.MyInitializer"/> 
2713  * <p>
2714  * Note that this operation does not attempt to validate classpath containers
2715  * or access the resources at the given paths.
2716  * <p>
2717  * The resulting entry is not exported to dependent projects. This method is equivalent to
2718  * <code>newContainerEntry(-,false)</code>.
2719  * <p>
2720  * @param containerPath the path identifying the container, it must be formed of two
2721  *      segments
2722  * @return a new container classpath entry
2723  * 
2724  * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
2725  * @see JavaCore#newContainerEntry(IPath, boolean)
2726  * @since 2.0
2727  */
2728 public static IClasspathEntry newContainerEntry(IPath containerPath) {
2729                         
2730         return newContainerEntry(containerPath, false);
2731 }
2732
2733 /**
2734  * Creates and returns a new classpath entry of kind <code>CPE_CONTAINER</code>
2735  * for the given path. The path of the container will be used during resolution so as to map this
2736  * container entry to a set of other classpath entries the container is acting for.
2737  * <p>
2738  * A container entry allows to express indirect references to a set of libraries, projects and variable entries,
2739  * which can be interpreted differently for each Java project where it is used.
2740  * A classpath container entry can be resolved using <code>JavaCore.getResolvedClasspathContainer</code>,
2741  * and updated with <code>JavaCore.classpathContainerChanged</code>
2742  * <p>
2743  * A container is exclusively resolved by a <code>ClasspathContainerInitializer</code> registered onto the
2744  * extension point "org.eclipse.jdt.core.classpathContainerInitializer".
2745  * <p>
2746  * A container path must be formed of at least one segment, where: <ul>
2747  * <li> the first segment is a unique ID identifying the target container, there must be a container initializer registered
2748  *      onto this ID through the extension point  "org.eclipse.jdt.core.classpathContainerInitializer". </li>
2749  * <li> the remaining segments will be passed onto the initializer, and can be used as additional
2750  *      hints during the initialization phase. </li>
2751  * </ul>
2752  * <p>
2753  * Example of an ClasspathContainerInitializer for a classpath container denoting a default JDK container:
2754  * 
2755  * containerEntry = JavaCore.newContainerEntry(new Path("MyProvidedJDK/default"));
2756  * 
2757  * <extension
2758  *    point="org.eclipse.jdt.core.classpathContainerInitializer">
2759  *    <containerInitializer
2760  *       id="MyProvidedJDK"
2761  *       class="com.example.MyInitializer"/> 
2762  * <p>
2763  * Note that this operation does not attempt to validate classpath containers
2764  * or access the resources at the given paths.
2765  * <p>
2766  * @param containerPath the path identifying the container, it must be formed of at least
2767  *      one segment (ID+hints)
2768  * @param isExported a boolean indicating whether this entry is contributed to dependent
2769  *    projects in addition to the output location
2770  * @return a new container classpath entry
2771  * 
2772  * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
2773  * @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)
2774  * @see JavaCore#newContainerEntry(IPath, boolean)
2775  * @since 2.0
2776  */
2777 public static IClasspathEntry newContainerEntry(IPath containerPath, boolean isExported) {
2778                         
2779         if (containerPath == null || containerPath.segmentCount() < 1) {
2780                 Assert.isTrue(
2781                         false,
2782                         "Illegal classpath container path: \'" + containerPath.makeRelative().toString() + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$//$NON-NLS-2$
2783         }
2784         return new ClasspathEntry(
2785                 IPackageFragmentRoot.K_SOURCE,
2786                 IClasspathEntry.CPE_CONTAINER,
2787                 containerPath,
2788                 ClasspathEntry.NO_EXCLUSION_PATTERNS, 
2789                 null, // source attachment
2790                 null, // source attachment root
2791                 null, // specific output folder
2792                 isExported);
2793 }
2794
2795 /**
2796  * Creates and returns a new non-exported classpath entry of kind <code>CPE_LIBRARY</code> for the 
2797  * JAR or folder identified by the given absolute path. This specifies that all package fragments 
2798  * within the root will have children of type <code>IClassFile</code>.
2799  * <p>
2800  * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
2801  * The target JAR or folder can either be defined internally to the workspace (absolute path relative
2802  * to the workspace root) or externally to the workspace (absolute path in the file system).
2803  * <p>
2804  * e.g. Here are some examples of binary path usage<ul>
2805  *      <li><code> "c:/jdk1.2.2/jre/lib/rt.jar" </code> - reference to an external JAR</li>
2806  *      <li><code> "/Project/someLib.jar" </code> - reference to an internal JAR </li>
2807  *      <li><code> "c:/classes/" </code> - reference to an external binary folder</li>
2808  * </ul>
2809  * Note that this operation does not attempt to validate or access the 
2810  * resources at the given paths.
2811  * <p>
2812  * The resulting entry is not exported to dependent projects. This method is equivalent to
2813  * <code>newLibraryEntry(-,-,-,false)</code>.
2814  * <p>
2815  * 
2816  * @param path the absolute path of the binary archive
2817  * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder, 
2818  *    or <code>null</code> if none
2819  * @param sourceAttachmentRootPath the location of the root within the source archive or folder
2820  *    or <code>null</code> if this location should be automatically detected.
2821  * @return a new library classpath entry
2822  * 
2823  * @see #newLibraryEntry(IPath, IPath, IPath, boolean)
2824  */
2825 //public static IClasspathEntry newLibraryEntry(
2826 //      IPath path,
2827 //      IPath sourceAttachmentPath,
2828 //      IPath sourceAttachmentRootPath) {
2829 //                      
2830 //      return newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, false);
2831 //}
2832
2833 /**
2834  * Creates and returns a new classpath entry of kind <code>CPE_LIBRARY</code> for the JAR or folder
2835  * identified by the given absolute path. This specifies that all package fragments within the root 
2836  * will have children of type <code>IClassFile</code>.
2837  * <p>
2838  * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
2839  * The target JAR or folder can either be defined internally to the workspace (absolute path relative
2840  * to the workspace root) or externally to the workspace (absolute path in the file system).
2841  *      <p>
2842  * e.g. Here are some examples of binary path usage<ul>
2843  *      <li><code> "c:/jdk1.2.2/jre/lib/rt.jar" </code> - reference to an external JAR</li>
2844  *      <li><code> "/Project/someLib.jar" </code> - reference to an internal JAR </li>
2845  *      <li><code> "c:/classes/" </code> - reference to an external binary folder</li>
2846  * </ul>
2847  * Note that this operation does not attempt to validate or access the 
2848  * resources at the given paths.
2849  * <p>
2850  * 
2851  * @param path the absolute path of the binary archive
2852  * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder, 
2853  *    or <code>null</code> if none
2854  * @param sourceAttachmentRootPath the location of the root within the source archive or folder
2855  *    or <code>null</code> if this location should be automatically detected.
2856  * @param isExported indicates whether this entry is contributed to dependent
2857  *        projects in addition to the output location
2858  * @return a new library classpath entry
2859  * @since 2.0
2860  */
2861 //public static IClasspathEntry newLibraryEntry(
2862 //      IPath path,
2863 //      IPath sourceAttachmentPath,
2864 //      IPath sourceAttachmentRootPath,
2865 //      boolean isExported) {
2866 //                      
2867 //      if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
2868 //
2869 //      return new ClasspathEntry(
2870 //              IPackageFragmentRoot.K_BINARY,
2871 //              IClasspathEntry.CPE_LIBRARY,
2872 //              JavaProject.canonicalizedPath(path),
2873 //              ClasspathEntry.NO_EXCLUSION_PATTERNS, 
2874 //              sourceAttachmentPath,
2875 //              sourceAttachmentRootPath,
2876 //              null, // specific output folder
2877 //              isExported);
2878 //}
2879
2880 /**
2881  * Creates and returns a new non-exported classpath entry of kind <code>CPE_PROJECT</code>
2882  * for the project identified by the given absolute path.
2883  * <p>
2884  * A project entry is used to denote a prerequisite project on a classpath.
2885  * The referenced project will be contributed as a whole, either as sources (in the Java Model, it
2886  * contributes all its package fragment roots) or as binaries (when building, it contributes its 
2887  * whole output location).
2888  * <p>
2889  * A project reference allows to indirect through another project, independently from its internal layout. 
2890  * <p>
2891  * The prerequisite project is referred to using an absolute path relative to the workspace root.
2892  * <p>
2893  * The resulting entry is not exported to dependent projects. This method is equivalent to
2894  * <code>newProjectEntry(_,false)</code>.
2895  * <p>
2896  * 
2897  * @param path the absolute path of the binary archive
2898  * @return a new project classpath entry
2899  * 
2900  * @see JavaCore#newProjectEntry(IPath, boolean)
2901  */
2902 public static IClasspathEntry newProjectEntry(IPath path) {
2903         return newProjectEntry(path, false);
2904 }
2905         
2906 /**
2907  * Creates and returns a new classpath entry of kind <code>CPE_PROJECT</code>
2908  * for the project identified by the given absolute path.
2909  * <p>
2910  * A project entry is used to denote a prerequisite project on a classpath.
2911  * The referenced project will be contributed as a whole, either as sources (in the Java Model, it
2912  * contributes all its package fragment roots) or as binaries (when building, it contributes its 
2913  * whole output location).
2914  * <p>
2915  * A project reference allows to indirect through another project, independently from its internal layout. 
2916  * <p>
2917  * The prerequisite project is referred to using an absolute path relative to the workspace root.
2918  * <p>
2919  * 
2920  * @param path the absolute path of the prerequisite project
2921  * @param isExported indicates whether this entry is contributed to dependent
2922  *        projects in addition to the output location
2923  * @return a new project classpath entry
2924  * @since 2.0
2925  */
2926 public static IClasspathEntry newProjectEntry(IPath path, boolean isExported) {
2927                 
2928         if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
2929                 
2930         return new ClasspathEntry(
2931                 IPackageFragmentRoot.K_SOURCE,
2932                 IClasspathEntry.CPE_PROJECT,
2933                 path,
2934                 ClasspathEntry.NO_EXCLUSION_PATTERNS, 
2935                 null, // source attachment
2936                 null, // source attachment root
2937                 null, // specific output folder
2938                 isExported);
2939 }
2940
2941 /**
2942  * Returns a new empty region.
2943  * 
2944  * @return a new empty region
2945  */
2946 public static IRegion newRegion() {
2947         return new Region();
2948 }
2949
2950 /**
2951  * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
2952  * for the project's source folder identified by the given absolute 
2953  * workspace-relative path. This specifies that all package fragments
2954  * within the root will have children of type <code>ICompilationUnit</code>.
2955  * <p>
2956  * The source folder is referred to using an absolute path relative to the
2957  * workspace root, e.g. <code>/Project/src</code>. A project's source 
2958  * folders are located with that project. That is, a source classpath
2959  * entry specifying the path <code>/P1/src</code> is only usable for
2960  * project <code>P1</code>.
2961  * </p>
2962  * <p>
2963  * The source classpath entry created by this method includes all source
2964  * files below the given workspace-relative path. To selectively exclude
2965  * some of these source files, use the factory method 
2966  * <code>JavaCore.newSourceEntry(IPath,IPath[])</code> instead.
2967  * </p>
2968  * <p>
2969  * Note that all sources/binaries inside a project are contributed as a whole through
2970  * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
2971  * source entries cannot be selectively exported.
2972  * </p>
2973  * 
2974  * @param path the absolute workspace-relative path of a source folder
2975  * @return a new source classpath entry with not exclusion patterns
2976  * 
2977  * @see #newSourceEntry(org.eclipse.core.runtime.IPath,org.eclipse.core.runtime.IPath[])
2978  */
2979 public static IClasspathEntry newSourceEntry(IPath path) {
2980
2981         return newSourceEntry(path, ClasspathEntry.NO_EXCLUSION_PATTERNS, null /*output location*/);
2982 }
2983         
2984 /**
2985  * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
2986  * for the project's source folder identified by the given absolute 
2987  * workspace-relative path but excluding all source files with paths
2988  * matching any of the given patterns. This specifies that all package
2989  * fragments within the root will have children of type 
2990  * <code>ICompilationUnit</code>.
2991  * <p>
2992  * The source folder is referred to using an absolute path relative to the
2993  * workspace root, e.g. <code>/Project/src</code>. A project's source 
2994  * folders are located with that project. That is, a source classpath
2995  * entry specifying the path <code>/P1/src</code> is only usable for
2996  * project <code>P1</code>.
2997  * </p>
2998  * <p>
2999  * The source classpath entry created by this method includes all source
3000  * files below the given workspace-relative path except for those matched
3001  * by one (or more) of the given exclusion patterns. Each exclusion pattern
3002  * is represented by a relative path, which is interpreted as relative to
3003  * the source folder. For example, if the source folder path is 
3004  * <code>/Project/src</code> and the exclusion pattern is 
3005  * <code>com/xyz/tests/&#42;&#42;</code>, then source files
3006  * like <code>/Project/src/com/xyz/Foo.java</code>
3007  * and <code>/Project/src/com/xyz/utils/Bar.java</code> would be included,
3008  * whereas <code>/Project/src/com/xyz/tests/T1.java</code>
3009  * and <code>/Project/src/com/xyz/tests/quick/T2.java</code> would be
3010  * excluded. Exclusion patterns can contain can contain '**', '*' or '?'
3011  * wildcards; see <code>IClasspathEntry.getExclusionPatterns</code>
3012  * for the full description of the syntax and semantics of exclusion
3013  * patterns.
3014  * </p>
3015  * If the empty list of exclusion patterns is specified, the source folder
3016  * will automatically include all resources located inside the source
3017  * folder. In that case, the result is entirely equivalent to using the
3018  * factory method <code>JavaCore.newSourceEntry(IPath)</code>. 
3019  * </p>
3020  * <p>
3021  * Note that all sources/binaries inside a project are contributed as a whole through
3022  * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
3023  * source entries cannot be selectively exported.
3024  * </p>
3025  *
3026  * @param path the absolute workspace-relative path of a source folder
3027  * @param exclusionPatterns the possibly empty list of exclusion patterns
3028  *    represented as relative paths
3029  * @return a new source classpath entry with the given exclusion patterns
3030  * @see #newSourceEntry(org.eclipse.core.runtime.IPath)
3031  * @see IClasspathEntry#getExclusionPatterns
3032  * 
3033  * @since 2.1
3034  */
3035 public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) {
3036
3037         return newSourceEntry(path, exclusionPatterns, null /*output location*/); 
3038 }
3039
3040 /**
3041  * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
3042  * for the project's source folder identified by the given absolute 
3043  * workspace-relative path but excluding all source files with paths
3044  * matching any of the given patterns, and associated with a specific output location
3045  * (that is, ".class" files are not going to the project default output location). 
3046  * All package fragments within the root will have children of type 
3047  * <code>ICompilationUnit</code>.
3048  * <p>
3049  * The source folder is referred to using an absolute path relative to the
3050  * workspace root, e.g. <code>/Project/src</code>. A project's source 
3051  * folders are located with that project. That is, a source classpath
3052  * entry specifying the path <code>/P1/src</code> is only usable for
3053  * project <code>P1</code>.
3054  * </p>
3055  * <p>
3056  * The source classpath entry created by this method includes all source
3057  * files below the given workspace-relative path except for those matched
3058  * by one (or more) of the given exclusion patterns. Each exclusion pattern
3059  * is represented by a relative path, which is interpreted as relative to
3060  * the source folder. For example, if the source folder path is 
3061  * <code>/Project/src</code> and the exclusion pattern is 
3062  * <code>com/xyz/tests/&#42;&#42;</code>, then source files
3063  * like <code>/Project/src/com/xyz/Foo.java</code>
3064  * and <code>/Project/src/com/xyz/utils/Bar.java</code> would be included,
3065  * whereas <code>/Project/src/com/xyz/tests/T1.java</code>
3066  * and <code>/Project/src/com/xyz/tests/quick/T2.java</code> would be
3067  * excluded. Exclusion patterns can contain can contain '**', '*' or '?'
3068  * wildcards; see <code>IClasspathEntry.getExclusionPatterns</code>
3069  * for the full description of the syntax and semantics of exclusion
3070  * patterns.
3071  * </p>
3072  * If the empty list of exclusion patterns is specified, the source folder
3073  * will automatically include all resources located inside the source
3074  * folder. In that case, the result is entirely equivalent to using the
3075  * factory method <code>JavaCore.newSourceEntry(IPath)</code>. 
3076  * </p>
3077  * <p>
3078  * Additionally, a source entry can be associated with a specific output location. 
3079  * By doing so, the Java builder will ensure that the generated ".class" files will 
3080  * be issued inside this output location, as opposed to be generated into the 
3081  * project default output location (when output location is <code>null</code>). 
3082  * Note that multiple source entries may target the same output location.
3083  * The output location is referred to using an absolute path relative to the 
3084  * workspace root, e.g. <code>"/Project/bin"</code>, it must be located inside 
3085  * the same project as the source folder.
3086  * </p>
3087  * <p>
3088  * Also note that all sources/binaries inside a project are contributed as a whole through
3089  * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
3090  * source entries cannot be selectively exported.
3091  * </p>
3092  *
3093  * @param path the absolute workspace-relative path of a source folder
3094  * @param exclusionPatterns the possibly empty list of exclusion patterns
3095  *    represented as relative paths
3096  * @param outputLocation the specific output location for this source entry (<code>null</code> if using project default ouput location)
3097  * @return a new source classpath entry with the given exclusion patterns
3098  * @see #newSourceEntry(org.eclipse.core.runtime.IPath)
3099  * @see IClasspathEntry#getExclusionPatterns
3100  * @see IClasspathEntry#getOutputLocation()
3101  * 
3102  * @since 2.1
3103  */
3104 public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns, IPath specificOutputLocation) {
3105
3106         if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
3107         if (exclusionPatterns == null) Assert.isTrue(false, "Exclusion pattern set cannot be null"); //$NON-NLS-1$
3108
3109         return new ClasspathEntry(
3110                 IPackageFragmentRoot.K_SOURCE,
3111                 IClasspathEntry.CPE_SOURCE,
3112                 path,
3113                 exclusionPatterns,
3114                 null, // source attachment
3115                 null, // source attachment root
3116                 specificOutputLocation, // custom output location
3117                 false);
3118 }
3119                 
3120 /**
3121  * Creates and returns a new non-exported classpath entry of kind <code>CPE_VARIABLE</code>
3122  * for the given path. The first segment of the path is the name of a classpath variable.
3123  * The trailing segments of the path will be appended to resolved variable path.
3124  * <p>
3125  * A variable entry allows to express indirect references on a classpath to other projects or libraries,
3126  * depending on what the classpath variable is referring.
3127  * <p>
3128  *      It is possible to register an automatic initializer (<code>ClasspathVariableInitializer</code>),
3129  * which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
3130  * After resolution, a classpath variable entry may either correspond to a project or a library entry. </li>     
3131  * <p>
3132  * e.g. Here are some examples of variable path usage<ul>
3133  * <li> "JDTCORE" where variable <code>JDTCORE</code> is 
3134  *              bound to "c:/jars/jdtcore.jar". The resolved classpath entry is denoting the library "c:\jars\jdtcore.jar"</li>
3135  * <li> "JDTCORE" where variable <code>JDTCORE</code> is 
3136  *              bound to "/Project_JDTCORE". The resolved classpath entry is denoting the project "/Project_JDTCORE"</li>
3137  * <li> "PLUGINS/com.example/example.jar" where variable <code>PLUGINS</code>
3138  *      is bound to "c:/eclipse/plugins". The resolved classpath entry is denoting the library "c:/eclipse/plugins/com.example/example.jar"</li>
3139  * </ul>
3140  * Note that this operation does not attempt to validate classpath variables
3141  * or access the resources at the given paths.
3142  * <p>
3143  * The resulting entry is not exported to dependent projects. This method is equivalent to
3144  * <code>newVariableEntry(-,-,-,false)</code>.
3145  * <p>
3146  * 
3147  * @param variablePath the path of the binary archive; first segment is the
3148  *   name of a classpath variable
3149  * @param variableSourceAttachmentPath the path of the corresponding source archive, 
3150  *    or <code>null</code> if none; if present, the first segment is the
3151  *    name of a classpath variable (not necessarily the same variable
3152  *    as the one that begins <code>variablePath</code>)
3153  * @param sourceAttachmentRootPath the location of the root within the source archive
3154  *    or <code>null</code> if <code>archivePath</code> is also <code>null</code>
3155  * @return a new library classpath entry
3156  * 
3157  * @see JavaCore#newVariableEntry(IPath, IPath, IPath, boolean)
3158  */
3159 //public static IClasspathEntry newVariableEntry(
3160 //      IPath variablePath,
3161 //      IPath variableSourceAttachmentPath,
3162 //      IPath sourceAttachmentRootPath) {
3163 //
3164 //      return newVariableEntry(variablePath, variableSourceAttachmentPath, sourceAttachmentRootPath, false);
3165 //}
3166
3167 /**
3168  * Creates and returns a new non-exported classpath entry of kind <code>CPE_VARIABLE</code>
3169  * for the given path. The first segment of the path is the name of a classpath variable.
3170  * The trailing segments of the path will be appended to resolved variable path.
3171  * <p>
3172  * A variable entry allows to express indirect references on a classpath to other projects or libraries,
3173  * depending on what the classpath variable is referring.
3174  * <p>
3175  *      It is possible to register an automatic initializer (<code>ClasspathVariableInitializer</code>),
3176  * which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
3177  * After resolution, a classpath variable entry may either correspond to a project or a library entry. </li>     
3178  * <p>
3179  * e.g. Here are some examples of variable path usage<ul>
3180  * <li> "JDTCORE" where variable <code>JDTCORE</code> is 
3181  *              bound to "c:/jars/jdtcore.jar". The resolved classpath entry is denoting the library "c:\jars\jdtcore.jar"</li>
3182  * <li> "JDTCORE" where variable <code>JDTCORE</code> is 
3183  *              bound to "/Project_JDTCORE". The resolved classpath entry is denoting the project "/Project_JDTCORE"</li>
3184  * <li> "PLUGINS/com.example/example.jar" where variable <code>PLUGINS</code>
3185  *      is bound to "c:/eclipse/plugins". The resolved classpath entry is denoting the library "c:/eclipse/plugins/com.example/example.jar"</li>
3186  * </ul>
3187  * Note that this operation does not attempt to validate classpath variables
3188  * or access the resources at the given paths.
3189  * <p>
3190  *
3191  * @param variablePath the path of the binary archive; first segment is the
3192  *   name of a classpath variable
3193  * @param variableSourceAttachmentPath the path of the corresponding source archive, 
3194  *    or <code>null</code> if none; if present, the first segment is the
3195  *    name of a classpath variable (not necessarily the same variable
3196  *    as the one that begins <code>variablePath</code>)
3197  * @param sourceAttachmentRootPath the location of the root within the source archive
3198  *    or <code>null</code> if <code>archivePath</code> is also <code>null</code>
3199  * @param isExported indicates whether this entry is contributed to dependent
3200  *        projects in addition to the output location
3201  * @return a new variable classpath entry
3202  * @since 2.0
3203  */
3204 //public static IClasspathEntry newVariableEntry(
3205 //      IPath variablePath,
3206 //      IPath variableSourceAttachmentPath,
3207 //      IPath variableSourceAttachmentRootPath,
3208 //      boolean isExported) {
3209 //                      
3210 //      if (variablePath == null || variablePath.segmentCount() < 1) {
3211 //              Assert.isTrue(
3212 //                      false,
3213 //                      "Illegal classpath variable path: \'" + variablePath.makeRelative().toString() + "\', must have at least one segment"); //$NON-NLS-1$//$NON-NLS-2$
3214 //      }
3215 //      
3216 //      return new ClasspathEntry(
3217 //              IPackageFragmentRoot.K_SOURCE,
3218 //              IClasspathEntry.CPE_VARIABLE,
3219 //              variablePath,
3220 //              ClasspathEntry.NO_EXCLUSION_PATTERNS, 
3221 //              variableSourceAttachmentPath, // source attachment
3222 //              variableSourceAttachmentRootPath, // source attachment root                     
3223 //              null, // specific output folder
3224 //              isExported);
3225 //}
3226
3227 /**
3228  * Removed the given classpath variable. Does nothing if no value was
3229  * set for this classpath variable.
3230  * <p>
3231  * This functionality cannot be used while the resource tree is locked.
3232  * <p>
3233  * Classpath variable values are persisted locally to the workspace, and 
3234  * are preserved from session to session.
3235  * <p>
3236  *
3237  * @param variableName the name of the classpath variable
3238  * @see #setClasspathVariable
3239  *
3240  * @deprecated - use version with extra IProgressMonitor
3241  */
3242 //public static void removeClasspathVariable(String variableName) {
3243 //      removeClasspathVariable(variableName, null);
3244 //}
3245
3246 /**
3247  * Removed the given classpath variable. Does nothing if no value was
3248  * set for this classpath variable.
3249  * <p>
3250  * This functionality cannot be used while the resource tree is locked.
3251  * <p>
3252  * Classpath variable values are persisted locally to the workspace, and 
3253  * are preserved from session to session.
3254  * <p>
3255  *
3256  * @param variableName the name of the classpath variable
3257  * @param monitor the progress monitor to report progress
3258  * @see #setClasspathVariable
3259  */
3260 //public static void removeClasspathVariable(
3261 //      String variableName,
3262 //      IProgressMonitor monitor) {
3263 //
3264 //      try {
3265 //              updateVariableValues(new String[]{ variableName}, new IPath[]{ null }, monitor);
3266 //      } catch (JavaModelException e) {
3267 //      }
3268 //}
3269
3270 /**
3271  * Removes the given element changed listener.
3272  * Has no affect if an identical listener is not registered.
3273  *
3274  * @param listener the listener
3275  */
3276 public static void removeElementChangedListener(IElementChangedListener listener) {
3277         JavaModelManager.getJavaModelManager().removeElementChangedListener(listener);
3278 }
3279
3280 /** 
3281  * Bind a container reference path to some actual containers (<code>IClasspathContainer</code>).
3282  * This API must be invoked whenever changes in container need to be reflected onto the JavaModel.
3283  * Containers can have distinct values in different projects, therefore this API considers a
3284  * set of projects with their respective containers.
3285  * <p>
3286  * <code>containerPath</code> is the path under which these values can be referenced through
3287  * container classpath entries (<code>IClasspathEntry#CPE_CONTAINER</code>). A container path 
3288  * is formed by a first ID segment followed with extra segments, which can be used as additional hints
3289  * for the resolution. The container ID is used to identify a <code>ClasspathContainerInitializer</code> 
3290  * registered on the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
3291  * <p>
3292  * There is no assumption that each individual container value passed in argument 
3293  * (<code>respectiveContainers</code>) must answer the exact same path when requested 
3294  * <code>IClasspathContainer#getPath</code>. 
3295  * Indeed, the containerPath is just an indication for resolving it to an actual container object. It can be 
3296  * delegated to a <code>ClasspathContainerInitializer</code>, which can be activated through the extension
3297  * point "org.eclipse.jdt.core.ClasspathContainerInitializer"). 
3298  * <p>
3299  * In reaction to changing container values, the JavaModel will be updated to reflect the new
3300  * state of the updated container. 
3301  * <p>
3302  * This functionality cannot be used while the resource tree is locked.
3303  * <p>
3304  * Classpath container values are persisted locally to the workspace, but 
3305  * are not preserved from a session to another. It is thus highly recommended to register a 
3306  * <code>ClasspathContainerInitializer</code> for each referenced container 
3307  * (through the extension point "org.eclipse.jdt.core.ClasspathContainerInitializer").
3308  * <p>
3309  * Note: setting a container to <code>null</code> will cause it to be lazily resolved again whenever
3310  * its value is required. In particular, this will cause a registered initializer to be invoked
3311  * again.
3312  * <p>
3313  * @param containerPath - the name of the container reference, which is being updated
3314  * @param affectedProjects - the set of projects for which this container is being bound
3315  * @param respectiveContainers - the set of respective containers for the affected projects
3316  * @param monitor a monitor to report progress
3317  * 
3318  * @see ClasspathContainerInitializer
3319  * @see #getClasspathContainer(IPath, IJavaProject)
3320  * @see IClasspathContainer
3321  * @since 2.0
3322  */
3323 //public static void setClasspathContainer(final IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
3324 //
3325 //      if (affectedProjects.length != respectiveContainers.length) Assert.isTrue(false, "Projects and containers collections should have the same size"); //$NON-NLS-1$
3326 //      
3327 //      if (monitor != null && monitor.isCanceled()) return;
3328 //      
3329 //      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3330 //              System.out.println("CPContainer SET  - setting container: ["+containerPath+"] for projects: {" //$NON-NLS-1$ //$NON-NLS-2$
3331 //                      + (Util.toString(affectedProjects, 
3332 //                                      new Util.Displayable(){ 
3333 //                                              public String displayString(Object o) { return ((IJavaProject) o).getElementName(); }
3334 //                                      }))
3335 //                      + "} with values: " //$NON-NLS-1$
3336 //                      + (Util.toString(respectiveContainers, 
3337 //                                      new Util.Displayable(){ 
3338 //                                              public String displayString(Object o) { return ((IClasspathContainer) o).getDescription(); }
3339 //                                      }))
3340 //                              );
3341 //      }
3342 //
3343 //      final int projectLength = affectedProjects.length;
3344 //      final IJavaProject[] modifiedProjects;
3345 //      System.arraycopy(affectedProjects, 0, modifiedProjects = new IJavaProject[projectLength], 0, projectLength);
3346 //      final IClasspathEntry[][] oldResolvedPaths = new IClasspathEntry[projectLength][];
3347 //                      
3348 //      // filter out unmodified project containers
3349 //      int remaining = 0;
3350 //      for (int i = 0; i < projectLength; i++){
3351 //      
3352 //              if (monitor != null && monitor.isCanceled()) return;
3353 //      
3354 //              IJavaProject affectedProject = affectedProjects[i];
3355 //              IClasspathContainer newContainer = respectiveContainers[i];
3356 //              if (newContainer == null) newContainer = JavaModelManager.ContainerInitializationInProgress; // 30920 - prevent infinite loop
3357 //              boolean found = false;
3358 //              if (JavaProject.hasJavaNature(affectedProject.getProject())){
3359 //                      IClasspathEntry[] rawClasspath = affectedProject.getRawClasspath();
3360 //                      for (int j = 0, cpLength = rawClasspath.length; j <cpLength; j++) {
3361 //                              IClasspathEntry entry = rawClasspath[j];
3362 //                              if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(containerPath)){
3363 //                                      found = true;
3364 //                                      break;
3365 //                              }
3366 //                      }
3367 //              }
3368 //              if (!found){
3369 //                      modifiedProjects[i] = null; // filter out this project - does not reference the container path, or isnt't yet Java project
3370 //                      JavaModelManager.containerPut(affectedProject, containerPath, newContainer);
3371 //                      continue;
3372 //              }
3373 //              IClasspathContainer oldContainer = JavaModelManager.containerGet(affectedProject, containerPath);
3374 //              if (oldContainer == JavaModelManager.ContainerInitializationInProgress) {
3375 //                      Map previousContainerValues = (Map)JavaModelManager.PreviousSessionContainers.get(affectedProject);
3376 //                      if (previousContainerValues != null){
3377 //                              IClasspathContainer previousContainer = (IClasspathContainer)previousContainerValues.get(containerPath);
3378 //                              if (previousContainer != null) {
3379 //                                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3380 //                                              System.out.println("CPContainer INIT - reentering access to project container: ["+affectedProject.getElementName()+"] " + containerPath + " during its initialization, will see previous value: "+ previousContainer.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
3381 //                                      }
3382 //                                      JavaModelManager.containerPut(affectedProject, containerPath, previousContainer); 
3383 //                              }
3384 //                              oldContainer = null; //33695 - cannot filter out restored container, must update affected project to reset cached CP
3385 //                      } else {
3386 //                              oldContainer = null;
3387 //                      }
3388 //              }
3389 //              if (oldContainer != null && oldContainer.equals(respectiveContainers[i])){// TODO: could improve to only compare entries
3390 //                      modifiedProjects[i] = null; // filter out this project - container did not change
3391 //                      continue;
3392 //              }
3393 //              remaining++; 
3394 //              oldResolvedPaths[i] = affectedProject.getResolvedClasspath(true);
3395 //              JavaModelManager.containerPut(affectedProject, containerPath, newContainer);
3396 //      }
3397 //              
3398 //      if (remaining == 0) return;
3399 //              
3400 //      // trigger model refresh
3401 //      try {
3402 //              JavaCore.run(new IWorkspaceRunnable() {
3403 //                      public void run(IProgressMonitor monitor) throws CoreException {
3404 //                              for(int i = 0; i < projectLength; i++){
3405 //              
3406 //                                      if (monitor != null && monitor.isCanceled()) return;
3407 //              
3408 //                                      JavaProject affectedProject = (JavaProject)modifiedProjects[i];
3409 //                                      if (affectedProject == null) continue; // was filtered out
3410 //                                              
3411 //                                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3412 //                                              System.out.println("CPContainer SET  - updating affected project: ["+affectedProject.getElementName()+"] due to setting container: " + containerPath); //$NON-NLS-1$ //$NON-NLS-2$
3413 //                                      }
3414 //
3415 //                                      // force a refresh of the affected project (will compute deltas)
3416 //                                      affectedProject.setRawClasspath(
3417 //                                                      affectedProject.getRawClasspath(),
3418 //                                                      SetClasspathOperation.ReuseOutputLocation,
3419 //                                                      monitor,
3420 //                                                      !ResourcesPlugin.getWorkspace().isTreeLocked(), // can save resources
3421 //                                                      oldResolvedPaths[i],
3422 //                                                      false, // updating - no validation
3423 //                                                      false); // updating - no need to save
3424 //                              }
3425 //                      }
3426 //              },
3427 //              monitor);
3428 //      } catch(CoreException e) {
3429 //              if (JavaModelManager.CP_RESOLVE_VERBOSE){
3430 //                      System.out.println("CPContainer SET  - FAILED DUE TO EXCEPTION: "+containerPath); //$NON-NLS-1$
3431 //                      e.printStackTrace();
3432 //              }
3433 //              if (e instanceof JavaModelException) {
3434 //                      throw (JavaModelException)e;
3435 //              } else {
3436 //                      throw new JavaModelException(e);
3437 //              }
3438 //      } finally {
3439 //              for (int i = 0; i < projectLength; i++) {
3440 //                      if (respectiveContainers[i] == null) {
3441 //                              JavaModelManager.containerPut(affectedProjects[i], containerPath, null); // reset init in progress marker
3442 //                      }
3443 //              }
3444 //      }
3445 //                                      
3446 //}
3447
3448 /**
3449  * Sets the value of the given classpath variable.
3450  * The path must have at least one segment.
3451  * <p>
3452  * This functionality cannot be used while the resource tree is locked.
3453  * <p>
3454  * Classpath variable values are persisted locally to the workspace, and 
3455  * are preserved from session to session.
3456  * <p>
3457  *
3458  * @param variableName the name of the classpath variable
3459  * @param path the path
3460  * @see #getClasspathVariable
3461  *
3462  * @deprecated - use API with IProgressMonitor
3463  */
3464 //public static void setClasspathVariable(String variableName, IPath path)
3465 //      throws JavaModelException {
3466 //
3467 //      setClasspathVariable(variableName, path, null);
3468 //}
3469
3470 /**
3471  * Sets the value of the given classpath variable.
3472  * The path must not be null.
3473  * <p>
3474  * This functionality cannot be used while the resource tree is locked.
3475  * <p>
3476  * Classpath variable values are persisted locally to the workspace, and 
3477  * are preserved from session to session.
3478  * <p>
3479  * Updating a variable with the same value has no effect.
3480  *
3481  * @param variableName the name of the classpath variable
3482  * @param path the path
3483  * @param monitor a monitor to report progress
3484  * @see #getClasspathVariable
3485  */
3486 //public static void setClasspathVariable(
3487 //      String variableName,
3488 //      IPath path,
3489 //      IProgressMonitor monitor)
3490 //      throws JavaModelException {
3491 //
3492 //      if (path == null) Assert.isTrue(false, "Variable path cannot be null"); //$NON-NLS-1$
3493 //      setClasspathVariables(new String[]{variableName}, new IPath[]{ path }, monitor);
3494 //}
3495
3496 /**
3497  * Sets the values of all the given classpath variables at once.
3498  * Null paths can be used to request corresponding variable removal.
3499  * <p>
3500  * This functionality cannot be used while the resource tree is locked.
3501  * <p>
3502  * Classpath variable values are persisted locally to the workspace, and 
3503  * are preserved from session to session.
3504  * <p>
3505  * Updating a variable with the same value has no effect.
3506  * 
3507  * @param variableNames an array of names for the updated classpath variables
3508  * @param paths an array of path updates for the modified classpath variables (null
3509  *       meaning that the corresponding value will be removed
3510  * @param monitor a monitor to report progress
3511  * @see #getClasspathVariable
3512  * @since 2.0
3513  */
3514 //public static void setClasspathVariables(
3515 //      String[] variableNames,
3516 //      IPath[] paths,
3517 //      IProgressMonitor monitor)
3518 //      throws JavaModelException {
3519 //
3520 //      if (variableNames.length != paths.length)       Assert.isTrue(false, "Variable names and paths collections should have the same size"); //$NON-NLS-1$
3521 //      //TODO: should check that null cannot be used as variable paths
3522 //      updateVariableValues(variableNames, paths, monitor);
3523 //}
3524
3525 /* (non-Javadoc)
3526  * Method declared on IExecutableExtension.
3527  * Record any necessary initialization data from the plugin.
3528  */
3529 public void setInitializationData(
3530         IConfigurationElement cfig,
3531         String propertyName,
3532         Object data)
3533         throws CoreException {
3534 }
3535
3536 /**
3537  * Sets the current table of options. All and only the options explicitly included in the given table 
3538  * are remembered; all previous option settings are forgotten, including ones not explicitly
3539  * mentioned.
3540  * <p>
3541  * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
3542  * </p>
3543  * 
3544  * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
3545  *   or <code>null</code> to reset all options to their default values
3546  * @see JavaCore#getDefaultOptions
3547  */
3548 public static void setOptions(Hashtable newOptions) {
3549                 
3550         // see #initializeDefaultPluginPreferences() for changing default settings
3551         Preferences preferences = getPlugin().getPluginPreferences();
3552
3553         if (newOptions == null){
3554                 newOptions = PHPCore.getDefaultOptions();
3555         }
3556         Enumeration keys = newOptions.keys();
3557         while (keys.hasMoreElements()){
3558                 String key = (String)keys.nextElement();
3559                 if (!JavaModelManager.OptionNames.contains(key)) continue; // unrecognized option
3560                 if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
3561                 String value = (String)newOptions.get(key);
3562                 preferences.setValue(key, value);
3563         }
3564                 
3565         // persist options
3566         getPlugin().savePluginPreferences();
3567 }
3568         
3569 /**
3570  * Shutdown the JavaCore plug-in.
3571  * <p>
3572  * De-registers the JavaModelManager as a resource changed listener and save participant.
3573  * <p>
3574  * @see org.eclipse.core.runtime.Plugin#shutdown()
3575  */
3576 public void shutdown() {
3577
3578         //savePluginPreferences();
3579         getPlugin().savePluginPreferences();
3580         IWorkspace workspace = ResourcesPlugin.getWorkspace();
3581         workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaProcessor);
3582         workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
3583
3584         ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
3585 }
3586
3587 /**
3588  * Initiate the background indexing process.
3589  * This should be deferred after the plugin activation.
3590  */
3591 //private void startIndexing() {
3592 //
3593 //      JavaModelManager.getJavaModelManager().getIndexManager().reset();
3594 //}
3595
3596 /**
3597  * Startup of the JavaCore plug-in.
3598  * <p>
3599  * Registers the JavaModelManager as a resource changed listener and save participant.
3600  * Starts the background indexing, and restore saved classpath variable values.
3601  * <p>
3602  * @see org.eclipse.core.runtime.Plugin#startup()
3603  */
3604 public void startup() {
3605                 
3606         JavaModelManager manager = JavaModelManager.getJavaModelManager();
3607         try {
3608                 manager.configurePluginDebugOptions();
3609
3610                 // request state folder creation (workaround 19885)
3611                 PHPCore.getPlugin().getStateLocation();
3612
3613                 // retrieve variable values
3614                 PHPCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener());
3615 //      TODO khartlage temp-del
3616 //              manager.loadVariablesAndContainers();
3617
3618                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
3619                 workspace.addResourceChangeListener(
3620                         manager.deltaProcessor,
3621                         IResourceChangeEvent.PRE_AUTO_BUILD
3622                                 | IResourceChangeEvent.POST_AUTO_BUILD
3623                                 | IResourceChangeEvent.POST_CHANGE
3624                                 | IResourceChangeEvent.PRE_DELETE
3625                                 | IResourceChangeEvent.PRE_CLOSE);
3626
3627 //              startIndexing();
3628                 workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
3629                         
3630         } catch (CoreException e) {
3631         } catch (RuntimeException e) {
3632                 manager.shutdown();
3633                 throw e;
3634         }
3635 }
3636
3637
3638 /**
3639  * Internal updating of a variable values (null path meaning removal), allowing to change multiple variable values at once.
3640  */
3641 //private static void updateVariableValues(
3642 //      String[] variableNames,
3643 //      IPath[] variablePaths,
3644 //      IProgressMonitor monitor) throws JavaModelException {
3645 //      
3646 //      if (monitor != null && monitor.isCanceled()) return;
3647 //              
3648 //      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3649 //              System.out.println("CPVariable SET  - setting variables: {" + Util.toString(variableNames)  //$NON-NLS-1$
3650 //                      + "} with values: " + Util.toString(variablePaths)); //$NON-NLS-1$
3651 //      }
3652 //
3653 //      int varLength = variableNames.length;
3654 //              
3655 //      // gather classpath information for updating
3656 //      final HashMap affectedProjects = new HashMap(5);
3657 //      JavaModelManager manager = JavaModelManager.getJavaModelManager();
3658 //      IJavaModel model = manager.getJavaModel();
3659 //      
3660 //      // filter out unmodified variables
3661 //      int discardCount = 0;
3662 //      for (int i = 0; i < varLength; i++){
3663 //              String variableName = variableNames[i];
3664 //              IPath oldPath = (IPath)JavaModelManager.variableGet(variableName); // if reentering will provide previous session value 
3665 //              if (oldPath == JavaModelManager.VariableInitializationInProgress){
3666 //                      IPath previousPath = (IPath)JavaModelManager.PreviousSessionVariables.get(variableName);
3667 //                      if (previousPath != null){
3668 //                              if (JavaModelManager.CP_RESOLVE_VERBOSE){
3669 //                                      System.out.println("CPVariable INIT - reentering access to variable: " + variableName+ " during its initialization, will see previous value: "+ previousPath); //$NON-NLS-1$ //$NON-NLS-2$
3670 //                              }
3671 //                              JavaModelManager.variablePut(variableName, previousPath); // replace value so reentering calls are seeing old value
3672 //                      }
3673 //                      oldPath = null;  //33695 - cannot filter out restored variable, must update affected project to reset cached CP
3674 //              }
3675 //              if (oldPath != null && oldPath.equals(variablePaths[i])){
3676 //                      variableNames[i] = null;
3677 //                      discardCount++;
3678 //              }
3679 //      }
3680 //      if (discardCount > 0){
3681 //              if (discardCount == varLength) return;
3682 //              int changedLength = varLength - discardCount;
3683 //              String[] changedVariableNames = new String[changedLength];
3684 //              IPath[] changedVariablePaths = new IPath[changedLength];
3685 //              for (int i = 0, index = 0; i < varLength; i++){
3686 //                      if (variableNames[i] != null){
3687 //                              changedVariableNames[index] = variableNames[i];
3688 //                              changedVariablePaths[index] = variablePaths[i];
3689 //                              index++;
3690 //                      }
3691 //              }
3692 //              variableNames = changedVariableNames;
3693 //              variablePaths = changedVariablePaths;
3694 //              varLength = changedLength;
3695 //      }
3696 //              
3697 //      if (monitor != null && monitor.isCanceled()) return;
3698 //
3699 //      if (model != null) {
3700 //              IJavaProject[] projects = model.getJavaProjects();
3701 //              nextProject : for (int i = 0, projectLength = projects.length; i < projectLength; i++){
3702 //                      IJavaProject project = projects[i];
3703 //                                              
3704 //                      // check to see if any of the modified variables is present on the classpath
3705 //                      IClasspathEntry[] classpath = project.getRawClasspath();
3706 //                      for (int j = 0, cpLength = classpath.length; j < cpLength; j++){
3707 //                                      
3708 //                              IClasspathEntry entry = classpath[j];
3709 //                              for (int k = 0; k < varLength; k++){
3710 //      
3711 //                                      String variableName = variableNames[k];                                         
3712 //                                      if (entry.getEntryKind() ==  IClasspathEntry.CPE_VARIABLE){
3713 //      
3714 //                                              if (variableName.equals(entry.getPath().segment(0))){
3715 //                                                      affectedProjects.put(project, project.getResolvedClasspath(true));
3716 //                                                      continue nextProject;
3717 //                                              }
3718 //                                              IPath sourcePath, sourceRootPath;
3719 //                                              if (((sourcePath = entry.getSourceAttachmentPath()) != null     && variableName.equals(sourcePath.segment(0)))
3720 //                                                      || ((sourceRootPath = entry.getSourceAttachmentRootPath()) != null      && variableName.equals(sourceRootPath.segment(0)))) {
3721 //      
3722 //                                                      affectedProjects.put(project, project.getResolvedClasspath(true));
3723 //                                                      continue nextProject;
3724 //                                              }
3725 //                                      }                                                                                               
3726 //                              }
3727 //                      }
3728 //              }
3729 //      }
3730 //      // update variables
3731 //      for (int i = 0; i < varLength; i++){
3732 //              JavaModelManager.variablePut(variableNames[i], variablePaths[i]);
3733 //      }
3734 //      final String[] dbgVariableNames = variableNames;
3735 //                              
3736 //      // update affected project classpaths
3737 //      if (!affectedProjects.isEmpty()) {
3738 //              try {
3739 //                      JavaCore_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt_DeleteIt.run(
3740 //                              new IWorkspaceRunnable() {
3741 //                                      public void run(IProgressMonitor monitor) throws CoreException {
3742 //                                              // propagate classpath change
3743 //                                              Iterator projectsToUpdate = affectedProjects.keySet().iterator();
3744 //                                              while (projectsToUpdate.hasNext()) {
3745 //                      
3746 //                                                      if (monitor != null && monitor.isCanceled()) return;
3747 //                      
3748 //                                                      JavaProject project = (JavaProject) projectsToUpdate.next();
3749 //
3750 //                                                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3751 //                                                              System.out.println("CPVariable SET  - updating affected project: ["+project.getElementName()+"] due to setting variables: "+ Util.toString(dbgVariableNames)); //$NON-NLS-1$ //$NON-NLS-2$
3752 //                                                      }
3753 //                                                              
3754 //                                                      project
3755 //                                                              .setRawClasspath(
3756 //                                                                      project.getRawClasspath(),
3757 //                                                                      SetClasspathOperation.ReuseOutputLocation,
3758 //                                                                      null, // don't call beginTask on the monitor (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=3717)
3759 //                                                                      !ResourcesPlugin.getWorkspace().isTreeLocked(), // can change resources
3760 //                                                                      (IClasspathEntry[]) affectedProjects.get(project),
3761 //                                                                      false, // updating - no validation
3762 //                                                                      false); // updating - no need to save
3763 //                                              }
3764 //                                      }
3765 //                              },
3766 //                              monitor);
3767 //              } catch (CoreException e) {
3768 //                      if (JavaModelManager.CP_RESOLVE_VERBOSE){
3769 //                              System.out.println("CPVariable SET  - FAILED DUE TO EXCEPTION: "+Util.toString(dbgVariableNames)); //$NON-NLS-1$
3770 //                              e.printStackTrace();
3771 //                      }
3772 //                      if (e instanceof JavaModelException) {
3773 //                              throw (JavaModelException)e;
3774 //                      } else {
3775 //                              throw new JavaModelException(e);
3776 //                      }
3777 //              }
3778 //      }
3779 //}
3780 }