<s> package org . eclipse . jdt . core ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Hashtable ; import java . util . Map ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IConfigurationElement ; import org . eclipse . core . runtime . IExtension ; import org . eclipse . core . runtime . IExtensionPoint ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Platform ; import org . eclipse . core . runtime . Plugin ; import org . eclipse . core . runtime . QualifiedName ; import org . eclipse . core . runtime . SubProgressMonitor ; import org . eclipse . core . runtime . jobs . ISchedulingRule ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IMarkerDelta ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . IResourceChangeListener ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . TypeNameRequestor ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; import org . eclipse . jdt . internal . core . * ; import org . eclipse . jdt . internal . core . builder . JavaBuilder ; import org . eclipse . jdt . internal . core . builder . State ; import org . eclipse . jdt . internal . core . util . MementoTokenizer ; import org . eclipse . jdt . internal . core . util . Messages ; import org . eclipse . jdt . internal . core . util . Util ; import org . osgi . framework . BundleContext ; public final class JavaCore extends Plugin { private static final IResource [ ] NO_GENERATED_RESOURCES = new IResource [ 0 ] ; private static Plugin JAVA_CORE_PLUGIN = null ; public static final String PLUGIN_ID = "" ; public static final String BUILDER_ID = PLUGIN_ID + ".javabuilder" ; public static final String MODEL_ID = PLUGIN_ID + ".javamodel" ; public static final String NATURE_ID = PLUGIN_ID + ".javanature" ; protected static final String ATT_HANDLE_ID = "" ; public static final String USER_LIBRARY_CONTAINER_ID = "" ; public static final String COMPILER_LOCAL_VARIABLE_ATTR = PLUGIN_ID + "" ; public static final String COMPILER_LINE_NUMBER_ATTR = PLUGIN_ID + "" ; public static final String COMPILER_SOURCE_FILE_ATTR = PLUGIN_ID + "" ; public static final String COMPILER_CODEGEN_UNUSED_LOCAL = PLUGIN_ID + "" ; public static final String COMPILER_CODEGEN_TARGET_PLATFORM = PLUGIN_ID + "" ; public static final String COMPILER_CODEGEN_INLINE_JSR_BYTECODE = PLUGIN_ID + "" ; public static final String COMPILER_DOC_COMMENT_SUPPORT = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNREACHABLE_CODE = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_IMPORT = PLUGIN_ID + "" ; public static final String COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD = PLUGIN_ID + "" ; public static final String COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME = PLUGIN_ID + "" ; public static final String COMPILER_PB_DEPRECATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_DEPRECATION_IN_DEPRECATED_CODE = PLUGIN_ID + "" ; public static final String COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD = "" ; public static final String COMPILER_PB_HIDDEN_CATCH_BLOCK = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_LOCAL = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_PARAMETER = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_IMPLEMENTING_ABSTRACT = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_PARAMETER_WHEN_OVERRIDING_CONCRETE = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_IMPORT = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_SYNTHETIC_ACCESS_EMULATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_NON_NLS_STRING_LITERAL = PLUGIN_ID + "" ; public static final String COMPILER_PB_ASSERT_IDENTIFIER = PLUGIN_ID + "" ; public static final String COMPILER_PB_ENUM_IDENTIFIER = PLUGIN_ID + "" ; public static final String COMPILER_PB_STATIC_ACCESS_RECEIVER = PLUGIN_ID + "" ; public static final String COMPILER_PB_INDIRECT_STATIC_ACCESS = PLUGIN_ID + "" ; public static final String COMPILER_PB_NO_EFFECT_ASSIGNMENT = PLUGIN_ID + "" ; public static final String COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_PRIVATE_MEMBER = PLUGIN_ID + "" ; public static final String COMPILER_PB_LOCAL_VARIABLE_HIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_SPECIAL_PARAMETER_HIDING_FIELD = PLUGIN_ID + "" ; public static final String COMPILER_PB_FIELD_HIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_TYPE_PARAMETER_HIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT = PLUGIN_ID + "" ; public static final String COMPILER_PB_FALLTHROUGH_CASE = PLUGIN_ID + "" ; public static final String COMPILER_PB_EMPTY_STATEMENT = PLUGIN_ID + "" ; public static final String COMPILER_PB_BOOLEAN_METHOD_THROWING_EXCEPTION = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNNECESSARY_TYPE_CHECK = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNNECESSARY_ELSE = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNDOCUMENTED_EMPTY_BLOCK = PLUGIN_ID + "" ; public static final String COMPILER_PB_FINALLY_BLOCK_NOT_COMPLETING = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_WHEN_OVERRIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNQUALIFIED_FIELD_ACCESS = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNSAFE_TYPE_OPERATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNCHECKED_TYPE_OPERATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_RAW_TYPE_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_FINAL_PARAMETER_BOUND = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_SERIAL_VERSION = PLUGIN_ID + "" ; public static final String COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST = PLUGIN_ID + "" ; public static final String COMPILER_PB_AUTOBOXING = PLUGIN_ID + "" ; public static final String COMPILER_PB_ANNOTATION_SUPER_INTERFACE = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_OVERRIDE_ANNOTATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_DEPRECATED_ANNOTATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_HASHCODE_METHOD = PLUGIN_ID + "" ; public static final String COMPILER_PB_DEAD_CODE = PLUGIN_ID + "" ; public static final String COMPILER_PB_DEAD_CODE_IN_TRIVIAL_IF_STATEMENT = PLUGIN_ID + "" ; public static final String COMPILER_PB_INCOMPLETE_ENUM_SWITCH = PLUGIN_ID + "" ; public static final String COMPILER_PB_INCONSISTENT_NULL_CHECK = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_LABEL = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_JAVADOC = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_JAVADOC_TAGS = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_JAVADOC_TAGS__DEPRECATED_REF = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_JAVADOC_TAGS__NOT_VISIBLE_REF = PLUGIN_ID + "" ; public static final String COMPILER_PB_INVALID_JAVADOC_TAGS_VISIBILITY = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_TAGS = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_TAGS_VISIBILITY = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_TAGS_OVERRIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_COMMENTS = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING = PLUGIN_ID + "" ; public static final String COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_MAX_PER_UNIT = PLUGIN_ID + "" ; public static final String COMPILER_PB_FATAL_OPTIONAL_ERROR = PLUGIN_ID + "" ; public static final String COMPILER_PB_PARAMETER_ASSIGNMENT = PLUGIN_ID + "" ; public static final String COMPILER_SOURCE = PLUGIN_ID + "" ; public static final String COMPILER_COMPLIANCE = PLUGIN_ID + "" ; public static final String COMPILER_TASK_PRIORITIES = PLUGIN_ID + "" ; public static final String COMPILER_TASK_TAGS = PLUGIN_ID + "" ; public static final String COMPILER_TASK_CASE_SENSITIVE = PLUGIN_ID + "" ; public static final String COMPILER_PB_FORBIDDEN_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_DISCOURAGED_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_SUPPRESS_WARNINGS = PLUGIN_ID + "" ; public static final String COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNHANDLED_WARNING_TOKEN = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_WARNING_TOKEN = PLUGIN_ID + "" ; public static final String COMPILER_PB_NULL_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_POTENTIAL_NULL_REFERENCE = PLUGIN_ID + "" ; public static final String COMPILER_PB_REDUNDANT_NULL_CHECK = PLUGIN_ID + "" ; public static final String COMPILER_PB_OVERRIDING_METHOD_WITHOUT_SUPER_INVOCATION = PLUGIN_ID + "" ; public static final String COMPILER_PB_REDUNDANT_SUPERINTERFACE = PLUGIN_ID + "" ; public static final String COMPILER_PB_COMPARING_IDENTICAL = PLUGIN_ID + "" ; public static final String COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD = PLUGIN_ID + "" ; public static final String COMPILER_PB_UNUSED_OBJECT_ALLOCATION = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_ORDER = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_RESOURCE_COPY_FILTER = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_DUPLICATE_RESOURCE = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER = PLUGIN_ID + "" ; public static final String CORE_INCOMPLETE_CLASSPATH = PLUGIN_ID + "" ; public static final String CORE_CIRCULAR_CLASSPATH = PLUGIN_ID + "" ; public static final String CORE_INCOMPATIBLE_JDK_LEVEL = PLUGIN_ID + "" ; public static final String CORE_JAVA_BUILD_INVALID_CLASSPATH = PLUGIN_ID + "" ; public static final String CORE_ENCODING = PLUGIN_ID + ".encoding" ; public static final String CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS = PLUGIN_ID + "" ; public static final String CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS = PLUGIN_ID + "" ; public static final String TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC = PLUGIN_ID + "" ; public static final String FORMATTER_NEWLINE_OPENING_BRACE = PLUGIN_ID + "" ; public static final String FORMATTER_NEWLINE_CONTROL = PLUGIN_ID + "" ; public static final String FORMATTER_NEWLINE_ELSE_IF = PLUGIN_ID + "" ; public static final String FORMATTER_NEWLINE_EMPTY_BLOCK = PLUGIN_ID + "" ; public static final String FORMATTER_CLEAR_BLANK_LINES = PLUGIN_ID + "" ; public static final String FORMATTER_LINE_SPLIT = PLUGIN_ID + "" ; public static final String FORMATTER_COMPACT_ASSIGNMENT = PLUGIN_ID + "" ; public static final String FORMATTER_TAB_CHAR = PLUGIN_ID + "" ; public static final String FORMATTER_TAB_SIZE = PLUGIN_ID + "" ; public static final String FORMATTER_SPACE_CASTEXPRESSION = PLUGIN_ID + "" ; public static final String CODEASSIST_VISIBILITY_CHECK = PLUGIN_ID + "" ; public static final String CODEASSIST_DEPRECATION_CHECK = PLUGIN_ID + "" ; public static final String CODEASSIST_CAMEL_CASE_MATCH = PLUGIN_ID + "" ; public static final String CODEASSIST_IMPLICIT_QUALIFICATION = PLUGIN_ID + "" ; public static final String CODEASSIST_FIELD_PREFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_STATIC_FIELD_PREFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_STATIC_FINAL_FIELD_PREFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_LOCAL_PREFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_ARGUMENT_PREFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_FIELD_SUFFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_STATIC_FIELD_SUFFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_LOCAL_SUFFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_ARGUMENT_SUFFIXES = PLUGIN_ID + "" ; public static final String CODEASSIST_FORBIDDEN_REFERENCE_CHECK = PLUGIN_ID + "" ; public static final String CODEASSIST_DISCOURAGED_REFERENCE_CHECK = PLUGIN_ID + "" ; public static final String CODEASSIST_SUGGEST_STATIC_IMPORTS = PLUGIN_ID + "" ; public static final String DEFAULT_TASK_TAG = "TODO" ; public static final String DEFAULT_TASK_PRIORITY = "NORMAL" ; public static final String DEFAULT_TASK_TAGS = "" ; public static final String DEFAULT_TASK_PRIORITIES = "" ; public static final String GENERATE = "generate" ; public static final String DO_NOT_GENERATE = "" ; public static final String PRESERVE = "preserve" ; public static final String OPTIMIZE_OUT = "optimize out" ; public static final String COMPILER_TASK_PRIORITY_HIGH = "HIGH" ; public static final String COMPILER_TASK_PRIORITY_LOW = "LOW" ; public static final String COMPILER_TASK_PRIORITY_NORMAL = "NORMAL" ; public static final String VERSION_1_1 = "1.1" ; public static final String VERSION_1_2 = "1.2" ; public static final String VERSION_1_3 = "1.3" ; public static final String VERSION_1_4 = "1.4" ; public static final String VERSION_1_5 = "1.5" ; public static final String VERSION_1_6 = "1.6" ; public static final String VERSION_1_7 = "1.7" ; public static final String VERSION_CLDC_1_1 = "cldc1.1" ; public static final String ABORT = "abort" ; public static final String ERROR = "error" ; public static final String WARNING = "warning" ; public static final String IGNORE = "ignore" ; public static final String COMPUTE = "compute" ; public static final String INSERT = "insert" ; public static final String DO_NOT_INSERT = "" ; public static final String PRESERVE_ONE = "preserve one" ; public static final String CLEAR_ALL = "clear all" ; public static final String NORMAL = "normal" ; public static final String COMPACT = "compact" ; public static final String TAB = "tab" ; public static final String SPACE = "space" ; public static final String ENABLED = "enabled" ; public static final String DISABLED = "disabled" ; public static final String CLEAN = "clean" ; public static final String PUBLIC = "public" ; public static final String PROTECTED = "protected" ; public static final String DEFAULT = "default" ; public static final String PRIVATE = "private" ; public static final String NEVER = "never" ; public static final String COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_NO_TAG = CompilerOptions . NO_TAG ; public static final String COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_RETURN_TAG = CompilerOptions . RETURN_TAG ; public static final String COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_ALL_STANDARD_TAGS = CompilerOptions . ALL_STANDARD_TAGS ; public static final String JAVA_SOURCE_CONTENT_TYPE = JavaCore . PLUGIN_ID + ".javaSource" ; public JavaCore ( ) { super ( ) ; JAVA_CORE_PLUGIN = this ; } public static void addElementChangedListener ( IElementChangedListener listener ) { addElementChangedListener ( listener , ElementChangedEvent . POST_CHANGE | ElementChangedEvent . POST_RECONCILE ) ; } public static void addElementChangedListener ( IElementChangedListener listener , int eventMask ) { JavaModelManager . getDeltaState ( ) . addElementChangedListener ( listener , eventMask ) ; } public static void addJavaElementMarkerAttributes ( Map attributes , IJavaElement element ) { if ( element instanceof IMember ) element = ( ( IMember ) element ) . getClassFile ( ) ; if ( attributes != null && element != null ) attributes . put ( ATT_HANDLE_ID , element . getHandleIdentifier ( ) ) ; } private static void addNonJavaResources ( Object [ ] nonJavaResources , IContainer container , int rootPathSegmentCounts , ArrayList collector ) { for ( int i = 0 , max = nonJavaResources . length ; i < max ; i ++ ) { Object nonJavaResource = nonJavaResources [ i ] ; if ( nonJavaResource instanceof IFile ) { IFile file = ( IFile ) nonJavaResource ; IPath path = file . getFullPath ( ) . removeFirstSegments ( rootPathSegmentCounts ) ; IResource member = container . findMember ( path ) ; if ( member != null && member . exists ( ) ) { collector . add ( member ) ; } } else if ( nonJavaResource instanceof IFolder ) { IFolder folder = ( IFolder ) nonJavaResource ; IResource [ ] members = null ; try { members = folder . members ( ) ; } catch ( CoreException e ) { } if ( members != null ) { addNonJavaResources ( members , container , rootPathSegmentCounts , collector ) ; } } } } public static void addPreProcessingResourceChangedListener ( IResourceChangeListener listener ) { addPreProcessingResourceChangedListener ( listener , IResourceChangeEvent . POST_CHANGE ) ; } public static void addPreProcessingResourceChangedListener ( IResourceChangeListener listener , int eventMask ) { JavaModelManager . getDeltaState ( ) . addPreResourceChangedListener ( listener , eventMask ) ; } public void configureJavaElementMarker ( IMarker marker , IJavaElement element ) throws CoreException { if ( element instanceof IMember ) element = ( ( IMember ) element ) . getClassFile ( ) ; if ( marker != null && element != null ) marker . setAttribute ( ATT_HANDLE_ID , element . getHandleIdentifier ( ) ) ; } public static IJavaElement create ( String handleIdentifier ) { return create ( handleIdentifier , DefaultWorkingCopyOwner . PRIMARY ) ; } public static IJavaElement create ( String handleIdentifier , WorkingCopyOwner owner ) { if ( handleIdentifier == null ) { return null ; } if ( owner == null ) owner = DefaultWorkingCopyOwner . PRIMARY ; MementoTokenizer memento = new MementoTokenizer ( handleIdentifier ) ; JavaModel model = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) ; return model . getHandleFromMemento ( memento , owner ) ; } public static IJavaElement create ( IFile file ) { return JavaModelManager . create ( file , null ) ; } public static IJavaElement create ( IFolder folder ) { return JavaModelManager . create ( folder , null ) ; } public static IJavaProject create ( IProject project ) { if ( project == null ) { return null ; } JavaModel javaModel = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) ; return javaModel . getJavaProject ( project ) ; } public static IJavaElement create ( IResource resource ) { return JavaModelManager . create ( resource , null ) ; } public static IJavaElement create ( IResource resource , IJavaProject project ) { return JavaModelManager . create ( resource , project ) ; } public static IJavaModel create ( IWorkspaceRoot root ) { if ( root == null ) { return null ; } return JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) ; } public static IClassFile createClassFileFrom ( IFile file ) { return JavaModelManager . createClassFileFrom ( file , null ) ; } public static ICompilationUnit createCompilationUnitFrom ( IFile file ) { return JavaModelManager . createCompilationUnitFrom ( file , null ) ; } public static IPackageFragmentRoot createJarPackageFragmentRootFrom ( IFile file ) { return JavaModelManager . createJarPackageFragmentRootFrom ( file , null ) ; } public static IClasspathContainer getClasspathContainer ( IPath containerPath , IJavaProject project ) throws JavaModelException { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; IClasspathContainer container = manager . getClasspathContainer ( containerPath , project ) ; if ( container == JavaModelManager . CONTAINER_INITIALIZATION_IN_PROGRESS ) { return manager . getPreviousSessionContainer ( containerPath , project ) ; } return container ; } public static ClasspathContainerInitializer getClasspathContainerInitializer ( String containerID ) { Hashtable containerInitializersCache = JavaModelManager . getJavaModelManager ( ) . containerInitializersCache ; ClasspathContainerInitializer initializer = ( ClasspathContainerInitializer ) containerInitializersCache . get ( containerID ) ; if ( initializer == null ) { initializer = computeClasspathContainerInitializer ( containerID ) ; if ( initializer == null ) return null ; containerInitializersCache . put ( containerID , initializer ) ; } return initializer ; } private static ClasspathContainerInitializer computeClasspathContainerInitializer ( String containerID ) { Plugin jdtCorePlugin = JavaCore . getPlugin ( ) ; if ( jdtCorePlugin == null ) return null ; IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , JavaModelManager . CPCONTAINER_INITIALIZER_EXTPOINT_ID ) ; if ( extension != null ) { IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { IConfigurationElement configurationElement = configElements [ j ] ; String initializerID = configurationElement . getAttribute ( "id" ) ; if ( initializerID != null && initializerID . equals ( containerID ) ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED ) verbose_found_container_initializer ( containerID , configurationElement ) ; try { Object execExt = configurationElement . createExecutableExtension ( "class" ) ; if ( execExt instanceof ClasspathContainerInitializer ) { return ( ClasspathContainerInitializer ) execExt ; } } catch ( CoreException e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE ) { verbose_failed_to_instanciate_container_initializer ( containerID , configurationElement ) ; e . printStackTrace ( ) ; } } } } } } return null ; } private static void verbose_failed_to_instanciate_container_initializer ( String containerID , IConfigurationElement configurationElement ) { Util . verbose ( "" + "" + containerID + '\n' + "tclass: " + configurationElement . getAttribute ( "class" ) , System . err ) ; } private static void verbose_found_container_initializer ( String containerID , IConfigurationElement configurationElement ) { Util . verbose ( "" + "" + containerID + '\n' + "tclass: " + configurationElement . getAttribute ( "class" ) ) ; } public static IPath getClasspathVariable ( final String variableName ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; IPath variablePath = manager . variableGet ( variableName ) ; if ( variablePath == JavaModelManager . VARIABLE_INITIALIZATION_IN_PROGRESS ) { return manager . getPreviousSessionVariable ( variableName ) ; } if ( variablePath != null ) { if ( variablePath == JavaModelManager . CP_ENTRY_IGNORE_PATH ) return null ; return variablePath ; } final ClasspathVariableInitializer initializer = JavaCore . getClasspathVariableInitializer ( variableName ) ; if ( initializer != null ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE ) verbose_triggering_variable_initialization ( variableName , initializer ) ; if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED ) verbose_triggering_variable_initialization_invocation_trace ( ) ; manager . variablePut ( variableName , JavaModelManager . VARIABLE_INITIALIZATION_IN_PROGRESS ) ; boolean ok = false ; try { initializer . initialize ( variableName ) ; variablePath = manager . variableGet ( variableName ) ; if ( variablePath == JavaModelManager . VARIABLE_INITIALIZATION_IN_PROGRESS ) return null ; if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED ) verbose_variable_value_after_initialization ( variableName , variablePath ) ; manager . variablesWithInitializer . add ( variableName ) ; ok = true ; } catch ( RuntimeException e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE ) e . printStackTrace ( ) ; throw e ; } catch ( Error e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE ) e . printStackTrace ( ) ; throw e ; } finally { if ( ! ok ) JavaModelManager . getJavaModelManager ( ) . variablePut ( variableName , null ) ; } } else { if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED || JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE ) verbose_no_variable_initializer_found ( variableName ) ; } return variablePath ; } private static void verbose_no_variable_initializer_found ( String variableName ) { Util . verbose ( "" + "tvariable: " + variableName ) ; } private static void verbose_variable_value_after_initialization ( String variableName , IPath variablePath ) { Util . verbose ( "" + "tvariable: " + variableName + '\n' + "" + variablePath ) ; } private static void verbose_triggering_variable_initialization ( String variableName , ClasspathVariableInitializer initializer ) { Util . verbose ( "" + "tvariable: " + variableName + '\n' + "" + initializer ) ; } private static void verbose_triggering_variable_initialization_invocation_trace ( ) { Util . verbose ( "" + "" ) ; new Exception ( "" ) . printStackTrace ( System . out ) ; } public static String getClasspathVariableDeprecationMessage ( String variableName ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; String message = ( String ) manager . deprecatedVariables . get ( variableName ) ; if ( message != null ) { return message ; } IPath variablePath = manager . variableGet ( variableName ) ; if ( variablePath != null && variablePath != JavaModelManager . VARIABLE_INITIALIZATION_IN_PROGRESS ) { return null ; } Plugin jdtCorePlugin = JavaCore . getPlugin ( ) ; if ( jdtCorePlugin == null ) return null ; IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , JavaModelManager . CPVARIABLE_INITIALIZER_EXTPOINT_ID ) ; if ( extension != null ) { IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { IConfigurationElement configElement = configElements [ j ] ; String varAttribute = configElement . getAttribute ( "variable" ) ; if ( variableName . equals ( varAttribute ) ) { String deprecatedAttribute = configElement . getAttribute ( "deprecated" ) ; if ( deprecatedAttribute != null ) { return deprecatedAttribute ; } } } } } return null ; } public static ClasspathVariableInitializer getClasspathVariableInitializer ( String variable ) { Plugin jdtCorePlugin = JavaCore . getPlugin ( ) ; if ( jdtCorePlugin == null ) return null ; IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , JavaModelManager . CPVARIABLE_INITIALIZER_EXTPOINT_ID ) ; if ( extension != null ) { IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { IConfigurationElement configElement = configElements [ j ] ; try { String varAttribute = configElement . getAttribute ( "variable" ) ; if ( variable . equals ( varAttribute ) ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED ) verbose_found_variable_initializer ( variable , configElement ) ; Object execExt = configElement . createExecutableExtension ( "class" ) ; if ( execExt instanceof ClasspathVariableInitializer ) { ClasspathVariableInitializer initializer = ( ClasspathVariableInitializer ) execExt ; String deprecatedAttribute = configElement . getAttribute ( "deprecated" ) ; if ( deprecatedAttribute != null ) { JavaModelManager . getJavaModelManager ( ) . deprecatedVariables . put ( variable , deprecatedAttribute ) ; } String readOnlyAttribute = configElement . getAttribute ( "readOnly" ) ; if ( JavaModelManager . TRUE . equals ( readOnlyAttribute ) ) { JavaModelManager . getJavaModelManager ( ) . readOnlyVariables . add ( variable ) ; } return initializer ; } } } catch ( CoreException e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE ) { verbose_failed_to_instanciate_variable_initializer ( variable , configElement ) ; e . printStackTrace ( ) ; } } } } } return null ; } private static void verbose_failed_to_instanciate_variable_initializer ( String variable , IConfigurationElement configElement ) { Util . verbose ( "" + "tvariable: " + variable + '\n' + "tclass: " + configElement . getAttribute ( "class" ) , System . err ) ; } private static void verbose_found_variable_initializer ( String variable , IConfigurationElement configElement ) { Util . verbose ( "" + "tvariable: " + variable + '\n' + "tclass: " + configElement . getAttribute ( "class" ) ) ; } public static String [ ] getClasspathVariableNames ( ) { return JavaModelManager . getJavaModelManager ( ) . variableNames ( ) ; } public static Hashtable getDefaultOptions ( ) { return JavaModelManager . getJavaModelManager ( ) . getDefaultOptions ( ) ; } public static String getEncoding ( ) { try { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getDefaultCharset ( ) ; } catch ( IllegalStateException ise ) { return System . getProperty ( "" ) ; } catch ( CoreException ce ) { } return ResourcesPlugin . getEncoding ( ) ; } public static IResource [ ] getGeneratedResources ( IRegion region , boolean includesNonJavaResources ) { if ( region == null ) throw new IllegalArgumentException ( "" ) ; IJavaElement [ ] elements = region . getElements ( ) ; HashMap projectsStates = new HashMap ( ) ; ArrayList collector = new ArrayList ( ) ; for ( int i = 0 , max = elements . length ; i < max ; i ++ ) { IJavaElement element = elements [ i ] ; IJavaProject javaProject = element . getJavaProject ( ) ; IProject project = javaProject . getProject ( ) ; State state = null ; State currentState = ( State ) projectsStates . get ( project ) ; if ( currentState != null ) { state = currentState ; } else { state = ( State ) JavaModelManager . getJavaModelManager ( ) . getLastBuiltState ( project , null ) ; if ( state != null ) { projectsStates . put ( project , state ) ; } } if ( state == null ) continue ; if ( element . getElementType ( ) == IJavaElement . JAVA_PROJECT ) { IPackageFragmentRoot [ ] roots = null ; try { roots = javaProject . getPackageFragmentRoots ( ) ; } catch ( JavaModelException e ) { } if ( roots == null ) continue ; IRegion region2 = JavaCore . newRegion ( ) ; for ( int j = 0 ; j < roots . length ; j ++ ) { region2 . add ( roots [ j ] ) ; } IResource [ ] res = getGeneratedResources ( region2 , includesNonJavaResources ) ; for ( int j = 0 , max2 = res . length ; j < max2 ; j ++ ) { collector . add ( res [ j ] ) ; } continue ; } IPath outputLocation = null ; try { outputLocation = javaProject . getOutputLocation ( ) ; } catch ( JavaModelException e ) { } IJavaElement root = element ; while ( root != null && root . getElementType ( ) != IJavaElement . PACKAGE_FRAGMENT_ROOT ) { root = root . getParent ( ) ; } if ( root == null ) continue ; IPackageFragmentRoot packageFragmentRoot = ( IPackageFragmentRoot ) root ; int rootPathSegmentCounts = packageFragmentRoot . getPath ( ) . segmentCount ( ) ; try { IClasspathEntry entry = packageFragmentRoot . getRawClasspathEntry ( ) ; IPath entryOutputLocation = entry . getOutputLocation ( ) ; if ( entryOutputLocation != null ) { outputLocation = entryOutputLocation ; } } catch ( JavaModelException e ) { e . printStackTrace ( ) ; } if ( outputLocation == null ) continue ; IContainer container = ( IContainer ) project . getWorkspace ( ) . getRoot ( ) . findMember ( outputLocation ) ; switch ( element . getElementType ( ) ) { case IJavaElement . COMPILATION_UNIT : ICompilationUnit unit = ( ICompilationUnit ) element ; getGeneratedResource ( unit , container , state , rootPathSegmentCounts , collector ) ; break ; case IJavaElement . PACKAGE_FRAGMENT : IPackageFragment fragment = ( IPackageFragment ) element ; ICompilationUnit [ ] compilationUnits = null ; try { compilationUnits = fragment . getCompilationUnits ( ) ; } catch ( JavaModelException e ) { } if ( compilationUnits == null ) continue ; for ( int j = 0 , max2 = compilationUnits . length ; j < max2 ; j ++ ) { getGeneratedResource ( compilationUnits [ j ] , container , state , rootPathSegmentCounts , collector ) ; } if ( includesNonJavaResources ) { Object [ ] nonJavaResources = null ; try { nonJavaResources = fragment . getNonJavaResources ( ) ; } catch ( JavaModelException e ) { } if ( nonJavaResources != null ) { addNonJavaResources ( nonJavaResources , container , rootPathSegmentCounts , collector ) ; } } break ; case IJavaElement . PACKAGE_FRAGMENT_ROOT : IPackageFragmentRoot fragmentRoot = ( IPackageFragmentRoot ) element ; if ( fragmentRoot . isArchive ( ) ) continue ; IJavaElement [ ] children = null ; try { children = fragmentRoot . getChildren ( ) ; } catch ( JavaModelException e ) { } if ( children == null ) continue ; for ( int j = 0 , max2 = children . length ; j < max2 ; j ++ ) { fragment = ( IPackageFragment ) children [ j ] ; ICompilationUnit [ ] units = null ; try { units = fragment . getCompilationUnits ( ) ; } catch ( JavaModelException e ) { } if ( units == null ) continue ; for ( int n = 0 , max3 = units . length ; n < max3 ; n ++ ) { getGeneratedResource ( units [ n ] , container , state , rootPathSegmentCounts , collector ) ; } if ( includesNonJavaResources ) { Object [ ] nonJavaResources = null ; try { nonJavaResources = fragment . getNonJavaResources ( ) ; } catch ( JavaModelException e ) { } if ( nonJavaResources != null ) { addNonJavaResources ( nonJavaResources , container , rootPathSegmentCounts , collector ) ; } } } break ; } } int size = collector . size ( ) ; if ( size != 0 ) { IResource [ ] result = new IResource [ size ] ; collector . toArray ( result ) ; return result ; } return NO_GENERATED_RESOURCES ; } private static void getGeneratedResource ( ICompilationUnit unit , IContainer container , State state , int rootPathSegmentCounts , ArrayList collector ) { IResource resource = unit . getResource ( ) ; char [ ] [ ] typeNames = state . getDefinedTypeNamesFor ( resource . getProjectRelativePath ( ) . toString ( ) ) ; if ( typeNames != null ) { IPath path = unit . getPath ( ) . removeFirstSegments ( rootPathSegmentCounts ) . removeLastSegments ( 1 ) ; for ( int j = 0 , max2 = typeNames . length ; j < max2 ; j ++ ) { IPath localPath = path . append ( new String ( typeNames [ j ] ) + ".class" ) ; IResource member = container . findMember ( localPath ) ; if ( member != null && member . exists ( ) ) { collector . add ( member ) ; } } } else { IPath path = unit . getPath ( ) . removeFirstSegments ( rootPathSegmentCounts ) . removeLastSegments ( 1 ) ; path = path . append ( Util . getNameWithoutJavaLikeExtension ( unit . getElementName ( ) ) + ".class" ) ; IResource member = container . findMember ( path ) ; if ( member != null && member . exists ( ) ) { collector . add ( member ) ; } } } public static JavaCore getJavaCore ( ) { return ( JavaCore ) getPlugin ( ) ; } public static String [ ] getJavaLikeExtensions ( ) { return CharOperation . toStrings ( Util . getJavaLikeExtensions ( ) ) ; } public static String getOption ( String optionName ) { return JavaModelManager . getJavaModelManager ( ) . getOption ( optionName ) ; } public static String getOptionForConfigurableSeverity ( int problemID ) { return CompilerOptions . optionKeyFromIrritant ( ProblemReporter . getIrritant ( problemID ) ) ; } public static Hashtable getOptions ( ) { return JavaModelManager . getJavaModelManager ( ) . getOptions ( ) ; } public static Plugin getPlugin ( ) { return JAVA_CORE_PLUGIN ; } public static IClasspathEntry getResolvedClasspathEntry ( IClasspathEntry entry ) { return JavaModelManager . getJavaModelManager ( ) . resolveVariableEntry ( entry , false ) ; } public static IPath getResolvedVariablePath ( IPath variablePath ) { return JavaModelManager . getJavaModelManager ( ) . getResolvedVariablePath ( variablePath , false ) ; } public static IWorkingCopy [ ] getSharedWorkingCopies ( IBufferFactory factory ) { if ( factory == null ) factory = BufferManager . getDefaultBufferManager ( ) . getDefaultBufferFactory ( ) ; return getWorkingCopies ( BufferFactoryWrapper . create ( factory ) ) ; } public static String [ ] getUserLibraryNames ( ) { return JavaModelManager . getUserLibraryManager ( ) . getUserLibraryNames ( ) ; } public static ICompilationUnit [ ] getWorkingCopies ( WorkingCopyOwner owner ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; if ( owner == null ) owner = DefaultWorkingCopyOwner . PRIMARY ; ICompilationUnit [ ] result = manager . getWorkingCopies ( owner , false ) ; if ( result == null ) return JavaModelManager . NO_WORKING_COPY ; return result ; } public static void initializeAfterLoad ( IProgressMonitor monitor ) throws CoreException { try { if ( monitor != null ) { monitor . beginTask ( Messages . javamodel_initialization , 100 ) ; monitor . subTask ( Messages . javamodel_configuring_classpath_containers ) ; } JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; SubProgressMonitor subMonitor = null ; try { if ( monitor != null ) { subMonitor = new SubProgressMonitor ( monitor , 50 ) ; subMonitor . beginTask ( "" , 100 ) ; subMonitor . worked ( 5 ) ; manager . batchContainerInitializationsProgress . initializeAfterLoadMonitor . set ( subMonitor ) ; } if ( manager . forceBatchInitializations ( true ) ) { manager . getClasspathContainer ( Path . EMPTY , null ) ; } else { while ( manager . batchContainerInitializations == JavaModelManager . BATCH_INITIALIZATION_IN_PROGRESS ) { if ( subMonitor != null ) { subMonitor . subTask ( manager . batchContainerInitializationsProgress . subTaskName ) ; subMonitor . worked ( manager . batchContainerInitializationsProgress . getWorked ( ) ) ; } synchronized ( manager ) { try { manager . wait ( 100 ) ; } catch ( InterruptedException e ) { } } } } } finally { if ( subMonitor != null ) subMonitor . done ( ) ; manager . batchContainerInitializationsProgress . initializeAfterLoadMonitor . set ( null ) ; } if ( monitor != null ) monitor . subTask ( Messages . javamodel_resetting_source_attachment_properties ) ; ExternalFoldersManager externalFoldersManager = JavaModelManager . getExternalManager ( ) ; final IJavaProject [ ] projects = manager . getJavaModel ( ) . getJavaProjects ( ) ; HashSet visitedPaths = new HashSet ( ) ; for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { JavaProject javaProject = ( JavaProject ) projects [ i ] ; IClasspathEntry [ ] classpath ; try { classpath = javaProject . getResolvedClasspath ( ) ; } catch ( JavaModelException e ) { continue ; } if ( classpath != null ) { boolean needExternalFolderCreation = false ; for ( int j = 0 , length2 = classpath . length ; j < length2 ; j ++ ) { IClasspathEntry entry = classpath [ j ] ; if ( entry . getSourceAttachmentPath ( ) != null ) { IPath entryPath = entry . getPath ( ) ; if ( visitedPaths . add ( entryPath ) ) { Util . setSourceAttachmentProperty ( entryPath , null ) ; } } if ( ! needExternalFolderCreation && entry . getEntryKind ( ) == IClasspathEntry . CPE_LIBRARY ) { IPath entryPath = entry . getPath ( ) ; if ( ExternalFoldersManager . isExternalFolderPath ( entryPath ) && externalFoldersManager . getFolder ( entryPath ) == null ) { needExternalFolderCreation = true ; } } } if ( needExternalFolderCreation ) manager . deltaState . addExternalFolderChange ( javaProject , null ) ; } } if ( monitor != null ) monitor . subTask ( Messages . javamodel_initializing_delta_state ) ; manager . deltaState . rootsAreStale = true ; manager . deltaState . initializeRoots ( true ) ; if ( monitor != null ) monitor . subTask ( Messages . javamodel_configuring_searchengine ) ; SearchEngine engine = new SearchEngine ( ) ; IJavaSearchScope scope = SearchEngine . createWorkspaceScope ( ) ; try { engine . searchAllTypeNames ( null , SearchPattern . R_EXACT_MATCH , "!@$#!@" . toCharArray ( ) , SearchPattern . R_PATTERN_MATCH | SearchPattern . R_CASE_SENSITIVE , IJavaSearchConstants . CLASS , scope , new TypeNameRequestor ( ) { public void acceptType ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path ) { } } , IJavaSearchConstants . CANCEL_IF_NOT_READY_TO_SEARCH , monitor == null ? null : new SubProgressMonitor ( monitor , 49 ) ) ; } catch ( JavaModelException e ) { } catch ( OperationCanceledException e ) { if ( monitor != null && monitor . isCanceled ( ) ) throw e ; } if ( monitor != null ) monitor . subTask ( Messages . javamodel_getting_build_state_number ) ; QualifiedName qName = new QualifiedName ( JavaCore . PLUGIN_ID , "" ) ; IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; String versionNumber = null ; try { versionNumber = root . getPersistentProperty ( qName ) ; } catch ( CoreException e ) { } final JavaModel model = manager . getJavaModel ( ) ; String newVersionNumber = Byte . toString ( State . VERSION ) ; if ( ! newVersionNumber . equals ( versionNumber ) ) { if ( JavaBuilder . DEBUG ) System . out . println ( "" ) ; IWorkspaceRunnable runnable = new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor progressMonitor2 ) throws CoreException { for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { IJavaProject project = projects [ i ] ; try { if ( JavaBuilder . DEBUG ) System . out . println ( "Touching " + project . getElementName ( ) ) ; project . getProject ( ) . touch ( progressMonitor2 ) ; } catch ( CoreException e ) { } } } } ; if ( monitor != null ) monitor . subTask ( Messages . javamodel_building_after_upgrade ) ; try { ResourcesPlugin . getWorkspace ( ) . run ( runnable , monitor ) ; } catch ( CoreException e ) { } try { root . setPersistentProperty ( qName , newVersionNumber ) ; } catch ( CoreException e ) { Util . log ( e , "" ) ; } } try { if ( monitor != null ) monitor . subTask ( Messages . javamodel_refreshing_external_jars ) ; model . refreshExternalArchives ( null , monitor == null ? null : new SubProgressMonitor ( monitor , 1 ) ) ; } catch ( JavaModelException e ) { } } finally { if ( monitor != null ) monitor . done ( ) ; } } public static boolean isClasspathVariableReadOnly ( String variableName ) { return JavaModelManager . getJavaModelManager ( ) . readOnlyVariables . contains ( variableName ) ; } public static boolean isJavaLikeFileName ( String fileName ) { return Util . isJavaLikeFileName ( fileName ) ; } public static boolean isReferencedBy ( IJavaElement element , IMarker marker ) throws CoreException { if ( element instanceof IMember ) { IMember member = ( IMember ) element ; if ( member . isBinary ( ) ) { element = member . getClassFile ( ) ; } else { element = member . getCompilationUnit ( ) ; } } if ( element == null ) return false ; if ( marker == null ) return false ; String markerHandleId = ( String ) marker . getAttribute ( ATT_HANDLE_ID ) ; if ( markerHandleId == null ) return false ; IJavaElement markerElement = JavaCore . create ( markerHandleId ) ; while ( true ) { if ( element . equals ( markerElement ) ) return true ; if ( markerElement instanceof IClassFile ) { IType enclosingType = ( ( IClassFile ) markerElement ) . getType ( ) . getDeclaringType ( ) ; if ( enclosingType != null ) { markerElement = enclosingType . getClassFile ( ) ; continue ; } } break ; } return false ; } public static boolean isReferencedBy ( IJavaElement element , IMarkerDelta markerDelta ) throws CoreException { if ( element instanceof IMember ) { IMember member = ( IMember ) element ; if ( member . isBinary ( ) ) { element = member . getClassFile ( ) ; } else { element = member . getCompilationUnit ( ) ; } } if ( element == null ) return false ; if ( markerDelta == null ) return false ; String markerDeltarHandleId = ( String ) markerDelta . getAttribute ( ATT_HANDLE_ID ) ; if ( markerDeltarHandleId == null ) return false ; IJavaElement markerElement = JavaCore . create ( markerDeltarHandleId ) ; while ( true ) { if ( element . equals ( markerElement ) ) return true ; if ( markerElement instanceof IClassFile ) { IType enclosingType = ( ( IClassFile ) markerElement ) . getType ( ) . getDeclaringType ( ) ; if ( enclosingType != null ) { markerElement = enclosingType . getClassFile ( ) ; continue ; } } break ; } return false ; } public static IAccessRule newAccessRule ( IPath filePattern , int kind ) { return new ClasspathAccessRule ( filePattern , kind ) ; } public static IClasspathAttribute newClasspathAttribute ( String name , String value ) { return new ClasspathAttribute ( name , value ) ; } public static IClasspathEntry newContainerEntry ( IPath containerPath ) { return newContainerEntry ( containerPath , ClasspathEntry . NO_ACCESS_RULES , ClasspathEntry . NO_EXTRA_ATTRIBUTES , false ) ; } public static IClasspathEntry newContainerEntry ( IPath containerPath , boolean isExported ) { return newContainerEntry ( containerPath , ClasspathEntry . NO_ACCESS_RULES , ClasspathEntry . NO_EXTRA_ATTRIBUTES , isExported ) ; } public static IClasspathEntry newContainerEntry ( IPath containerPath , IAccessRule [ ] accessRules , IClasspathAttribute [ ] extraAttributes , boolean isExported ) { if ( containerPath == null ) { throw new ClasspathEntry . AssertionFailedException ( "" ) ; } else if ( containerPath . segmentCount ( ) < 1 ) { throw new ClasspathEntry . AssertionFailedException ( "" + containerPath . makeRelative ( ) . toString ( ) + "" ) ; } if ( accessRules == null ) { accessRules = ClasspathEntry . NO_ACCESS_RULES ; } if ( extraAttributes == null ) { extraAttributes = ClasspathEntry . NO_EXTRA_ATTRIBUTES ; } return new ClasspathEntry ( IPackageFragmentRoot . K_SOURCE , IClasspathEntry . CPE_CONTAINER , containerPath , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , null , null , null , isExported , accessRules , true , extraAttributes ) ; } public static ITypeHierarchy newTypeHierarchy ( IRegion region , WorkingCopyOwner owner , IProgressMonitor monitor ) throws JavaModelException { if ( region == null ) { throw new IllegalArgumentException ( Messages . hierarchy_nullRegion ) ; } ICompilationUnit [ ] workingCopies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( owner , true ) ; CreateTypeHierarchyOperation op = new CreateTypeHierarchyOperation ( region , workingCopies , null , true ) ; op . runOperation ( monitor ) ; return op . getResult ( ) ; } public static IClasspathEntry newLibraryEntry ( IPath path , IPath sourceAttachmentPath , IPath sourceAttachmentRootPath ) { return newLibraryEntry ( path , sourceAttachmentPath , sourceAttachmentRootPath , ClasspathEntry . NO_ACCESS_RULES , ClasspathEntry . NO_EXTRA_ATTRIBUTES , false ) ; } public static IClasspathEntry newLibraryEntry ( IPath path , IPath sourceAttachmentPath , IPath sourceAttachmentRootPath , boolean isExported ) { return newLibraryEntry ( path , sourceAttachmentPath , sourceAttachmentRootPath , ClasspathEntry . NO_ACCESS_RULES , ClasspathEntry . NO_EXTRA_ATTRIBUTES , isExported ) ; } public static IClasspathEntry newLibraryEntry ( IPath path , IPath sourceAttachmentPath , IPath sourceAttachmentRootPath , IAccessRule [ ] accessRules , IClasspathAttribute [ ] extraAttributes , boolean isExported ) { if ( path == null ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( accessRules == null ) { accessRules = ClasspathEntry . NO_ACCESS_RULES ; } if ( extraAttributes == null ) { extraAttributes = ClasspathEntry . NO_EXTRA_ATTRIBUTES ; } boolean hasDotDot = ClasspathEntry . hasDotDot ( path ) ; if ( ! hasDotDot && ! path . isAbsolute ( ) ) throw new ClasspathEntry . AssertionFailedException ( "" + path ) ; if ( sourceAttachmentPath != null ) { if ( sourceAttachmentPath . isEmpty ( ) ) { sourceAttachmentPath = null ; } else if ( ! sourceAttachmentPath . isAbsolute ( ) ) { throw new ClasspathEntry . AssertionFailedException ( "" + sourceAttachmentPath + "" ) ; } } return new ClasspathEntry ( IPackageFragmentRoot . K_BINARY , IClasspathEntry . CPE_LIBRARY , hasDotDot ? path : JavaProject . canonicalizedPath ( path ) , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , sourceAttachmentPath , sourceAttachmentRootPath , null , isExported , accessRules , false , extraAttributes ) ; } public static IClasspathEntry newProjectEntry ( IPath path ) { return newProjectEntry ( path , false ) ; } public static IClasspathEntry newProjectEntry ( IPath path , boolean isExported ) { if ( ! path . isAbsolute ( ) ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; return newProjectEntry ( path , ClasspathEntry . NO_ACCESS_RULES , true , ClasspathEntry . NO_EXTRA_ATTRIBUTES , isExported ) ; } public static IClasspathEntry newProjectEntry ( IPath path , IAccessRule [ ] accessRules , boolean combineAccessRules , IClasspathAttribute [ ] extraAttributes , boolean isExported ) { if ( ! path . isAbsolute ( ) ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( accessRules == null ) { accessRules = ClasspathEntry . NO_ACCESS_RULES ; } if ( extraAttributes == null ) { extraAttributes = ClasspathEntry . NO_EXTRA_ATTRIBUTES ; } return new ClasspathEntry ( IPackageFragmentRoot . K_SOURCE , IClasspathEntry . CPE_PROJECT , path , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , null , null , null , isExported , accessRules , combineAccessRules , extraAttributes ) ; } public static IRegion newRegion ( ) { return new Region ( ) ; } public static IClasspathEntry newSourceEntry ( IPath path ) { return newSourceEntry ( path , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , null ) ; } public static IClasspathEntry newSourceEntry ( IPath path , IPath [ ] exclusionPatterns ) { return newSourceEntry ( path , ClasspathEntry . INCLUDE_ALL , exclusionPatterns , null ) ; } public static IClasspathEntry newSourceEntry ( IPath path , IPath [ ] exclusionPatterns , IPath specificOutputLocation ) { return newSourceEntry ( path , ClasspathEntry . INCLUDE_ALL , exclusionPatterns , specificOutputLocation ) ; } public static IClasspathEntry newSourceEntry ( IPath path , IPath [ ] inclusionPatterns , IPath [ ] exclusionPatterns , IPath specificOutputLocation ) { return newSourceEntry ( path , inclusionPatterns , exclusionPatterns , specificOutputLocation , ClasspathEntry . NO_EXTRA_ATTRIBUTES ) ; } public static IClasspathEntry newSourceEntry ( IPath path , IPath [ ] inclusionPatterns , IPath [ ] exclusionPatterns , IPath specificOutputLocation , IClasspathAttribute [ ] extraAttributes ) { if ( path == null ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( ! path . isAbsolute ( ) ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( exclusionPatterns == null ) { exclusionPatterns = ClasspathEntry . EXCLUDE_NONE ; } if ( inclusionPatterns == null ) { inclusionPatterns = ClasspathEntry . INCLUDE_ALL ; } if ( extraAttributes == null ) { extraAttributes = ClasspathEntry . NO_EXTRA_ATTRIBUTES ; } return new ClasspathEntry ( IPackageFragmentRoot . K_SOURCE , IClasspathEntry . CPE_SOURCE , path , inclusionPatterns , exclusionPatterns , null , null , specificOutputLocation , false , null , false , extraAttributes ) ; } public static IClasspathEntry newVariableEntry ( IPath variablePath , IPath variableSourceAttachmentPath , IPath sourceAttachmentRootPath ) { return newVariableEntry ( variablePath , variableSourceAttachmentPath , sourceAttachmentRootPath , false ) ; } public static IClasspathEntry newVariableEntry ( IPath variablePath , IPath variableSourceAttachmentPath , IPath variableSourceAttachmentRootPath , boolean isExported ) { return newVariableEntry ( variablePath , variableSourceAttachmentPath , variableSourceAttachmentRootPath , ClasspathEntry . NO_ACCESS_RULES , ClasspathEntry . NO_EXTRA_ATTRIBUTES , isExported ) ; } public static IClasspathEntry newVariableEntry ( IPath variablePath , IPath variableSourceAttachmentPath , IPath variableSourceAttachmentRootPath , IAccessRule [ ] accessRules , IClasspathAttribute [ ] extraAttributes , boolean isExported ) { if ( variablePath == null ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( variablePath . segmentCount ( ) < 1 ) { throw new ClasspathEntry . AssertionFailedException ( "" + variablePath . makeRelative ( ) . toString ( ) + "" ) ; } if ( accessRules == null ) { accessRules = ClasspathEntry . NO_ACCESS_RULES ; } if ( extraAttributes == null ) { extraAttributes = ClasspathEntry . NO_EXTRA_ATTRIBUTES ; } return new ClasspathEntry ( IPackageFragmentRoot . K_SOURCE , IClasspathEntry . CPE_VARIABLE , variablePath , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , variableSourceAttachmentPath , variableSourceAttachmentRootPath , null , isExported , accessRules , false , extraAttributes ) ; } public static IClasspathEntry [ ] getReferencedClasspathEntries ( IClasspathEntry libraryEntry , IJavaProject project ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; return manager . getReferencedClasspathEntries ( libraryEntry , project ) ; } public static void removeClasspathVariable ( String variableName ) { removeClasspathVariable ( variableName , null ) ; } public static void removeClasspathVariable ( String variableName , IProgressMonitor monitor ) { try { SetVariablesOperation operation = new SetVariablesOperation ( new String [ ] { variableName } , new IPath [ ] { null } , true ) ; operation . runOperation ( monitor ) ; } catch ( JavaModelException e ) { Util . log ( e , "" + variableName ) ; } } public static void removeElementChangedListener ( IElementChangedListener listener ) { JavaModelManager . getDeltaState ( ) . removeElementChangedListener ( listener ) ; } public static String removeJavaLikeExtension ( String fileName ) { return Util . getNameWithoutJavaLikeExtension ( fileName ) ; } public static void removePreProcessingResourceChangedListener ( IResourceChangeListener listener ) { JavaModelManager . getDeltaState ( ) . removePreResourceChangedListener ( listener ) ; } public static void run ( IWorkspaceRunnable action , IProgressMonitor monitor ) throws CoreException { run ( action , ResourcesPlugin . getWorkspace ( ) . getRoot ( ) , monitor ) ; } public static void run ( IWorkspaceRunnable action , ISchedulingRule rule , IProgressMonitor monitor ) throws CoreException { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; if ( workspace . isTreeLocked ( ) ) { new BatchOperation ( action ) . run ( monitor ) ; } else { workspace . run ( new BatchOperation ( action ) , rule , IWorkspace . AVOID_UPDATE , monitor ) ; } } public static void setClasspathContainer ( IPath containerPath , IJavaProject [ ] affectedProjects , IClasspathContainer [ ] respectiveContainers , IProgressMonitor monitor ) throws JavaModelException { if ( affectedProjects . length != respectiveContainers . length ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; if ( affectedProjects . length == 1 ) { IClasspathContainer container = respectiveContainers [ 0 ] ; if ( container != null ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; IJavaProject project = affectedProjects [ 0 ] ; IClasspathContainer existingCointainer = manager . containerGet ( project , containerPath ) ; if ( existingCointainer == JavaModelManager . CONTAINER_INITIALIZATION_IN_PROGRESS ) { manager . containerBeingInitializedPut ( project , containerPath , container ) ; return ; } } } SetContainerOperation operation = new SetContainerOperation ( containerPath , affectedProjects , respectiveContainers ) ; operation . runOperation ( monitor ) ; } public static void setClasspathVariable ( String variableName , IPath path ) throws JavaModelException { setClasspathVariable ( variableName , path , null ) ; } public static void setClasspathVariable ( String variableName , IPath path , IProgressMonitor monitor ) throws JavaModelException { if ( path == null ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; setClasspathVariables ( new String [ ] { variableName } , new IPath [ ] { path } , monitor ) ; } public static void setClasspathVariables ( String [ ] variableNames , IPath [ ] paths , IProgressMonitor monitor ) throws JavaModelException { if ( variableNames . length != paths . length ) throw new ClasspathEntry . AssertionFailedException ( "" ) ; SetVariablesOperation operation = new SetVariablesOperation ( variableNames , paths , true ) ; operation . runOperation ( monitor ) ; } public static void setComplianceOptions ( String compliance , Map options ) { switch ( ( int ) ( CompilerOptions . versionToJdkLevel ( compliance ) >>> 16 ) ) { case ClassFileConstants . MAJOR_VERSION_1_3 : options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_1 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . IGNORE ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . IGNORE ) ; break ; case ClassFileConstants . MAJOR_VERSION_1_4 : options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_4 ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_2 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . WARNING ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . WARNING ) ; break ; case ClassFileConstants . MAJOR_VERSION_1_5 : options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_5 ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_5 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_5 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_CODEGEN_INLINE_JSR_BYTECODE , JavaCore . ENABLED ) ; break ; case ClassFileConstants . MAJOR_VERSION_1_6 : options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_6 ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_6 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_6 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_CODEGEN_INLINE_JSR_BYTECODE , JavaCore . ENABLED ) ; break ; case ClassFileConstants . MAJOR_VERSION_1_7 : options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_7 ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_7 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_7 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_CODEGEN_INLINE_JSR_BYTECODE , JavaCore . ENABLED ) ; } } public static void setOptions ( Hashtable newOptions ) { JavaModelManager . getJavaModelManager ( ) . setOptions ( newOptions ) ; } public void stop ( BundleContext context ) throws Exception { try { JavaModelManager . getJavaModelManager ( ) . shutdown ( ) ; } finally { super . stop ( context ) ; } } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; JavaModelManager . getJavaModelManager ( ) . startup ( ) ; } } </s>