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