1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 * IBM Corporation - added the following constants:
11 * COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE
12 * COMPILER_PB_STATIC_ACCESS_RECEIVER
14 * CORE_CIRCULAR_CLASSPATH
15 * CORE_INCOMPLETE_CLASSPATH
16 * IBM Corporation - added run(IWorkspaceRunnable, IProgressMonitor)
17 * IBM Corporation - added exclusion patterns to source classpath entries
18 * IBM Corporation - added specific output location to source classpath entries
19 * IBM Corporation - added the following constants:
20 * CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER
22 * IBM Corporation - added getClasspathContainerInitializer(String)
23 * IBM Corporation - added the following constants:
24 * CODEASSIST_ARGUMENT_PREFIXES
25 * CODEASSIST_ARGUMENT_SUFFIXES
26 * CODEASSIST_FIELD_PREFIXES
27 * CODEASSIST_FIELD_SUFFIXES
28 * CODEASSIST_LOCAL_PREFIXES
29 * CODEASSIST_LOCAL_SUFFIXES
30 * CODEASSIST_STATIC_FIELD_PREFIXES
31 * CODEASSIST_STATIC_FIELD_SUFFIXES
32 * COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION
33 *******************************************************************************/
34 package net.sourceforge.phpdt.core;
36 import java.util.Collection;
37 import java.util.Enumeration;
38 import java.util.HashSet;
39 import java.util.Hashtable;
42 import net.sourceforge.phpdt.internal.core.BatchOperation;
43 import net.sourceforge.phpdt.internal.core.BufferManager;
44 import net.sourceforge.phpdt.internal.core.JavaModel;
45 import net.sourceforge.phpdt.internal.core.JavaModelManager;
46 import net.sourceforge.phpdt.internal.core.Region;
48 import org.eclipse.core.resources.IFile;
49 import org.eclipse.core.resources.IFolder;
50 import org.eclipse.core.resources.IMarker;
51 import org.eclipse.core.resources.IMarkerDelta;
52 import org.eclipse.core.resources.IProject;
53 import org.eclipse.core.resources.IResource;
54 import org.eclipse.core.resources.IResourceChangeEvent;
55 import org.eclipse.core.resources.IWorkspace;
56 import org.eclipse.core.resources.IWorkspaceRoot;
57 import org.eclipse.core.resources.IWorkspaceRunnable;
58 import org.eclipse.core.resources.ResourcesPlugin;
59 import org.eclipse.core.runtime.CoreException;
60 import org.eclipse.core.runtime.IConfigurationElement;
61 import org.eclipse.core.runtime.IExecutableExtension;
62 import org.eclipse.core.runtime.IPluginDescriptor;
63 import org.eclipse.core.runtime.IProgressMonitor;
64 import org.eclipse.core.runtime.Plugin;
65 import org.eclipse.core.runtime.Preferences;
69 * The plug-in runtime class for the Java model plug-in containing the core
70 * (UI-free) support for Java projects.
72 * Like all plug-in runtime classes (subclasses of <code>Plugin</code>), this
73 * class is automatically instantiated by the platform when the plug-in gets
74 * activated. Clients must not attempt to instantiate plug-in runtime classes
78 * The single instance of this class can be accessed from any plug-in declaring
79 * the Java model plug-in as a prerequisite via
80 * <code>JavaCore.getJavaCore()</code>. The Java model plug-in will be activated
81 * automatically if not already active.
84 public final class JavaCore extends Plugin implements IExecutableExtension {
86 private static Plugin JAVA_CORE_PLUGIN = null;
88 * The plug-in identifier of the Java core support
89 * (value <code>"org.eclipse.jdt.core"</code>).
91 public static final String PLUGIN_ID = "org.eclipse.jdt.core" ; //$NON-NLS-1$
94 * The identifier for the Java builder
95 * (value <code>"org.eclipse.jdt.core.javabuilder"</code>).
97 public static final String BUILDER_ID = PLUGIN_ID + ".javabuilder" ; //$NON-NLS-1$
100 * The identifier for the Java model
101 * (value <code>"org.eclipse.jdt.core.javamodel"</code>).
103 public static final String MODEL_ID = PLUGIN_ID + ".javamodel" ; //$NON-NLS-1$
106 * The identifier for the Java nature
107 * (value <code>"org.eclipse.jdt.core.javanature"</code>).
108 * The presence of this nature on a project indicates that it is
111 * @see org.eclipse.core.resources.IProject#hasNature(java.lang.String)
113 public static final String NATURE_ID = PLUGIN_ID + ".javanature" ; //$NON-NLS-1$
116 * Name of the handle id attribute in a Java marker.
118 protected static final String ATT_HANDLE_ID =
119 "org.eclipse.jdt.internal.core.JavaModelManager.handleId" ; //$NON-NLS-1$
121 // *************** Possible IDs for configurable options. ********************
124 * Possible configurable option ID.
125 * @see #getDefaultOptions()
127 public static final String COMPILER_LOCAL_VARIABLE_ATTR = PLUGIN_ID + ".compiler.debug.localVariable"; //$NON-NLS-1$
129 * Possible configurable option ID.
130 * @see #getDefaultOptions()
132 public static final String COMPILER_LINE_NUMBER_ATTR = PLUGIN_ID + ".compiler.debug.lineNumber"; //$NON-NLS-1$
134 * Possible configurable option ID.
135 * @see #getDefaultOptions
137 public static final String COMPILER_SOURCE_FILE_ATTR = PLUGIN_ID + ".compiler.debug.sourceFile"; //$NON-NLS-1$
139 * Possible configurable option ID.
140 * @see #getDefaultOptions
142 public static final String COMPILER_CODEGEN_UNUSED_LOCAL = PLUGIN_ID + ".compiler.codegen.unusedLocal"; //$NON-NLS-1$
144 * Possible configurable option ID.
145 * @see #getDefaultOptions
147 public static final String COMPILER_CODEGEN_TARGET_PLATFORM = PLUGIN_ID + ".compiler.codegen.targetPlatform"; //$NON-NLS-1$
149 * Possible configurable option ID.
150 * @see #getDefaultOptions
152 public static final String COMPILER_PB_UNREACHABLE_CODE = PLUGIN_ID + ".compiler.problem.unreachableCode"; //$NON-NLS-1$
154 * Possible configurable option ID.
155 * @see #getDefaultOptions
157 public static final String COMPILER_PB_INVALID_IMPORT = PLUGIN_ID + ".compiler.problem.invalidImport"; //$NON-NLS-1$
159 * Possible configurable option ID.
160 * @see #getDefaultOptions
162 public static final String COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD = PLUGIN_ID + ".compiler.problem.overridingPackageDefaultMethod"; //$NON-NLS-1$
164 * Possible configurable option ID.
165 * @see #getDefaultOptions
167 public static final String COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME = PLUGIN_ID + ".compiler.problem.methodWithConstructorName"; //$NON-NLS-1$
169 * Possible configurable option ID.
170 * @see #getDefaultOptions
172 public static final String COMPILER_PB_DEPRECATION = PLUGIN_ID + ".compiler.problem.deprecation"; //$NON-NLS-1$
174 * Possible configurable option ID.
175 * @see #getDefaultOptions
178 public static final String COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE = PLUGIN_ID + ".compiler.problem.deprecationInDeprecatedCode"; //$NON-NLS-1$
180 * Possible configurable option ID.
181 * @see #getDefaultOptions
183 public static final String COMPILER_PB_HIDDEN_CATCH_BLOCK = PLUGIN_ID + ".compiler.problem.hiddenCatchBlock"; //$NON-NLS-1$
185 * Possible configurable option ID.
186 * @see #getDefaultOptions
188 public static final String COMPILER_PB_UNUSED_LOCAL = PLUGIN_ID + ".compiler.problem.unusedLocal"; //$NON-NLS-1$
190 * Possible configurable option ID.
191 * @see #getDefaultOptions
193 public static final String COMPILER_PB_UNUSED_PARAMETER = PLUGIN_ID + ".compiler.problem.unusedParameter"; //$NON-NLS-1$
195 * Possible configurable option ID.
196 * @see #getDefaultOptions
199 public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT = PLUGIN_ID + ".compiler.problem.unusedParameterWhenImplementingAbstract"; //$NON-NLS-1$
201 * Possible configurable option ID.
202 * @see #getDefaultOptions
205 public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE = PLUGIN_ID + ".compiler.problem.unusedParameterWhenOverridingConcrete"; //$NON-NLS-1$
207 * Possible configurable option ID.
208 * @see #getDefaultOptions
211 public static final String COMPILER_PB_UNUSED_IMPORT = PLUGIN_ID + ".compiler.problem.unusedImport"; //$NON-NLS-1$
213 * Possible configurable option ID.
214 * @see #getDefaultOptions
216 public static final String COMPILER_PB_SYNTHETIC_ACCESS_EMULATION = PLUGIN_ID + ".compiler.problem.syntheticAccessEmulation"; //$NON-NLS-1$
218 * Possible configurable option ID.
219 * @see #getDefaultOptions
222 public static final String COMPILER_PB_NON_NLS_STRING_LITERAL = PLUGIN_ID + ".compiler.problem.nonExternalizedStringLiteral"; //$NON-NLS-1$
224 * Possible configurable option ID.
225 * @see #getDefaultOptions
228 public static final String COMPILER_PB_ASSERT_IDENTIFIER = PLUGIN_ID + ".compiler.problem.assertIdentifier"; //$NON-NLS-1$
230 * Possible configurable option ID.
231 * @see #getDefaultOptions
234 public static final String COMPILER_PB_STATIC_ACCESS_RECEIVER = PLUGIN_ID + ".compiler.problem.staticAccessReceiver"; //$NON-NLS-1$
236 * Possible configurable option ID.
237 * @see #getDefaultOptions
240 public static final String COMPILER_PB_NO_EFFECT_ASSIGNMENT = PLUGIN_ID + ".compiler.problem.noEffectAssignment"; //$NON-NLS-1$
242 * Possible configurable option ID.
243 * @see #getDefaultOptions
246 public static final String COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD = PLUGIN_ID + ".compiler.problem.incompatibleNonInheritedInterfaceMethod"; //$NON-NLS-1$
248 * Possible configurable option ID.
249 * @see #getDefaultOptions
252 public static final String COMPILER_PB_UNUSED_PRIVATE_MEMBER = PLUGIN_ID + ".compiler.problem.unusedPrivateMember"; //$NON-NLS-1$
254 * Possible configurable option ID.
255 * @see #getDefaultOptions
258 public static final String COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION = PLUGIN_ID + ".compiler.problem.noImplicitStringConversion"; //$NON-NLS-1$
260 * Possible configurable option ID.
261 * @see #getDefaultOptions
264 public static final String COMPILER_PB_MAX_PER_UNIT = PLUGIN_ID + ".compiler.maxProblemPerUnit"; //$NON-NLS-1$
266 * Possible configurable option ID.
267 * @see #getDefaultOptions
270 public static final String COMPILER_SOURCE = PLUGIN_ID + ".compiler.source"; //$NON-NLS-1$
272 * Possible configurable option ID.
273 * @see #getDefaultOptions
276 public static final String COMPILER_COMPLIANCE = PLUGIN_ID + ".compiler.compliance"; //$NON-NLS-1$
278 * Possible configurable option ID.
279 * @see #getDefaultOptions
282 public static final String COMPILER_TASK_PRIORITIES = PLUGIN_ID + ".compiler.taskPriorities"; //$NON-NLS-1$
284 * Possible configurable option value for COMPILER_TASK_PRIORITIES.
285 * @see #getDefaultOptions
288 public static final String COMPILER_TASK_PRIORITY_HIGH = "HIGH"; //$NON-NLS-1$
290 * Possible configurable option value for COMPILER_TASK_PRIORITIES.
291 * @see #getDefaultOptions
294 public static final String COMPILER_TASK_PRIORITY_LOW = "LOW"; //$NON-NLS-1$
296 * Possible configurable option value for COMPILER_TASK_PRIORITIES.
297 * @see #getDefaultOptions
300 public static final String COMPILER_TASK_PRIORITY_NORMAL = "NORMAL"; //$NON-NLS-1$
302 * Possible configurable option ID.
303 * @see #getDefaultOptions
306 public static final String COMPILER_TASK_TAGS = PLUGIN_ID + ".compiler.taskTags"; //$NON-NLS-1$
308 * Possible configurable option ID.
309 * @see #getDefaultOptions
311 public static final String CORE_JAVA_BUILD_ORDER = PLUGIN_ID + ".computeJavaBuildOrder"; //$NON-NLS-1$
313 * Possible configurable option ID.
314 * @see #getDefaultOptions
317 public static final String CORE_JAVA_BUILD_RESOURCE_COPY_FILTER = PLUGIN_ID + ".builder.resourceCopyExclusionFilter"; //$NON-NLS-1$
319 * Possible configurable option ID.
320 * @see #getDefaultOptions
323 public static final String CORE_JAVA_BUILD_DUPLICATE_RESOURCE = PLUGIN_ID + ".builder.duplicateResourceTask"; //$NON-NLS-1$
325 * Possible configurable option ID.
326 * @see #getDefaultOptions
329 public static final String CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER = PLUGIN_ID + ".builder.cleanOutputFolder"; //$NON-NLS-1$
331 * Possible configurable option ID.
332 * @see #getDefaultOptions
335 public static final String CORE_INCOMPLETE_CLASSPATH = PLUGIN_ID + ".incompleteClasspath"; //$NON-NLS-1$
337 * Possible configurable option ID.
338 * @see #getDefaultOptions
341 public static final String CORE_CIRCULAR_CLASSPATH = PLUGIN_ID + ".circularClasspath"; //$NON-NLS-1$
343 * Possible configurable option ID.
344 * @see #getDefaultOptions
347 public static final String CORE_JAVA_BUILD_INVALID_CLASSPATH = PLUGIN_ID + ".builder.invalidClasspath"; //$NON-NLS-1$
349 * Possible configurable option ID.
350 * @see #getDefaultOptions
353 public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$
355 * Possible configurable option ID.
356 * @see #getDefaultOptions
359 public static final String CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS = PLUGIN_ID + ".classpath.exclusionPatterns"; //$NON-NLS-1$
361 * Possible configurable option ID.
362 * @see #getDefaultOptions
365 public static final String CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS = PLUGIN_ID + ".classpath.multipleOutputLocations"; //$NON-NLS-1$
370 public static final String DEFAULT_TASK_TAG = "TODO"; //$NON-NLS-1$
372 * Default task priority
375 public static final String DEFAULT_TASK_PRIORITY = "NORMAL"; //$NON-NLS-1$
377 * Possible configurable option ID.
378 * @see #getDefaultOptions
381 public static final String FORMATTER_NEWLINE_OPENING_BRACE = PLUGIN_ID + ".formatter.newline.openingBrace"; //$NON-NLS-1$
383 * Possible configurable option ID.
384 * @see #getDefaultOptions
387 public static final String FORMATTER_NEWLINE_CONTROL = PLUGIN_ID + ".formatter.newline.controlStatement"; //$NON-NLS-1$
389 * Possible configurable option ID.
390 * @see #getDefaultOptions
393 public static final String FORMATTER_NEWLINE_ELSE_IF = PLUGIN_ID + ".formatter.newline.elseIf"; //$NON-NLS-1$
395 * Possible configurable option ID.
396 * @see #getDefaultOptions
399 public static final String FORMATTER_NEWLINE_EMPTY_BLOCK = PLUGIN_ID + ".formatter.newline.emptyBlock"; //$NON-NLS-1$
401 * Possible configurable option ID.
402 * @see #getDefaultOptions
405 public static final String FORMATTER_CLEAR_BLANK_LINES = PLUGIN_ID + ".formatter.newline.clearAll"; //$NON-NLS-1$
407 * Possible configurable option ID.
408 * @see #getDefaultOptions
411 public static final String FORMATTER_LINE_SPLIT = PLUGIN_ID + ".formatter.lineSplit"; //$NON-NLS-1$
413 * Possible configurable option ID.
414 * @see #getDefaultOptions
417 public static final String FORMATTER_COMPACT_ASSIGNMENT = PLUGIN_ID + ".formatter.style.assignment"; //$NON-NLS-1$
419 * Possible configurable option ID.
420 * @see #getDefaultOptions
423 public static final String FORMATTER_TAB_CHAR = PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$
425 * Possible configurable option ID.
426 * @see #getDefaultOptions
429 public static final String FORMATTER_TAB_SIZE = PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$
431 * Possible configurable option ID
432 * @see #getDefaultOptions
435 public static final String FORMATTER_SPACE_CASTEXPRESSION = PLUGIN_ID + ".formatter.space.castexpression"; //$NON-NLS-1$
437 * Possible configurable option ID.
438 * @see #getDefaultOptions
441 public static final String CODEASSIST_VISIBILITY_CHECK = PLUGIN_ID + ".codeComplete.visibilityCheck"; //$NON-NLS-1$
443 * Possible configurable option ID.
444 * @see #getDefaultOptions
447 public static final String CODEASSIST_IMPLICIT_QUALIFICATION = PLUGIN_ID + ".codeComplete.forceImplicitQualification"; //$NON-NLS-1$
449 * Possible configurable option ID.
450 * @see #getDefaultOptions
453 public static final String CODEASSIST_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.fieldPrefixes"; //$NON-NLS-1$
455 * Possible configurable option ID.
456 * @see #getDefaultOptions
459 public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + ".codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
461 * Possible configurable option ID.
462 * @see #getDefaultOptions
465 public static final String CODEASSIST_LOCAL_PREFIXES = PLUGIN_ID + ".codeComplete.localPrefixes"; //$NON-NLS-1$
467 * Possible configurable option ID.
468 * @see #getDefaultOptions
471 public static final String CODEASSIST_ARGUMENT_PREFIXES = PLUGIN_ID + ".codeComplete.argumentPrefixes"; //$NON-NLS-1$
473 * Possible configurable option ID.
474 * @see #getDefaultOptions
477 public static final String CODEASSIST_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.fieldSuffixes"; //$NON-NLS-1$
479 * Possible configurable option ID.
480 * @see #getDefaultOptions
483 public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + ".codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
485 * Possible configurable option ID.
486 * @see #getDefaultOptions
489 public static final String CODEASSIST_LOCAL_SUFFIXES = PLUGIN_ID + ".codeComplete.localSuffixes"; //$NON-NLS-1$
491 * Possible configurable option ID.
492 * @see #getDefaultOptions
495 public static final String CODEASSIST_ARGUMENT_SUFFIXES = PLUGIN_ID + ".codeComplete.argumentSuffixes"; //$NON-NLS-1$
497 // *************** Possible values for configurable options. ********************
500 * Possible configurable option value.
501 * @see #getDefaultOptions
503 public static final String GENERATE = "generate"; //$NON-NLS-1$
505 * Possible configurable option value.
506 * @see #getDefaultOptions
508 public static final String DO_NOT_GENERATE = "do not generate"; //$NON-NLS-1$
510 * Possible configurable option value.
511 * @see #getDefaultOptions
513 public static final String PRESERVE = "preserve"; //$NON-NLS-1$
515 * Possible configurable option value.
516 * @see #getDefaultOptions
518 public static final String OPTIMIZE_OUT = "optimize out"; //$NON-NLS-1$
520 * Possible configurable option value.
521 * @see #getDefaultOptions
523 public static final String VERSION_1_1 = "1.1"; //$NON-NLS-1$
525 * Possible configurable option value.
526 * @see #getDefaultOptions
528 public static final String VERSION_1_2 = "1.2"; //$NON-NLS-1$
530 * Possible configurable option value.
531 * @see #getDefaultOptions
534 public static final String VERSION_1_3 = "1.3"; //$NON-NLS-1$
536 * Possible configurable option value.
537 * @see #getDefaultOptions
540 public static final String VERSION_1_4 = "1.4"; //$NON-NLS-1$
542 * Possible configurable option value.
543 * @see #getDefaultOptions
546 public static final String ABORT = "abort"; //$NON-NLS-1$
548 * Possible configurable option value.
549 * @see #getDefaultOptions
551 public static final String ERROR = "error"; //$NON-NLS-1$
553 * Possible configurable option value.
554 * @see #getDefaultOptions
556 public static final String WARNING = "warning"; //$NON-NLS-1$
558 * Possible configurable option value.
559 * @see #getDefaultOptions
561 public static final String IGNORE = "ignore"; //$NON-NLS-1$
563 * Possible configurable option value.
564 * @see #getDefaultOptions
566 public static final String COMPUTE = "compute"; //$NON-NLS-1$
568 * Possible configurable option value.
569 * @see #getDefaultOptions
572 public static final String INSERT = "insert"; //$NON-NLS-1$
574 * Possible configurable option value.
575 * @see #getDefaultOptions
578 public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$
580 * Possible configurable option value.
581 * @see #getDefaultOptions
584 public static final String PRESERVE_ONE = "preserve one"; //$NON-NLS-1$
586 * Possible configurable option value.
587 * @see #getDefaultOptions
590 public static final String CLEAR_ALL = "clear all"; //$NON-NLS-1$
592 * Possible configurable option value.
593 * @see #getDefaultOptions
596 public static final String NORMAL = "normal"; //$NON-NLS-1$
598 * Possible configurable option value.
599 * @see #getDefaultOptions
602 public static final String COMPACT = "compact"; //$NON-NLS-1$
604 * Possible configurable option value.
605 * @see #getDefaultOptions
608 public static final String TAB = "tab"; //$NON-NLS-1$
610 * Possible configurable option value.
611 * @see #getDefaultOptions
614 public static final String SPACE = "space"; //$NON-NLS-1$
616 * Possible configurable option value.
617 * @see #getDefaultOptions
620 public static final String ENABLED = "enabled"; //$NON-NLS-1$
622 * Possible configurable option value.
623 * @see #getDefaultOptions
626 public static final String DISABLED = "disabled"; //$NON-NLS-1$
628 * Possible configurable option value.
629 * @see #getDefaultOptions
632 public static final String CLEAN = "clean"; //$NON-NLS-1$
635 * Creates the Java core plug-in.
638 public JavaCore(IPluginDescriptor pluginDescriptor) {
639 super(pluginDescriptor);
640 JAVA_CORE_PLUGIN = this;
644 * Adds the given listener for changes to Java elements.
645 * Has no effect if an identical listener is already registered.
647 * This listener will only be notified during the POST_CHANGE resource change notification
648 * and any reconcile operation (POST_RECONCILE).
649 * For finer control of the notification, use <code>addElementChangedListener(IElementChangedListener,int)</code>,
650 * which allows to specify a different eventMask.
652 * @see ElementChangedEvent
653 * @param listener the listener
655 public static void addElementChangedListener(IElementChangedListener listener) {
656 addElementChangedListener(listener, ElementChangedEvent.POST_CHANGE | ElementChangedEvent.POST_RECONCILE);
660 * Adds the given listener for changes to Java elements.
661 * Has no effect if an identical listener is already registered.
662 * After completion of this method, the given listener will be registered for exactly
663 * the specified events. If they were previously registered for other events, they
664 * will be deregistered.
666 * Once registered, a listener starts receiving notification of changes to
667 * java elements in the model. The listener continues to receive
668 * notifications until it is replaced or removed.
671 * Listeners can listen for several types of event as defined in <code>ElementChangeEvent</code>.
672 * Clients are free to register for any number of event types however if they register
673 * for more than one, it is their responsibility to ensure they correctly handle the
674 * case where the same java element change shows up in multiple notifications.
675 * Clients are guaranteed to receive only the events for which they are registered.
678 * @param listener the listener
679 * @param eventMask the bit-wise OR of all event types of interest to the listener
680 * @see IElementChangedListener
681 * @see ElementChangedEvent
682 * @see #removeElementChangedListener(IElementChangedListener)
685 public static void addElementChangedListener(IElementChangedListener listener, int eventMask) {
686 JavaModelManager.getJavaModelManager().addElementChangedListener(listener, eventMask);
690 * Configures the given marker attribute map for the given Java element.
691 * Used for markers, which denote a Java element rather than a resource.
693 * @param attributes the mutable marker attribute map (key type: <code>String</code>,
694 * value type: <code>String</code>)
695 * @param element the Java element for which the marker needs to be configured
697 public static void addJavaElementMarkerAttributes(
699 IJavaElement element) {
700 // if (element instanceof IMember)
701 // element = ((IMember) element).getClassFile();
702 if (attributes != null && element != null)
703 attributes.put(ATT_HANDLE_ID, element.getHandleIdentifier());
707 * Configures the given marker for the given Java element.
708 * Used for markers, which denote a Java element rather than a resource.
710 * @param marker the marker to be configured
711 * @param element the Java element for which the marker needs to be configured
712 * @exception CoreException if the <code>IMarker.setAttribute</code> on the marker fails
714 public void configureJavaElementMarker(IMarker marker, IJavaElement element)
715 throws CoreException {
716 // if (element instanceof IMember)
717 // element = ((IMember) element).getClassFile();
718 if (marker != null && element != null)
719 marker.setAttribute(ATT_HANDLE_ID, element.getHandleIdentifier());
723 * Returns the Java model element corresponding to the given handle identifier
724 * generated by <code>IJavaElement.getHandleIdentifier()</code>, or
725 * <code>null</code> if unable to create the associated element.
727 public static IJavaElement create(String handleIdentifier) {
728 if (handleIdentifier == null) {
732 return JavaModelManager.getJavaModelManager().getHandleFromMemento(handleIdentifier);
733 } catch (JavaModelException e) {
738 * Returns the Java element corresponding to the given file, or
739 * <code>null</code> if unable to associate the given file
740 * with a Java element.
742 * <p>The file must be one of:<ul>
743 * <li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
744 * <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
745 * <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
748 * Creating a Java element has the side effect of creating and opening all of the
749 * element's parents if they are not yet open.
751 * @param the given file
752 * @return the Java element corresponding to the given file, or
753 * <code>null</code> if unable to associate the given file
754 * with a Java element
756 public static IJavaElement create(IFile file) {
757 return JavaModelManager.create(file, null);
760 * Returns the package fragment or package fragment root corresponding to the given folder, or
761 * <code>null</code> if unable to associate the given folder with a Java element.
763 * Note that a package fragment root is returned rather than a default package.
765 * Creating a Java element has the side effect of creating and opening all of the
766 * element's parents if they are not yet open.
768 * @param the given folder
769 * @return the package fragment or package fragment root corresponding to the given folder, or
770 * <code>null</code> if unable to associate the given folder with a Java element
772 public static IJavaElement create(IFolder folder) {
773 return JavaModelManager.create(folder, null);
776 * Returns the Java project corresponding to the given project.
778 * Creating a Java Project has the side effect of creating and opening all of the
779 * project's parents if they are not yet open.
781 * Note that no check is done at this time on the existence or the java nature of this project.
783 * @param project the given project
784 * @return the Java project corresponding to the given project, null if the given project is null
786 public static IJavaProject create(IProject project) {
787 if (project == null) {
790 JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
791 return javaModel.getJavaProject(project);
794 * Returns the Java element corresponding to the given resource, or
795 * <code>null</code> if unable to associate the given resource
796 * with a Java element.
798 * The resource must be one of:<ul>
799 * <li>a project - the element returned is the corresponding <code>IJavaProject</code></li>
800 * <li>a <code>.java</code> file - the element returned is the corresponding <code>ICompilationUnit</code></li>
801 * <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
802 * <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
803 * <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
804 * or <code>IPackageFragment</code></li>
805 * <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
808 * Creating a Java element has the side effect of creating and opening all of the
809 * element's parents if they are not yet open.
811 * @param resource the given resource
812 * @return the Java element corresponding to the given resource, or
813 * <code>null</code> if unable to associate the given resource
814 * with a Java element
816 public static IJavaElement create(IResource resource) {
817 return JavaModelManager.create(resource, null);
820 * Returns the Java model.
822 * @param root the given root
823 * @return the Java model, or <code>null</code> if the root is null
825 public static IJavaModel create(IWorkspaceRoot root) {
829 return JavaModelManager.getJavaModelManager().getJavaModel();
832 * Creates and returns a class file element for
833 * the given <code>.class</code> file. Returns <code>null</code> if unable
834 * to recognize the class file.
836 * @param file the given <code>.class</code> file
837 * @return a class file element for the given <code>.class</code> file, or <code>null</code> if unable
838 * to recognize the class file
840 // public static IClassFile createClassFileFrom(IFile file) {
841 // return JavaModelManager.createClassFileFrom(file, null);
844 * Creates and returns a compilation unit element for
845 * the given <code>.java</code> file. Returns <code>null</code> if unable
846 * to recognize the compilation unit.
848 * @param file the given <code>.java</code> file
849 * @return a compilation unit element for the given <code>.java</code> file, or <code>null</code> if unable
850 * to recognize the compilation unit
852 public static ICompilationUnit createCompilationUnitFrom(IFile file) {
853 return JavaModelManager.createCompilationUnitFrom(file, null);
856 * Creates and returns a handle for the given JAR file.
857 * The Java model associated with the JAR's project may be
858 * created as a side effect.
860 * @param file the given JAR file
861 * @return a handle for the given JAR file, or <code>null</code> if unable to create a JAR package fragment root.
862 * (for example, if the JAR file represents a non-Java resource)
864 // public static IPackageFragmentRoot createJarPackageFragmentRootFrom(IFile file) {
865 // return JavaModelManager.createJarPackageFragmentRootFrom(file, null);
869 * Answers the project specific value for a given classpath container.
870 * In case this container path could not be resolved, then will answer <code>null</code>.
871 * Both the container path and the project context are supposed to be non-null.
873 * The containerPath is a formed by a first ID segment followed with extra segments, which can be
874 * used as additional hints for resolution. If no container was ever recorded for this container path
875 * onto this project (using <code>setClasspathContainer</code>, then a
876 * <code>ClasspathContainerInitializer</code> will be activated if any was registered for this container
877 * ID onto the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
879 * There is no assumption that the returned container must answer the exact same containerPath
880 * when requested <code>IClasspathContainer#getPath</code>.
881 * Indeed, the containerPath is just an indication for resolving it to an actual container object.
883 * Classpath container values are persisted locally to the workspace, but
884 * are not preserved from a session to another. It is thus highly recommended to register a
885 * <code>ClasspathContainerInitializer</code> for each referenced container
886 * (through the extension point "org.eclipse.jdt.core.ClasspathContainerInitializer").
888 * @param containerPath the name of the container, which needs to be resolved
889 * @param project a specific project in which the container is being resolved
890 * @return the corresponding classpath container or <code>null</code> if unable to find one.
892 * @exception JavaModelException if an exception occurred while resolving the container, or if the resolved container
893 * contains illegal entries (contains CPE_CONTAINER entries or null entries).
895 * @see ClasspathContainerInitializer
896 * @see IClasspathContainer
897 * @see #setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)
900 // public static IClasspathContainer getClasspathContainer(final IPath containerPath, final IJavaProject project) throws JavaModelException {
902 // IClasspathContainer container = JavaModelManager.containerGet(project, containerPath);
903 // if (container == JavaModelManager.ContainerInitializationInProgress) return null; // break cycle
905 // if (container == null){
906 // final ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
907 // if (initializer != null){
908 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
909 // System.out.println("CPContainer INIT - triggering initialization of: ["+project.getElementName()+"] " + containerPath + " using initializer: "+ initializer); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
910 // 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$
912 // JavaModelManager.containerPut(project, containerPath, JavaModelManager.ContainerInitializationInProgress); // avoid initialization cycles
913 // boolean ok = false;
915 // // wrap initializer call with Safe runnable in case initializer would be causing some grief
916 // Platform.run(new ISafeRunnable() {
917 // public void handleException(Throwable exception) {
918 // Util.log(exception, "Exception occurred in classpath container initializer: "+initializer); //$NON-NLS-1$
920 // public void run() throws Exception {
921 // initializer.initialize(containerPath, project);
925 // // retrieve value (if initialization was successful)
926 // container = JavaModelManager.containerGet(project, containerPath);
927 // if (container == JavaModelManager.ContainerInitializationInProgress) return null; // break cycle
930 // if (!ok) JavaModelManager.containerPut(project, containerPath, null); // flush cache
932 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
933 // System.out.print("CPContainer INIT - after resolution: ["+project.getElementName()+"] " + containerPath + " --> "); //$NON-NLS-2$//$NON-NLS-1$//$NON-NLS-3$
934 // if (container != null){
935 // System.out.print("container: "+container.getDescription()+" {"); //$NON-NLS-2$//$NON-NLS-1$
936 // IClasspathEntry[] entries = container.getClasspathEntries();
937 // if (entries != null){
938 // for (int i = 0; i < entries.length; i++){
939 // if (i > 0) System.out.println(", ");//$NON-NLS-1$
940 // System.out.println(entries[i]);
943 // System.out.println("}");//$NON-NLS-1$
945 // System.out.println("{unbound}");//$NON-NLS-1$
949 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
950 // System.out.println("CPContainer INIT - no initializer found for: "+project.getElementName()+"] " + containerPath); //$NON-NLS-1$ //$NON-NLS-2$
958 * Helper method finding the classpath container initializer registered for a given classpath container ID
959 * or <code>null</code> if none was found while iterating over the contributions to extension point to
960 * the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
962 * A containerID is the first segment of any container path, used to identify the registered container initializer.
964 * @param String - a containerID identifying a registered initializer
965 * @return ClasspathContainerInitializer - the registered classpath container initializer or <code>null</code> if
969 // public static ClasspathContainerInitializer getClasspathContainerInitializer(String containerID){
971 // Plugin jdtCorePlugin = JavaCore.getPlugin();
972 // if (jdtCorePlugin == null) return null;
974 // IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.CPCONTAINER_INITIALIZER_EXTPOINT_ID);
975 // if (extension != null) {
976 // IExtension[] extensions = extension.getExtensions();
977 // for(int i = 0; i < extensions.length; i++){
978 // IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
979 // for(int j = 0; j < configElements.length; j++){
980 // String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$
981 // if (initializerID != null && initializerID.equals(containerID)){
982 // if (JavaModelManager.CP_RESOLVE_VERBOSE) {
983 // System.out.println("CPContainer INIT - found initializer: "+containerID +" --> " + configElements[j].getAttribute("class"));//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
986 // Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
987 // if (execExt instanceof ClasspathContainerInitializer){
988 // return (ClasspathContainerInitializer)execExt;
990 // } catch(CoreException e) {
1000 * Returns the path held in the given classpath variable.
1001 * Returns <node>null</code> if unable to bind.
1003 * Classpath variable values are persisted locally to the workspace, and
1004 * are preserved from session to session.
1006 * Note that classpath variables can be contributed registered initializers for,
1007 * using the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
1008 * If an initializer is registered for a variable, its persisted value will be ignored:
1009 * its initializer will thus get the opportunity to rebind the variable differently on
1012 * @param variableName the name of the classpath variable
1013 * @return the path, or <code>null</code> if none
1014 * @see #setClasspathVariable
1016 // public static IPath getClasspathVariable(final String variableName) {
1018 // IPath variablePath = JavaModelManager.variableGet(variableName);
1019 // if (variablePath == JavaModelManager.VariableInitializationInProgress) return null; // break cycle
1021 // if (variablePath != null) {
1022 // return variablePath;
1025 // // even if persisted value exists, initializer is given priority, only if no initializer is found the persisted value is reused
1026 // final ClasspathVariableInitializer initializer = JavaCore.getClasspathVariableInitializer(variableName);
1027 // if (initializer != null){
1028 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
1029 // System.out.println("CPVariable INIT - triggering initialization of: " + variableName+ " using initializer: "+ initializer); //$NON-NLS-1$ //$NON-NLS-2$
1030 // new Exception("FAKE exception for dumping current CPVariable ("+variableName+ ")INIT invocation stack trace").printStackTrace(); //$NON-NLS-1$//$NON-NLS-2$
1032 // JavaModelManager.variablePut(variableName, JavaModelManager.VariableInitializationInProgress); // avoid initialization cycles
1033 // boolean ok = false;
1035 // // wrap initializer call with Safe runnable in case initializer would be causing some grief
1036 // Platform.run(new ISafeRunnable() {
1037 // public void handleException(Throwable exception) {
1038 // Util.log(exception, "Exception occurred in classpath variable initializer: "+initializer+" while initializing variable: "+variableName); //$NON-NLS-1$ //$NON-NLS-2$
1040 // public void run() throws Exception {
1041 // initializer.initialize(variableName);
1044 // variablePath = (IPath) JavaModelManager.variableGet(variableName); // initializer should have performed side-effect
1045 // if (variablePath == JavaModelManager.VariableInitializationInProgress) return null; // break cycle (initializer did not init or reentering call)
1046 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
1047 // System.out.println("CPVariable INIT - after initialization: " + variableName + " --> " + variablePath); //$NON-NLS-2$//$NON-NLS-1$
1051 // if (!ok) JavaModelManager.variablePut(variableName, null); // flush cache
1054 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
1055 // System.out.println("CPVariable INIT - no initializer found for: " + variableName); //$NON-NLS-1$
1058 // return variablePath;
1062 * Helper method finding the classpath variable initializer registered for a given classpath variable name
1063 * or <code>null</code> if none was found while iterating over the contributions to extension point to
1064 * the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
1066 * @param the given variable
1067 * @return ClasspathVariableInitializer - the registered classpath variable initializer or <code>null</code> if
1071 // public static ClasspathVariableInitializer getClasspathVariableInitializer(String variable){
1073 // Plugin jdtCorePlugin = JavaCore.getPlugin();
1074 // if (jdtCorePlugin == null) return null;
1076 // IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID);
1077 // if (extension != null) {
1078 // IExtension[] extensions = extension.getExtensions();
1079 // for(int i = 0; i < extensions.length; i++){
1080 // IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
1081 // for(int j = 0; j < configElements.length; j++){
1083 // String varAttribute = configElements[j].getAttribute("variable"); //$NON-NLS-1$
1084 // if (variable.equals(varAttribute)) {
1085 // if (JavaModelManager.CP_RESOLVE_VERBOSE) {
1086 // System.out.println("CPVariable INIT - found initializer: "+variable+" --> " + configElements[j].getAttribute("class"));//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
1088 // Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
1089 // if (execExt instanceof ClasspathVariableInitializer){
1090 // return (ClasspathVariableInitializer)execExt;
1093 // } catch(CoreException e){
1102 * Returns the names of all known classpath variables.
1104 * Classpath variable values are persisted locally to the workspace, and
1105 * are preserved from session to session.
1108 * @return the list of classpath variable names
1109 * @see #setClasspathVariable
1111 // public static String[] getClasspathVariableNames() {
1112 // return JavaModelManager.variableNames();
1116 * Returns a table of all known configurable options with their default values.
1117 * These options allow to configure the behaviour of the underlying components.
1118 * The client may safely use the result as a template that they can modify and
1119 * then pass to <code>setOptions</code>.
1121 * Helper constants have been defined on JavaCore for each of the option ID and
1122 * their possible constant values.
1124 * Note: more options might be added in further releases.
1126 * RECOGNIZED OPTIONS:
1127 * COMPILER / Generating Local Variable Debug Attribute
1128 * When generated, this attribute will enable local variable names
1129 * to be displayed in debugger, only in place where variables are
1130 * definitely assigned (.class file is then bigger)
1131 * - option id: "org.eclipse.jdt.core.compiler.debug.localVariable"
1132 * - possible values: { "generate", "do not generate" }
1133 * - default: "generate"
1135 * COMPILER / Generating Line Number Debug Attribute
1136 * When generated, this attribute will enable source code highlighting in debugger
1137 * (.class file is then bigger).
1138 * - option id: "org.eclipse.jdt.core.compiler.debug.lineNumber"
1139 * - possible values: { "generate", "do not generate" }
1140 * - default: "generate"
1142 * COMPILER / Generating Source Debug Attribute
1143 * When generated, this attribute will enable the debugger to present the
1144 * corresponding source code.
1145 * - option id: "org.eclipse.jdt.core.compiler.debug.sourceFile"
1146 * - possible values: { "generate", "do not generate" }
1147 * - default: "generate"
1149 * COMPILER / Preserving Unused Local Variables
1150 * Unless requested to preserve unused local variables (that is, never read), the
1151 * compiler will optimize them out, potentially altering debugging
1152 * - option id: "org.eclipse.jdt.core.compiler.codegen.unusedLocal"
1153 * - possible values: { "preserve", "optimize out" }
1154 * - default: "preserve"
1156 * COMPILER / Defining Target Java Platform
1157 * For binary compatibility reason, .class files can be tagged to with certain VM versions and later.
1158 * Note that "1.4" target require to toggle compliance mode to "1.4" too.
1159 * - option id: "org.eclipse.jdt.core.compiler.codegen.targetPlatform"
1160 * - possible values: { "1.1", "1.2", "1.3", "1.4" }
1163 * COMPILER / Reporting Unreachable Code
1164 * Unreachable code can optionally be reported as an error, warning or simply
1165 * ignored. The bytecode generation will always optimized it out.
1166 * - option id: "org.eclipse.jdt.core.compiler.problem.unreachableCode"
1167 * - possible values: { "error", "warning", "ignore" }
1168 * - default: "error"
1170 * COMPILER / Reporting Invalid Import
1171 * An import statement that cannot be resolved might optionally be reported
1172 * as an error, as a warning or ignored.
1173 * - option id: "org.eclipse.jdt.core.compiler.problem.invalidImport"
1174 * - possible values: { "error", "warning", "ignore" }
1175 * - default: "error"
1177 * COMPILER / Reporting Attempt to Override Package-Default Method
1178 * A package default method is not visible in a different package, and thus
1179 * cannot be overridden. When enabling this option, the compiler will signal
1180 * such scenarii either as an error or a warning.
1181 * - option id: "org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod"
1182 * - possible values: { "error", "warning", "ignore" }
1183 * - default: "warning"
1185 * COMPILER / Reporting Method With Constructor Name
1186 * Naming a method with a constructor name is generally considered poor
1187 * style programming. When enabling this option, the compiler will signal such
1188 * scenarii either as an error or a warning.
1189 * - option id: "org.eclipse.jdt.core.compiler.problem.methodWithConstructorName"
1190 * - possible values: { "error", "warning", "ignore" }
1191 * - default: "warning"
1193 * COMPILER / Reporting Deprecation
1194 * When enabled, the compiler will signal use of deprecated API either as an
1195 * error or a warning.
1196 * - option id: "org.eclipse.jdt.core.compiler.problem.deprecation"
1197 * - possible values: { "error", "warning", "ignore" }
1198 * - default: "warning"
1200 * COMPILER / Reporting Deprecation Inside Deprecated Code
1201 * When enabled, the compiler will signal use of deprecated API inside deprecated code.
1202 * The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.deprecation".
1203 * - option id: "org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode"
1204 * - possible values: { "enabled", "disabled" }
1205 * - default: "disabled"
1207 * COMPILER / Reporting Hidden Catch Block
1208 * Locally to a try statement, some catch blocks may hide others . For example,
1209 * try { throw new java.io.CharConversionException();
1210 * } catch (java.io.CharConversionException e) {
1211 * } catch (java.io.IOException e) {}.
1212 * When enabling this option, the compiler will issue an error or a warning for hidden
1213 * catch blocks corresponding to checked exceptions
1214 * - option id: "org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock"
1215 * - possible values: { "error", "warning", "ignore" }
1216 * - default: "warning"
1218 * COMPILER / Reporting Unused Local
1219 * When enabled, the compiler will issue an error or a warning for unused local
1220 * variables (that is, variables never read from)
1221 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedLocal"
1222 * - possible values: { "error", "warning", "ignore" }
1223 * - default: "ignore"
1225 * COMPILER / Reporting Unused Parameter
1226 * When enabled, the compiler will issue an error or a warning for unused method
1227 * parameters (that is, parameters never read from)
1228 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedParameter"
1229 * - possible values: { "error", "warning", "ignore" }
1230 * - default: "ignore"
1232 * COMPILER / Reporting Unused Parameter if Implementing Abstract Method
1233 * When enabled, the compiler will signal unused parameters in abstract method implementations.
1234 * The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.unusedParameter".
1235 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract"
1236 * - possible values: { "enabled", "disabled" }
1237 * - default: "disabled"
1239 * COMPILER / Reporting Unused Parameter if Overriding Concrete Method
1240 * When enabled, the compiler will signal unused parameters in methods overriding concrete ones.
1241 * The severity of the problem is controlled with option "org.eclipse.jdt.core.compiler.problem.unusedParameter".
1242 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete"
1243 * - possible values: { "enabled", "disabled" }
1244 * - default: "disabled"
1246 * COMPILER / Reporting Unused Import
1247 * When enabled, the compiler will issue an error or a warning for unused import
1249 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedImport"
1250 * - possible values: { "error", "warning", "ignore" }
1251 * - default: "warning"
1253 * COMPILER / Reporting Unused Private Members
1254 * When enabled, the compiler will issue an error or a warning whenever a private
1255 * method or field is declared but never used within the same unit.
1256 * - option id: "org.eclipse.jdt.core.compiler.problem.unusedPrivateMember"
1257 * - possible values: { "error", "warning", "ignore" }
1258 * - default: "ignore"
1260 * COMPILER / Reporting Synthetic Access Emulation
1261 * When enabled, the compiler will issue an error or a warning whenever it emulates
1262 * access to a non-accessible member of an enclosing type. Such access can have
1263 * performance implications.
1264 * - option id: "org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation"
1265 * - possible values: { "error", "warning", "ignore" }
1266 * - default: "ignore"
1268 * COMPILER / Reporting Non-Externalized String Literal
1269 * When enabled, the compiler will issue an error or a warning for non externalized
1270 * String literal (that is, not tagged with //$NON-NLS-<n>$).
1271 * - option id: "org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral"
1272 * - possible values: { "error", "warning", "ignore" }
1273 * - default: "ignore"
1275 * COMPILER / Reporting Usage of 'assert' Identifier
1276 * When enabled, the compiler will issue an error or a warning whenever 'assert' is
1277 * used as an identifier (reserved keyword in 1.4)
1278 * - option id: "org.eclipse.jdt.core.compiler.problem.assertIdentifier"
1279 * - possible values: { "error", "warning", "ignore" }
1280 * - default: "ignore"
1282 * COMPILER / Reporting Non-Static Reference to a Static Member
1283 * When enabled, the compiler will issue an error or a warning whenever a static field
1284 * or method is accessed with an expression receiver. A reference to a static member should
1285 * be qualified with a type name.
1286 * - option id: "org.eclipse.jdt.core.compiler.problem.staticAccessReceiver"
1287 * - possible values: { "error", "warning", "ignore" }
1288 * - default: "warning"
1290 * COMPILER / Reporting Assignment with no Effect
1291 * When enabled, the compiler will issue an error or a warning whenever an assignment
1292 * has no effect (e.g 'x = x').
1293 * - option id: "org.eclipse.jdt.core.compiler.problem.noEffectAssignment"
1294 * - possible values: { "error", "warning", "ignore" }
1295 * - default: "warning"
1297 * COMPILER / Reporting Interface Method not Compatible with non-Inherited Methods
1298 * When enabled, the compiler will issue an error or a warning whenever an interface
1299 * defines a method incompatible with a non-inherited Object method. Until this conflict
1300 * is resolved, such an interface cannot be implemented, For example,
1304 * - option id: "org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod"
1305 * - possible values: { "error", "warning", "ignore" }
1306 * - default: "warning"
1308 * COMPILER / Reporting Usage of char[] Expressions in String Concatenations
1309 * When enabled, the compiler will issue an error or a warning whenever a char[] expression
1310 * is used in String concatenations (for example, "hello" + new char[]{'w','o','r','l','d'}).
1311 * - option id: "org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion"
1312 * - possible values: { "error", "warning", "ignore" }
1313 * - default: "warning"
1315 * COMPILER / Setting Source Compatibility Mode
1316 * Specify whether source is 1.3 or 1.4 compatible. From 1.4 on, 'assert' is a keyword
1317 * reserved for assertion support. Also note, than when toggling to 1.4 mode, the target VM
1318 * level should be set to "1.4" and the compliance mode should be "1.4".
1319 * - option id: "org.eclipse.jdt.core.compiler.source"
1320 * - possible values: { "1.3", "1.4" }
1323 * COMPILER / Setting Compliance Level
1324 * Select the compliance level for the compiler. In "1.3" mode, source and target settings
1325 * should not go beyond "1.3" level.
1326 * - option id: "org.eclipse.jdt.core.compiler.compliance"
1327 * - possible values: { "1.3", "1.4" }
1330 * COMPILER / Maximum number of problems reported per compilation unit
1331 * Specify the maximum number of problems reported on each compilation unit.
1332 * - option id: "org.eclipse.jdt.core.compiler.maxProblemPerUnit"
1333 * - possible values: "<n>" where <n> is zero or a positive integer (if zero then all problems are reported).
1336 * COMPILER / Define the Automatic Task Tags
1337 * When the tag list is not empty, the compiler will issue a task marker whenever it encounters
1338 * one of the corresponding tag inside any comment in Java source code.
1339 * Generated task messages will include the tag, and range until the next line separator or comment ending.
1340 * Note that tasks messages are trimmed.
1341 * - option id: "org.eclipse.jdt.core.compiler.taskTags"
1342 * - possible values: { "<tag>[,<tag>]*" } where <tag> is a String without any wild-card or leading/trailing spaces
1345 * COMPILER / Define the Automatic Task Priorities
1346 * In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low)
1347 * of the task markers issued by the compiler.
1348 * If the default is specified, the priority of each task marker is "NORMAL".
1349 * - option id: "org.eclipse.jdt.core.compiler.taskPriorities"
1350 * - possible values: { "<priority>[,<priority>]*" } where <priority> is one of "HIGH", "NORMAL" or "LOW"
1353 * BUILDER / Specifying Filters for Resource Copying Control
1354 * Allow to specify some filters to control the resource copy process.
1355 * - option id: "org.eclipse.jdt.core.builder.resourceCopyExclusionFilter"
1356 * - possible values: { "<name>[,<name>]* } where <name> is a file name pattern (* and ? wild-cards allowed)
1357 * or the name of a folder which ends with '/'
1360 * BUILDER / Abort if Invalid Classpath
1361 * Allow to toggle the builder to abort if the classpath is invalid
1362 * - option id: "org.eclipse.jdt.core.builder.invalidClasspath"
1363 * - possible values: { "abort", "ignore" }
1364 * - default: "abort"
1366 * BUILDER / Cleaning Output Folder(s)
1367 * Indicate whether the JavaBuilder is allowed to clean the output folders
1368 * when performing full build operations.
1369 * - option id: "org.eclipse.jdt.core.builder.cleanOutputFolder"
1370 * - possible values: { "clean", "ignore" }
1371 * - default: "clean"
1373 * BUILDER / Reporting Duplicate Resources
1374 * Indicate the severity of the problem reported when more than one occurrence
1375 * of a resource is to be copied into the output location.
1376 * - option id: "org.eclipse.jdt.core.builder.duplicateResourceTask"
1377 * - possible values: { "error", "warning" }
1378 * - default: "warning"
1380 * JAVACORE / Computing Project Build Order
1381 * Indicate whether JavaCore should enforce the project build order to be based on
1382 * the classpath prerequisite chain. When requesting to compute, this takes over
1383 * the platform default order (based on project references).
1384 * - option id: "org.eclipse.jdt.core.computeJavaBuildOrder"
1385 * - possible values: { "compute", "ignore" }
1386 * - default: "ignore"
1388 * JAVACORE / Specify Default Source Encoding Format
1389 * Get the encoding format for compiled sources. This setting is read-only, it is equivalent
1390 * to 'ResourcesPlugin.getEncoding()'.
1391 * - option id: "org.eclipse.jdt.core.encoding"
1392 * - possible values: { any of the supported encoding name}.
1393 * - default: <platform default>
1395 * JAVACORE / Reporting Incomplete Classpath
1396 * Indicate the severity of the problem reported when an entry on the classpath does not exist,
1397 * is not legite or is not visible (for example, a referenced project is closed).
1398 * - option id: "org.eclipse.jdt.core.incompleteClasspath"
1399 * - possible values: { "error", "warning"}
1400 * - default: "error"
1402 * JAVACORE / Reporting Classpath Cycle
1403 * Indicate the severity of the problem reported when a project is involved in a cycle.
1404 * - option id: "org.eclipse.jdt.core.circularClasspath"
1405 * - possible values: { "error", "warning" }
1406 * - default: "error"
1408 * JAVACORE / Enabling Usage of Classpath Exclusion Patterns
1409 * When disabled, no entry on a project classpath can be associated with
1410 * an exclusion pattern.
1411 * - option id: "org.eclipse.jdt.core.classpath.exclusionPatterns"
1412 * - possible values: { "enabled", "disabled" }
1413 * - default: "enabled"
1415 * JAVACORE / Enabling Usage of Classpath Multiple Output Locations
1416 * When disabled, no entry on a project classpath can be associated with
1417 * a specific output location, preventing thus usage of multiple output locations.
1418 * - option id: "org.eclipse.jdt.core.classpath.multipleOutputLocations"
1419 * - possible values: { "enabled", "disabled" }
1420 * - default: "enabled"
1422 * FORMATTER / Inserting New Line Before Opening Brace
1423 * When Insert, a new line is inserted before an opening brace, otherwise nothing
1425 * - option id: "org.eclipse.jdt.core.formatter.newline.openingBrace"
1426 * - possible values: { "insert", "do not insert" }
1427 * - default: "do not insert"
1429 * FORMATTER / Inserting New Line Inside Control Statement
1430 * When Insert, a new line is inserted between } and following else, catch, finally
1431 * - option id: "org.eclipse.jdt.core.formatter.newline.controlStatement"
1432 * - possible values: { "insert", "do not insert" }
1433 * - default: "do not insert"
1435 * FORMATTER / Clearing Blank Lines
1436 * When Clear all, all blank lines are removed. When Preserve one, only one is kept
1437 * and all others removed.
1438 * - option id: "org.eclipse.jdt.core.formatter.newline.clearAll"
1439 * - possible values: { "clear all", "preserve one" }
1440 * - default: "preserve one"
1442 * FORMATTER / Inserting New Line Between Else/If
1443 * When Insert, a blank line is inserted between an else and an if when they are
1444 * contiguous. When choosing to not insert, else-if will be kept on the same
1445 * line when possible.
1446 * - option id: "org.eclipse.jdt.core.formatter.newline.elseIf"
1447 * - possible values: { "insert", "do not insert" }
1448 * - default: "do not insert"
1450 * FORMATTER / Inserting New Line In Empty Block
1451 * When insert, a line break is inserted between contiguous { and }, if } is not followed
1453 * - option id: "org.eclipse.jdt.core.formatter.newline.emptyBlock"
1454 * - possible values: { "insert", "do not insert" }
1455 * - default: "insert"
1457 * FORMATTER / Splitting Lines Exceeding Length
1458 * Enable splitting of long lines (exceeding the configurable length). Length of 0 will
1459 * disable line splitting
1460 * - option id: "org.eclipse.jdt.core.formatter.lineSplit"
1461 * - possible values: "<n>", where n is zero or a positive integer
1464 * FORMATTER / Compacting Assignment
1465 * Assignments can be formatted asymmetrically, for example 'int x= 2;', when Normal, a space
1466 * is inserted before the assignment operator
1467 * - option id: "org.eclipse.jdt.core.formatter.style.assignment"
1468 * - possible values: { "compact", "normal" }
1469 * - default: "normal"
1471 * FORMATTER / Defining Indentation Character
1472 * Either choose to indent with tab characters or spaces
1473 * - option id: "org.eclipse.jdt.core.formatter.tabulation.char"
1474 * - possible values: { "tab", "space" }
1477 * FORMATTER / Defining Space Indentation Length
1478 * When using spaces, set the amount of space characters to use for each
1480 * - option id: "org.eclipse.jdt.core.formatter.tabulation.size"
1481 * - possible values: "<n>", where n is a positive integer
1484 * FORMATTER / Inserting space in cast expression
1485 * When Insert, a space is added between the type and the expression in a cast expression.
1486 * - option id: "org.eclipse.jdt.core.formatter.space.castexpression"
1487 * - possible values: { "insert", "do not insert" }
1488 * - default: "insert"
1490 * CODEASSIST / Activate Visibility Sensitive Completion
1491 * When active, completion doesn't show that you can not see
1492 * (for example, you can not see private methods of a super class).
1493 * - option id: "org.eclipse.jdt.core.codeComplete.visibilityCheck"
1494 * - possible values: { "enabled", "disabled" }
1495 * - default: "disabled"
1497 * CODEASSIST / Automatic Qualification of Implicit Members
1498 * When active, completion automatically qualifies completion on implicit
1499 * field references and message expressions.
1500 * - option id: "org.eclipse.jdt.core.codeComplete.forceImplicitQualification"
1501 * - possible values: { "enabled", "disabled" }
1502 * - default: "disabled"
1504 * CODEASSIST / Define the Prefixes for Field Name
1505 * When the prefixes is non empty, completion for field name will begin with
1506 * one of the proposed prefixes.
1507 * - option id: "org.eclipse.jdt.core.codeComplete.fieldPrefixes"
1508 * - possible values: { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
1511 * CODEASSIST / Define the Prefixes for Static Field Name
1512 * When the prefixes is non empty, completion for static field name will begin with
1513 * one of the proposed prefixes.
1514 * - option id: "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"
1515 * - possible values: { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
1518 * CODEASSIST / Define the Prefixes for Local Variable Name
1519 * When the prefixes is non empty, completion for local variable name will begin with
1520 * one of the proposed prefixes.
1521 * - option id: "org.eclipse.jdt.core.codeComplete.localPrefixes"
1522 * - possible values: { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
1525 * CODEASSIST / Define the Prefixes for Argument Name
1526 * When the prefixes is non empty, completion for argument name will begin with
1527 * one of the proposed prefixes.
1528 * - option id: "org.eclipse.jdt.core.codeComplete.argumentPrefixes"
1529 * - possible values: { "<prefix>[,<prefix>]*" } where <prefix> is a String without any wild-card
1532 * CODEASSIST / Define the Suffixes for Field Name
1533 * When the suffixes is non empty, completion for field name will end with
1534 * one of the proposed suffixes.
1535 * - option id: "org.eclipse.jdt.core.codeComplete.fieldSuffixes"
1536 * - possible values: { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card
1539 * CODEASSIST / Define the Suffixes for Static Field Name
1540 * When the suffixes is non empty, completion for static field name will end with
1541 * one of the proposed suffixes.
1542 * - option id: "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"
1543 * - possible values: { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card
1546 * CODEASSIST / Define the Suffixes for Local Variable Name
1547 * When the suffixes is non empty, completion for local variable name will end with
1548 * one of the proposed suffixes.
1549 * - option id: "org.eclipse.jdt.core.codeComplete.localSuffixes"
1550 * - possible values: { "<suffix>[,<suffix>]*" } where <suffix> is a String without any wild-card
1553 * CODEASSIST / Define the Suffixes for Argument Name
1554 * When the suffixes is non empty, completion for argument name will end with
1555 * one of the proposed suffixes.
1556 * - option id: "org.eclipse.jdt.core.codeComplete.argumentSuffixes"
1557 * - possible values: { "<suffix>[,<suffix>]*" } where <prefix> is a String without any wild-card
1561 * @return a mutable table containing the default settings of all known options
1562 * (key type: <code>String</code>; value type: <code>String</code>)
1565 public static Hashtable getDefaultOptions(){
1567 Hashtable defaultOptions = new Hashtable(10);
1569 // see #initializeDefaultPluginPreferences() for changing default settings
1570 Preferences preferences = getPlugin().getPluginPreferences();
1571 HashSet optionNames = JavaModelManager.OptionNames;
1573 // get preferences set to their default
1574 String[] defaultPropertyNames = preferences.defaultPropertyNames();
1575 for (int i = 0; i < defaultPropertyNames.length; i++){
1576 String propertyName = defaultPropertyNames[i];
1577 if (optionNames.contains(propertyName)) {
1578 defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
1581 // get preferences not set to their default
1582 String[] propertyNames = preferences.propertyNames();
1583 for (int i = 0; i < propertyNames.length; i++){
1584 String propertyName = propertyNames[i];
1585 if (optionNames.contains(propertyName)) {
1586 defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
1589 // get encoding through resource plugin
1590 defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
1592 return defaultOptions;
1596 * Returns the single instance of the Java core plug-in runtime class.
1597 * Equivalent to <code>(JavaCore) getPlugin()</code>.
1599 * @return the single instance of the Java core plug-in runtime class
1601 public static JavaCore getJavaCore() {
1602 return (JavaCore) getPlugin();
1606 * Helper method for returning one option value only. Equivalent to <code>(String)JavaCore.getOptions().get(optionName)</code>
1607 * Note that it may answer <code>null</code> if this option does not exist.
1609 * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
1612 * @param optionName the name of an option
1613 * @return the String value of a given option
1614 * @see JavaCore#getDefaultOptions
1617 public static String getOption(String optionName) {
1619 if (CORE_ENCODING.equals(optionName)){
1620 return ResourcesPlugin.getEncoding();
1622 if (JavaModelManager.OptionNames.contains(optionName)){
1623 Preferences preferences = getPlugin().getPluginPreferences();
1624 return preferences.getString(optionName).trim();
1630 * Returns the table of the current options. Initially, all options have their default values,
1631 * and this method returns a table that includes all known options.
1633 * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
1636 * @return table of current settings of all options
1637 * (key type: <code>String</code>; value type: <code>String</code>)
1638 * @see JavaCore#getDefaultOptions
1640 public static Hashtable getOptions() {
1642 Hashtable options = new Hashtable(10);
1644 // see #initializeDefaultPluginPreferences() for changing default settings
1645 Plugin plugin = getPlugin();
1646 if (plugin != null) {
1647 Preferences preferences = getPlugin().getPluginPreferences();
1648 HashSet optionNames = JavaModelManager.OptionNames;
1650 // get preferences set to their default
1651 String[] defaultPropertyNames = preferences.defaultPropertyNames();
1652 for (int i = 0; i < defaultPropertyNames.length; i++){
1653 String propertyName = defaultPropertyNames[i];
1654 if (optionNames.contains(propertyName)){
1655 options.put(propertyName, preferences.getDefaultString(propertyName));
1658 // get preferences not set to their default
1659 String[] propertyNames = preferences.propertyNames();
1660 for (int i = 0; i < propertyNames.length; i++){
1661 String propertyName = propertyNames[i];
1662 if (optionNames.contains(propertyName)){
1663 options.put(propertyName, preferences.getString(propertyName).trim());
1666 // get encoding through resource plugin
1667 options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
1673 * Returns the single instance of the Java core plug-in runtime class.
1675 * @return the single instance of the Java core plug-in runtime class
1677 public static Plugin getPlugin() {
1678 return JAVA_CORE_PLUGIN;
1682 * This is a helper method, which returns the resolved classpath entry denoted
1683 * by a given entry (if it is a variable entry). It is obtained by resolving the variable
1684 * reference in the first segment. Returns <node>null</code> if unable to resolve using
1685 * the following algorithm:
1687 * <li> if variable segment cannot be resolved, returns <code>null</code></li>
1688 * <li> finds a project, JAR or binary folder in the workspace at the resolved path location</li>
1689 * <li> if none finds an external JAR file or folder outside the workspace at the resolved path location </li>
1690 * <li> if none returns <code>null</code></li>
1693 * Variable source attachment path and root path are also resolved and recorded in the resulting classpath entry.
1695 * NOTE: This helper method does not handle classpath containers, for which should rather be used
1696 * <code>JavaCore#getClasspathContainer(IPath, IJavaProject)</code>.
1699 * @param entry the given variable entry
1700 * @return the resolved library or project classpath entry, or <code>null</code>
1701 * if the given variable entry could not be resolved to a valid classpath entry
1703 // public static IClasspathEntry getResolvedClasspathEntry(IClasspathEntry entry) {
1705 // if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
1708 // IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1709 // IPath resolvedPath = JavaCore.getResolvedVariablePath(entry.getPath());
1710 // if (resolvedPath == null)
1713 // Object target = JavaModel.getTarget(workspaceRoot, resolvedPath, false);
1714 // if (target == null)
1717 // // inside the workspace
1718 // if (target instanceof IResource) {
1719 // IResource resolvedResource = (IResource) target;
1720 // if (resolvedResource != null) {
1721 // switch (resolvedResource.getType()) {
1723 // case IResource.PROJECT :
1724 // // internal project
1725 // return JavaCore.newProjectEntry(resolvedPath, entry.isExported());
1727 // case IResource.FILE :
1728 // if (Util.isArchiveFileName(resolvedResource.getName())) {
1729 // // internal binary archive
1730 // return JavaCore.newLibraryEntry(
1732 // getResolvedVariablePath(entry.getSourceAttachmentPath()),
1733 // getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
1734 // entry.isExported());
1738 // case IResource.FOLDER :
1739 // // internal binary folder
1740 // return JavaCore.newLibraryEntry(
1742 // getResolvedVariablePath(entry.getSourceAttachmentPath()),
1743 // getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
1744 // entry.isExported());
1748 // // outside the workspace
1749 // if (target instanceof File) {
1750 // File externalFile = (File) target;
1751 // if (externalFile.isFile()) {
1752 // String fileName = externalFile.getName().toLowerCase();
1753 // if (fileName.endsWith(".jar" //$NON-NLS-1$
1754 // ) || fileName.endsWith(".zip" //$NON-NLS-1$
1755 // )) { // external binary archive
1756 // return JavaCore.newLibraryEntry(
1758 // getResolvedVariablePath(entry.getSourceAttachmentPath()),
1759 // getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
1760 // entry.isExported());
1762 // } else { // external binary folder
1763 // if (resolvedPath.isAbsolute()){
1764 // return JavaCore.newLibraryEntry(
1766 // getResolvedVariablePath(entry.getSourceAttachmentPath()),
1767 // getResolvedVariablePath(entry.getSourceAttachmentRootPath()),
1768 // entry.isExported());
1777 * Resolve a variable path (helper method).
1779 * @param variablePath the given variable path
1780 * @return the resolved variable path or <code>null</code> if none
1782 // public static IPath getResolvedVariablePath(IPath variablePath) {
1784 // if (variablePath == null)
1786 // int count = variablePath.segmentCount();
1790 // // lookup variable
1791 // String variableName = variablePath.segment(0);
1792 // IPath resolvedPath = JavaCore.getClasspathVariable(variableName);
1793 // if (resolvedPath == null)
1796 // // append path suffix
1798 // resolvedPath = resolvedPath.append(variablePath.removeFirstSegments(1));
1800 // return resolvedPath;
1804 * Answers the shared working copies currently registered for this buffer factory.
1805 * Working copies can be shared by several clients using the same buffer factory,see
1806 * <code>IWorkingCopy.getSharedWorkingCopy</code>.
1808 * @param factory the given buffer factory
1809 * @return the list of shared working copies for a given buffer factory
1813 public static IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory){
1815 // if factory is null, default factory must be used
1816 if (factory == null) factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
1817 Map sharedWorkingCopies = JavaModelManager.getJavaModelManager().sharedWorkingCopies;
1819 Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
1820 if (perFactoryWorkingCopies == null) return JavaModelManager.NoWorkingCopy;
1821 Collection copies = perFactoryWorkingCopies.values();
1822 IWorkingCopy[] result = new IWorkingCopy[copies.size()];
1823 copies.toArray(result);
1828 * Initializes the default preferences settings for this plug-in.
1830 protected void initializeDefaultPluginPreferences() {
1832 Preferences preferences = getPluginPreferences();
1833 HashSet optionNames = JavaModelManager.OptionNames;
1835 // Compiler settings
1836 preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
1837 optionNames.add(COMPILER_LOCAL_VARIABLE_ATTR);
1839 preferences.setDefault(COMPILER_LINE_NUMBER_ATTR, GENERATE);
1840 optionNames.add(COMPILER_LINE_NUMBER_ATTR);
1842 preferences.setDefault(COMPILER_SOURCE_FILE_ATTR, GENERATE);
1843 optionNames.add(COMPILER_SOURCE_FILE_ATTR);
1845 preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE);
1846 optionNames.add(COMPILER_CODEGEN_UNUSED_LOCAL);
1848 preferences.setDefault(COMPILER_CODEGEN_TARGET_PLATFORM, VERSION_1_1);
1849 optionNames.add(COMPILER_CODEGEN_TARGET_PLATFORM);
1851 preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR);
1852 optionNames.add(COMPILER_PB_UNREACHABLE_CODE);
1854 preferences.setDefault(COMPILER_PB_INVALID_IMPORT, ERROR);
1855 optionNames.add(COMPILER_PB_INVALID_IMPORT);
1857 preferences.setDefault(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, WARNING);
1858 optionNames.add(COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD);
1860 preferences.setDefault(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, WARNING);
1861 optionNames.add(COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME);
1863 preferences.setDefault(COMPILER_PB_DEPRECATION, WARNING);
1864 optionNames.add(COMPILER_PB_DEPRECATION);
1866 preferences.setDefault(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE, DISABLED);
1867 optionNames.add(COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE);
1869 preferences.setDefault(COMPILER_PB_HIDDEN_CATCH_BLOCK, WARNING);
1870 optionNames.add(COMPILER_PB_HIDDEN_CATCH_BLOCK);
1872 preferences.setDefault(COMPILER_PB_UNUSED_LOCAL, IGNORE);
1873 optionNames.add(COMPILER_PB_UNUSED_LOCAL);
1875 preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER, IGNORE);
1876 optionNames.add(COMPILER_PB_UNUSED_PARAMETER);
1878 preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT, DISABLED);
1879 optionNames.add(COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT);
1881 preferences.setDefault(COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE, DISABLED);
1882 optionNames.add(COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE);
1884 preferences.setDefault(COMPILER_PB_UNUSED_IMPORT, WARNING);
1885 optionNames.add(COMPILER_PB_UNUSED_IMPORT);
1887 preferences.setDefault(COMPILER_PB_UNUSED_PRIVATE_MEMBER, IGNORE);
1888 optionNames.add(COMPILER_PB_UNUSED_PRIVATE_MEMBER);
1890 preferences.setDefault(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, IGNORE);
1891 optionNames.add(COMPILER_PB_SYNTHETIC_ACCESS_EMULATION);
1893 preferences.setDefault(COMPILER_PB_NON_NLS_STRING_LITERAL, IGNORE);
1894 optionNames.add(COMPILER_PB_NON_NLS_STRING_LITERAL);
1896 preferences.setDefault(COMPILER_PB_ASSERT_IDENTIFIER, IGNORE);
1897 optionNames.add(COMPILER_PB_ASSERT_IDENTIFIER);
1899 preferences.setDefault(COMPILER_PB_STATIC_ACCESS_RECEIVER, WARNING);
1900 optionNames.add(COMPILER_PB_STATIC_ACCESS_RECEIVER);
1902 preferences.setDefault(COMPILER_PB_NO_EFFECT_ASSIGNMENT, WARNING);
1903 optionNames.add(COMPILER_PB_NO_EFFECT_ASSIGNMENT);
1905 preferences.setDefault(COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD, WARNING);
1906 optionNames.add(COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD);
1908 preferences.setDefault(COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION, WARNING);
1909 optionNames.add(COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION);
1911 preferences.setDefault(COMPILER_TASK_TAGS, DEFAULT_TASK_TAG); //$NON-NLS-1$
1912 optionNames.add(COMPILER_TASK_TAGS);
1914 preferences.setDefault(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITY); //$NON-NLS-1$
1915 optionNames.add(COMPILER_TASK_PRIORITIES);
1917 preferences.setDefault(COMPILER_SOURCE, VERSION_1_3);
1918 optionNames.add(COMPILER_SOURCE);
1920 preferences.setDefault(COMPILER_COMPLIANCE, VERSION_1_3);
1921 optionNames.add(COMPILER_COMPLIANCE);
1923 preferences.setDefault(COMPILER_PB_MAX_PER_UNIT, "100"); //$NON-NLS-1$
1924 optionNames.add(COMPILER_PB_MAX_PER_UNIT);
1927 preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
1928 optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
1930 preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT);
1931 optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
1933 preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING);
1934 optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
1936 preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN);
1937 optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
1939 // JavaCore settings
1940 preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE);
1941 optionNames.add(CORE_JAVA_BUILD_ORDER);
1943 preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR);
1944 optionNames.add(CORE_CIRCULAR_CLASSPATH);
1946 preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR);
1947 optionNames.add(CORE_INCOMPLETE_CLASSPATH);
1949 preferences.setDefault(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED);
1950 optionNames.add(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
1952 preferences.setDefault(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED);
1953 optionNames.add(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
1955 // encoding setting comes from resource plug-in
1956 optionNames.add(CORE_ENCODING);
1958 // Formatter settings
1959 preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT);
1960 optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
1962 preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
1963 optionNames.add(FORMATTER_NEWLINE_CONTROL);
1965 preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE);
1966 optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
1968 preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
1969 optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
1971 preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT);
1972 optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
1974 preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
1975 optionNames.add(FORMATTER_LINE_SPLIT);
1977 preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL);
1978 optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
1980 preferences.setDefault(FORMATTER_TAB_CHAR, TAB);
1981 optionNames.add(FORMATTER_TAB_CHAR);
1983 preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$
1984 optionNames.add(FORMATTER_TAB_SIZE);
1986 preferences.setDefault(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$
1987 optionNames.add(FORMATTER_SPACE_CASTEXPRESSION);
1989 // CodeAssist settings
1990 preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
1991 optionNames.add(CODEASSIST_VISIBILITY_CHECK);
1993 preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
1994 optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
1996 preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
1997 optionNames.add(CODEASSIST_FIELD_PREFIXES);
1999 preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
2000 optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
2002 preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
2003 optionNames.add(CODEASSIST_LOCAL_PREFIXES);
2005 preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
2006 optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
2008 preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2009 optionNames.add(CODEASSIST_FIELD_SUFFIXES);
2011 preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2012 optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
2014 preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
2015 optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
2017 preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
2018 optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
2022 * Returns whether the given marker references the given Java element.
2023 * Used for markers, which denote a Java element rather than a resource.
2025 * @param element the element
2026 * @param marker the marker
2027 * @return <code>true</code> if the marker references the element, false otherwise
2028 * @exception CoreException if the <code>IMarker.getAttribute</code> on the marker fails
2030 public static boolean isReferencedBy(IJavaElement element, IMarker marker) throws CoreException {
2032 // only match units or classfiles
2033 if (element instanceof IMember){
2034 IMember member = (IMember) element;
2035 if (member.isBinary()){
2036 element = null; //member.getClassFile();
2038 element = member.getCompilationUnit();
2041 if (element == null) return false;
2042 if (marker == null) return false;
2044 String markerHandleId = (String)marker.getAttribute(ATT_HANDLE_ID);
2045 if (markerHandleId == null) return false;
2047 IJavaElement markerElement = JavaCore.create(markerHandleId);
2049 if (element.equals(markerElement)) return true; // external elements may still be equal with different handleIDs.
2051 // cycle through enclosing types in case marker is associated with a classfile (15568)
2052 // if (markerElement instanceof IClassFile){
2053 // IType enclosingType = ((IClassFile)markerElement).getType().getDeclaringType();
2054 // if (enclosingType != null){
2055 // markerElement = enclosingType.getClassFile(); // retry with immediate enclosing classfile
2065 * Returns whether the given marker delta references the given Java element.
2066 * Used for markers deltas, which denote a Java element rather than a resource.
2068 * @param element the element
2069 * @param markerDelta the marker delta
2070 * @return <code>true</code> if the marker delta references the element
2071 * @exception CoreException if the <code>IMarkerDelta.getAttribute</code> on the marker delta fails
2073 public static boolean isReferencedBy(IJavaElement element, IMarkerDelta markerDelta) throws CoreException {
2075 // only match units or classfiles
2076 if (element instanceof IMember){
2077 IMember member = (IMember) element;
2078 if (member.isBinary()){
2079 element = null; //member.getClassFile();
2081 element = member.getCompilationUnit();
2084 if (element == null) return false;
2085 if (markerDelta == null) return false;
2087 String markerDeltarHandleId = (String)markerDelta.getAttribute(ATT_HANDLE_ID);
2088 if (markerDeltarHandleId == null) return false;
2090 IJavaElement markerElement = JavaCore.create(markerDeltarHandleId);
2092 if (element.equals(markerElement)) return true; // external elements may still be equal with different handleIDs.
2094 // cycle through enclosing types in case marker is associated with a classfile (15568)
2095 // if (markerElement instanceof IClassFile){
2096 // IType enclosingType = ((IClassFile)markerElement).getType().getDeclaringType();
2097 // if (enclosingType != null){
2098 // markerElement = enclosingType.getClassFile(); // retry with immediate enclosing classfile
2108 * Creates and returns a new classpath entry of kind <code>CPE_CONTAINER</code>
2109 * for the given path. The path of the container will be used during resolution so as to map this
2110 * container entry to a set of other classpath entries the container is acting for.
2112 * A container entry allows to express indirect references to a set of libraries, projects and variable entries,
2113 * which can be interpreted differently for each Java project where it is used.
2114 * A classpath container entry can be resolved using <code>JavaCore.getResolvedClasspathContainer</code>,
2115 * and updated with <code>JavaCore.classpathContainerChanged</code>
2117 * A container is exclusively resolved by a <code>ClasspathContainerInitializer</code> registered onto the
2118 * extension point "org.eclipse.jdt.core.classpathContainerInitializer".
2120 * A container path must be formed of at least one segment, where: <ul>
2121 * <li> the first segment is a unique ID identifying the target container, there must be a container initializer registered
2122 * onto this ID through the extension point "org.eclipse.jdt.core.classpathContainerInitializer". </li>
2123 * <li> the remaining segments will be passed onto the initializer, and can be used as additional
2124 * hints during the initialization phase. </li>
2127 * Example of an ClasspathContainerInitializer for a classpath container denoting a default JDK container:
2129 * containerEntry = JavaCore.newContainerEntry(new Path("MyProvidedJDK/default"));
2132 * point="org.eclipse.jdt.core.classpathContainerInitializer">
2133 * <containerInitializer
2134 * id="MyProvidedJDK"
2135 * class="com.example.MyInitializer"/>
2137 * Note that this operation does not attempt to validate classpath containers
2138 * or access the resources at the given paths.
2140 * The resulting entry is not exported to dependent projects. This method is equivalent to
2141 * <code>newContainerEntry(-,false)</code>.
2143 * @param containerPath the path identifying the container, it must be formed of two
2145 * @return a new container classpath entry
2147 * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
2148 * @see JavaCore#newContainerEntry(IPath, boolean)
2151 // public static IClasspathEntry newContainerEntry(IPath containerPath) {
2153 // return newContainerEntry(containerPath, false);
2157 * Creates and returns a new classpath entry of kind <code>CPE_CONTAINER</code>
2158 * for the given path. The path of the container will be used during resolution so as to map this
2159 * container entry to a set of other classpath entries the container is acting for.
2161 * A container entry allows to express indirect references to a set of libraries, projects and variable entries,
2162 * which can be interpreted differently for each Java project where it is used.
2163 * A classpath container entry can be resolved using <code>JavaCore.getResolvedClasspathContainer</code>,
2164 * and updated with <code>JavaCore.classpathContainerChanged</code>
2166 * A container is exclusively resolved by a <code>ClasspathContainerInitializer</code> registered onto the
2167 * extension point "org.eclipse.jdt.core.classpathContainerInitializer".
2169 * A container path must be formed of at least one segment, where: <ul>
2170 * <li> the first segment is a unique ID identifying the target container, there must be a container initializer registered
2171 * onto this ID through the extension point "org.eclipse.jdt.core.classpathContainerInitializer". </li>
2172 * <li> the remaining segments will be passed onto the initializer, and can be used as additional
2173 * hints during the initialization phase. </li>
2176 * Example of an ClasspathContainerInitializer for a classpath container denoting a default JDK container:
2178 * containerEntry = JavaCore.newContainerEntry(new Path("MyProvidedJDK/default"));
2181 * point="org.eclipse.jdt.core.classpathContainerInitializer">
2182 * <containerInitializer
2183 * id="MyProvidedJDK"
2184 * class="com.example.MyInitializer"/>
2186 * Note that this operation does not attempt to validate classpath containers
2187 * or access the resources at the given paths.
2189 * @param containerPath the path identifying the container, it must be formed of at least
2190 * one segment (ID+hints)
2191 * @param isExported a boolean indicating whether this entry is contributed to dependent
2192 * projects in addition to the output location
2193 * @return a new container classpath entry
2195 * @see JavaCore#getClasspathContainer(IPath, IJavaProject)
2196 * @see JavaCore#setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor)
2197 * @see JavaCore#newContainerEntry(IPath, boolean)
2200 // public static IClasspathEntry newContainerEntry(IPath containerPath, boolean isExported) {
2202 // if (containerPath == null || containerPath.segmentCount() < 1) {
2205 // "Illegal classpath container path: \'" + containerPath.makeRelative().toString() + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$//$NON-NLS-2$
2207 // return new ClasspathEntry(
2208 // IPackageFragmentRoot.K_SOURCE,
2209 // IClasspathEntry.CPE_CONTAINER,
2211 // ClasspathEntry.NO_EXCLUSION_PATTERNS,
2212 // null, // source attachment
2213 // null, // source attachment root
2214 // null, // specific output folder
2219 * Creates and returns a new non-exported classpath entry of kind <code>CPE_LIBRARY</code> for the
2220 * JAR or folder identified by the given absolute path. This specifies that all package fragments
2221 * within the root will have children of type <code>IClassFile</code>.
2223 * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
2224 * The target JAR or folder can either be defined internally to the workspace (absolute path relative
2225 * to the workspace root) or externally to the workspace (absolute path in the file system).
2227 * e.g. Here are some examples of binary path usage<ul>
2228 * <li><code> "c:/jdk1.2.2/jre/lib/rt.jar" </code> - reference to an external JAR</li>
2229 * <li><code> "/Project/someLib.jar" </code> - reference to an internal JAR </li>
2230 * <li><code> "c:/classes/" </code> - reference to an external binary folder</li>
2232 * Note that this operation does not attempt to validate or access the
2233 * resources at the given paths.
2235 * The resulting entry is not exported to dependent projects. This method is equivalent to
2236 * <code>newLibraryEntry(-,-,-,false)</code>.
2239 * @param path the absolute path of the binary archive
2240 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
2241 * or <code>null</code> if none
2242 * @param sourceAttachmentRootPath the location of the root within the source archive or folder
2243 * or <code>null</code> if this location should be automatically detected.
2244 * @return a new library classpath entry
2246 * @see #newLibraryEntry(IPath, IPath, IPath, boolean)
2248 // public static IClasspathEntry newLibraryEntry(
2250 // IPath sourceAttachmentPath,
2251 // IPath sourceAttachmentRootPath) {
2253 // return newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, false);
2257 * Creates and returns a new classpath entry of kind <code>CPE_LIBRARY</code> for the JAR or folder
2258 * identified by the given absolute path. This specifies that all package fragments within the root
2259 * will have children of type <code>IClassFile</code>.
2261 * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
2262 * The target JAR or folder can either be defined internally to the workspace (absolute path relative
2263 * to the workspace root) or externally to the workspace (absolute path in the file system).
2265 * e.g. Here are some examples of binary path usage<ul>
2266 * <li><code> "c:/jdk1.2.2/jre/lib/rt.jar" </code> - reference to an external JAR</li>
2267 * <li><code> "/Project/someLib.jar" </code> - reference to an internal JAR </li>
2268 * <li><code> "c:/classes/" </code> - reference to an external binary folder</li>
2270 * Note that this operation does not attempt to validate or access the
2271 * resources at the given paths.
2274 * @param path the absolute path of the binary archive
2275 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
2276 * or <code>null</code> if none
2277 * @param sourceAttachmentRootPath the location of the root within the source archive or folder
2278 * or <code>null</code> if this location should be automatically detected.
2279 * @param isExported indicates whether this entry is contributed to dependent
2280 * projects in addition to the output location
2281 * @return a new library classpath entry
2284 // public static IClasspathEntry newLibraryEntry(
2286 // IPath sourceAttachmentPath,
2287 // IPath sourceAttachmentRootPath,
2288 // boolean isExported) {
2290 // if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
2292 // return new ClasspathEntry(
2293 // IPackageFragmentRoot.K_BINARY,
2294 // IClasspathEntry.CPE_LIBRARY,
2295 // JavaProject.canonicalizedPath(path),
2296 // ClasspathEntry.NO_EXCLUSION_PATTERNS,
2297 // sourceAttachmentPath,
2298 // sourceAttachmentRootPath,
2299 // null, // specific output folder
2304 * Creates and returns a new non-exported classpath entry of kind <code>CPE_PROJECT</code>
2305 * for the project identified by the given absolute path.
2307 * A project entry is used to denote a prerequisite project on a classpath.
2308 * The referenced project will be contributed as a whole, either as sources (in the Java Model, it
2309 * contributes all its package fragment roots) or as binaries (when building, it contributes its
2310 * whole output location).
2312 * A project reference allows to indirect through another project, independently from its internal layout.
2314 * The prerequisite project is referred to using an absolute path relative to the workspace root.
2316 * The resulting entry is not exported to dependent projects. This method is equivalent to
2317 * <code>newProjectEntry(_,false)</code>.
2320 * @param path the absolute path of the binary archive
2321 * @return a new project classpath entry
2323 * @see JavaCore#newProjectEntry(IPath, boolean)
2325 // public static IClasspathEntry newProjectEntry(IPath path) {
2326 // return newProjectEntry(path, false);
2330 * Creates and returns a new classpath entry of kind <code>CPE_PROJECT</code>
2331 * for the project identified by the given absolute path.
2333 * A project entry is used to denote a prerequisite project on a classpath.
2334 * The referenced project will be contributed as a whole, either as sources (in the Java Model, it
2335 * contributes all its package fragment roots) or as binaries (when building, it contributes its
2336 * whole output location).
2338 * A project reference allows to indirect through another project, independently from its internal layout.
2340 * The prerequisite project is referred to using an absolute path relative to the workspace root.
2343 * @param path the absolute path of the prerequisite project
2344 * @param isExported indicates whether this entry is contributed to dependent
2345 * projects in addition to the output location
2346 * @return a new project classpath entry
2349 // public static IClasspathEntry newProjectEntry(IPath path, boolean isExported) {
2351 // if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
2353 // return new ClasspathEntry(
2354 // IPackageFragmentRoot.K_SOURCE,
2355 // IClasspathEntry.CPE_PROJECT,
2357 // ClasspathEntry.NO_EXCLUSION_PATTERNS,
2358 // null, // source attachment
2359 // null, // source attachment root
2360 // null, // specific output folder
2365 * Returns a new empty region.
2367 * @return a new empty region
2369 public static IRegion newRegion() {
2370 return new Region();
2374 * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
2375 * for the project's source folder identified by the given absolute
2376 * workspace-relative path. This specifies that all package fragments
2377 * within the root will have children of type <code>ICompilationUnit</code>.
2379 * The source folder is referred to using an absolute path relative to the
2380 * workspace root, e.g. <code>/Project/src</code>. A project's source
2381 * folders are located with that project. That is, a source classpath
2382 * entry specifying the path <code>/P1/src</code> is only usable for
2383 * project <code>P1</code>.
2386 * The source classpath entry created by this method includes all source
2387 * files below the given workspace-relative path. To selectively exclude
2388 * some of these source files, use the factory method
2389 * <code>JavaCore.newSourceEntry(IPath,IPath[])</code> instead.
2392 * Note that all sources/binaries inside a project are contributed as a whole through
2393 * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
2394 * source entries cannot be selectively exported.
2397 * @param path the absolute workspace-relative path of a source folder
2398 * @return a new source classpath entry with not exclusion patterns
2400 * @see #newSourceEntry(org.eclipse.core.runtime.IPath,org.eclipse.core.runtime.IPath[])
2402 // public static IClasspathEntry newSourceEntry(IPath path) {
2404 // return newSourceEntry(path, ClasspathEntry.NO_EXCLUSION_PATTERNS, null /*output location*/);
2408 * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
2409 * for the project's source folder identified by the given absolute
2410 * workspace-relative path but excluding all source files with paths
2411 * matching any of the given patterns. This specifies that all package
2412 * fragments within the root will have children of type
2413 * <code>ICompilationUnit</code>.
2415 * The source folder is referred to using an absolute path relative to the
2416 * workspace root, e.g. <code>/Project/src</code>. A project's source
2417 * folders are located with that project. That is, a source classpath
2418 * entry specifying the path <code>/P1/src</code> is only usable for
2419 * project <code>P1</code>.
2422 * The source classpath entry created by this method includes all source
2423 * files below the given workspace-relative path except for those matched
2424 * by one (or more) of the given exclusion patterns. Each exclusion pattern
2425 * is represented by a relative path, which is interpreted as relative to
2426 * the source folder. For example, if the source folder path is
2427 * <code>/Project/src</code> and the exclusion pattern is
2428 * <code>com/xyz/tests/**</code>, then source files
2429 * like <code>/Project/src/com/xyz/Foo.java</code>
2430 * and <code>/Project/src/com/xyz/utils/Bar.java</code> would be included,
2431 * whereas <code>/Project/src/com/xyz/tests/T1.java</code>
2432 * and <code>/Project/src/com/xyz/tests/quick/T2.java</code> would be
2433 * excluded. Exclusion patterns can contain can contain '**', '*' or '?'
2434 * wildcards; see <code>IClasspathEntry.getExclusionPatterns</code>
2435 * for the full description of the syntax and semantics of exclusion
2438 * If the empty list of exclusion patterns is specified, the source folder
2439 * will automatically include all resources located inside the source
2440 * folder. In that case, the result is entirely equivalent to using the
2441 * factory method <code>JavaCore.newSourceEntry(IPath)</code>.
2444 * Note that all sources/binaries inside a project are contributed as a whole through
2445 * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
2446 * source entries cannot be selectively exported.
2449 * @param path the absolute workspace-relative path of a source folder
2450 * @param exclusionPatterns the possibly empty list of exclusion patterns
2451 * represented as relative paths
2452 * @return a new source classpath entry with the given exclusion patterns
2453 * @see #newSourceEntry(org.eclipse.core.runtime.IPath)
2454 * @see IClasspathEntry#getExclusionPatterns
2458 // public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) {
2460 // return newSourceEntry(path, exclusionPatterns, null /*output location*/);
2464 * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code>
2465 * for the project's source folder identified by the given absolute
2466 * workspace-relative path but excluding all source files with paths
2467 * matching any of the given patterns, and associated with a specific output location
2468 * (that is, ".class" files are not going to the project default output location).
2469 * All package fragments within the root will have children of type
2470 * <code>ICompilationUnit</code>.
2472 * The source folder is referred to using an absolute path relative to the
2473 * workspace root, e.g. <code>/Project/src</code>. A project's source
2474 * folders are located with that project. That is, a source classpath
2475 * entry specifying the path <code>/P1/src</code> is only usable for
2476 * project <code>P1</code>.
2479 * The source classpath entry created by this method includes all source
2480 * files below the given workspace-relative path except for those matched
2481 * by one (or more) of the given exclusion patterns. Each exclusion pattern
2482 * is represented by a relative path, which is interpreted as relative to
2483 * the source folder. For example, if the source folder path is
2484 * <code>/Project/src</code> and the exclusion pattern is
2485 * <code>com/xyz/tests/**</code>, then source files
2486 * like <code>/Project/src/com/xyz/Foo.java</code>
2487 * and <code>/Project/src/com/xyz/utils/Bar.java</code> would be included,
2488 * whereas <code>/Project/src/com/xyz/tests/T1.java</code>
2489 * and <code>/Project/src/com/xyz/tests/quick/T2.java</code> would be
2490 * excluded. Exclusion patterns can contain can contain '**', '*' or '?'
2491 * wildcards; see <code>IClasspathEntry.getExclusionPatterns</code>
2492 * for the full description of the syntax and semantics of exclusion
2495 * If the empty list of exclusion patterns is specified, the source folder
2496 * will automatically include all resources located inside the source
2497 * folder. In that case, the result is entirely equivalent to using the
2498 * factory method <code>JavaCore.newSourceEntry(IPath)</code>.
2501 * Additionally, a source entry can be associated with a specific output location.
2502 * By doing so, the Java builder will ensure that the generated ".class" files will
2503 * be issued inside this output location, as opposed to be generated into the
2504 * project default output location (when output location is <code>null</code>).
2505 * Note that multiple source entries may target the same output location.
2506 * The output location is referred to using an absolute path relative to the
2507 * workspace root, e.g. <code>"/Project/bin"</code>, it must be located inside
2508 * the same project as the source folder.
2511 * Also note that all sources/binaries inside a project are contributed as a whole through
2512 * a project entry (see <code>JavaCore.newProjectEntry</code>). Particular
2513 * source entries cannot be selectively exported.
2516 * @param path the absolute workspace-relative path of a source folder
2517 * @param exclusionPatterns the possibly empty list of exclusion patterns
2518 * represented as relative paths
2519 * @param outputLocation the specific output location for this source entry (<code>null</code> if using project default ouput location)
2520 * @return a new source classpath entry with the given exclusion patterns
2521 * @see #newSourceEntry(org.eclipse.core.runtime.IPath)
2522 * @see IClasspathEntry#getExclusionPatterns
2523 * @see IClasspathEntry#getOutputLocation()
2527 // public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns, IPath specificOutputLocation) {
2529 // if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
2530 // if (exclusionPatterns == null) Assert.isTrue(false, "Exclusion pattern set cannot be null"); //$NON-NLS-1$
2532 // return new ClasspathEntry(
2533 // IPackageFragmentRoot.K_SOURCE,
2534 // IClasspathEntry.CPE_SOURCE,
2536 // exclusionPatterns,
2537 // null, // source attachment
2538 // null, // source attachment root
2539 // specificOutputLocation, // custom output location
2544 * Creates and returns a new non-exported classpath entry of kind <code>CPE_VARIABLE</code>
2545 * for the given path. The first segment of the path is the name of a classpath variable.
2546 * The trailing segments of the path will be appended to resolved variable path.
2548 * A variable entry allows to express indirect references on a classpath to other projects or libraries,
2549 * depending on what the classpath variable is referring.
2551 * It is possible to register an automatic initializer (<code>ClasspathVariableInitializer</code>),
2552 * which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
2553 * After resolution, a classpath variable entry may either correspond to a project or a library entry. </li>
2555 * e.g. Here are some examples of variable path usage<ul>
2556 * <li> "JDTCORE" where variable <code>JDTCORE</code> is
2557 * bound to "c:/jars/jdtcore.jar". The resolved classpath entry is denoting the library "c:\jars\jdtcore.jar"</li>
2558 * <li> "JDTCORE" where variable <code>JDTCORE</code> is
2559 * bound to "/Project_JDTCORE". The resolved classpath entry is denoting the project "/Project_JDTCORE"</li>
2560 * <li> "PLUGINS/com.example/example.jar" where variable <code>PLUGINS</code>
2561 * is bound to "c:/eclipse/plugins". The resolved classpath entry is denoting the library "c:/eclipse/plugins/com.example/example.jar"</li>
2563 * Note that this operation does not attempt to validate classpath variables
2564 * or access the resources at the given paths.
2566 * The resulting entry is not exported to dependent projects. This method is equivalent to
2567 * <code>newVariableEntry(-,-,-,false)</code>.
2570 * @param variablePath the path of the binary archive; first segment is the
2571 * name of a classpath variable
2572 * @param variableSourceAttachmentPath the path of the corresponding source archive,
2573 * or <code>null</code> if none; if present, the first segment is the
2574 * name of a classpath variable (not necessarily the same variable
2575 * as the one that begins <code>variablePath</code>)
2576 * @param sourceAttachmentRootPath the location of the root within the source archive
2577 * or <code>null</code> if <code>archivePath</code> is also <code>null</code>
2578 * @return a new library classpath entry
2580 * @see JavaCore#newVariableEntry(IPath, IPath, IPath, boolean)
2582 // public static IClasspathEntry newVariableEntry(
2583 // IPath variablePath,
2584 // IPath variableSourceAttachmentPath,
2585 // IPath sourceAttachmentRootPath) {
2587 // return newVariableEntry(variablePath, variableSourceAttachmentPath, sourceAttachmentRootPath, false);
2591 * Creates and returns a new non-exported classpath entry of kind <code>CPE_VARIABLE</code>
2592 * for the given path. The first segment of the path is the name of a classpath variable.
2593 * The trailing segments of the path will be appended to resolved variable path.
2595 * A variable entry allows to express indirect references on a classpath to other projects or libraries,
2596 * depending on what the classpath variable is referring.
2598 * It is possible to register an automatic initializer (<code>ClasspathVariableInitializer</code>),
2599 * which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
2600 * After resolution, a classpath variable entry may either correspond to a project or a library entry. </li>
2602 * e.g. Here are some examples of variable path usage<ul>
2603 * <li> "JDTCORE" where variable <code>JDTCORE</code> is
2604 * bound to "c:/jars/jdtcore.jar". The resolved classpath entry is denoting the library "c:\jars\jdtcore.jar"</li>
2605 * <li> "JDTCORE" where variable <code>JDTCORE</code> is
2606 * bound to "/Project_JDTCORE". The resolved classpath entry is denoting the project "/Project_JDTCORE"</li>
2607 * <li> "PLUGINS/com.example/example.jar" where variable <code>PLUGINS</code>
2608 * is bound to "c:/eclipse/plugins". The resolved classpath entry is denoting the library "c:/eclipse/plugins/com.example/example.jar"</li>
2610 * Note that this operation does not attempt to validate classpath variables
2611 * or access the resources at the given paths.
2614 * @param variablePath the path of the binary archive; first segment is the
2615 * name of a classpath variable
2616 * @param variableSourceAttachmentPath the path of the corresponding source archive,
2617 * or <code>null</code> if none; if present, the first segment is the
2618 * name of a classpath variable (not necessarily the same variable
2619 * as the one that begins <code>variablePath</code>)
2620 * @param sourceAttachmentRootPath the location of the root within the source archive
2621 * or <code>null</code> if <code>archivePath</code> is also <code>null</code>
2622 * @param isExported indicates whether this entry is contributed to dependent
2623 * projects in addition to the output location
2624 * @return a new variable classpath entry
2627 // public static IClasspathEntry newVariableEntry(
2628 // IPath variablePath,
2629 // IPath variableSourceAttachmentPath,
2630 // IPath variableSourceAttachmentRootPath,
2631 // boolean isExported) {
2633 // if (variablePath == null || variablePath.segmentCount() < 1) {
2636 // "Illegal classpath variable path: \'" + variablePath.makeRelative().toString() + "\', must have at least one segment"); //$NON-NLS-1$//$NON-NLS-2$
2639 // return new ClasspathEntry(
2640 // IPackageFragmentRoot.K_SOURCE,
2641 // IClasspathEntry.CPE_VARIABLE,
2643 // ClasspathEntry.NO_EXCLUSION_PATTERNS,
2644 // variableSourceAttachmentPath, // source attachment
2645 // variableSourceAttachmentRootPath, // source attachment root
2646 // null, // specific output folder
2651 * Removed the given classpath variable. Does nothing if no value was
2652 * set for this classpath variable.
2654 * This functionality cannot be used while the resource tree is locked.
2656 * Classpath variable values are persisted locally to the workspace, and
2657 * are preserved from session to session.
2660 * @param variableName the name of the classpath variable
2661 * @see #setClasspathVariable
2663 * @deprecated - use version with extra IProgressMonitor
2665 // public static void removeClasspathVariable(String variableName) {
2666 // removeClasspathVariable(variableName, null);
2670 * Removed the given classpath variable. Does nothing if no value was
2671 * set for this classpath variable.
2673 * This functionality cannot be used while the resource tree is locked.
2675 * Classpath variable values are persisted locally to the workspace, and
2676 * are preserved from session to session.
2679 * @param variableName the name of the classpath variable
2680 * @param monitor the progress monitor to report progress
2681 * @see #setClasspathVariable
2683 // public static void removeClasspathVariable(
2684 // String variableName,
2685 // IProgressMonitor monitor) {
2688 // updateVariableValues(new String[]{ variableName}, new IPath[]{ null }, monitor);
2689 // } catch (JavaModelException e) {
2694 * Removes the given element changed listener.
2695 * Has no affect if an identical listener is not registered.
2697 * @param listener the listener
2699 public static void removeElementChangedListener(IElementChangedListener listener) {
2700 JavaModelManager.getJavaModelManager().removeElementChangedListener(listener);
2703 * Runs the given action as an atomic Java model operation.
2705 * After running a method that modifies Java elements,
2706 * registered listeners receive after-the-fact notification of
2707 * what just transpired, in the form of a element changed event.
2708 * This method allows clients to call a number of
2709 * methods that modify java elements and only have element
2710 * changed event notifications reported at the end of the entire
2714 * If this method is called outside the dynamic scope of another such
2715 * call, this method runs the action and then reports a single
2716 * element changed event describing the net effect of all changes
2717 * done to java elements by the action.
2720 * If this method is called in the dynamic scope of another such
2721 * call, this method simply runs the action.
2724 * @param action the action to perform
2725 * @param monitor a progress monitor, or <code>null</code> if progress
2726 * reporting and cancellation are not desired
2727 * @exception CoreException if the operation failed.
2730 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
2731 IWorkspace workspace = ResourcesPlugin.getWorkspace();
2732 if (workspace.isTreeLocked()) {
2733 new BatchOperation(action).run(monitor);
2735 // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode
2736 workspace.run(new BatchOperation(action), monitor);
2740 * Bind a container reference path to some actual containers (<code>IClasspathContainer</code>).
2741 * This API must be invoked whenever changes in container need to be reflected onto the JavaModel.
2742 * Containers can have distinct values in different projects, therefore this API considers a
2743 * set of projects with their respective containers.
2745 * <code>containerPath</code> is the path under which these values can be referenced through
2746 * container classpath entries (<code>IClasspathEntry#CPE_CONTAINER</code>). A container path
2747 * is formed by a first ID segment followed with extra segments, which can be used as additional hints
2748 * for the resolution. The container ID is used to identify a <code>ClasspathContainerInitializer</code>
2749 * registered on the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
2751 * There is no assumption that each individual container value passed in argument
2752 * (<code>respectiveContainers</code>) must answer the exact same path when requested
2753 * <code>IClasspathContainer#getPath</code>.
2754 * Indeed, the containerPath is just an indication for resolving it to an actual container object. It can be
2755 * delegated to a <code>ClasspathContainerInitializer</code>, which can be activated through the extension
2756 * point "org.eclipse.jdt.core.ClasspathContainerInitializer").
2758 * In reaction to changing container values, the JavaModel will be updated to reflect the new
2759 * state of the updated container.
2761 * This functionality cannot be used while the resource tree is locked.
2763 * Classpath container values are persisted locally to the workspace, but
2764 * are not preserved from a session to another. It is thus highly recommended to register a
2765 * <code>ClasspathContainerInitializer</code> for each referenced container
2766 * (through the extension point "org.eclipse.jdt.core.ClasspathContainerInitializer").
2768 * Note: setting a container to <code>null</code> will cause it to be lazily resolved again whenever
2769 * its value is required. In particular, this will cause a registered initializer to be invoked
2772 * @param containerPath - the name of the container reference, which is being updated
2773 * @param affectedProjects - the set of projects for which this container is being bound
2774 * @param respectiveContainers - the set of respective containers for the affected projects
2775 * @param monitor a monitor to report progress
2777 * @see ClasspathContainerInitializer
2778 * @see #getClasspathContainer(IPath, IJavaProject)
2779 * @see IClasspathContainer
2782 // public static void setClasspathContainer(final IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
2784 // if (affectedProjects.length != respectiveContainers.length) Assert.isTrue(false, "Projects and containers collections should have the same size"); //$NON-NLS-1$
2786 // if (monitor != null && monitor.isCanceled()) return;
2788 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
2789 // System.out.println("CPContainer SET - setting container: ["+containerPath+"] for projects: {" //$NON-NLS-1$ //$NON-NLS-2$
2790 // + (Util.toString(affectedProjects,
2791 // new Util.Displayable(){
2792 // public String displayString(Object o) { return ((IJavaProject) o).getElementName(); }
2794 // + "} with values: " //$NON-NLS-1$
2795 // + (Util.toString(respectiveContainers,
2796 // new Util.Displayable(){
2797 // public String displayString(Object o) { return ((IClasspathContainer) o).getDescription(); }
2802 // final int projectLength = affectedProjects.length;
2803 // final IJavaProject[] modifiedProjects;
2804 // System.arraycopy(affectedProjects, 0, modifiedProjects = new IJavaProject[projectLength], 0, projectLength);
2805 // final IClasspathEntry[][] oldResolvedPaths = new IClasspathEntry[projectLength][];
2807 // // filter out unmodified project containers
2808 // int remaining = 0;
2809 // for (int i = 0; i < projectLength; i++){
2811 // if (monitor != null && monitor.isCanceled()) return;
2813 // IJavaProject affectedProject = affectedProjects[i];
2814 // IClasspathContainer newContainer = respectiveContainers[i];
2815 // if (newContainer == null) newContainer = JavaModelManager.ContainerInitializationInProgress; // 30920 - prevent infinite loop
2816 // boolean found = false;
2817 // if (JavaProject.hasJavaNature(affectedProject.getProject())){
2818 // IClasspathEntry[] rawClasspath = affectedProject.getRawClasspath();
2819 // for (int j = 0, cpLength = rawClasspath.length; j <cpLength; j++) {
2820 // IClasspathEntry entry = rawClasspath[j];
2821 // if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(containerPath)){
2828 // modifiedProjects[i] = null; // filter out this project - does not reference the container path, or isnt't yet Java project
2829 // JavaModelManager.containerPut(affectedProject, containerPath, newContainer);
2832 // IClasspathContainer oldContainer = JavaModelManager.containerGet(affectedProject, containerPath);
2833 // if (oldContainer == JavaModelManager.ContainerInitializationInProgress) {
2834 // Map previousContainerValues = (Map)JavaModelManager.PreviousSessionContainers.get(affectedProject);
2835 // if (previousContainerValues != null){
2836 // IClasspathContainer previousContainer = (IClasspathContainer)previousContainerValues.get(containerPath);
2837 // if (previousContainer != null) {
2838 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
2839 // 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$
2841 // JavaModelManager.containerPut(affectedProject, containerPath, previousContainer);
2843 // oldContainer = null; //33695 - cannot filter out restored container, must update affected project to reset cached CP
2845 // oldContainer = null;
2848 // if (oldContainer != null && oldContainer.equals(respectiveContainers[i])){// TODO: could improve to only compare entries
2849 // modifiedProjects[i] = null; // filter out this project - container did not change
2853 // oldResolvedPaths[i] = affectedProject.getResolvedClasspath(true);
2854 // JavaModelManager.containerPut(affectedProject, containerPath, newContainer);
2857 // if (remaining == 0) return;
2859 // // trigger model refresh
2861 // JavaCore.run(new IWorkspaceRunnable() {
2862 // public void run(IProgressMonitor monitor) throws CoreException {
2863 // for(int i = 0; i < projectLength; i++){
2865 // if (monitor != null && monitor.isCanceled()) return;
2867 // JavaProject affectedProject = (JavaProject)modifiedProjects[i];
2868 // if (affectedProject == null) continue; // was filtered out
2870 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
2871 // System.out.println("CPContainer SET - updating affected project: ["+affectedProject.getElementName()+"] due to setting container: " + containerPath); //$NON-NLS-1$ //$NON-NLS-2$
2874 // // force a refresh of the affected project (will compute deltas)
2875 // affectedProject.setRawClasspath(
2876 // affectedProject.getRawClasspath(),
2877 // SetClasspathOperation.ReuseOutputLocation,
2879 // !ResourcesPlugin.getWorkspace().isTreeLocked(), // can save resources
2880 // oldResolvedPaths[i],
2881 // false, // updating - no validation
2882 // false); // updating - no need to save
2887 // } catch(CoreException e) {
2888 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
2889 // System.out.println("CPContainer SET - FAILED DUE TO EXCEPTION: "+containerPath); //$NON-NLS-1$
2890 // e.printStackTrace();
2892 // if (e instanceof JavaModelException) {
2893 // throw (JavaModelException)e;
2895 // throw new JavaModelException(e);
2898 // for (int i = 0; i < projectLength; i++) {
2899 // if (respectiveContainers[i] == null) {
2900 // JavaModelManager.containerPut(affectedProjects[i], containerPath, null); // reset init in progress marker
2908 * Sets the value of the given classpath variable.
2909 * The path must have at least one segment.
2911 * This functionality cannot be used while the resource tree is locked.
2913 * Classpath variable values are persisted locally to the workspace, and
2914 * are preserved from session to session.
2917 * @param variableName the name of the classpath variable
2918 * @param path the path
2919 * @see #getClasspathVariable
2921 * @deprecated - use API with IProgressMonitor
2923 // public static void setClasspathVariable(String variableName, IPath path)
2924 // throws JavaModelException {
2926 // setClasspathVariable(variableName, path, null);
2930 * Sets the value of the given classpath variable.
2931 * The path must not be null.
2933 * This functionality cannot be used while the resource tree is locked.
2935 * Classpath variable values are persisted locally to the workspace, and
2936 * are preserved from session to session.
2938 * Updating a variable with the same value has no effect.
2940 * @param variableName the name of the classpath variable
2941 * @param path the path
2942 * @param monitor a monitor to report progress
2943 * @see #getClasspathVariable
2945 // public static void setClasspathVariable(
2946 // String variableName,
2948 // IProgressMonitor monitor)
2949 // throws JavaModelException {
2951 // if (path == null) Assert.isTrue(false, "Variable path cannot be null"); //$NON-NLS-1$
2952 // setClasspathVariables(new String[]{variableName}, new IPath[]{ path }, monitor);
2956 * Sets the values of all the given classpath variables at once.
2957 * Null paths can be used to request corresponding variable removal.
2959 * This functionality cannot be used while the resource tree is locked.
2961 * Classpath variable values are persisted locally to the workspace, and
2962 * are preserved from session to session.
2964 * Updating a variable with the same value has no effect.
2966 * @param variableNames an array of names for the updated classpath variables
2967 * @param paths an array of path updates for the modified classpath variables (null
2968 * meaning that the corresponding value will be removed
2969 * @param monitor a monitor to report progress
2970 * @see #getClasspathVariable
2973 // public static void setClasspathVariables(
2974 // String[] variableNames,
2976 // IProgressMonitor monitor)
2977 // throws JavaModelException {
2979 // if (variableNames.length != paths.length) Assert.isTrue(false, "Variable names and paths collections should have the same size"); //$NON-NLS-1$
2980 // //TODO: should check that null cannot be used as variable paths
2981 // updateVariableValues(variableNames, paths, monitor);
2985 * Method declared on IExecutableExtension.
2986 * Record any necessary initialization data from the plugin.
2988 public void setInitializationData(
2989 IConfigurationElement cfig,
2990 String propertyName,
2992 throws CoreException {
2996 * Sets the current table of options. All and only the options explicitly included in the given table
2997 * are remembered; all previous option settings are forgotten, including ones not explicitly
3000 * For a complete description of the configurable options, see <code>getDefaultOptions</code>.
3003 * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
3004 * or <code>null</code> to reset all options to their default values
3005 * @see JavaCore#getDefaultOptions
3007 public static void setOptions(Hashtable newOptions) {
3009 // see #initializeDefaultPluginPreferences() for changing default settings
3010 Preferences preferences = getPlugin().getPluginPreferences();
3012 if (newOptions == null){
3013 newOptions = JavaCore.getDefaultOptions();
3015 Enumeration keys = newOptions.keys();
3016 while (keys.hasMoreElements()){
3017 String key = (String)keys.nextElement();
3018 if (!JavaModelManager.OptionNames.contains(key)) continue; // unrecognized option
3019 if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
3020 String value = (String)newOptions.get(key);
3021 preferences.setValue(key, value);
3025 getPlugin().savePluginPreferences();
3029 * Shutdown the JavaCore plug-in.
3031 * De-registers the JavaModelManager as a resource changed listener and save participant.
3033 * @see org.eclipse.core.runtime.Plugin#shutdown()
3035 public void shutdown() {
3037 savePluginPreferences();
3038 IWorkspace workspace = ResourcesPlugin.getWorkspace();
3039 workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaProcessor);
3040 workspace.removeSaveParticipant(this);
3042 ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
3046 * Initiate the background indexing process.
3047 * This should be deferred after the plugin activation.
3049 // private void startIndexing() {
3051 // JavaModelManager.getJavaModelManager().getIndexManager().reset();
3055 * Startup of the JavaCore plug-in.
3057 * Registers the JavaModelManager as a resource changed listener and save participant.
3058 * Starts the background indexing, and restore saved classpath variable values.
3060 * @see org.eclipse.core.runtime.Plugin#startup()
3062 public void startup() {
3064 JavaModelManager manager = JavaModelManager.getJavaModelManager();
3066 manager.configurePluginDebugOptions();
3068 // request state folder creation (workaround 19885)
3069 JavaCore.getPlugin().getStateLocation();
3071 // retrieve variable values
3072 JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener());
3073 // TODO khartlage temp-del
3074 // manager.loadVariablesAndContainers();
3076 IWorkspace workspace = ResourcesPlugin.getWorkspace();
3077 workspace.addResourceChangeListener(
3078 manager.deltaProcessor,
3079 IResourceChangeEvent.PRE_AUTO_BUILD
3080 | IResourceChangeEvent.POST_AUTO_BUILD
3081 | IResourceChangeEvent.POST_CHANGE
3082 | IResourceChangeEvent.PRE_DELETE
3083 | IResourceChangeEvent.PRE_CLOSE);
3086 workspace.addSaveParticipant(this, manager);
3088 } catch (CoreException e) {
3089 } catch (RuntimeException e) {
3097 * Internal updating of a variable values (null path meaning removal), allowing to change multiple variable values at once.
3099 // private static void updateVariableValues(
3100 // String[] variableNames,
3101 // IPath[] variablePaths,
3102 // IProgressMonitor monitor) throws JavaModelException {
3104 // if (monitor != null && monitor.isCanceled()) return;
3106 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
3107 // System.out.println("CPVariable SET - setting variables: {" + Util.toString(variableNames) //$NON-NLS-1$
3108 // + "} with values: " + Util.toString(variablePaths)); //$NON-NLS-1$
3111 // int varLength = variableNames.length;
3113 // // gather classpath information for updating
3114 // final HashMap affectedProjects = new HashMap(5);
3115 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
3116 // IJavaModel model = manager.getJavaModel();
3118 // // filter out unmodified variables
3119 // int discardCount = 0;
3120 // for (int i = 0; i < varLength; i++){
3121 // String variableName = variableNames[i];
3122 // IPath oldPath = (IPath)JavaModelManager.variableGet(variableName); // if reentering will provide previous session value
3123 // if (oldPath == JavaModelManager.VariableInitializationInProgress){
3124 // IPath previousPath = (IPath)JavaModelManager.PreviousSessionVariables.get(variableName);
3125 // if (previousPath != null){
3126 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
3127 // System.out.println("CPVariable INIT - reentering access to variable: " + variableName+ " during its initialization, will see previous value: "+ previousPath); //$NON-NLS-1$ //$NON-NLS-2$
3129 // JavaModelManager.variablePut(variableName, previousPath); // replace value so reentering calls are seeing old value
3131 // oldPath = null; //33695 - cannot filter out restored variable, must update affected project to reset cached CP
3133 // if (oldPath != null && oldPath.equals(variablePaths[i])){
3134 // variableNames[i] = null;
3138 // if (discardCount > 0){
3139 // if (discardCount == varLength) return;
3140 // int changedLength = varLength - discardCount;
3141 // String[] changedVariableNames = new String[changedLength];
3142 // IPath[] changedVariablePaths = new IPath[changedLength];
3143 // for (int i = 0, index = 0; i < varLength; i++){
3144 // if (variableNames[i] != null){
3145 // changedVariableNames[index] = variableNames[i];
3146 // changedVariablePaths[index] = variablePaths[i];
3150 // variableNames = changedVariableNames;
3151 // variablePaths = changedVariablePaths;
3152 // varLength = changedLength;
3155 // if (monitor != null && monitor.isCanceled()) return;
3157 // if (model != null) {
3158 // IJavaProject[] projects = model.getJavaProjects();
3159 // nextProject : for (int i = 0, projectLength = projects.length; i < projectLength; i++){
3160 // IJavaProject project = projects[i];
3162 // // check to see if any of the modified variables is present on the classpath
3163 // IClasspathEntry[] classpath = project.getRawClasspath();
3164 // for (int j = 0, cpLength = classpath.length; j < cpLength; j++){
3166 // IClasspathEntry entry = classpath[j];
3167 // for (int k = 0; k < varLength; k++){
3169 // String variableName = variableNames[k];
3170 // if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE){
3172 // if (variableName.equals(entry.getPath().segment(0))){
3173 // affectedProjects.put(project, project.getResolvedClasspath(true));
3174 // continue nextProject;
3176 // IPath sourcePath, sourceRootPath;
3177 // if (((sourcePath = entry.getSourceAttachmentPath()) != null && variableName.equals(sourcePath.segment(0)))
3178 // || ((sourceRootPath = entry.getSourceAttachmentRootPath()) != null && variableName.equals(sourceRootPath.segment(0)))) {
3180 // affectedProjects.put(project, project.getResolvedClasspath(true));
3181 // continue nextProject;
3188 // // update variables
3189 // for (int i = 0; i < varLength; i++){
3190 // JavaModelManager.variablePut(variableNames[i], variablePaths[i]);
3192 // final String[] dbgVariableNames = variableNames;
3194 // // update affected project classpaths
3195 // if (!affectedProjects.isEmpty()) {
3198 // new IWorkspaceRunnable() {
3199 // public void run(IProgressMonitor monitor) throws CoreException {
3200 // // propagate classpath change
3201 // Iterator projectsToUpdate = affectedProjects.keySet().iterator();
3202 // while (projectsToUpdate.hasNext()) {
3204 // if (monitor != null && monitor.isCanceled()) return;
3206 // JavaProject project = (JavaProject) projectsToUpdate.next();
3208 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
3209 // System.out.println("CPVariable SET - updating affected project: ["+project.getElementName()+"] due to setting variables: "+ Util.toString(dbgVariableNames)); //$NON-NLS-1$ //$NON-NLS-2$
3213 // .setRawClasspath(
3214 // project.getRawClasspath(),
3215 // SetClasspathOperation.ReuseOutputLocation,
3216 // null, // don't call beginTask on the monitor (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=3717)
3217 // !ResourcesPlugin.getWorkspace().isTreeLocked(), // can change resources
3218 // (IClasspathEntry[]) affectedProjects.get(project),
3219 // false, // updating - no validation
3220 // false); // updating - no need to save
3225 // } catch (CoreException e) {
3226 // if (JavaModelManager.CP_RESOLVE_VERBOSE){
3227 // System.out.println("CPVariable SET - FAILED DUE TO EXCEPTION: "+Util.toString(dbgVariableNames)); //$NON-NLS-1$
3228 // e.printStackTrace();
3230 // if (e instanceof JavaModelException) {
3231 // throw (JavaModelException)e;
3233 // throw new JavaModelException(e);