Java Code Examples for org.eclipse.emf.ecore.EReference#isContainment()
The following examples show how to use
org.eclipse.emf.ecore.EReference#isContainment() .
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: ASTGraphProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void getConnectedEdgesForEObjectManyCase(Node node, final List<Node> allNodes, final List<Edge> result, EReference currRef, final Object targets) { final List<Node> targetNodes = new ArrayList<>(); final List<String> targetNodesExternal = new ArrayList<>(); for (Object currTarget : (Collection<?>) targets) { final Node currTargetNode = GraphUtils.getNodeForElement(currTarget, allNodes); if (currTargetNode != null) targetNodes.add(currTargetNode); else if (currTarget instanceof EObject && ((EObject) currTarget).eIsProxy()) targetNodesExternal.add(EcoreUtil.getURI((EObject) currTarget).toString()); } if (!targetNodes.isEmpty() || !targetNodesExternal.isEmpty()) { Edge edge = new Edge( currRef.getName(), !currRef.isContainment(), node, targetNodes, targetNodesExternal); result.add(edge); } }
Example 2
Source File: N4JSPostProcessor.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static void exposeTypesReferencedBy(EObject root) { final TreeIterator<EObject> i = root.eAllContents(); while (i.hasNext()) { final EObject object = i.next(); for (EReference currRef : object.eClass().getEAllReferences()) { if (!currRef.isContainment() && !currRef.isContainer()) { final Object currTarget = object.eGet(currRef); if (currTarget instanceof Collection<?>) { for (Object currObj : (Collection<?>) currTarget) { exposeType(currObj); } } else { exposeType(currTarget); } } } } }
Example 3
Source File: AssignmentFinder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public Set<AbstractElement> findAssignmentsByValue(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, Object value, INode node) { List<AbstractElement> assignedElements = Lists.newArrayList(assignments.keySet()); EStructuralFeature feature = FeatureFinderUtil.getFeature(assignedElements.iterator().next(), semanticObj.eClass()); if (feature instanceof EAttribute) { Class<?> clazz = feature.getEType().getInstanceClass(); if (clazz == Boolean.class || clazz == boolean.class) return findValidBooleanAssignments(semanticObj, assignedElements, value); else return findValidValueAssignments(semanticObj, assignedElements, value); } else if (feature instanceof EReference) { EReference ref = (EReference) feature; if (ref.isContainment()) return findValidAssignmentsForContainmentRef(semanticObj, assignments, (EObject) value); else return findValidAssignmentsForCrossRef(semanticObj, assignedElements, (EObject) value, node); } throw new RuntimeException("unknown feature type"); }
Example 4
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private ITextRegion doGetTextRegion(final EObject owner, EStructuralFeature feature, final int indexInList, final RegionDescription query) { if (feature == null) return null; if (feature instanceof EAttribute) { return doGetLocationOfFeature(owner, feature, indexInList, query); } if (feature instanceof EReference) { EReference reference = (EReference) feature; if (reference.isContainment() || reference.isContainer()) { return getLocationOfContainmentReference(owner, reference, indexInList, query); } else { return doGetLocationOfFeature(owner, reference, indexInList, query); } } return null; }
Example 5
Source File: EClassifierInfo.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public boolean addFeature(EStructuralFeature prototype) { try { boolean isContainment = false; if (prototype instanceof EReference) { EReference reference = (EReference) prototype; isContainment = reference.isContainment(); } boolean result = addFeature(prototype.getName(), prototype.getEType(), prototype.isMany(), isContainment, null); if (result) { EStructuralFeature newFeature = getEClass().getEStructuralFeature(prototype.getName()); SourceAdapter oldAdapter = SourceAdapter.find(prototype); if (oldAdapter != null) { for(EObject source: oldAdapter.getSources()) SourceAdapter.adapt(newFeature, source); } } return result; } catch (TransformationException e) { throw new IllegalArgumentException(e.getMessage()); } }
Example 6
Source File: NotationClipboardOperationHelper.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * Customized Method to find the semantic target which should contain the * copied elements. * * @param view * @param container * @return the semantic target. */ public static EObject getSemanticPasteTarget(View view, View container) { EObject copiedSemanticObject = view.getElement(); EObject semanticTarget = container.getElement(); if (copiedSemanticObject instanceof Transition) { semanticTarget = copiedSemanticObject.eContainer(); } EList<EReference> eAllReferences = semanticTarget.eClass() .getEAllReferences(); for (EReference eReference : eAllReferences) { EClass eReferenceType = eReference.getEReferenceType(); if (eReference.isContainment() && eReferenceType.isSuperTypeOf(copiedSemanticObject .eClass())) { return semanticTarget; } } return null; }
Example 7
Source File: N4JSValidationTestHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Asserts that root and the entire object tree below root does not contain any dangling references, i.e. * cross-references to target {@link EObject}s that are not contained in a {@link Resource}. */ public void assertNoDanglingReferences(EObject root) { final List<String> errMsgs = new ArrayList<>(); final TreeIterator<EObject> iter = root.eAllContents(); while (iter.hasNext()) { final EObject currObj = iter.next(); if (currObj != null && !currObj.eIsProxy()) { for (EReference currRef : currObj.eClass().getEAllReferences()) { if (!currRef.isContainment() && !currRef.isContainer() && currRef.getEOpposite() == null) { if (currRef.isMany()) { @SuppressWarnings("unchecked") final EList<? extends EObject> targets = (EList<? extends EObject>) currObj.eGet(currRef, false); for (EObject currTarget : targets) { if (isDangling(currTarget)) { errMsgs.add(getErrorInfoForDanglingEObject(currObj, currRef)); break; } } } else { final EObject target = (EObject) currObj.eGet(currRef, false); if (isDangling(target)) errMsgs.add(getErrorInfoForDanglingEObject(currObj, currRef)); } } } } } if (!errMsgs.isEmpty()) fail("Expected no dangling references, but found the following: " + Joiner.on("; ").join(errMsgs) + "."); }
Example 8
Source File: SemanticNodeProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected SemanticNode add(String featureName, INode child, SemanticNode last) { if (featureName == null) return last; EClass eClass = this.semanticObject.eClass(); EStructuralFeature feature = eClass.getEStructuralFeature(featureName); if (feature == null) return last; SemanticNode sem = new SemanticNode(child); if (last != null) { last.follower = sem; } if (this.first == null) { this.first = sem; } int id = eClass.getFeatureID(feature); if (feature.isMany()) { @SuppressWarnings("unchecked") List<SemanticNode> nodes = (List<SemanticNode>) childrenByFeatureIDAndIndex[id]; if (nodes == null) childrenByFeatureIDAndIndex[id] = nodes = Lists.<SemanticNode>newArrayList(); nodes.add(sem); } else { childrenByFeatureIDAndIndex[id] = sem; } if (feature instanceof EReference) { EReference reference = (EReference) feature; if (reference.isContainment()) { EObject semanitcChild = getSemanticChild(child); if (semanitcChild != null) { if (this.childrenBySemanticChild == null) this.childrenBySemanticChild = Maps.newHashMap(); this.childrenBySemanticChild.put(semanitcChild, sem); } } } return sem; }
Example 9
Source File: DotEObjectFormatter.java From gef with Eclipse Public License 2.0 | 5 votes |
protected String format(EObject object, EStructuralFeature feature, Object value) { if (feature instanceof EAttribute) return formatAttributeValue(object, (EAttribute) feature, value); else if (feature instanceof EReference) { EReference ref = (EReference) feature; if (ref.isContainment()) return format((EObject) value); return formatCrossRefValue(object, ref, (EObject) value); } return ""; }
Example 10
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private ITextRegion getTextRegion(final EObject owner, EStructuralFeature feature, final int indexInList, final boolean isSignificant) { if (feature instanceof EAttribute) { return getLocationOfAttribute(owner, (EAttribute)feature, indexInList, isSignificant); } else if (feature instanceof EReference) { EReference reference = (EReference) feature; if (reference.isContainment() || reference.isContainer()) { return getLocationOfContainmentReference(owner, reference, indexInList, isSignificant); } else { return getLocationOfCrossReference(owner, reference, indexInList, isSignificant); } } else { return null; } }
Example 11
Source File: EmfFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private static void objToStrImpl(Object obj, String indent, Appendable buf, Predicate<EStructuralFeature> ignoredFeatures) throws Exception { String innerIdent = INDENT + indent; if (obj instanceof EObject) { EObject eobj = (EObject) obj; buf.append(eobj.eClass().getName()).append(" {\n"); for (EStructuralFeature f : eobj.eClass().getEAllStructuralFeatures()) { if (!eobj.eIsSet(f) || ignoredFeatures.apply(f)) continue; buf.append(innerIdent); if (f instanceof EReference) { EReference r = (EReference) f; if (r.isContainment()) { buf.append("cref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); objToStrImpl(eobj.eGet(f), innerIdent, buf, ignoredFeatures); } else { buf.append("ref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); refToStr(eobj, r, innerIdent, buf); } } else if (f instanceof EAttribute) { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); // logger.debug(Msg.create("Path:").path(eobj)); Object at = eobj.eGet(f); if (eobj != at) objToStrImpl(at, innerIdent, buf, ignoredFeatures); else buf.append("<same as container object>"); } else { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(" ??????"); } buf.append('\n'); } buf.append(indent).append("}"); return; } if(obj instanceof FeatureMap.Entry) { FeatureMap.Entry e = (FeatureMap.Entry)obj; buf.append(e.getEStructuralFeature().getEContainingClass().getName()); buf.append("."); buf.append(e.getEStructuralFeature().getName()); buf.append("->"); objToStrImpl(e.getValue(), innerIdent, buf, ignoredFeatures); return ; } if (obj instanceof Collection<?>) { int counter = 0; Collection<?> coll = (Collection<?>) obj; buf.append("[\n"); for (Object o : coll) { buf.append(innerIdent); printInt(counter++, coll.size(), buf); buf.append(": "); objToStrImpl(o, innerIdent, buf, ignoredFeatures); buf.append("\n"); } buf.append(indent + "]"); return; } if (obj != null) { buf.append("'").append(Strings.notNull(obj)).append("'"); return; } buf.append("null"); }
Example 12
Source File: AbstractCleaningLinker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void clearReference(EObject obj, EReference ref) { if (!ref.isContainment() && !ref.isContainer() && !ref.isDerived() && ref.isChangeable() && !ref.isTransient()) obj.eUnset(ref); }
Example 13
Source File: XtextLinker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public void notifyChanged(Notification msg) { super.notifyChanged(msg); if (!msg.isTouch() && msg.getOldValue() != null) { ResourceSet set; Resource notifyingResource; if (!(msg.getNotifier() instanceof Resource)) { Object feature = msg.getFeature(); if (!(feature instanceof EReference)) return; EReference ref = (EReference) feature; if (!ref.isContainment()) return; notifyingResource = ((EObject) msg.getNotifier()).eResource(); } else { notifyingResource = ((Resource) msg.getNotifier()); } if (notifyingResource == null) return; set = notifyingResource.getResourceSet(); if (set == null) return; switch (msg.getEventType()) { case Notification.REMOVE_MANY: case Notification.REMOVE: case Notification.SET: Object oldValue = msg.getOldValue(); Collection<Resource> resourcesToRemove = Sets.newHashSet(); Collection<Resource> resourcesToUnload = Sets.newHashSet(); Collection<Resource> referencedResources = Sets.newHashSet(notifyingResource); if (oldValue instanceof Grammar) { processMetamodelDeclarations(((Grammar) oldValue).getMetamodelDeclarations(), set, resourcesToRemove, resourcesToUnload, referencedResources); } else if (oldValue instanceof AbstractMetamodelDeclaration) { processMetamodelDeclarations(Collections .singletonList((AbstractMetamodelDeclaration) oldValue), set, resourcesToRemove, resourcesToUnload, referencedResources); } else if (oldValue instanceof Collection<?>) { if (XtextPackage.Literals.GRAMMAR__METAMODEL_DECLARATIONS == msg.getFeature()) { Collection<AbstractMetamodelDeclaration> metamodelDeclarations = (Collection<AbstractMetamodelDeclaration>) oldValue; processMetamodelDeclarations(metamodelDeclarations, set, resourcesToRemove, resourcesToUnload, referencedResources); } } resourcesToRemove.removeAll(referencedResources); if (unloader != null) { resourcesToUnload.removeAll(referencedResources); for (Resource resource : resourcesToUnload) { if(resource.getResourceSet() == set) { for (EObject content : resource.getContents()) unloader.unloadRoot(content); } } } set.getResources().removeAll(resourcesToRemove); break; default: break; } } }
Example 14
Source File: URIsInEcoreFilesXtendTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 15
Source File: AbstractPortableURIsTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 16
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 17
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
Example 18
Source File: OrderedEmfFormatter.java From n4js with Eclipse Public License 1.0 | 4 votes |
private static void objToStrImpl(Object obj, String indent, Appendable buf) throws Exception { String innerIdent = INDENT + indent; if (obj instanceof EObject) { EObject eobj = (EObject) obj; buf.append(eobj.eClass().getName()).append(" {\n"); for (EStructuralFeature f : getAllFeatures(eobj.eClass())) { if (!eobj.eIsSet(f)) continue; buf.append(innerIdent); if (f instanceof EReference) { EReference r = (EReference) f; if (r.isContainment()) { buf.append("cref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); objToStrImpl(eobj.eGet(f), innerIdent, buf); } else { buf.append("ref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); refToStr(eobj, r, innerIdent, buf); } } else if (f instanceof EAttribute) { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); // logger.debug(Msg.create("Path:").path(eobj)); Object at = eobj.eGet(f); if (eobj != at) objToStrImpl(at, innerIdent, buf); else buf.append("<same as container object>"); } else { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(" ??????"); } buf.append('\n'); } buf.append(indent).append("}"); return; } if (obj instanceof FeatureMap.Entry) { FeatureMap.Entry e = (FeatureMap.Entry) obj; buf.append(e.getEStructuralFeature().getEContainingClass().getName()); buf.append("."); buf.append(e.getEStructuralFeature().getName()); buf.append("->"); objToStrImpl(e.getValue(), innerIdent, buf); return; } if (obj instanceof Collection<?>) { int counter = 0; Collection<?> coll = (Collection<?>) obj; buf.append("[\n"); for (Object o : coll) { buf.append(innerIdent); printInt(counter++, coll.size(), buf); buf.append(": "); objToStrImpl(o, innerIdent, buf); buf.append("\n"); } buf.append(indent + "]"); return; } if (obj != null) { buf.append("'").append(Strings.notNull(obj)).append("'"); return; } buf.append("null"); }
Example 19
Source File: AbstractFingerprintComputer.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Computes a fingerprint for a referenced {@link EObject} in a given context. * <p> * If the reference is a containment reference and the referenced eObject is in the same resource as the context eObject, then it calls {@link #fingerprint} * to dispatch the finger-print computation for the referenced eObject. This will usually dispatch to a generated method in a subclass. Otherwise it computes * the finger-print based on the referenced eObject's URI. * <p> * <em>Note</em> - if {@code reference} is {@code null} and either {@code context} or {@code context.eResource()} is {@code null}, then the referenced * {@code target} eObject is treated as if the reference were a containment reference and the referenced eObject were in the same resource as the context * eObject. In other words, in this case it calls {@link #fingerprint} to dispatch the computation. * </p> * * @see #fingerprintEObject(EObject, EObject) * @see #fingerprint(EObject) * @param target * the referenced {@link EObject}, may be {@code null} * @param context * the context {@link EObject}, may be {@code null} * @param reference * the {@link EReference} of the {@code context} eObject that references the {@code target} eObject, may be {@code null} * @return the {@code target} eObject's fingerprint */ private ExportItem fingerprintIndirection(final EObject target, final EObject context, final EReference reference) { if (target == null) { return NO_EXPORT; } final Resource rsc = context != null ? context.eResource() : null; if ((reference == null || reference.isContainment()) && (rsc == null || target.eResource() == rsc)) { return fingerprint(target); } else { return new ExportItem(fingerprintEObject(target, context)); } }
Example 20
Source File: AbstractStreamingFingerprintComputer.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Computes a fingerprint for a referenced {@link EObject} in a given context. * <p> * If the reference is a containment reference and the referenced eObject is in the same resource as the context eObject, then it calls {@link #fingerprint} * to dispatch the finger-print computation for the referenced eObject. This will usually dispatch to a generated method in a subclass. Otherwise it computes * the finger-print based on the referenced eObject's URI. * <p> * <em>Note</em> - if {@code reference} is {@code null} and either {@code context} or {@code context.eResource()} is {@code null}, then the referenced * {@code target} eObject is treated as if the reference were a containment reference and the referenced eObject were in the same resource as the context * eObject. In other words, in this case it calls {@link #fingerprint} to dispatch the computation. * </p> * * @see #fingerprintEObject(EObject, EObject, Hasher) * @see #fingerprint(EObject, Hasher) * @param target * the referenced {@link EObject}, may be {@code null} * @param context * the context {@link EObject}, may be {@code null} * @param reference * the {@link EReference} of the {@code context} eObject that references the {@code target} eObject, may be {@code null} * @param hasher * hasher to stream to */ private void fingerprintIndirection(final EObject target, final EObject context, final EReference reference, final Hasher hasher) { if (target == null) { return; } final Resource rsc = context != null ? context.eResource() : null; if ((reference == null || reference.isContainment()) && (rsc == null || target.eResource() == rsc)) { fingerprint(target, hasher); } else { fingerprintEObject(target, context, hasher); } }