Java Code Examples for org.eclipse.emf.ecore.InternalEObject#eSetProxyURI()
The following examples show how to use
org.eclipse.emf.ecore.InternalEObject#eSetProxyURI() .
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: FastReferenceSearchResultContentProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Adds the given reference to the contents. * * @param referenceDescription * reference to add */ private void addReference(final IReferenceDescription referenceDescription) { URI containerEObjectURI = referenceDescription.getContainerEObjectURI(); final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI; IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment()); if (resourceDescription != null) { ReferenceSearchViewTreeNode resourceNode = resourceNode(resourceDescription); new DynamicReferenceSearchViewTreeNode(resourceNode, referenceDescription, new Supplier<Object>() { @Override public Object get() { InternalEObject dummyProxy = (InternalEObject) EcoreFactory.eINSTANCE.createEObject(); dummyProxy.eSetProxyURI(eObjectURI); Iterator<IEObjectDescription> sourceObjects = resourceDescriptions.getExportedObjectsByObject(dummyProxy).iterator(); return sourceObjects.hasNext() ? sourceObjects.next() : referenceDescription; } }); } }
Example 2
Source File: CrossRefTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testSerializingProxiedCrossReference() throws Exception { XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB "); Main model = (Main) r.getContents().get(0); Type type = model.getTypes().get(0); Type superType = type.getExtends(); CrossRefLinkingService linkingService = (CrossRefLinkingService) get(ILinkingService.class); InternalEObject typeProxy = (InternalEObject) LangATestLanguageFactory.eINSTANCE.createType(); typeProxy.eSetProxyURI(EcoreUtil.getURI(superType)); linkingService.returnOnceForGetLinkedObjects(typeProxy); INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType); String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node); assertEquals(ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL, linkText); }
Example 3
Source File: XtextReferableElementsUnloader.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private void caseEPackage(EPackage ePackage) { // guard against infinite recursion // EPackage.eSetProxyURI and friends tries to be smart thus // we have to make sure to compute all URIs before they are // set Resource resource = ePackage.eResource(); URI resourceURI = resource.getURI(); List<EClassifier> classifiers = ePackage.getEClassifiers(); List<URI> uris = new ArrayList<URI>(classifiers.size()); for(int i = 0, size = classifiers.size(); i < size; i++) { uris.add(resourceURI.appendFragment(resource.getURIFragment(classifiers.get(i)))); } // and we have to set them in a proper order unload(ePackage); for(int i = 0, size = classifiers.size(); i < size; i++) { InternalEObject classifier = (InternalEObject) classifiers.get(i); classifier.eSetProxyURI(uris.get(i)); } }
Example 4
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Discard the AST and proxify all referenced nodes. Does nothing if the AST is already unloaded. */ private void discardAST() { EObject script = getScript(); if (script != null && !script.eIsProxy()) { // Create a proxy for the AST. InternalEObject scriptProxy = (InternalEObject) EcoreUtil.create(script.eClass()); scriptProxy.eSetProxyURI(EcoreUtil.getURI(script)); TModule module = null; ModuleAwareContentsList theContents = (ModuleAwareContentsList) contents; if (isFullyInitialized()) { module = getModule(); if (module != null && !module.eIsProxy()) { proxifyASTReferences(module); module.setAstElement(scriptProxy); } } // Unload the AST. unloadElements(theContents.subList(0, 1)); theContents.sneakyClear(); if (module != null) { theContents.sneakyAdd(scriptProxy); theContents.sneakyAdd(module); } else { // there was no module (not even a proxy) // -> don't add the script proxy // (i.e. transition from resource load state "Loaded" to "Created", not to "Loaded from Description") } // Clear AST meta cache and Xtext cache this.setASTMetaInfoCache(null); getCache().clear(this); } }
Example 5
Source File: FormalParameterBuilderImpl.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the JvmIdentifiable that corresponds to the formal parameter. * * @param container the feature call that is supposed to contains the replied identifiable element. */ public void setReferenceInto(XFeatureCall container) { JvmVoid jvmVoid = this.jvmTypesFactory.createJvmVoid(); if (jvmVoid instanceof InternalEObject) { final InternalEObject jvmVoidProxy = (InternalEObject) jvmVoid; final EObject param = getSarlFormalParameter(); final Resource resource = param.eResource(); // Get the derived object final SarlFormalParameter jvmParam = getAssociatedElement(SarlFormalParameter.class, param, resource); // Set the proxy URI final URI uri = EcoreUtil2.getNormalizedURI(jvmParam); jvmVoidProxy.eSetProxyURI(uri); } container.setFeature(jvmVoid); }
Example 6
Source File: DetachableEObjectDescription.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** {@inheritDoc} */ @Override public EObject getEObjectOrProxy() { InternalEObject result = (InternalEObject) EcoreUtil.create(eClass); result.eSetProxyURI(eObjectURI); return result; }
Example 7
Source File: ImportScopeTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public EObject getEObjectOrProxy() { EObject element = super.getEObjectOrProxy(); InternalEObject result = (InternalEObject) EcoreFactory.eINSTANCE.create(element.eClass()); result.eSetProxyURI(EcoreUtil.getURI(element)); return result; }
Example 8
Source File: EObjectDescriptionImplTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testNoNPE() { EObjectDescriptionImpl objectDescription = (EObjectDescriptionImpl) BuilderStateFactory.eINSTANCE.createEObjectDescription(); objectDescription.setFragment("myFragment"); ResourceDescriptionImpl resourceDescription = (ResourceDescriptionImpl) BuilderStateFactory.eINSTANCE.createResourceDescription(); resourceDescription.getExportedObjects().add(objectDescription); resourceDescription.setURI(URI.createURI("does.not.matter")); EClass doesNotExist = EcoreFactory.eINSTANCE.createEClass(); InternalEObject proxy = (InternalEObject) doesNotExist; proxy.eSetProxyURI(URI.createURI("does.not.exist")); objectDescription.setEClass(doesNotExist); assertSame(doesNotExist, objectDescription.getEClass()); assertNull(objectDescription.getEObjectOrProxy()); assertEquals("does.not.matter#myFragment", objectDescription.getEObjectURI().toString()); }
Example 9
Source File: GenconfUtils.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Gets the variables {@link Map} from the given {@link Generation} and {@link ResourceSet}. * * @param generation * the {@link Generation} holding the {@link Generation#getDefinitions() definitions} * @param resourceSetForModels * the {@link ResourceSet} used to load the model instances * @return the created variables {@link Map} from the given {@link Generation} and {@link ResourceSet} */ public static Map<String, Object> getVariables(Generation generation, ResourceSet resourceSetForModels) { Map<String, Object> result = new HashMap<String, Object>(); for (Definition def : generation.getDefinitions()) { if (def instanceof ModelDefinition) { EObject val = null; final EObject originalValue = ((ModelDefinition) def).getValue(); if (originalValue != null) { URI uri = EcoreUtil.getURI(originalValue); try { val = resourceSetForModels.getEObject(uri, true); } catch (WrappedException e) { /* * The resource could not be loaded, in that case the value is reset to a proxy with the same uri. */ if (originalValue != null) { InternalEObject eobj = (InternalEObject) EcoreUtil.create(originalValue.eClass()); eobj.eSetProxyURI(uri); val = eobj; } } } result.put(((ModelDefinition) def).getKey(), val); } else if (def instanceof StringDefinition) { result.put(((StringDefinition) def).getKey(), ((StringDefinition) def).getValue()); } else if (def instanceof IntegerDefinition) { result.put(((IntegerDefinition) def).getKey(), ((IntegerDefinition) def).getValue()); } else if (def instanceof RealDefinition) { result.put(((RealDefinition) def).getKey(), ((RealDefinition) def).getValue()); } else if (def instanceof BooleanDefinition) { result.put(((BooleanDefinition) def).getKey(), ((BooleanDefinition) def).isValue()); } else { throw new UnsupportedOperationException(); } } return result; }
Example 10
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmEnumerationLiteral createEnumLiteralProxy(Enum<?> e) { JvmEnumerationLiteral enumLiteralProxy = TypesFactory.eINSTANCE.createJvmEnumerationLiteral(); InternalEObject internalEObject = (InternalEObject) enumLiteralProxy; Class<?> type = e.getDeclaringClass(); try { Field field = type.getDeclaredField(e.name()); internalEObject.eSetProxyURI(uriHelper.getFullURI(field)); } catch (Exception exception) { log.error(exception.getMessage(), exception); return null; } return enumLiteralProxy; }
Example 11
Source File: Proxies.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmEnumerationLiteral createEnumLiteral(String literalName, BinaryTypeSignature typeName) { JvmEnumerationLiteral enumLiteralProxy = TypesFactory.eINSTANCE.createJvmEnumerationLiteral(); InternalEObject internalEObject = (InternalEObject) enumLiteralProxy; BinarySimpleMemberSignature fieldSignature = typeName.appendField(literalName); URI uri = fieldSignature.getURI(); internalEObject.eSetProxyURI(uri); return enumLiteralProxy; }
Example 12
Source File: N4JSUnloader.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void unload(ObjectToFragment element, URI resourceURI) { InternalEObject eObject = (InternalEObject) element.object; if (eObject instanceof SyntaxRelatedTElement) { SyntaxRelatedTElement casted = (SyntaxRelatedTElement) eObject; EObject astElementOrProxy = (EObject) casted.eGet( TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT, false); if (astElementOrProxy != null && !astElementOrProxy.eIsProxy()) { // release the reference to the AST casted.eSetDeliver(false); casted.setAstElement(null); } } eObject.eSetProxyURI(resourceURI.appendFragment(element.fragment)); }
Example 13
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void proxifyASTReferences(EObject object) { if (object instanceof SyntaxRelatedTElement) { SyntaxRelatedTElement element = (SyntaxRelatedTElement) object; EObject astElement = element.getAstElement(); if (astElement != null && !astElement.eIsProxy()) { InternalEObject proxy = (InternalEObject) EcoreUtil.create(astElement.eClass()); proxy.eSetProxyURI(EcoreUtil.getURI(astElement)); element.setAstElement(proxy); } } for (EObject child : object.eContents()) { proxifyASTReferences(child); } }
Example 14
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Populate the contents list from the serialized type data of an {@link IEObjectDescription}. See * {@link #isLoadedFromDescription()} for details on resources that are being loaded from a description. * * @param description * the description that carries the type data in its user data */ public synchronized boolean loadFromDescription(IResourceDescription description) { if (isLoaded) throw new IllegalStateException("Resource was already loaded"); TModule deserializedModule = null; Iterable<IEObjectDescription> modules = description.getExportedObjectsByType(TypesPackage.Literals.TMODULE); for (IEObjectDescription module : modules) { deserializedModule = UserDataMapper.getDeserializedModuleFromDescription(module, getURI()); if (deserializedModule != null) { break; } } if (deserializedModule != null) { boolean wasDeliver = eDeliver(); try { eSetDeliver(false); ModuleAwareContentsList theContents = (ModuleAwareContentsList) getContents(); if (!theContents.isEmpty()) throw new IllegalStateException("There is already something in the contents list: " + theContents); InternalEObject astProxy = (InternalEObject) N4JSFactory.eINSTANCE.createScript(); astProxy.eSetProxyURI(URI.createURI("#" + AST_PROXY_FRAGMENT)); theContents.sneakyAdd(astProxy); theContents.sneakyAdd(deserializedModule); fullyInitialized = true; // TModule loaded from index had been fully post-processed prior to serialization fullyPostProcessed = true; } finally { eSetDeliver(wasDeliver); } return true; } return false; }
Example 15
Source File: JdtBasedSimpleTypeScope.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected InternalEObject createProxy(String fullyQualifiedName) { URI uri = getTypeProvider().getTypeUriHelper().getFullURIForClass(fullyQualifiedName); InternalEObject proxy = (InternalEObject) TypesFactory.eINSTANCE.createJvmVoid(); proxy.eSetProxyURI(uri); return proxy; }
Example 16
Source File: JdtBasedConstructorScope.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected JvmConstructor createProxy() { InternalEObject proxy = (InternalEObject) TypesFactory.eINSTANCE.createJvmConstructor(); proxy.eSetProxyURI(getEObjectURI()); return (JvmConstructor) proxy; }
Example 17
Source File: JdtBasedConstructorScope.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected JvmConstructor createProxy() { InternalEObject proxy = (InternalEObject) TypesFactory.eINSTANCE.createJvmConstructor(); proxy.eSetProxyURI(getEObjectURI()); return (JvmConstructor) proxy; }
Example 18
Source File: XtextReferableElementsUnloader.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void unload(EObject object) { InternalEObject internalEObject = (InternalEObject) object; Resource resource = object.eResource(); internalEObject.eSetProxyURI(resource.getURI().appendFragment(resource.getURIFragment(internalEObject))); }
Example 19
Source File: ContextFinderTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private EObject createProxy(EObject old) { EClass type = old.eClass(); InternalEObject proxy = (InternalEObject) type.getEPackage().getEFactoryInstance().create(type); proxy.eSetProxyURI(old.eResource().getURI().appendFragment("some_invalid_fragment")); return proxy; }
Example 20
Source File: XFunctionTypeRefs.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public static JvmType getType(Class<?> clazz, EObject context) { InternalEObject proxy = (InternalEObject) TypesFactory.eINSTANCE.createJvmVoid(); proxy.eSetProxyURI(computeTypeUri(clazz)); return (JvmType) EcoreUtil.resolve(proxy, context); }