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

The following examples show how to use org.eclipse.emf.ecore.EReference#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: DeletePluginConfigurationDatabaseAction.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
	PluginConfiguration pluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), oid, OldQuery.getDefault());
	UserSettings settings = (UserSettings) pluginConfiguration.eGet(pluginConfiguration.eClass().getEStructuralFeature("userSettings"));
	if (settings == null) {
		throw new UserException("No user settings found...");
	}
	for (EReference eReference : settings.eClass().getEAllReferences()) {
		if (eReference.getEType() == pluginConfiguration.eClass() && eReference.isMany()) {
			List list = (List) settings.eGet(eReference);
			list.remove(pluginConfiguration);
		}
	}
	getDatabaseSession().store(settings);
	pluginConfiguration.remove();
	return null;
}
 
Example 2
Source File: IfcModel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private void fixOids(IdEObject idEObject, OidProvider oidProvider, BiMap<Long, IdEObject> temp) {
	if (idEObject == null) {
		return;
	}
	if (temp.containsValue(idEObject)) {
		return;
	}
	((IdEObjectImpl) idEObject).setOid(oidProvider.newOid(idEObject.eClass()));
	if (objects.containsValue(idEObject)) {
		temp.put(idEObject.getOid(), idEObject);
	}
	for (EReference eReference : idEObject.eClass().getEAllReferences()) {
		Object val = idEObject.eGet(eReference);
		if (eReference.isMany()) {
			List list = (List) val;
			for (Object o : list) {
				fixOids((IdEObject) o, oidProvider, temp);
			}
		} else {
			fixOids((IdEObject) val, oidProvider, temp);
		}
	}
}
 
Example 3
Source File: ResourceLifecycleManager.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initOppositeInfo() {
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			EClass eClass = (EClass)eClassifier;
			boolean hasOpposites = false;
			boolean hasManyOpposites = false;
			for (EReference eReference : eClass.getEAllReferences()) {
				if (eReference.getEOpposite() != null) {
					hasOpposites = true;
					if (eReference.isMany()) {
						hasManyOpposites = true;
					}
				}
			}
			oppositeInfos.put(eClass, new OppositeInfo(hasOpposites, hasManyOpposites));
		}
	}
}
 
Example 5
Source File: RecordSizeEstimater.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private int estimateBufferSize(EClass eClass) {
	int size = 0;
	for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
		if (eStructuralFeature instanceof EAttribute) {
			EAttribute eAttribute = (EAttribute)eStructuralFeature;
			if (eAttribute.isMany()) {
				size += 2 + AVERAGE_PRIMITIVE_LIST_SIZE * getPrimitiveSize((EDataType) eAttribute.getEType());
			} else {
				size += getPrimitiveSize((EDataType) eAttribute.getEType());
			}
		} else if (eStructuralFeature instanceof EReference) {
			EReference eReference = (EReference)eStructuralFeature;
			if (eReference.isMany()) {
				size += 2 + AVERAGE_REFERENCE_LIST_SIZE * 10;
			} else {
				size += 10;
			}
		}
	}
	return size;
}
 
Example 6
Source File: EObjectAtOffsetHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if (referenceOwner != null) {
		EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
				referenceOwner.eClass());
		if (!crossReference.isMany()) {
			return (EObject) referenceOwner.eGet(crossReference);
		} else {
			List<?> listValue = (List<?>) referenceOwner.eGet(crossReference);
			List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(referenceOwner, crossReference);
			int currentIndex = 0;
			for (INode nodeForFeature : nodesForFeature) {
				if (currentIndex >= listValue.size())
					return null;
				if (nodeForFeature.getTotalOffset() <= node.getTotalOffset()
						&& nodeForFeature.getTotalEndOffset() >= node.getTotalEndOffset())
					return (EObject) listValue.get(currentIndex);
				currentIndex++;
			}
		}
	}
	return null;
}
 
