Java源码示例:org.eclipse.xtext.resource.IResourceDescriptions
示例1
/**
* Bulk method to return all resources (managed by this manager) which are affected by the given set of deltas.
*
* @param deltas
* deltas
* @param candidates
* candidates
* @param context
* context index
* @return collection of affected resources
*/
public Collection<URI> getAffectedResources(final Collection<Delta> deltas, final Collection<URI> candidates, final IResourceDescriptions context) {
// Don't filter by isInterestedIn() in this bulk method. First, isInterestedIn() is based on file extensions, which may or may not
// work precisely. Second, it filters by haveEObjectdescriptionsChanged(), but the MonitoredClusteringBuilderState already ensures that
// the delta does not contain unchanged resource descriptions.
//
// By not pre-filtering the deltas, we can also ensure that resource description managers for different languages will end up making
// identical queries to findAllReferencingResources() and findExactReferencingResources(), which is crucial to make the cache in
// MonitoredClusteringBuilderState be effective.
//
// See also the comment on MonitoredClusteringBuilderState.FindReferenceCachingState.
if (deltas.isEmpty() || candidates.isEmpty()) {
return Collections.emptySet();
}
return getAffectedResources(deltas, uri -> candidates.contains(uri) && isManagerFor(uri), (IResourceDescriptions2) context);
}
示例2
/**
* Deletes all entries in the Xtext index that start with one of the given project URIs will be cleaned from the
* index.
*
* @param toBeWiped
* URIs of project roots
*/
public void wipeURIsFromIndex(IProgressMonitor monitor, Collection<FileURI> toBeWiped) {
Set<String> toBeWipedStrings = new HashSet<>();
for (FileURI toWipe : toBeWiped) {
toBeWipedStrings.add(toWipe.toString());
N4JSProjectName projectName = toWipe.getProjectName();
validatorExtension.clearAllMarkersOfExternalProject(projectName);
}
ResourceSet resourceSet = core.createResourceSet(Optional.absent());
IResourceDescriptions index = core.getXtextIndex(resourceSet);
Set<URI> toBeRemoved = new HashSet<>();
for (IResourceDescription res : index.getAllResourceDescriptions()) {
URI resUri = res.getURI();
String resUriString = resUri.toString();
for (String toWipeProject : toBeWipedStrings) {
if (resUriString.startsWith(toWipeProject)) {
toBeRemoved.add(resUri);
break;
}
}
}
builderState.clean(toBeRemoved, monitor);
}
示例3
/**
* Returns a map that maps the names of projects as they can be found in the index to their locations and versions.
*/
public Map<N4JSProjectName, Pair<FileURI, String>> findNpmsInIndex() {
// keep map of all NPMs that were discovered in the index
Map<N4JSProjectName, Pair<FileURI, String>> discoveredNpmsInIndex = new HashMap<>();
final ResourceSet resourceSet = core.createResourceSet(Optional.absent());
final IResourceDescriptions index = core.getXtextIndex(resourceSet);
for (IResourceDescription resourceDescription : index.getAllResourceDescriptions()) {
boolean isExternal = resourceDescription.getURI().isFile();
if (isExternal) {
addToIndex(discoveredNpmsInIndex, resourceDescription);
}
}
return discoveredNpmsInIndex;
}
示例4
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
return delegate.getContainer(desc, resourceDescriptions);
}
ResourceDescriptionsBasedContainer result = new ResourceDescriptionsBasedContainer(resourceDescriptions) {
// this used to be the default implementation, which is wrong.
// we fixed the orginal and moved the wrong impl here since old clients might see much worse performance with the new impl.
@Override
public boolean hasResourceDescription(URI uri) {
return true;
}
};
result.setUriToDescriptionCacheEnabled(false);
return result;
}
示例5
/**
* Register a name as imported.
*
* @param context
* context object within which a reference is being set to some object, must not be {@code null}
* @param target
* the associated target eObject. Its exported name is recorded as imported, must not be {@code null}
* @param type
* the lookup type, may be {@code null}
*/
public void importObject(final EObject context, final EObject target, final EClass type) {
Resource eResource = target.eResource();
QualifiedName targetName = null;
if (eResource instanceof LazyLinkingResource2) {
IQualifiedNameProvider nameProvider = ((LazyLinkingResource2) eResource).getService(IQualifiedNameProvider.class);
if (nameProvider != null) {
targetName = nameProvider.getFullyQualifiedName(target);
}
} else {
final IResourceDescriptions resourceDescriptions = provider.getResourceDescriptions(context.eResource());
Iterator<IEObjectDescription> exports = resourceDescriptions.getExportedObjectsByObject(target).iterator();
if (exports.hasNext()) {
targetName = exports.next().getName();
}
}
if (targetName != null && !targetName.isEmpty()) {
registerNamedType(context, targetName.toLowerCase(), type); // NOPMD targetName not a String!
}
}
示例6
@Test public void testOutgoingReferencesToAnotherResourceWithBuilderStateNoAffection() {
String exportedName = "exportedName";
String importedName = "importedName";
testMe.setBuilderStateProvider(Providers.<IResourceDescriptions>of(new MyBuilderState(exportedName)));
documentResource.importedName = importedName;
documentURI = URI.createURI("document");
targetURI = URI.createURI("target");
ReferenceDescriptionImpl reference = (ReferenceDescriptionImpl) BuilderStateFactory.eINSTANCE.createReferenceDescription();
reference.setTargetEObjectUri(URI.createURI("anothertarget"));
referenceDescriptions.add(reference);
noDocumentDescription = false;
announceDirtyStateChanged();
validationScheduled = false;
testMe.scheduleInitialValidation(document);
assertFalse(validationScheduled);
}
示例7
private EPackage findPackageInAllDescriptions(EObject context, QualifiedName packageNsURI) {
IResourceDescriptions descriptions = descriptionsProvider.getResourceDescriptions(context.eResource());
if (descriptions != null) {
Iterable<IEObjectDescription> exported = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, packageNsURI, false);
for(IEObjectDescription candidate: exported) {
if (isNsUriIndexEntry(candidate)) {
EPackage result = getResolvedEPackage(candidate, context);
if (result != null)
return result;
}
}
}
return null;
}
示例8
/***/
public static boolean indexContainsElement(final String fileUri, final String eObjectName) {
IResourceDescriptions descriptions = getBuilderState();
URI uri = URI.createURI("platform:/resource" + fileUri);
IResourceDescription description = descriptions.getResourceDescription(uri);
if (description != null) {
return description
.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(eObjectName), false)
.iterator().hasNext();
}
return false;
}
示例9
@Before
public void setup() {
Module m = new Module() {
@Override
public void configure(Binder binder) {
binder.bind(INamingService.class).to(DefaultNamingService.class);
binder.bind(IQualifiedNameProvider.class).to(SGraphNameProvider.class);
binder.bind(ITypeSystem.class).toInstance(GenericTypeSystem.getInstance());
binder.bind(IResourceDescriptions.class).to(ResourceSetBasedResourceDescriptions.class);
binder.bind(String.class).annotatedWith(Names.named("Separator")).toInstance("_");
}
};
Injector injector = Guice.createInjector(m);
injector.injectMembers(this);
}
示例10
/**
* Low-level method to collect all test modules, i.e. N4JS files containing classes containing at least one method
* annotated with @Test, as {@link IResourceDescription}s.
*/
private List<URI> collectDistinctTestLocations(Function<? super URI, ? extends ResourceSet> resourceSetAccess,
List<URI> locations) {
return locations.stream().flatMap(loc -> {
ResourceSet resSet = resourceSetAccess.apply(loc);
IResourceDescriptions index = n4jsCore.getXtextIndex(resSet);
return collectTestLocations(index, resSet, loc);
}).distinct().collect(Collectors.toList());
}
示例11
@Inject
public FastReferenceSearchResultContentProvider(final IResourceDescriptions resourceDescriptions) {
super(resourceDescriptions);
this.resourceDescriptions = resourceDescriptions;
if (resourceDescriptions instanceof IResourceDescription.Event.Source) {
((IResourceDescription.Event.Source) resourceDescriptions).addListener(this);
}
}
示例12
protected JavaSearchHelper createSearchHelper(ISearchRequestor requestor) {
JavaSearchHelper searchHelper = javaSearchHelperProvider.get();
IResourceDescriptions descriptionsToSearch = resourceDescriptionsProvider.get();
if(descriptionsToSearch.isEmpty()) {
waitForBuild();
descriptionsToSearch = resourceDescriptionsProvider.get();
}
searchHelper.init(requestor, descriptionsToSearch);
return searchHelper;
}
示例13
/**
* Create a new tested project wizard page.
*
* @param projectInfo
* The N4JSProjectInfo to use as model
* @param resourceDescriptions
* A {@link IResourceDescriptions} implementation.
*/
public N4JSTestedProjectWizardPage(N4JSProjectInfo projectInfo, IResourceDescriptions resourceDescriptions) {
super("Select projects to be tested");
this.resourceDescriptions = resourceDescriptions;
this.projectInfo = projectInfo;
this.setTitle("Select projects to be tested");
this.setMessage("Select projects to be tested in your new test project");
}
示例14
@Test public void testNoCopiedResourceDescription() throws Exception {
createPluginProject("foo");
build();
IResourceDescriptions descriptions = BuilderUtil.getBuilderState();
assertFalse(Iterables.isEmpty(descriptions.getAllResourceDescriptions()));
for(IResourceDescription description: descriptions.getAllResourceDescriptions()) {
if (description instanceof CopiedResourceDescription) {
fail("Did not expect an instance of copied resource description in builder state");
}
}
}
示例15
@Override
protected IHierarchyBuilder createHierarchyBuilder(EObject target) {
AssociationHierarchyBuilder xtextCallHierarchyBuilder = globalServiceProvider.findService(target,
AssociationHierarchyBuilder.class);
xtextCallHierarchyBuilder.setResourceAccess(resourceAccess);
xtextCallHierarchyBuilder.setIndexData(globalServiceProvider.findService(target, IResourceDescriptions.class));
DeferredHierarchyBuilder deferredHierarchyBuilder = globalServiceProvider.findService(target, DeferredHierarchyBuilder.class);
deferredHierarchyBuilder.setHierarchyBuilder(xtextCallHierarchyBuilder);
return deferredHierarchyBuilder;
}
示例16
protected List<IContainer> getVisibleContainers(List<String> handles, IResourceDescriptions resourceDescriptions) {
if (handles.isEmpty())
return Collections.emptyList();
List<IContainer> result = Lists.newArrayListWithExpectedSize(handles.size());
for(String handle: handles) {
IContainer container = createContainer(handle, resourceDescriptions);
if (!container.isEmpty() || result.isEmpty())
result.add(container);
}
return result;
}
示例17
private ProjectComparisonEntry createEntries(
ProjectComparison root,
IN4JSProject api, IN4JSProject[] impls,
ResourceSet resourceSet, IResourceDescriptions index) {
final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);
for (IN4JSSourceContainer currSrcConti : api.getSourceContainers()) {
for (URI uri : currSrcConti) {
final String uriStr = uri.toString();
if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION)
|| uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
final IResourceDescription resDesc = index.getResourceDescription(uri);
final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
if (moduleApi != null) {
final TModule[] moduleImpls = new TModule[impls.length];
for (int idx = 0; idx < impls.length; idx++) {
final IN4JSProject projectImpl = impls[idx];
if (projectImpl != null)
moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
else
moduleImpls[idx] = null;
}
createEntries(entry, -1, moduleApi, moduleImpls, false);
}
}
}
}
return entry;
}
示例18
/** {@inheritDoc} */
@Override
public Set<Binding> getGuiceBindingsUi(final Grammar grammar) {
final Set<Binding> bindings = super.getGuiceBindingsUi(grammar);
final BindFactory factory = new BindFactory();
factory.addConfiguredBinding(IResourceDescriptions.class.getName() + "BuilderScope", "binder.bind(" + IResourceDescriptions.class.getName() + ".class"
+ ").annotatedWith(com.google.inject.name.Names.named(" + ResourceDescriptionsProvider.class.getName() + ".NAMED_BUILDER_SCOPE)).to("
+ "com.avaloq.tools.ddk.xtext.builder.CurrentDescriptions2.ResourceSetAware.class)");
final Set<Binding> result = factory.getBindings();
result.addAll(bindings);
return result;
}
示例19
@Override
public Context tryGetContext(Resource resource, CancelIndicator cancelIndicator) {
IResourceDescriptions index = getIndex(resource);
if (index == null) {
return null;
}
IResourceDescription description = getResourceDescription(resource);
if (description == null) {
return null;
}
IContainer container = containerManager.getContainer(description, index);
return new DefaultUniqueNameContext(description, container, getCaseInsensitivityHelper(), cancelIndicator);
}
示例20
protected void assertLiveModelScopeLocal(boolean enabled) throws IOException {
final URI resourceURI = URI.createPlatformResourceURI("test/assertLiveModelScopeLocal." + fileExt.getPrimaryFileExtension(), true);
Resource resource = resourceSet.createResource(resourceURI);
resource.load(new StringInputStream("stuff foo"), null);
Stuff stuffFoo = ((File) resource.getContents().get(0)).getStuff().get(0);
if (enabled) {
assertExportedObject(resource, "foo");
stuffFoo.setName("bar");
assertExportedObject(resource, "bar");
} else {
IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
assertNull(resourceDescription);
}
}
示例21
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc,
IResourceDescriptions resourceDescriptions) {
ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
if (descriptions == null)
throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
ProjectDescription projectDescription = ProjectDescription.findInEmfObject(descriptions.getResourceSet());
List<IContainer> allContainers = new ArrayList<>();
allContainers.add(createContainer(resourceDescriptions, descriptions, projectDescription.getName()));
for (String name : projectDescription.getDependencies())
allContainers.add(createContainer(resourceDescriptions, descriptions, name));
return allContainers;
}
示例22
public DefaultReferenceFinder(IResourceDescriptions indexData,
IResourceServiceProvider.Registry serviceProviderRegistry,
TargetURIConverter converter) {
super(serviceProviderRegistry);
this.indexData = indexData;
this.converter = converter;
}
示例23
public IndexAwareNameEnvironment(Resource resource, ClassLoader classLoader,
IResourceDescriptions resourceDescriptions, EObjectDescriptionBasedStubGenerator stubGenerator,
ClassFileCache classFileCache) {
this.resource = resource;
this.classLoader = classLoader;
this.resourceDescriptions = resourceDescriptions;
this.stubGenerator = stubGenerator;
this.classFileCache = classFileCache;
}
示例24
/**
* @since 2.4
*/
protected ResourceSet getResourceSet(IResourceDescriptions context) {
if (context instanceof IResourceSetAware)
return ((IResourceSetAware) context).getResourceSet();
String contextType = context == null ? "null" : context.getClass().getName();
throw new IllegalStateException("Passed " + contextType + " is not based on a resource set");
}
示例25
public void configureIResourceDescriptionsPersisted(Binder binder) {
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(ResourceSetBasedResourceDescriptions.class);
}
示例26
public void configureIResourceDescriptionsPersisted(Binder binder) {
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(IBuilderState.class);
}
示例27
public void configureIResourceDescriptionsPersisted(Binder binder) {
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(IBuilderState.class);
}
示例28
public void configureIResourceDescriptions(Binder binder) {
binder.bind(IResourceDescriptions.class).to(EagerResourceSetBasedResourceDescriptions.class);
}
示例29
@Override
public boolean isAffectedByAny(final Collection<Delta> deltas, final IResourceDescription candidate,
final IResourceDescriptions context) throws IllegalArgumentException {
return isAffected(deltas, candidate, context);
}
示例30
public void configureIResourceDescriptionsPersisted(Binder binder) {
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(ResourceSetBasedResourceDescriptions.class);
}