org.eclipse.emf.ecore.EStructuralFeature.Setting Java Examples

The following examples show how to use org.eclipse.emf.ecore.EStructuralFeature.Setting. 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: StatechartNavigatorContentProvider.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private View getReferenceView(EObject eObject) {
	
	CrossReferenceAdapter refAdapter = (CrossReferenceAdapter) CrossReferenceAdapter
			.getExistingCrossReferenceAdapter(eObject.eResource());
	if(refAdapter == null)
		return null;
	@SuppressWarnings("unchecked")
	Collection<Setting> inverseReferences = refAdapter.getInverseReferences(eObject, true);

	for (Setting setting : inverseReferences) {
		if (setting.getEObject() instanceof View
				&& setting.getEStructuralFeature() == NotationPackage.eINSTANCE.getView_Element()) {
			return (View) setting.getEObject();
		}
	}
	return null;
}
 
Example #2
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies if the given object is locally assigned.
 *
 * <p>An object is locally assigned when it is the left operand of an assignment operation.
 *
 * @param target the object to test.
 * @param containerToFindUsage the container in which the usages should be find.
 * @return {@code true} if the given object is assigned.
 * @since 0.7
 */
protected boolean isLocallyAssigned(EObject target, EObject containerToFindUsage) {
	if (this.readAndWriteTracking.isAssigned(target)) {
		return true;
	}
	final Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage);
	// field are assigned when they are not used as the left operand of an assignment operator.
	for (final Setting usage : usages) {
		final EObject object = usage.getEObject();
		if (object instanceof XAssignment) {
			final XAssignment assignment = (XAssignment) object;
			if (assignment.getFeature() == target) {
				// Mark the field as assigned in order to be faster during the next assignment test.
				this.readAndWriteTracking.markAssignmentAccess(target);
				return true;
			}
		}
	}
	return false;
}
 
Example #3
Source File: BuiltInTypeScopeTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
@Test
public void testResolveAllBuiltInTypes() {
	BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
	IEObjectDescription description = scope.getSingleElement(QualifiedName.create("any")); // trigger loading
	// assert that the built in resources are loaded into a delegate resource set
	Assert.assertEquals(0, resourceSet.getResources().size());

	EObject objectOrProxy = description.getEObjectOrProxy();
	Assert.assertFalse(objectOrProxy.eIsProxy());

	ResourceSet builtInResourceSet = objectOrProxy.eResource().getResourceSet();
	Assert.assertNotSame(resourceSet, builtInResourceSet);

	// trigger more loading
	GlobalObjectScope.get(resourceSet).getAllElements();
	VirtualBaseTypeScope.get(resourceSet).getAllElements();

	Assert.assertEquals(FluentIterable.from(builtInResourceSet.getResources()).transform(Resource::getURI)
			.join(Joiner.on('\n')), 7, builtInResourceSet.getResources().size());

	EcoreUtil.resolveAll(builtInResourceSet);
	Map<EObject, Collection<Setting>> unresolvedProxies = EcoreUtil.UnresolvedProxyCrossReferencer
			.find(builtInResourceSet);
	Assert.assertTrue(unresolvedProxies.toString(), unresolvedProxies.isEmpty());

	Assert.assertTrue(N4Scheme.isFromResourceWithN4Scheme(objectOrProxy));

	EObject loadedViaPrimary = resourceSet.getEObject(description.getEObjectURI(), false);
	Assert.assertSame(objectOrProxy, loadedViaPrimary);

}
 
Example #4
Source File: PhysicalModelInitializer.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Remove the physical foreign key from the Physical Model and also remove pending references (ex in BusinessRelationship)
 *
 */
public void removePhysicalForeignKey(PhysicalModel physicalModel, PhysicalForeignKey physicalForeignKey) {
	physicalModel.getForeignKeys().remove(physicalForeignKey);

	// remove inverse references (if any)
	// ModelSingleton modelSingleton = ModelSingleton.getInstance();
	ECrossReferenceAdapter adapter = getCrossReferenceAdapter();
	Collection<Setting> settings = adapter.getInverseReferences(physicalForeignKey, true);
	for (Setting setting : settings) {
		EObject eobject = setting.getEObject();
		if (eobject instanceof BusinessRelationship) {
			BusinessRelationship businessRelationship = (BusinessRelationship) eobject;
			if (businessRelationship.getPhysicalForeignKey().equals(physicalForeignKey)) {
				// remove reference
				businessRelationship.setPhysicalForeignKey(null);
			}
		}
	}
}
 