Example 7
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addInverseAttribute(Attribute attrib, EClass cls) {
	InverseAttribute inverseAttribute = (InverseAttribute) attrib;
	EReference eRef = eFactory.createEReference();
	eRef.setUnsettable(true); // Inverses are always optional?
	eRef.getEAnnotations().add(createInverseAnnotation());
	eRef.setName(attrib.getName());
	if (inverseAttribute.getMax_cardinality() != null) {
		IntegerBound max_cardinality = (IntegerBound) inverseAttribute.getMax_cardinality();
		if (max_cardinality.getBound_value() == -1) {
			eRef.setUpperBound(max_cardinality.getBound_value());
		} else {
			eRef.setUpperBound(max_cardinality.getBound_value() + 1);
		}
	}
	String type = (inverseAttribute).getDomain().getName();
	EClass classifier = (EClass) schemaPack.getEClassifier(type);
	eRef.setEType(classifier);
	String reverseName = inverseAttribute.getInverted_attr().getName();
	EReference reference = (EReference) classifier.getEStructuralFeature(reverseName);
	reference.getEAnnotations().add(createInverseAnnotation());
	if (eRef.getEType() == classifier && reference.getEType() == cls) {
		if (eRef.isMany()) {
			eRef.setUnique(true);
		}
		if (reference.isMany()) {
			reference.setUnique(true);
		}
		reference.setEOpposite(eRef);
		eRef.setEOpposite(reference);
	} else {
		System.out.println("Inverse mismatch");
		System.out.println(classifier.getName() + "." + reference.getName() + " => " + cls.getName() + "." + eRef.getName());
	}
	cls.getEStructuralFeatures().add(eRef);
}
 
Example 8
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 9
Source File: ContextFinderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void proxify(EObject owner, EReference ref) {
	if (ref.isMany()) {
		@SuppressWarnings("unchecked")
		List<? super Object> list = (List<? super Object>) owner.eGet(ref);
		for (int i = 0; i < list.size(); i++)
			list.set(i, createProxy((EObject) list.get(i)));
	} else {
		owner.eSet(ref, createProxy((EObject) owner.eGet(ref)));
	}
}
 
Example 10
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void replaceReferencesInGeneratedPackages(final List<EPackage> generatedPackages, final Map<EObject, EObject> eNamedElementMapping) {
  final TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
  while (packageContentIterator.hasNext()) {
    {
      final EObject current = packageContentIterator.next();
      EList<EStructuralFeature> _eAllStructuralFeatures = current.eClass().getEAllStructuralFeatures();
      final EStructuralFeature[] crossReferenceFeatures = ((EClassImpl.FeatureSubsetSupplier) _eAllStructuralFeatures).crossReferences();
      if ((crossReferenceFeatures != null)) {
        for (final EStructuralFeature crossReferenceFeature : crossReferenceFeatures) {
          boolean _isChangeable = crossReferenceFeature.isChangeable();
          if (_isChangeable) {
            final EReference reference = ((EReference) crossReferenceFeature);
            boolean _isMany = reference.isMany();
            if (_isMany) {
              Object _eGet = current.eGet(reference);
              final List<EObject> values = ((List<EObject>) _eGet);
              for (final EObject value : values) {
                boolean _containsKey = eNamedElementMapping.containsKey(value);
                if (_containsKey) {
                  EcoreUtil.replace(current, reference, value, eNamedElementMapping.get(value));
                }
              }
            } else {
              Object _eGet_1 = current.eGet(reference);
              final EObject value_1 = ((EObject) _eGet_1);
              boolean _containsKey_1 = eNamedElementMapping.containsKey(value_1);
              if (_containsKey_1) {
                EcoreUtil.replace(current, reference, value_1, eNamedElementMapping.get(value_1));
              }
            }
          }
        }
      }
    }
  }
}
 
Example 11
Source File: LazyLinker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void createAndSetProxy(EObject obj, INode node, EReference eRef) {
	final EObject proxy = createProxy(obj, node, eRef);
	if (eRef.isMany()) {
		((InternalEList<EObject>) obj.eGet(eRef, false)).addUnique(proxy);
	} else {
		obj.eSet(eRef, proxy);
	}
}
 
Example 12
Source File: RemoveReferenceChange.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());

	Query query = new Query(packageMetaData);
	QueryPart queryPart = query.createQueryPart();
	queryPart.addOid(oid);
	
	HashMapVirtualObject object = transaction.get(oid);
	if (object == null) {
		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}

	EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
	if (eReference == null) {
		throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (!eReference.isMany()) {
		throw new UserException("Reference is not of type 'many'");
	}
	List list = (List) object.get(eReference.getName());
	if (referencedOid != -1) {
		list.remove((Object)referencedOid);
	}
	if (index != -1) {
		list.remove(index);
	}
}
 
Example 13
Source File: ConcreteSyntaxValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 14
Source File: ShortFragmentProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public EObject getEObjectFromSegment(final EObject container, final String segment) {
  final int listSeparatorIndex = segment.indexOf(LIST_SEPARATOR);
  int featureId;
  if (listSeparatorIndex == -1) {
    featureId = Integer.parseUnsignedInt(segment);
  } else {
    featureId = Integer.parseUnsignedInt(segment.substring(0, listSeparatorIndex));
  }
  final EReference reference = (EReference) container.eClass().getEStructuralFeature(featureId);
  if (reference.isMany()) {
    if (listSeparatorIndex == -1) {
      // if the model expects a list but the uri does not provide a listIndex, or the model changed and the URI is outdated,
      // then simply return null
      return null;
    }
    final List<?> list = (List<?>) container.eGet(reference, false);
    final int listIndex = Integer.parseUnsignedInt(segment.substring(listSeparatorIndex + 1));
    // If the uri references an element outside of the list range return null (i.e. cannot find element)
    if (listIndex >= list.size()) {
      return null;
    }
    return (EObject) list.get(listIndex);
  } else {
    return (EObject) container.eGet(reference, false);
  }
}
 
Example 15
Source File: GenericCheckinDatabaseAction.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void fixInverses(PackageMetaData packageMetaData, long newRoid, Map<Long, HashMapVirtualObject> cache, HashMapVirtualObject next, EReference eReference, long refOid)
			throws JsonParseException, JsonMappingException, IOException, QueryException, BimserverDatabaseException {
		HashMapVirtualObject referencedObject = cache.get(refOid);
		if (referencedObject == null) {
			referencedObject = getByOid(packageMetaData, getDatabaseSession(), newRoid, refOid);
			if (referencedObject == null) {
				throw new BimserverDatabaseException("Referenced object with oid " + refOid + " (" + getDatabaseSession().getEClassForOid(refOid).getName() + ")" + ", referenced from " + next.eClass().getName() + " not found");
			}
			cache.put(refOid, referencedObject);
		}
		EReference oppositeReference = packageMetaData.getInverseOrOpposite(referencedObject.eClass(), eReference);
		if (oppositeReference == null) {
			if (eReference.getName().equals("RelatedElements") && referencedObject.eClass().getName().equals("IfcSpace")) {
				// Ignore, IfcSpace should have  a field called RelatedElements, but it doesn't.
			} else {
//				LOGGER.error("No opposite " + eReference.getName() + " found");
			}
		} else {
			if (oppositeReference.isMany()) {
				Object existingList = referencedObject.eGet(oppositeReference);
				if (existingList != null) {
					int currentSize = ((List<?>)existingList).size();
					referencedObject.setListItemReference(oppositeReference, currentSize, next.eClass(), next.getOid(), 0);
				} else {
					referencedObject.setListItemReference(oppositeReference, 0, next.eClass(), next.getOid(), 0);
				}
			} else {
				referencedObject.setReference(oppositeReference, next.getOid(), 0);
			}
		}
	}
 
Example 16
Source File: RemoveAllReferencesChange.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException,
		BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());

	Query query = new Query(packageMetaData);
	QueryPart queryPart = query.createQueryPart();
	queryPart.addOid(oid);
	
	HashMapVirtualObject object = transaction.get(oid);
	if (object == null) {
		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}

	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
	if (eReference == null) {
		throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (!eReference.isMany()) {
		throw new UserException("Reference is not of type 'many'");
	}
	List list = (List) object.get(eReference.getName());
	while (!list.isEmpty()) {
		list.remove(0);
	}
}
 
Example 17
Source File: N4JSLinker.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a proxy instance that will later on allow to lazily resolve the semantically referenced instance for the
 * given {@link CrossReference xref}.
 */
@SuppressWarnings("unchecked")
private void createAndSetProxy(N4JSResource resource, EObject obj, INode node, EReference eRef,
		CrossReference xref,
		IDiagnosticProducer diagnosticProducer) {
	final EObject proxy = createProxy(resource, obj, node, eRef, xref, diagnosticProducer);
	proxy.eSetDeliver(false);
	if (eRef.isMany()) {
		((InternalEList<EObject>) obj.eGet(eRef, false)).addUnique(proxy);
	} else {
		obj.eSet(eRef, proxy);
	}
}
 
