[xtext][index] Generalize specialization of the ResourceDescriptionsProvider

Access to resources from the current project is disallowed during
the indexing phase.

see https://bugs.eclipse.org/bugs/show_bug.cgi?id=450046

Change-Id: Iff8875d5a74e30aa8d8e31cea599d128a01f1c30
This commit is contained in:
Sebastian Zarnekow 2015-01-05 11:13:22 +01:00
parent 80551f4162
commit afde505d19

View file

@ -18,8 +18,12 @@ import com.google.inject.Provider;
import com.google.inject.name.Named;
/**
* The {@link ResourceDescriptionsProvider} allows to obtain a readily configured instance of the
* {@link IResourceDescriptions} depending on the use case and lifecylce of the resource set.
*
* @author Sven Efftinge - Initial contribution and API
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class ResourceDescriptionsProvider {
@ -93,20 +97,7 @@ public class ResourceDescriptionsProvider {
*/
/* @NonNull */
public IResourceDescriptions getResourceDescriptions(/* @NonNull */ ResourceSet resourceSet) {
Map<Object, Object> loadOptions = resourceSet.getLoadOptions();
String[] mutualExclusiveFlags = new String[] { NAMED_BUILDER_SCOPE, LIVE_SCOPE, PERSISTED_DESCRIPTIONS };
String flag = null;
for (int i = 0; i < mutualExclusiveFlags.length; i++) {
String candidate = mutualExclusiveFlags[i];
if (loadOptions.containsKey(candidate)) {
if (flag == null) {
flag = candidate;
} else {
String msg = "Ambiguous scope for the resource set. Can't combine " + flag + " and " + candidate;
throw new IllegalStateException(msg);
}
}
}
String flag = getFlagFromLoadOptions(resourceSet);
final IResourceDescriptions result;
if (NAMED_BUILDER_SCOPE.equals(flag)) {
result = createBuilderScopeResourceDescriptions();
@ -123,6 +114,24 @@ public class ResourceDescriptionsProvider {
return result;
}
private String getFlagFromLoadOptions(ResourceSet resourceSet) {
Map<Object, Object> loadOptions = resourceSet.getLoadOptions();
String[] mutualExclusiveFlags = new String[] { NAMED_BUILDER_SCOPE, LIVE_SCOPE, PERSISTED_DESCRIPTIONS };
String result = null;
for (int i = 0; i < mutualExclusiveFlags.length; i++) {
String candidate = mutualExclusiveFlags[i];
if (loadOptions.containsKey(candidate)) {
if (result == null) {
result = candidate;
} else {
String msg = "Ambiguous scope for the resource set. Can't combine " + result + " and " + candidate;
throw new IllegalStateException(msg);
}
}
}
return result;
}
/**
* The returned IResourceDescriptions represent the Xtext Index' state shadowed by the Editors Dirty State shadowed
* by the current ResourceSets contents.