Java Code Examples for org.eclipse.emf.ecore.EStructuralFeature#isMany()
The following examples show how to use
org.eclipse.emf.ecore.EStructuralFeature#isMany() .
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: AbstractEObjectRegion.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void initChildrenFeatureIndexes() { EClass clazz = semanticElement.eClass(); int[] indices = new int[clazz.getFeatureCount()]; Arrays.fill(indices, 0); for (IAstRegion ele : children) { EStructuralFeature feat = ele.getContainingFeature(); if (feat != null && feat.isMany()) { int id = clazz.getFeatureID(feat); if (ele instanceof AbstractEObjectRegion) { ((AbstractEObjectRegion) ele).indexInFeature = indices[id]; } else if (ele instanceof NodeSemanticRegion) { ((NodeSemanticRegion) ele).indexInFeature = indices[id]; } else if (ele instanceof StringSemanticRegion) { ((StringSemanticRegion) ele).indexInFeature = indices[id]; } indices[id]++; } } }
Example 2
Source File: DirectLinkingEObjectOutputStream.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Computes a short positional URI fragment path. These are more efficient than fragments returned by {@link org.eclipse.xtext.resource.IFragmentProvider}, as * the latter may contain name-based segments, which require a lookup to resolve. * * @param obj * object to get URI fragment for, must not be {@code null} * @return URI fragment path, where the segments encode the feature IDs and position in case of multi-valued features, never {@code null} */ @SuppressWarnings("unchecked") private void writeEObjectURIFragmentPath(final EObject obj) throws IOException { list.clear(); InternalEObject internalEObject = (InternalEObject) obj; for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container = internalEObject.eInternalContainer()) { EStructuralFeature feature = internalEObject.eContainingFeature(); if (feature.isMany()) { list.add(((EList<EObject>) container.eGet(feature, false)).indexOf(internalEObject)); } list.add(container.eClass().getFeatureID(feature)); internalEObject = container; } list.add(internalEObject.eResource().getContents().indexOf(internalEObject)); writeCompressedInt(list.size()); for (int i = list.size() - 1; i >= 0; i--) { writeCompressedInt(list.get(i)); } }
Example 3
Source File: ReferenceCCDAValidator.java From reference-ccda-validator with BSD 2-Clause "Simplified" License | 6 votes |
public String getPath(EObject eObject) { String path = ""; while (eObject != null && !(eObject instanceof DocumentRoot)) { EStructuralFeature feature = eObject.eContainingFeature(); EObject container = eObject.eContainer(); Object value = container.eGet(feature); if (feature.isMany()) { List<?> list = (List<?>) value; int index = list.indexOf(eObject) + 1; path = "/" + feature.getName() + "[" + index + "]" + path; } else { path = "/" + feature.getName() + "[1]" + path; } eObject = eObject.eContainer(); } return path; }
Example 4
Source File: Ecore2XtextGrammarCreator.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public CharSequence assignmentOperator(final EStructuralFeature it) { StringConcatenation _builder = new StringConcatenation(); { boolean _isMany = it.isMany(); if (_isMany) { _builder.append("+="); } else { if ((Ecore2XtextExtensions.isBoolean(it.getEType()) && Ecore2XtextExtensions.isPrefixBooleanFeature(it))) { _builder.append("?="); } else { _builder.append("="); } } } return _builder; }
Example 5
Source File: TokenSequencePreservingPartialParsingHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void replaceOldSemanticElement(EObject oldElement, IParseResult previousParseResult, IParseResult newParseResult) { EObject oldSemanticParentElement = oldElement.eContainer(); if (oldSemanticParentElement != null) { EStructuralFeature feature = oldElement.eContainingFeature(); if (feature.isMany()) { List featureValueList = (List) oldSemanticParentElement.eGet(feature); int index = featureValueList.indexOf(oldElement); unloadSemanticObject(oldElement); featureValueList.set(index, newParseResult.getRootASTElement()); } else { unloadSemanticObject(oldElement); oldSemanticParentElement.eSet(feature, newParseResult.getRootASTElement()); } ((ParseResult) newParseResult).setRootASTElement(previousParseResult.getRootASTElement()); } else { unloadSemanticObject(oldElement); } }
Example 6
Source File: AbstractFingerprintComputer.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 7
Source File: HashMapVirtualObject.java From BIMserver with GNU Affero General Public License v3.0 | 6 votes |
private boolean useUnsetBit(EStructuralFeature feature) { // TODO non-unsettable boolean values can also be stored in these bits Object value = eGet(feature); if (feature.isUnsettable()) { if (!eIsSet(feature)) { return true; } } else { if (feature.isMany() && (value == null || ((List<?>)value).isEmpty())) { return true; } if (feature.getDefaultValue() == value || (feature.getDefaultValue() != null && feature.getDefaultValue().equals(value))) { return true; } } return false; }
Example 8
Source File: StringSemanticRegion.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public int getIndexInContainingFeature() { if (indexInFeature < -1) { EStructuralFeature feature = getContainingFeature(); if (feature != null && feature.isMany()) { ((AbstractEObjectRegion) eObjectRegion).initChildrenFeatureIndexes(); } else { indexInFeature = -1; } } return indexInFeature; }
Example 9
Source File: EObjectConsumer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Object getConsumable(String featureName, boolean allowDefault) { EStructuralFeature feature = getFeature(featureName); if (feature != null && isConsumable(feature, allowDefault)) { Object get = described.eGet(feature); if (feature.isMany()) { List<?> list = (List<?>) get; get = list.get(nextFeatureId[described.eClass().getFeatureID(feature)]); } return get; } return null; }
Example 10
Source File: TextRegionAccessToString.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String toString(IEObjectRegion region) { EObject obj = region.getSemanticElement(); StringBuilder builder = new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " "); EObject element = region.getGrammarElement(); if (element instanceof AbstractElement) builder.append(grammarToString.apply((AbstractElement) element)); else if (element instanceof AbstractRule) builder.append(((AbstractRule) element).getName()); else builder.append(": ERROR: No grammar element."); List<String> segments = Lists.newArrayList(); EObject current = obj; while (current.eContainer() != null) { EObject container = current.eContainer(); EStructuralFeature containingFeature = current.eContainingFeature(); StringBuilder segment = new StringBuilder(); segment.append(toClassWithName(container)); segment.append("/"); segment.append(containingFeature.getName()); if (containingFeature.isMany()) { int index = ((List<?>) container.eGet(containingFeature)).indexOf(current); segment.append("[" + index + "]"); } current = container; segments.add(segment.toString()); } if (!segments.isEmpty()) { builder.append(" path:"); builder.append(Joiner.on("=").join(segments)); } return builder.toString(); }
Example 11
Source File: AbstractHoverTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Returns values of the given feature. * * @param model * the model which the given feature belongs to, must not be {@code null} * @param feature * the feature of the model with one of many values, must not be {@code null} * @return the values of the feature, never {@code null} */ @SuppressWarnings("unchecked") private EList<EObject> getFeatureValues(final EObject model, final EStructuralFeature feature) { EList<EObject> values = new BasicEList<EObject>(); if (feature.isMany()) { values.addAll((EList<EObject>) model.eGet(feature)); } else { values.add((EObject) model.eGet(feature, false)); } return values; }
Example 12
Source File: ContextFinder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected boolean isValidValueQuantity(IConstraint constraint, EObject semanicObj) { if (constraint == null) return false; for (int featureID = 0; featureID < semanicObj.eClass().getFeatureCount(); featureID++) { IFeatureInfo featureInfo = constraint.getFeatures()[featureID]; EStructuralFeature feature = semanicObj.eClass().getEStructuralFeature(featureID); if (feature.isMany()) { int count = transientValueUtil.countNonTransientListValues(semanicObj, feature); if (count > featureInfo.getUpperBound()) return false; if (count < featureInfo.getLowerBound()) return false; } else { ValueTransient valueTransient = transientValues.isValueTransient(semanicObj, feature); switch (valueTransient) { case NO: if (featureInfo == null) return false; if (featureInfo.getUpperBound() <= 0) return false; break; case YES: if (featureInfo == null) break; if (featureInfo.getLowerBound() > 0) return false; break; case PREFERABLY: break; } } } return true; }
Example 13
Source File: SemanticSequencerExtensions.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public List<ISemanticSequencerNfaProvider.ISemState> getLinearListOfMandatoryAssignments(final IGrammarConstraintProvider.IConstraint constraint) { final Nfa<ISemanticSequencerNfaProvider.ISemState> nfa = constraint.getNfa(); ISemanticSequencerNfaProvider.ISemState state = nfa.getStart(); final List<ISemanticSequencerNfaProvider.ISemState> result = CollectionLiterals.<ISemanticSequencerNfaProvider.ISemState>newArrayList(); final Set<EStructuralFeature> features = CollectionLiterals.<EStructuralFeature>newHashSet(); while ((state != null)) { { ISemanticSequencerNfaProvider.ISemState _stop = nfa.getStop(); boolean _tripleEquals = (state == _stop); if (_tripleEquals) { List<ISemanticSequencerNfaProvider.ISemState> _xifexpression = null; boolean _isEmpty = result.isEmpty(); if (_isEmpty) { _xifexpression = null; } else { _xifexpression = result; } return _xifexpression; } int _size = state.getFollowers().size(); boolean _tripleNotEquals = (_size != 1); if (_tripleNotEquals) { return null; } ISemanticSequencerNfaProvider.ISemState _start = nfa.getStart(); boolean _tripleNotEquals_1 = (state != _start); if (_tripleNotEquals_1) { final EStructuralFeature feature = state.getFeature(); if ((((feature == null) || feature.isMany()) || (!features.add(feature)))) { return null; } result.add(state); } state = IterableExtensions.<ISemanticSequencerNfaProvider.ISemState>head(state.getFollowers()); } } return null; }
Example 14
Source File: IfcStepSerializer.java From IfcPlugins with GNU Affero General Public License v3.0 | 5 votes |
private void writeEDataType(IdEObject object, EntityDefinition entityBN, EStructuralFeature feature) throws SerializerException, IOException { if (entityBN != null && entityBN.isDerived(feature.getName())) { print(ASTERISK); } else if (feature.isMany()) { writeList(object, feature); } else { writeObject(object, feature); } }
Example 15
Source File: DerivedEObjectEList.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@Override public boolean contains(Object object) { if (sourceFeatureIDs != null) { for (int i = 0; i < sourceFeatureIDs.length; i++) { int sourceFeatureID = sourceFeatureIDs[i]; if (owner.eIsSet(sourceFeatureID)) { EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID); Object value = owner.eGet(sourceFeatureID, true, true); if (FeatureMapUtil.isFeatureMap(sourceFeature)) { FeatureMap featureMap = (FeatureMap) value; for (int j = 0, size = featureMap.size(); j < size; j++) { value = featureMap.getValue(j); if (isIncluded(featureMap.getEStructuralFeature(j)) ? value == object : isIncluded(value) && derive(value) == object) { return true; } } } else if (isIncluded(sourceFeature)) { if (sourceFeature.isMany() ? ((List<?>) value) .contains(object) : value == object) { return true; } } else { if (sourceFeature.isMany()) { InternalEList<?> valuesList = (InternalEList<?>) value; if (valuesList instanceof RandomAccess) { for (int j = 0, size = valuesList.size(); j < size; j++) { value = valuesList.basicGet(j); if (isIncluded(value) && derive(value) == object) { return true; } } } else { for (Iterator<?> v = valuesList.basicIterator(); v .hasNext();) { value = v.next(); if (isIncluded(value) && derive(value) == object) { return true; } } } } else if (isIncluded(value) && derive(value) == object) { return true; } } } } } return false; }
Example 16
Source File: CopyEObjectFeaturesCommand.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * @param targetElement * @param sourceElement * */ public static void copyFeatures(EObject sourceElement, EObject targetElement) { List<EStructuralFeature> targetFeatures = targetElement.eClass().getEAllStructuralFeatures(); for (EStructuralFeature feature : sourceElement.eClass().getEAllStructuralFeatures()) { if (targetFeatures.contains(feature)) { if (feature instanceof EReference) { EReference reference = (EReference)feature; Object value = sourceElement.eGet(reference); if (value instanceof EList<?>) { EList<EObject> sourceList = (EList<EObject>)value; EList<EObject> destList = (EList<EObject>)targetElement.eGet(feature); while (!sourceList.isEmpty()) { EObject referencedItem = sourceList.get(0); sourceList.remove(referencedItem); if (reference.getEOpposite() != null) { referencedItem.eSet(reference.getEOpposite(), targetElement); } else { destList.add(referencedItem); } } } else { targetElement.eSet(feature, sourceElement.eGet(feature)); } } else if (feature instanceof EAttribute) { targetElement.eSet(feature, sourceElement.eGet(feature)); } }else{//unset other features if(feature.isMany()){ sourceElement.eSet(feature, Collections.emptyList()); }else{ sourceElement.eSet(feature, feature.getDefaultValue()); } } } EObject container = sourceElement.eContainer(); if (container != null) { Object parentFeatureValue = container.eGet(sourceElement.eContainingFeature()); if (parentFeatureValue instanceof EList<?>) { // int index = ((EList) parentFeatureValue).indexOf(sourceElement); ((EList<?>) parentFeatureValue).remove(sourceElement); // Add the new element at the same place than the older one // ((EList) parentFeatureValue).set(((EList) // parentFeatureValue).indexOf(sourceElement), targetElement); ((EList) parentFeatureValue).add(/* index, */targetElement); } else { container.eSet(sourceElement.eContainingFeature(), targetElement); } } }
Example 17
Source File: AbstractSelectorFragmentProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** {@inheritDoc} */ @Override @SuppressWarnings({"unchecked", "PMD.NPathComplexity"}) public EObject getEObjectFromSegment(final EObject container, final String segment) { final int selectorEndOffset = segment.lastIndexOf(SELECTOR_END); if (selectorEndOffset != -1) { final int selectorOffset = segment.indexOf(SELECTOR_START); final int containmentFeatureId = Integer.parseUnsignedInt(segment.substring(0, selectorOffset)); final EStructuralFeature containmentFeature = container.eClass().getEStructuralFeature(containmentFeatureId); if (containmentFeature == null) { return null; } if (!containmentFeature.isMany()) { return (EObject) container.eGet(containmentFeature); } final int eqOffset = segment.indexOf(EQ_OP, selectorOffset); final int selectorFeatureId = Integer.parseUnsignedInt(segment.substring(selectorOffset + 1, eqOffset)); boolean uniqueMatch = segment.charAt(selectorEndOffset - 1) == UNIQUE; int matchedIndex = uniqueMatch ? 0 : Integer.parseUnsignedInt(segment.substring(selectorEndOffset + 2)); boolean isNull = segment.startsWith(NULL_VALUE, eqOffset + EQ_OP_LENGTH); String matchedValue = isNull ? null : unescape(segment.substring(eqOffset + EQ_OP_LENGTH + 1, uniqueMatch ? selectorEndOffset - 2 : selectorEndOffset - 1)); int index = 0; EList<? extends EObject> containmentList = (EList<? extends EObject>) container.eGet(containmentFeature); int containmentListSize = containmentList.size(); for (int i = 0; i < containmentListSize; i++) { EObject object = containmentList.get(i); Object value = object.eGet(object.eClass().getEStructuralFeature(selectorFeatureId)); if (value == null) { if (matchedValue == null && index++ == matchedIndex) { return object; } } else { if ((isCaseSensitive(object.eClass()) ? value.toString().equals(matchedValue) : value.toString().equalsIgnoreCase(matchedValue)) && index++ == matchedIndex) { return object; } } } return null; } else { return shortFragmentProvider.getEObjectFromSegment(container, segment); } }
Example 18
Source File: DerivedEObjectEList.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@Override public boolean isEmpty() { if (sourceFeatureIDs != null) { for (int i = 0; i < sourceFeatureIDs.length; i++) { int sourceFeatureID = sourceFeatureIDs[i]; if (owner.eIsSet(sourceFeatureID)) { EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID); Object value = owner.eGet(sourceFeatureID, false, true); if (FeatureMapUtil.isFeatureMap(sourceFeature)) { FeatureMap featureMap = (FeatureMap) value; for (int j = 0, size = featureMap.size(); j < size; j++) { if (isIncluded(featureMap.getEStructuralFeature(j)) ? featureMap .getValue(j) != null : isIncluded(featureMap.getValue(j))) { return false; } } } else if (isIncluded(sourceFeature)) { if (sourceFeature.isMany() ? ((List<?>) value).size() > 0 : value != null) { return false; } } else { if (sourceFeature.isMany()) { InternalEList<?> valuesList = (InternalEList<?>) value; if (valuesList instanceof RandomAccess) { for (int j = 0, size = valuesList.size(); j < size; j++) { if (isIncluded(valuesList.basicGet(j))) { return false; } } } else { for (Iterator<?> v = valuesList.basicIterator(); v .hasNext();) { if (isIncluded(v.next())) { return false; } } } } else if (isIncluded(value)) { return false; } } } } } return true; }
Example 19
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; }
Example 20
Source File: XtextSpyLabelProvider.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Decorate EStructuralFeature - if feature has multiplicity add * decoration. * * @param feature * the feature * @return multiplicity decorator if feature is many, else null */ protected Pair<Object, Integer> decorate(final EStructuralFeature feature) { if (feature.isMany()) { return Tuples.<Object, Integer> create(MANY_DECORATOR, IDecoration.BOTTOM_LEFT); } return null; }