org.eclipse.xtext.linking.lazy.LazyURIEncoder Java Examples
The following examples show how to use
org.eclipse.xtext.linking.lazy.LazyURIEncoder.
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: DirectLinkingEObjectOutputStream.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Writes a binary representation of the given object's URI to this output stream. For objects contained by the given resource the object's * {@link Resource#getURIFragment(EObject) URI fragment} will be used. For objects in other resources the * {@link org.eclipse.emf.ecore.util.EcoreUtil#getURI(EObject) full URI} will be written. * * @param obj * object to write, must not be {@code null} * @param context * resource being serialized, must not be {@code null} * @throws IOException * if an I/O exception occurred */ public void writeEObjectURI(final EObject obj, final Resource context) throws IOException { Resource resource = obj.eResource(); if (resource == context) { // NOPMD writeBoolean(LOCAL_EOBJECT); writeEObjectURIFragmentPath(obj); } else { String uriString = null; if (obj.eIsProxy()) { URI proxyURI = ((InternalEObject) obj).eProxyURI(); uriString = proxyURI.fragment().startsWith(LazyURIEncoder.XTEXT_LINK) ? null : proxyURI.toString(); } else if (resource != null) { uriString = resource.getURI().toString() + '#' + resource.getURIFragment(obj); } else { LOG.warn("Encountered dangling object while serializing " + context.getURI() + ": " + obj); //$NON-NLS-1$ //$NON-NLS-2$ } writeBoolean(!LOCAL_EOBJECT); writeString(uriString); } }
Example #2
Source File: ErrorTreeAppendable.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LazyURIEncoder getOrCreateURIEncoder() { Resource resource = getState().getResource(); if (resource instanceof LazyLinkingResource) { return ((LazyLinkingResource) resource).getEncoder(); } return new LazyURIEncoder(); }
Example #3
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IResourceDescription createResourceDescription(Resource testResource) { DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy(); strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() { @Override public QualifiedName getFullyQualifiedName(EObject obj) { String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); return (name != null) ? QualifiedName.create(name) : null; } }); strategy.setLazyURIEncoder(new LazyURIEncoder()); IResourceDescription resourceDescription = new DefaultResourceDescription(testResource, strategy); return resourceDescription; }
Example #4
Source File: BuilderIntegrationFragment.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public Set<Binding> getGuiceBindingsRt(final Grammar grammar) { final Set<Binding> bindings = super.getGuiceBindingsRt(grammar); final BindFactory factory = new BindFactory(); factory.addTypeToType(IContainer.Manager.class.getName(), "com.avaloq.tools.ddk.xtext.builder.CachingStateBasedContainerManager"); factory.addTypeToType(LazyLinkingResource.class.getName(), LazyLinkingResource2.class.getName()); factory.addTypeToType(LazyURIEncoder.class.getName(), FastLazyURIEncoder.class.getName()); final Set<Binding> result = factory.getBindings(); result.addAll(bindings); return result; }
Example #5
Source File: DefaultResourceDescriptionStrategy.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** @since 2.0 */ public void setLazyURIEncoder(LazyURIEncoder uriEncoder) { this.uriEncoder = uriEncoder; }
Example #6
Source File: DefaultResourceDescriptionStrategy.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** @since 2.0 */ public LazyURIEncoder getLazyURIEncoder() { return uriEncoder; }
Example #7
Source File: DefaultRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.7 */ public void configureUseIndexFragmentsForLazyLinking(com.google.inject.Binder binder) { binder.bind(Boolean.TYPE).annotatedWith(Names.named(LazyURIEncoder.USE_INDEXED_FRAGMENTS_BINDING)).toInstance(Boolean.TRUE); }
Example #8
Source File: Bug419429RuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public void configureUseIndexFragmentsForLazyLinking(Binder binder) { binder.bind(Boolean.TYPE).annotatedWith(Names.named(LazyURIEncoder.USE_INDEXED_FRAGMENTS_BINDING)).toInstance(Boolean.FALSE); }
Example #9
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=330812 */ @Test public void testLazyLinkingProxyReferences() { URI resourceUri = URI.createPlatformResourceURI("test.ecore", true); LazyURIEncoder lazyURIEncoder = new LazyURIEncoder(); ResourceSet resourceSet = new ResourceSetImpl(); Resource testResource = resourceSet.createResource(resourceUri); EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("test"); ePackage.setNsPrefix("test"); ePackage.setNsURI("test"); testResource.getContents().add(ePackage); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("Test"); ePackage.getEClassifiers().add(eClass); EClass multiRefType = EcoreFactory.eINSTANCE.createEClass(); ((InternalEObject) multiRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE)); eClass.getESuperTypes().add(multiRefType); EClass multiRefType2 = EcoreFactory.eINSTANCE.createEClass(); URI dummyProxyUri = resourceUri.appendFragment(lazyURIEncoder.encode(eClass, EcorePackage.Literals.ECLASS__ESUPER_TYPES, null)); ((InternalEObject) multiRefType2).eSetProxyURI(dummyProxyUri); eClass.getESuperTypes().add(multiRefType2); EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute(); nameAttribute.setName("name"); eClass.getEStructuralFeatures().add(nameAttribute); EDataType singleRefType = EcoreFactory.eINSTANCE.createEDataType(); ((InternalEObject) singleRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.ESTRING)); nameAttribute.setEType(singleRefType); assertTrue(multiRefType.eIsProxy()); assertTrue(multiRefType2.eIsProxy()); assertTrue(lazyURIEncoder.isCrossLinkFragment(testResource, EcoreUtil.getURI(multiRefType2).fragment())); assertTrue(singleRefType.eIsProxy()); IResourceDescription resourceDescription = createResourceDescription(testResource); Iterable<IReferenceDescription> referenceDescriptions = resourceDescription.getReferenceDescriptions(); assertEquals("Unexpected additional resources were loaded", 1, resourceSet.getResources().size()); assertEquals("Unexpected reference was exported", 3, Iterables.size(referenceDescriptions)); IReferenceDescription referenceDescription = Iterables.get(referenceDescriptions, 0); assertEquals(0, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(eClass), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.ECLASS__ESUPER_TYPES, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri()); referenceDescription = Iterables.get(referenceDescriptions, 1); assertEquals(-1, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(nameAttribute.getEGenericType()), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.ESTRING), referenceDescription.getTargetEObjectUri()); referenceDescription = Iterables.get(referenceDescriptions, 2); assertEquals(-1, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(eClass.getEGenericSuperTypes().get(0)), referenceDescription.getSourceEObjectUri()); assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri()); }
Example #10
Source File: EObjectUtil.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Checks if the given object represents an Xtext lazy-linking proxy. * * @param object * object to check, can be {@code null} * @return {@code true} if the given object is non-{@code null}, is a {@link EObject#eIsProxy() proxy} and has a * {@link LazyURIEncoder#isCrossLinkFragment(org.eclipse.emf.ecore.resource.Resource, String) lazy-linking proxy URI fragment}. */ public static boolean isLazyLinkingProxy(final EObject object) { return object != null && object.eIsProxy() && ((InternalEObject) object).eProxyURI().fragment().startsWith(LazyURIEncoder.XTEXT_LINK); }
Example #11
Source File: DefaultCrossReferenceHelper.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Returns the {@link LazyURIEncoder} used for the context language. * * @return {@link LazyURIEncoder} instance, never {@code null} */ protected LazyURIEncoder getLazyURIEncoder() { return uriEncoder; }