Java Code Examples for org.eclipse.emf.ecore.EObject#eContainmentFeature()
The following examples show how to use
org.eclipse.emf.ecore.EObject#eContainmentFeature() .
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: ContextAwareTypeScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** See {@link ContextAwareTypeScope}. */ public ContextAwareTypeScope(IScope parent, EObject context) { super(parent); final EObject container = context.eContainer(); final EReference eRef = context.eContainmentFeature(); this.isValidLocationForNull = false; // in the source code, 'null' is never a valid type this.isValidLocationForVoid = eRef == N4JSPackage.eINSTANCE.getFunctionDefinition_ReturnTypeRef() || eRef == TypeRefsPackage.eINSTANCE.getFunctionTypeExpression_ReturnTypeRef() || eRef == TypesPackage.eINSTANCE.getTFunction_ReturnTypeRef() // void is not truly allowed as the return type of a getter, but there's a separate validation for // that; so treat this case as legal here: || container instanceof GetterDeclaration && eRef == N4JSPackage.eINSTANCE.getTypedElement_DeclaredTypeRef(); this.isValidLocationForFunctionType = false // the following is only required for content assist in JSXElements (main scoping works without this) || eRef == N4JSPackage.eINSTANCE.getJSXElement_JsxElementName() // function types are not truly allowed within TypeTypeRefs (i.e. inside 'type{...}'), but there's a // separate validation for that; so treat this case as legal here: || eRef == TypeRefsPackage.eINSTANCE.getTypeTypeRef_TypeArg(); }
Example 2
Source File: ShortFragmentProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @Override public boolean appendFragmentSegment(final EObject object, final StringBuilder builder) { final EReference containmentFeature = object.eContainmentFeature(); if (containmentFeature == null) { builder.append(object.eResource().getContents().indexOf(object)); } else { final EObject container = object.eContainer(); builder.append(container.eClass().getFeatureID(containmentFeature)); if (containmentFeature.isMany()) { final List<?> list = (List<?>) container.eGet(containmentFeature, false); builder.append(LIST_SEPARATOR).append(list.indexOf(object)); } } return true; }
Example 3
Source File: EcoreUtilN4.java From n4js with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") private static <T> List<T> getAllContentsOfTypeStopAt(boolean findFirst, EObject eobj, final Class<T> filterType, final EReference... stopReferences) { if (eobj == null) { return Collections.EMPTY_LIST; } List<EReference> stopReferencesL = Arrays.asList(stopReferences); List<T> contentList = new LinkedList<>(); TreeIterator<EObject> tIter = eobj.eAllContents(); while (tIter.hasNext()) { EObject eObj = tIter.next(); EReference eRef = eObj.eContainmentFeature(); if (stopReferencesL != null && stopReferencesL.contains(eRef)) { tIter.prune(); } else { if (filterType.isInstance(eObj)) { contentList.add((T) eObj); if (findFirst) { return contentList; } } } } return contentList; }
Example 4
Source File: ExpressionUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean isBlockInsertable(EObject eContainer, EObject expression) { EReference ref = expression.eContainmentFeature(); return ref == XCLOSURE__EXPRESSION || ref == XIF_EXPRESSION__THEN || ref == XIF_EXPRESSION__ELSE || ref == XCASE_PART__THEN || ref == XSWITCH_EXPRESSION__DEFAULT || ref == XFOR_LOOP_EXPRESSION__EACH_EXPRESSION || ref == XABSTRACT_WHILE_EXPRESSION__BODY || ref == XTRY_CATCH_FINALLY_EXPRESSION__EXPRESSION || ref == XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION || ref == XCATCH_CLAUSE__EXPRESSION; }
Example 5
Source File: ConcreteSyntaxValidator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public boolean isEObjectTransient(EObject obj) { if (obj.eContainmentFeature() == null) return false; EReference ref = obj.eContainmentFeature(); EObject cnt = obj.eContainer(); if (ref.isMany() && transSrvc.isCheckElementsIndividually(cnt, ref)) { if (transSrvc.isTransient(cnt, ref, ((List<?>) cnt.eGet(ref)).indexOf(obj))) return true; } else if (transSrvc.isTransient(cnt, ref, 0)) return true; return false; }
Example 6
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 7
Source File: AbstractLiveValidationMarkerConstraint.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected boolean isAExpressionReferencedElement(final EObject target) { if (target != null) { EObject current = target; EReference ref = current.eContainmentFeature(); while (ref != null && !ref.equals(ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS)) { current = current.eContainer(); ref = current.eContainmentFeature(); } return ref != null; } return false; }
Example 8
Source File: AbstractSelectorFragmentProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** * Computes a segment of the fragment with a selector for the given object and appends it to the given {@link StringBuilder}. * * @param obj * object to compute fragment for * @param selectorFeature * selector feature * @param unique * {@code true} the values for selectorFeature are unique within the object's containment feature setting * @param builder * builder to append fragment segment to, must not be {@code null} * @return {@code true} if a fragment segment was appended to {@code builder} */ @SuppressWarnings("unchecked") protected boolean computeSelectorFragmentSegment(final EObject obj, final EStructuralFeature selectorFeature, final boolean unique, final StringBuilder builder) { final EObject container = obj.eContainer(); if (container == null) { return shortFragmentProvider.appendFragmentSegment(obj, builder); } // containment feature final EStructuralFeature containmentFeature = obj.eContainmentFeature(); builder.append(container.eClass().getFeatureID(containmentFeature)); // selector final Object selectorValue = obj.eGet(selectorFeature); builder.append(SELECTOR_START).append(obj.eClass().getFeatureID(selectorFeature)).append(EQ_OP); if (selectorValue != null) { builder.append(VALUE_SEP); appendEscaped(selectorValue.toString(), builder); builder.append(VALUE_SEP); } else { builder.append(NULL_VALUE); } if (unique) { builder.append(UNIQUE); } builder.append(SELECTOR_END); // selector index if (!unique && containmentFeature.isMany()) { builder.append(ShortFragmentProvider.LIST_SEPARATOR); final EList<? extends EObject> containmentList = (EList<? extends EObject>) container.eGet(containmentFeature); int selectorIndex = 0; final int objectIndex = containmentList.indexOf(obj); for (int i = 0; i < objectIndex; i++) { final Object value = containmentList.get(i).eGet(selectorFeature); if ((selectorValue == null && value == null) || (selectorValue != null && selectorValue.equals(value))) { selectorIndex++; } } builder.append(selectorIndex); } return true; }