mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[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:
parent
80551f4162
commit
afde505d19
1 changed files with 23 additions and 14 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue