Java Code Examples for org.eclipse.emf.ecore.EObject#eGet()
The following examples show how to use
org.eclipse.emf.ecore.EObject#eGet() .
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: TransientValueUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public List<EObject> getAllNonTransientValues(EObject container, EReference feature) { switch (transientValues.isListTransient(container, feature)) { case SOME: List<EObject> result = Lists.newArrayList(); List<?> values = (List<?>) container.eGet(feature); for (int i = 0; i < values.size(); i++) if (!transientValues.isValueInListTransient(container, i, feature)) result.add((EObject) values.get(i)); return result; case NO: return (List<EObject>) container.eGet(feature); case YES: return Collections.emptyList(); } return Collections.emptyList(); }
Example 2
Source File: TransientValueUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public ValueTransient isTransient(EObject obj, EStructuralFeature feature) { if (feature.isMany()) switch (transientValues.isListTransient(obj, feature)) { case NO: return ValueTransient.NO; case YES: return ValueTransient.YES; case SOME: List<?> values = (List<?>) obj.eGet(feature); for (int i = 0; i < values.size(); i++) if (!transientValues.isValueInListTransient(obj, i, feature)) return ValueTransient.NO; default: return ValueTransient.YES; } else return transientValues.isValueTransient(obj, feature); }
Example 3
Source File: ResourceLifecycleManager.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public Resource openAndApplyReferences(ResourceSet resourceSet, RelatedResource toLoad) { Resource resource = resourceSet.getResource(toLoad.getUri(), true); for (IReferenceSnapshot desc : toLoad.outgoingReferences) { EObject source = resource.getEObject(desc.getSourceEObjectUri().fragment()); EObject target = desc.getTarget().getObject(); EReference reference = desc.getEReference(); if (reference.isMany()) { @SuppressWarnings("unchecked") List<Object> list = (EList<Object>) source.eGet(reference, false); list.set(desc.getIndexInList(), target); } else { source.eSet(reference, target); } } return resource; }
Example 4
Source File: DataExpressionNatureProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public Expression[] getExpressions(final EObject context) { final Set<Expression> result = new HashSet<Expression>() ; EObject container = context ; while(container != null){ if(container.eClass().getEAllStructuralFeatures().contains(dataFeature)){ final List<?> data = (List<?>) container.eGet(dataFeature) ; for(final Object d : data){ if(d instanceof Data){ result.add(createExpression((Data) d)) ; } } container = null ; }else{ container = container.eContainer() ; } } return result.toArray(new Expression[result.size()]); }
Example 5
Source File: AbstractStreamingFingerprintComputer.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Return an Iterable containing all the contents of the given feature of the given object. If the * feature is not many-valued, the resulting iterable will have one element. If the feature is an EReference, * the iterable may contain proxies. The iterable may contain null values. * * @param <T> * The Generic type of the objects in the iterable * @param obj * The object * @param feature * The feature * @return An iterable over all the contents of the feature of the object. */ @SuppressWarnings("unchecked") private <T> Iterable<T> featureIterable(final EObject obj, final EStructuralFeature feature) { if (feature == null) { return Collections.emptyList(); } if (feature.isMany()) { if (feature instanceof EAttribute || ((EReference) feature).isContainment()) { return (Iterable<T>) obj.eGet(feature); } return new Iterable<T>() { @Override public Iterator<T> iterator() { return ((InternalEList<T>) obj.eGet(feature)).basicIterator(); // Don't resolve } }; } return Collections.singletonList((T) obj.eGet(feature, false)); // Don't resolve }
Example 6
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 7
Source File: TypeUsageCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmIdentifiableElement getReferencedElement(EObject owner, EReference reference) { JvmIdentifiableElement referencedThing = (JvmIdentifiableElement) owner.eGet(reference); if (referencedThing != null && owner instanceof XConstructorCall && referencedThing.eIsProxy()) { JvmIdentifiableElement potentiallyLinkedType = batchTypeResolver.resolveTypes(owner).getLinkedFeature((XConstructorCall)owner); if (potentiallyLinkedType != null && !potentiallyLinkedType.eIsProxy()) { referencedThing = potentiallyLinkedType; } } return referencedThing; }
Example 8
Source File: IfcStepSerializer.java From IfcPlugins with GNU Affero General Public License v3.0 | 5 votes |
private void writeEmbedded(EObject eObject) throws SerializerException, IOException { EClass class1 = eObject.eClass(); print(getPackageMetaData().getUpperCase(class1)); print(OPEN_PAREN); EStructuralFeature structuralFeature = class1.getEStructuralFeature(WRAPPED_VALUE); if (structuralFeature != null) { Object realVal = eObject.eGet(structuralFeature); if (structuralFeature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) { writeDoubleValue((Double)realVal, eObject, structuralFeature); } else { IfcParserWriterUtils.writePrimitive(realVal, outputStream); } } print(CLOSE_PAREN); }
Example 9
Source File: ParserTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testParseSimpleWithMultipleSpaces() throws Exception { String model = " a . b . c . d ;"; EObject parsedModel = getModel(model); assertNotNull(parsedModel); EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0); String id = (String) firstModel.eGet(idFeature); assertNotNull(id); assertEquals("a . b . c . d", id); assertFalse(firstModel.eIsSet(valueFeature)); }
Example 10
Source File: ModelPropertyMapEntryImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated */ @SuppressWarnings("unchecked") @JsonIgnore public EMap<String, ModelProperty> getEMap() { EObject container = eContainer(); return container == null ? null : (EMap<String, ModelProperty>) container.eGet(eContainmentFeature()); }
Example 11
Source File: EcoreUtil2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public static <T> List<T> collect(Collection<? extends EObject> instances, int featureId, Class<T> type) { final List<T> result = new ArrayList<T>(instances.size()); for (EObject obj : instances) { if (obj == null) throw new NullPointerException("obj may not be null"); final EStructuralFeature feature = obj.eClass().getEStructuralFeature(featureId); if (feature == null) throw new NullPointerException("feature may not be null"); final Object object = obj.eGet(feature); if (object != null) result.add(type.cast(object)); } return result; }
Example 12
Source File: EStringToStringMapEntryImpl.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") public EMap<String, String> getEMap( ) { EObject container = eContainer( ); return container == null ? null : (EMap<String, String>) container.eGet( eContainmentFeature( ) ); }
Example 13
Source File: StringAttributeParser.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public String getEditString(IAdaptable adapter, int flags) { EObject element = (EObject) adapter.getAdapter(EObject.class); EAttribute attribute = provider.getAttribute(); Assert.isTrue(attribute.getEAttributeType() == EcorePackage.Literals.ESTRING); String string = (String) element.eGet(attribute); if (string != null && !string.trim().isEmpty()) { return String.valueOf(string); } else { return createEmptyStringLabel(attribute); } }
Example 14
Source File: ParserTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testParseWithVector() throws Exception { String model = "a.b.c.d # (1 2);"; EObject parsedModel = getModel(model); assertNotNull(parsedModel); EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0); assertTrue(firstModel.eIsSet(vectorFeature)); String vector = (String) firstModel.eGet(vectorFeature); assertNotNull(vector); assertEquals("(1 2)", vector); }
Example 15
Source File: LazyURIEncoder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void appendShortFragment(EObject obj, StringBuilder target) { EReference containmentFeature = obj.eContainmentFeature(); if (containmentFeature == null) { target.append(obj.eResource().getContents().indexOf(obj)); } else { EObject container = obj.eContainer(); appendShortFragment(container, target); target.append('.').append(container.eClass().getFeatureID(containmentFeature)); if (containmentFeature.isMany()) { List<?> list = (List<?>) container.eGet(containmentFeature); target.append('.').append(list.indexOf(obj)); } } }
Example 16
Source File: XbaseSemanticSequencer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isBuilderSyntax(EObject expression, EReference reference, boolean explicitOperationCall, INodesForEObjectProvider nodes) { List<?> values = (List<?>) expression.eGet(reference); if (values.size() < 1) return false; if (values.size() == 1 && !explicitOperationCall) return true; return isBuilderSyntax(values, reference, nodes); }
Example 17
Source File: ParserTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testParseWithDotsAndComments() throws Exception { String model = "a.b.c.d + ./*comment*/.;"; EObject parsedModel = getModel(model); assertNotNull(parsedModel); EObject firstModel = ((List<EObject>) parsedModel.eGet(modelFeature)).get(0); assertTrue(firstModel.eIsSet(dotsFeature)); String vector = (String) firstModel.eGet(dotsFeature); assertNotNull(vector); assertEquals(". .", vector); }
Example 18
Source File: EReferenceIndex.java From kieker with Apache License 2.0 | 4 votes |
public static <K, V extends EObject> EReferenceIndex<K, V> create(final EObject object, final EReference reference, final Collection<EStructuralFeature> observedReferenceAttributes, final Function<V, K> keyCreator) { @SuppressWarnings("unchecked") final EList<V> values = (EList<V>) object.eGet(reference); return new EReferenceIndex<>(object, reference, observedReferenceAttributes, keyCreator, values); }
Example 19
Source File: OperationsComposite.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") private List<Operation> getActions() { final EObject eObject = getEObject(); return (List<Operation>) eObject.eGet(getActionTargetFeature()); }
Example 20
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"); }