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