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