Java Code Examples for org.eclipse.emf.ecore.EReference#isContainer()

The following examples show how to use org.eclipse.emf.ecore.EReference#isContainer() . 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: N4JSPostProcessor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
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 2
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkOppositeReferenceUsed(Assignment assignment) {
	Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(BIDIRECTIONAL_REFERENCE);
	if (severity == null || severity == Severity.IGNORE) {
		// Don't perform any check if the result is ignored
		return;
	}
	EClassifier classifier = GrammarUtil.findCurrentType(assignment);
	if (classifier instanceof EClass) {
		EStructuralFeature feature = ((EClass) classifier).getEStructuralFeature(assignment.getFeature());
		if (feature instanceof EReference) {
			EReference reference = (EReference) feature;
			if (reference.getEOpposite() != null && !(reference.isContainment() || reference.isContainer())) {
				addIssue("The feature '" + assignment.getFeature() + "' is a bidirectional reference."
						+ " This may cause problems in the linking process.",
						assignment, XtextPackage.eINSTANCE.getAssignment_Feature(), BIDIRECTIONAL_REFERENCE);
			}
		}
	}
}
 
Example 3
Source File: DefaultLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 4
Source File: N4JSValidationTestHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 5
Source File: ASTGraphProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add outgoing references
 */
private void getConnectedEdgesForEObject(Node node, final List<Node> allNodes, final List<Edge> result,
		final EObject eobj) {

	for (EReference currRef : eobj.eClass().getEAllReferences()) {
		if (!currRef.isDerived() && !currRef.isContainer()) {
			if (currRef.isMany()) {
				final Object targets = eobj.eGet(currRef, false);
				if (targets instanceof Collection<?>) {
					getConnectedEdgesForEObjectManyCase(node, allNodes, result, currRef, targets);
				}
			} else {
				final Object target = eobj.eGet(currRef, false);
				if (target instanceof EObject) {
					getConnectedEdgesForEObjectSingleCase(node, allNodes, result, currRef, target);
				}
			}
		}
	}

	// add reference to containing Resource if immediate container is not in graph
	// (required when showing lower-level objects while hiding their ancestors)
	Node nodeForElement = GraphUtils.getNodeForElement(eobj.eContainer(), allNodes);

	if (eobj.eResource() != null && eobj.eContainer() != null && nodeForElement == null) {
		final Node nodeForResource = GraphUtils.getNodeForElement(eobj.eResource(), allNodes);
		if (nodeForResource != null) {
			Edge edge = new Edge(
					"<... containment omitted ...>",
					false, // not a cross-link
					nodeForResource,
					Collections.singletonList(node),
					Collections.emptyList());

			result.add(edge);
		}
	}
}
 
Example 6
Source File: DefaultLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 7
Source File: DefaultResourceDescriptionStrategy.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isIndexable(EReference eReference) {
	return (!eReference.isContainment() || eReference.isResolveProxies()) 
			&& !eReference.isDerived() 
			&& !eReference.isVolatile()
			&& !eReference.isTransient() 
			&& (!eReference.isContainer() || eReference.isResolveProxies());
}
 
Example 8
Source File: ExportJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks that a interface field actually refers to a field and not a containment reference which should be an InterfaceNavigation instead.
 *
 * @param context
 *          the interface item to check
 */
@Check
public void checkContainmentInterfaceItemIsNavigation(final InterfaceField context) {
  if (!(context.getField() instanceof EReference)) {
    return;
  }
  EReference ref = (EReference) context.getField();
  if (ref.isContainment()) {
    error("Containment references must be used with a reference expression (using '@'): " + ref.getName(), ExportPackage.Literals.INTERFACE_FIELD__FIELD);
  } else if (ref.isContainer()) {
    error("Container references must not be specified as interface items: " + ref.getName(), ExportPackage.Literals.INTERFACE_FIELD__FIELD);
  }
}
 
Example 9
Source File: AbstractCleaningLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void clearReference(EObject obj, EReference ref) {
	if (!ref.isContainment() && !ref.isContainer() && !ref.isDerived() && ref.isChangeable() && !ref.isTransient())
		obj.eUnset(ref);
}
 
Example 10
Source File: Linker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean canSetDefaultValues(EReference ref) {
	return !ref.isContainment() && !ref.isContainer() && ref.isChangeable();
}
 
Example 11
Source File: AbstractResourceDescriptionStrategy.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** {@inheritDoc} */
protected boolean isIndexable(final EObject from, final EReference eReference) {
  return !eReference.isContainment() && !eReference.isContainer();
}