// Get cached preferences if exist
JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
// Init project preferences
IScopeContext context = new ProjectScope(getProject());
final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
updatePreferences(eclipsePreferences);
perProjectInfo.preferences = eclipsePreferences;
// Listen to node removal from parent in order to reset cache (see bug 68993)
IEclipsePreferences.INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
public void added(IEclipsePreferences.NodeChangeEvent event) {
// do nothing
}
public void removed(IEclipsePreferences.NodeChangeEvent event) {
if (event.getChild() == eclipsePreferences) {
JavaModelManager.getJavaModelManager().resetProjectPreferences(JavaProject.this);
}
}
};
((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
// Listen to preference changes
IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() {
public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
String propertyName = event.getKey();
JavaModelManager manager = JavaModelManager.getJavaModelManager();
if (propertyName.startsWith(JavaCore.PLUGIN_ID)) {
if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) ||
propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) ||
propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) ||
propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) ||
propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) ||
propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) ||
propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL))
{
manager.deltaState.addClasspathValidation(JavaProject.this);
}
manager.resetProjectOptions(JavaProject.this);
}
}
};
eclipsePreferences.addPreferenceChangeListener(preferenceListener);
return eclipsePreferences;
}