Example #5
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isLocallyUsed(EObject target, EObject containerToFindUsage) {
	if (readAndWriteTracking.isRead(target)) {
		return true;
	}
	Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage);
	// field and local variables are used when they are not used as the left operand of an assignment operator.
	if (target instanceof XVariableDeclaration || target instanceof JvmField) {
		for (final Setting usage : usages) {
			final EObject object = usage.getEObject();
			if (object instanceof XAssignment) {
				final XAssignment assignment = (XAssignment) object;
				if (assignment.getFeature() != target) {
					return true;
				}
			} else {
				return true;
			}
		}
		return false;
	}
	// for non-private members it is enough to check that there are usages
	if (!(target instanceof JvmOperation) || ((JvmOperation)target).getVisibility()!=JvmVisibility.PRIVATE) {
		return !usages.isEmpty();
	} else {
		// for private members it has to be checked if all usages are within the operation
		EObject targetSourceElem = associations.getPrimarySourceElement(target);
		for (Setting s : usages) {
			if (s.getEObject() instanceof XAbstractFeatureCall) {
				XAbstractFeatureCall fc = (XAbstractFeatureCall) s.getEObject();
				// when the feature call does not call itself or the call is
				// from another function, then it is locally used
				if (fc.getFeature() != target || !EcoreUtil.isAncestor(targetSourceElem, fc))
					return true;
			} else {
				return true;
			}
		}
		return false;
	}
}
 
Example #6
Source File: ECrossReferenceAdapterCrossReferenceProvider.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Collection<Setting> getInverseReferences(EObject self) {
    final Collection<Setting> res;

    final ECrossReferenceAdapter crossReferenceAdapter = getAdapter(self);
    if (crossReferenceAdapter != null) {
        res = crossReferenceAdapter.getInverseReferences(self);
    } else {
        throw new IllegalStateException("No ECrossReferenceAdapter found for :" + self);
    }

    return res;
}
 
Example #7
Source File: RenameRefactoring.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void internalExecute() {
	NamedElement element = getContextObject();
	Collection<Setting> usages = EcoreUtil.UsageCrossReferencer.find(element, getResource().getResourceSet());
	element.setName(newName);
	
	renameReferences(element, usages);
}
 
Example #8
Source File: RenameRefactoring.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void renameReferences(NamedElement element, Collection<Setting> usages) {
	for (EStructuralFeature.Setting setting : usages) {
		if (setting.getEStructuralFeature().isChangeable() && !setting.getEStructuralFeature().isMany()) {
			EObject holder = setting.getEObject();
			EStructuralFeature f = setting.getEStructuralFeature();
			holder.eSet(f, element);
		}
	}
}
 
Example #9
Source File: SequencerTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<Setting, INode> settingsToLink) {
	super.installProxies(obj, producer, settingsToLink);
	if (obj instanceof NullCrossRef)
		((NullCrossRef) obj).setRef(null);
}
 
Example #10
Source File: Bpmn2OppositeReferenceAdapter.java    From fixflow with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list that holds the opposite elements of the given reference for the given owner.
 * The opposite elements are those of type E that have the reference to owner.
 * 
 * The collection corresponding to opposite in the following picture is returned,
 * for given owner and reference.
 * <pre>
 *    <b>opposite</b>            reference
 *  E ----------------------------- owner
 *  </pre>
 *  
 *  reference has to be a key of the map observedRefToOpposite.
 * @param <E>
 * @param <E> The type of the elements in the collection.
 * @param dataClass The class of the elements in the collection.
 * @param owner The object whose list is retrieved.
 * @param reference The reference whose opposite reference is retrieved.
 * @return The opposite of reference for owner.
 */
public <E> List<E> getOppositeList(Class<E> dataClass, InternalEObject owner,
        EReference reference) {
    EReference opposite = observedRefToOpposite.get(reference);
    if (opposite == null)
        throw new IllegalArgumentException("This reference is not observed by this adapter: "
                + reference.toString());

    List<E> result = new BasicInternalEList<E>(dataClass);

    for (Setting cur : getNonNavigableInverseReferences(owner, false)) {
        if (cur.getEStructuralFeature().equals(reference))
            result.add(dataClass.cast(cur.getEObject()));
    }

    return result;
}