Example 18
Source File: EcoreUtilN4.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected boolean haveEqualReference(EObject eObject1, EObject eObject2, EReference reference) {
	Object value1 = eObject1.eGet(reference, false);
	Object value2 = eObject2.eGet(reference, false);

	return reference.isMany() ? equals((List<EObject>) value1, (List<EObject>) value2)
			: equals((EObject) value1, (EObject) value2);
}
 
Example 19
Source File: SetWrappedAttributeChange.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException,
		BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
	
	Query query = new Query(packageMetaData);
	QueryPart queryPart = query.createQueryPart();
	queryPart.addOid(oid);
	
	HashMapVirtualObject object = transaction.get(oid);
	
	if (object == null) {
		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}

	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EReference eReference = packageMetaData.getEReference(eClass.getName(), attributeName);
	if (eReference == null) {
		throw new UserException("No reference with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (value instanceof List && eReference.isMany()) {
		List sourceList = (List)value;
		if (!eReference.isMany()) {
			throw new UserException("Attribute is not of type 'many'");
		}
		List list = (List)object.eGet(eReference);
		for (Object o : sourceList) {
			if (eReference.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
				List asStringList = (List)object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
				asStringList.add(String.valueOf(o));
			}
			list.add(o);
		}
	} else {
		if (eReference.isMany()) {
			throw new UserException("Attribute is not of type 'single'");
		}
		if (eReference.getEType() instanceof EEnum) {
			EEnum eEnum = (EEnum) eReference.getEType();
			object.set(eReference.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
		} else {
			EClass typeEClass = (EClass) packageMetaData.getEClassifier(type);
			if (typeEClass.getEAnnotation("wrapped") == null) {
				throw new UserException("Not a wrapped type");
			}
			HashMapWrappedVirtualObject wrappedObject = new HashMapWrappedVirtualObject(typeEClass);
			if (typeEClass == Ifc2x3tc1Package.eINSTANCE.getIfcBoolean()) {
				if ((Boolean)value == true) {
					value = Tristate.TRUE;
				} else {
					value = Tristate.FALSE;
				}
			}
			wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValue").getName(), value);
			object.set(eReference.getName(), wrappedObject);
			if (value instanceof Double) {
				wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValueAsString").getName(), String.valueOf((Double)value));
			}
		}
	}
}
 
Example 20
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected StringConcatenationClient generateFormatMethod(final EClass clazz, final Collection<EReference> containmentRefs, final boolean isOverriding) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      {
        if (isOverriding) {
          _builder.append("override");
        } else {
          _builder.append("def");
        }
      }
      _builder.append(" dispatch void format(");
      _builder.append(clazz);
      _builder.append(" ");
      String _varName = Formatter2Fragment2.this.toVarName(clazz);
      _builder.append(_varName);
      _builder.append(", extension ");
      _builder.append(IFormattableDocument.class);
      _builder.append(" document) {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("// TODO: format HiddenRegions around keywords, attributes, cross references, etc. ");
      _builder.newLine();
      {
        for(final EReference ref : containmentRefs) {
          {
            boolean _isMany = ref.isMany();
            if (_isMany) {
              _builder.append("\t");
              _builder.append("for (");
              String _varName_1 = Formatter2Fragment2.this.toVarName(ref, Formatter2Fragment2.this.toVarName(clazz), "document");
              _builder.append(_varName_1, "\t");
              _builder.append(" : ");
              String _varName_2 = Formatter2Fragment2.this.toVarName(clazz);
              _builder.append(_varName_2, "\t");
              _builder.append(".");
              String _getAccessor = Formatter2Fragment2.this.getGetAccessor(ref);
              _builder.append(_getAccessor, "\t");
              _builder.append(") {");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("\t");
              String _varName_3 = Formatter2Fragment2.this.toVarName(ref, Formatter2Fragment2.this.toVarName(clazz), "document");
              _builder.append(_varName_3, "\t\t");
              _builder.append(".format");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("}");
              _builder.newLine();
            } else {
              _builder.append("\t");
              String _varName_4 = Formatter2Fragment2.this.toVarName(clazz);
              _builder.append(_varName_4, "\t");
              _builder.append(".");
              String _getAccessor_1 = Formatter2Fragment2.this.getGetAccessor(ref);
              _builder.append(_getAccessor_1, "\t");
              _builder.append(".format");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  };
  return _client;
}