Java Code Examples for org.eclipse.xtext.resource.IResourceDescription#getExportedObjects()
The following examples show how to use
org.eclipse.xtext.resource.IResourceDescription#getExportedObjects() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceDescriptionsData.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void removeDescription(URI uri) { IResourceDescription oldDescription = resourceDescriptionMap.remove(uri); if (oldDescription != null) { for(IEObjectDescription object: oldDescription.getExportedObjects()) { QualifiedName objectName = object.getName().toLowerCase(); Object existing = lookupMap.get(objectName); if (existing == oldDescription) { lookupMap.remove(objectName); } else if (existing instanceof Set<?>) { Set<?> casted = (Set<?>) existing; if (casted.remove(oldDescription)) { if (casted.size() == 1) { lookupMap.put(objectName, casted.iterator().next()); } else if (casted.isEmpty()) { lookupMap.remove(objectName); } } } } } }
Example 2
Source File: EObjectDescriptionBasedStubGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public String getJavaStubSource(IEObjectDescription description, IResourceDescription resourceDescription) { if(isNestedType(description) || !isJvmDeclaredType(description)) { return null; } Multimap<QualifiedName, IEObjectDescription> owner2nested = LinkedHashMultimap.create(); for(IEObjectDescription other: resourceDescription.getExportedObjects()) { if(isJvmDeclaredType(other) && isNestedType(other)) owner2nested.put(getOwnerClassName(other.getQualifiedName()), other); } StringBuilder classSignatureBuilder = new StringBuilder(); QualifiedName qualifiedName = description.getQualifiedName(); if (qualifiedName.getSegments().size() > 1) { String string = qualifiedName.toString(); classSignatureBuilder.append("package " + string.substring(0, string.lastIndexOf('.')) + ";"); } appendType(description, owner2nested, classSignatureBuilder); return classSignatureBuilder.toString(); }
Example 3
Source File: GenericResourceDescriptionManagerTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreateDeltaAndIsAffected() { GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager(); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("Test"); eClass.getESuperTypes().add(EcorePackage.Literals.EPACKAGE); Resource resource = new XMIResourceImpl(URI.createFileURI("test.ecore")); resource.getContents().add(eClass); EPackage copyOfEPackage = EcoreUtil.copy(EcorePackage.eINSTANCE); Resource ecoreResource = new XMIResourceImpl(URI.createURI(copyOfEPackage.getNsURI())); ecoreResource.getContents().add(copyOfEPackage); IResourceDescription oldDescription = new CopiedResourceDescription(manager.getResourceDescription(ecoreResource)); oldDescription.getExportedObjects(); copyOfEPackage.setName("ecore_new"); IResourceDescription newDescription = manager.getResourceDescription(ecoreResource); Delta delta = manager.createDelta(oldDescription, newDescription); assertTrue(delta.haveEObjectDescriptionsChanged()); IResourceDescription referrerDescription = manager.getResourceDescription(resource); assertTrue(manager.isAffected(delta, referrerDescription)); }
Example 4
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Deprecated protected Map<EObject, URI> createExportedElementsMap(final Resource resource) { return new ForwardingMap<EObject, URI>() { private Map<EObject, URI> delegate; @Override protected Map<EObject, URI> delegate() { if (delegate != null) { return delegate; } URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(resource); IResourceServiceProvider resourceServiceProvider = getServiceProviderRegistry().getResourceServiceProvider(uri); if (resourceServiceProvider == null) { return delegate = Collections.emptyMap(); } IResourceDescription.Manager resourceDescriptionManager = resourceServiceProvider.getResourceDescriptionManager(); if (resourceDescriptionManager == null) { return delegate = Collections.emptyMap(); } IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource); Map<EObject, URI> exportedElementMap = newIdentityHashMap(); if (resourceDescription != null) { for (IEObjectDescription exportedEObjectDescription : resourceDescription.getExportedObjects()) { EObject eObject = resource.getEObject(exportedEObjectDescription.getEObjectURI().fragment()); if (eObject != null) exportedElementMap.put(eObject, exportedEObjectDescription.getEObjectURI()); } } return delegate = exportedElementMap; } }; }
Example 5
Source File: DefaultResourceDescriptionManager.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void addExportedNames(Set<QualifiedName> names, IResourceDescription resourceDescriptor) { if (resourceDescriptor==null) return; Iterable<IEObjectDescription> iterable = resourceDescriptor.getExportedObjects(); for (IEObjectDescription ieObjectDescription : iterable) { names.add(ieObjectDescription.getName().toLowerCase()); } }
Example 6
Source File: LazyLinkingResourceTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public IResourceDescription getResourceDescription(URI uri) { final IResourceDescription resourceDescription = super.getResourceDescription(uri); Iterable<IEObjectDescription> objects = resourceDescription.getExportedObjects(); for (IEObjectDescription ieObjectDescription : objects) { EObject eObject = ieObjectDescription.getEClass().getEPackage().getEFactoryInstance().create(ieObjectDescription.getEClass()); ((InternalEObject)eObject).eSetProxyURI(ieObjectDescription.getEObjectURI()); try { Field field = ieObjectDescription.getClass().getDeclaredField("element"); field.setAccessible(true); field.set(ieObjectDescription, eObject); } catch (Exception e) {} } return resourceDescription; }
Example 7
Source File: DefaultUniqueNameContext.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected boolean intersects(IResourceDescription left, IResourceDescription right, boolean caseSensitive) { for (IEObjectDescription description : left.getExportedObjects()) { Iterable<IEObjectDescription> exportedObjects = right.getExportedObjects(EcorePackage.Literals.EOBJECT, description.getName(), !caseSensitive); if (!Iterables.isEmpty(exportedObjects)) { return true; } } return false; }
Example 8
Source File: SlotEntry.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected List<EObject> findEObjectsOfType(Set<EClass> eClasses, IResourceDescriptions resourceDescriptions, ResourceSet resourceSet) { List<EObject> elements = Lists.newArrayList(); Iterable<IResourceDescription> descriptions = resourceDescriptions.getAllResourceDescriptions(); for (IResourceDescription resDesc : descriptions) { Iterable<IEObjectDescription> objects = resDesc.getExportedObjects(); for (IEObjectDescription description : objects) { if (matches(eClasses, description)) elements.add(resourceSet.getEObject(description.getEObjectURI(), true)); } } return elements; }
Example 9
Source File: SearchFilterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected Iterator<IEObjectDescription> getExportedObjects(String model) throws Exception { XtendFile file = testHelper.xtendFile("test/Foo", model); IResourceDescription rd = resourceDescriptionManager.getResourceDescription(file.eResource()); Iterable<IEObjectDescription> exportedObjects = rd.getExportedObjects(); return filter(exportedObjects, new Predicate<IEObjectDescription>() { @Override public boolean apply(IEObjectDescription element) { return !searchFilter.reject(element); } }).iterator(); }
Example 10
Source File: JdtQueuedBuildData.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean namesIntersect(IResourceDescription resourceDescription, Set<QualifiedName> names) { if (resourceDescription == null) { return false; } for (IEObjectDescription objectDescription : resourceDescription.getExportedObjects()) { if (names.contains(objectDescription.getQualifiedName())) { return true; } } return false; }
Example 11
Source File: AbstractHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IEObjectDescription getDescription(URI objectURI) { IResourceDescription resourceDescription = getIndexData().getResourceDescription(objectURI.trimFragment()); if (resourceDescription == null) { return null; } for (IEObjectDescription o : resourceDescription.getExportedObjects()) { if (Objects.equal(o.getEObjectURI(), objectURI)) { return o; } } return null; }
Example 12
Source File: DirtyStateResourceDescription.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected List<IEObjectDescription> computeTypes(Resource resource) { IResourceDescription delegateDescription = delegate.getResourceDescription(resource); List<IEObjectDescription> result = newArrayList(); String hash = getTextHash(resource); ImmutableMap<String, String> userData = ImmutableMap.of(TEXT_HASH, hash); for (IEObjectDescription eObjectDescription : delegateDescription.getExportedObjects()) { result.add(new EObjectDescription(eObjectDescription.getQualifiedName(), eObjectDescription.getEObjectOrProxy(), userData)); } return result; }
Example 13
Source File: N4JSResourceDescriptionManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected void addExportedNames(Set<QualifiedName> names, IResourceDescription resourceDescriptor) { if (resourceDescriptor == null) return; Iterable<IEObjectDescription> iterable = resourceDescriptor.getExportedObjects(); for (IEObjectDescription ieObjectDescription : iterable) { names.add(ieObjectDescription.getName()); } }
Example 14
Source File: DefaultResourceDescriptionManager.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected boolean isAffected(Collection<QualifiedName> importedNames, IResourceDescription description) { if (description != null) { for (IEObjectDescription desc : description.getExportedObjects()) if (importedNames.contains(desc.getName().toLowerCase())) return true; } return false; }
Example 15
Source File: DocumentSymbolService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public List<? extends SymbolInformation> getSymbols(IResourceDescription resourceDescription, String query, IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) { List<SymbolInformation> symbols = new LinkedList<>(); for (IEObjectDescription description : resourceDescription.getExportedObjects()) { operationCanceledManager.checkCanceled(cancelIndicator); if (filter(description, query)) { createSymbol(description, resourceAccess, (SymbolInformation symbol) -> { symbols.add(symbol); }); } } return symbols; }
Example 16
Source File: EcoreResourceDescriptionManagerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Map<QualifiedName, IEObjectDescription> createIndex(Resource ecoreResoure) { GenericResourceDescriptionManager underTest = getEmfResourceDescriptionsManager(); IResourceDescription description = underTest.getResourceDescription(ecoreResoure); Map<QualifiedName,IEObjectDescription> index = Maps.newHashMap(); for (IEObjectDescription ieObjectDescription : description.getExportedObjects()) { index.put(ieObjectDescription.getName(), ieObjectDescription); } return index; }
Example 17
Source File: EObjectDescriptionBasedStubGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerateStubs(IFileSystemAccess access, IResourceDescription description) { for (IEObjectDescription objectDesc : description.getExportedObjects()) { String javaStubSource = getJavaStubSource(objectDesc, description); if(javaStubSource != null) { String javaFileName = getJavaFileName(objectDesc); access.generateFile(javaFileName, javaStubSource); } } }
Example 18
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testComputeEObjectDescriptionsForEmptyFile() throws Exception { Resource res = getResourceAndExpect(new StringInputStream(""),URI.createURI("foo.xtext"),1); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).isEmpty()); }
Example 19
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetExportedEObjectsErroneousResource() throws Exception { Resource res = getResourceAndExpect(new StringInputStream("grammar foo Start : 'main';"),URI.createURI("foo.xtext"),1); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).size()==2); }
Example 20
Source File: N4JSResourceDescriptionManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Overrides super implementation to replace case insensitive comparison logic by case sensitive comparison of * names. * <p> * It returns true, if there is a dependency (i.e. name imported by a candidate) to any name exported by the * description from a delta. That is, it computes if a candidate (with given importedNames) is affected by a change * represented by the description from the delta. */ @Override protected boolean isAffected(Collection<QualifiedName> namesImportedByCandidate, IResourceDescription descriptionFromDelta) { if (descriptionFromDelta != null) { for (IEObjectDescription desc : descriptionFromDelta.getExportedObjects()) if (namesImportedByCandidate.contains(desc.getName())) return true; } return false; }