blob: 1a044f43b998104e00a6ed65daec17443be1e247 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013 E.D.Willink and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*******************************************************************************/
package org.eclipse.ocl.examples.build.xtend;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTablesUtils;
import org.eclipse.ocl.pivot.CollectionType;
import org.eclipse.ocl.pivot.Comment;
import org.eclipse.ocl.pivot.Constraint;
import org.eclipse.ocl.pivot.DataType;
import org.eclipse.ocl.pivot.Element;
import org.eclipse.ocl.pivot.Enumeration;
import org.eclipse.ocl.pivot.Iteration;
import org.eclipse.ocl.pivot.LambdaType;
import org.eclipse.ocl.pivot.LanguageExpression;
import org.eclipse.ocl.pivot.Library;
import org.eclipse.ocl.pivot.MapType;
import org.eclipse.ocl.pivot.Model;
import org.eclipse.ocl.pivot.NamedElement;
import org.eclipse.ocl.pivot.Operation;
import org.eclipse.ocl.pivot.Parameter;
import org.eclipse.ocl.pivot.Precedence;
import org.eclipse.ocl.pivot.PrimitiveType;
import org.eclipse.ocl.pivot.Property;
import org.eclipse.ocl.pivot.TemplateBinding;
import org.eclipse.ocl.pivot.TemplateParameter;
import org.eclipse.ocl.pivot.TemplateParameterSubstitution;
import org.eclipse.ocl.pivot.TemplateSignature;
import org.eclipse.ocl.pivot.TemplateableElement;
import org.eclipse.ocl.pivot.TupleType;
import org.eclipse.ocl.pivot.internal.utilities.AS2Moniker;
import org.eclipse.ocl.pivot.utilities.Nameable;
import org.eclipse.xtext.util.Strings;
@SuppressWarnings("all")
public abstract class GenerateOCLCommon extends GenerateMetamodelWorkflowComponent
{
private final @NonNull Map<Element, String> element2moniker = new HashMap<Element, String>();
protected final @NonNull Comparator<Comment> commentComparator = new Comparator<Comment>()
{
public int compare(Comment o1, Comment o2) {
String m1 = o1.getBody();
String m2 = o2.getBody();
return m1.compareTo(m2);
}
};
protected final @NonNull Comparator<Element> monikerComparator = new Comparator<Element>()
{
public int compare(Element o1, Element o2) {
String m1 = getMoniker(o1);
String m2 = getMoniker(o2);
return m1.compareTo(m2);
}
};
protected final @NonNull Comparator<Nameable> nameableComparator = new Comparator<Nameable>()
{
public int compare(Nameable o1, Nameable o2) {
String m1 = o1.getName();
String m2 = o2.getName();
return m1.compareTo(m2);
}
};
protected @NonNull Set<CollectionType> getAllCollectionTypes(@NonNull Model root) {
Set<CollectionType> allElements = new HashSet<CollectionType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof CollectionType) {
allElements.add((CollectionType)eObject);
}
}
return allElements;
}
protected @NonNull Set<Enumeration> getAllEnumerations(@NonNull Model root) {
Set<Enumeration> allElements = new HashSet<Enumeration>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof Enumeration) {
allElements.add((Enumeration)eObject);
}
}
return allElements;
}
protected @NonNull Set<LambdaType> getAllLambdaTypes(@NonNull Model root) {
Set<LambdaType> allElements = new HashSet<LambdaType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof LambdaType) {
allElements.add((LambdaType)eObject);
}
}
return allElements;
}
protected @NonNull Set<MapType> getAllMapTypes(@NonNull Model root) {
Set<MapType> allElements = new HashSet<MapType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof MapType) {
allElements.add((MapType)eObject);
}
}
return allElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Package> getAllPackages(@NonNull Model root) {
Set<org.eclipse.ocl.pivot.Package> allElements = new HashSet<org.eclipse.ocl.pivot.Package>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof org.eclipse.ocl.pivot.Package) {
allElements.add((org.eclipse.ocl.pivot.Package)eObject);
}
}
List<org.eclipse.ocl.pivot.Package> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Package>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull Set<Precedence> getAllPrecedences(@NonNull Model root) {
Set<Precedence> allElements = new HashSet<Precedence>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof Precedence) {
allElements.add((Precedence)eObject);
}
}
return allElements;
}
protected @NonNull Set<PrimitiveType> getAllPrimitiveTypes(@NonNull Model root) {
Set<PrimitiveType> allElements = new HashSet<PrimitiveType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof PrimitiveType) {
allElements.add((PrimitiveType)eObject);
}
}
return allElements;
}
protected @NonNull List<Property> getAllProperties(@NonNull Model root) {
List<Property> allElements = new ArrayList<Property>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof Property) && !(eObject.eContainer() instanceof TupleType) &&
(((Property)eObject).getOwningClass() != null)) {
allElements.add((Property)eObject);
}
}
return allElements;
}
protected @NonNull Set<TemplateBinding> getAllTemplateBindings(@NonNull Model root) {
Set<TemplateBinding> allElements = new HashSet<TemplateBinding>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TemplateBinding) {
allElements.add((TemplateBinding)eObject);
}
}
return allElements;
}
protected @NonNull Set<TemplateSignature> getAllTemplateSignatures(@NonNull Model root) {
Set<TemplateSignature> allElements = new HashSet<TemplateSignature>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TemplateSignature) {
allElements.add((TemplateSignature)eObject);
}
}
return allElements;
}
protected @NonNull Set<TupleType> getAllTupleTypes(@NonNull Model root) {
Set<TupleType> allElements = new HashSet<TupleType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TupleType) {
allElements.add((TupleType)eObject);
}
}
return allElements;
}
protected @NonNull Set<org.eclipse.ocl.pivot.Class> getAllTypes(@NonNull Model root) {
Set<org.eclipse.ocl.pivot.Class> allElements = new HashSet<org.eclipse.ocl.pivot.Class>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof org.eclipse.ocl.pivot.Class) {
allElements.add((org.eclipse.ocl.pivot.Class)eObject);
}
}
return allElements;
}
protected @NonNull String getMoniker(@NonNull Element elem) {
String moniker = element2moniker.get(elem);
if (moniker == null) {
moniker = AS2Moniker.toString(elem);
element2moniker.put(elem, moniker);
}
return moniker;
}
protected @NonNull Collection<org.eclipse.ocl.pivot.Class> getOclTypes(@NonNull Model root) {
Set<org.eclipse.ocl.pivot.Class> allElements = new HashSet<org.eclipse.ocl.pivot.Class>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof org.eclipse.ocl.pivot.Class) && !(eObject instanceof Enumeration) && !(eObject instanceof LambdaType) &&
!(eObject instanceof CollectionType) && !(eObject instanceof PrimitiveType) &&
!(eObject instanceof MapType) && !(eObject instanceof TupleType) &&
(((org.eclipse.ocl.pivot.Class)eObject).isTemplateParameter() == null)) {
allElements.add((org.eclipse.ocl.pivot.Class)eObject);
}
}
return allElements;
}
protected @NonNull org.eclipse.ocl.pivot.Package getOrphanPackage(@NonNull org.eclipse.ocl.pivot.Package elem) {
return getOrphanPackage(getRootPackage(elem));
}
protected @NonNull org.eclipse.ocl.pivot.Package getOrphanPackage(@NonNull Model elem) {
for (org.eclipse.ocl.pivot.Package pkg : getAllPackages(elem)) {
if ("$$".equals(pkg.getName())) {
return pkg;
}
}
throw new IllegalStateException("Missing orphan package");
}
protected @NonNull String getPartialName(@NonNull Property property) {
org.eclipse.ocl.pivot.Class owningType = property.getOwningClass();
if (owningType == null) {
return "null_" + javaName(property);
}
String simpleName = partialName(owningType) + "_" + javaName(property);
if (!property.isIsImplicit()) {
return simpleName;
}
Property opposite = property.getOpposite();
if (opposite == null) {
return simpleName;
}
else {
return simpleName + "_" + javaName(opposite);
}
}
protected String getPrefixedSymbolName(@NonNull EObject elem, @NonNull String prefix) {
return NameQueries.getPrefixedSymbolName(prefix, elem);
}
protected ResourceSet getResourceSet() {
if (resourceSet == null) {
resourceSet = new ResourceSetImpl();
}
return resourceSet;
}
protected @NonNull Model getRootPackage(@Nullable org.eclipse.ocl.pivot.Package elem) {
EObject eObject = elem;
while (eObject != null) {
if (eObject instanceof Model) {
return (Model)eObject;
}
eObject = eObject.eContainer();
}
throw new IllegalStateException("Missing Root");
}
protected String getSignature(@NonNull NamedElement elem) {
EObject parent = elem.eContainer();
if (parent != null) {
return getSignature((NamedElement)parent) + "::" + elem.getName();
} else {
return elem.getName();
}
}
protected String getSignature(@NonNull Operation elem) {
EObject parent = elem.eContainer();
if (parent != null) {
return getSignature((NamedElement)parent) + "::" + elem.getName() + "()";
} else {
return elem.getName() + "()";
}
}
protected @NonNull List<Operation> getSortedCoercions(@NonNull Model root) {
Set<Operation> allElements = new HashSet<Operation>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof PrimitiveType) {
allElements.addAll(((PrimitiveType)eObject).getCoercions());
}
}
List<Operation> sortedElements = new ArrayList<Operation>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Operation> getSortedCoercions(@NonNull PrimitiveType type, @NonNull List<Operation> allCoercions) {
Set<Operation> allElements = new HashSet<Operation>();
for (Operation coercion : type.getCoercions()) {
if (allCoercions.contains(coercion)) {
allElements.add(coercion);
}
}
List<Operation> sortedElements = new ArrayList<Operation>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<CollectionType> getSortedCollectionTypes(@NonNull Model root) {
Set<CollectionType> allElements = new HashSet<CollectionType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof CollectionType) {
allElements.add((CollectionType)eObject);
}
}
return new ArrayList<CollectionType>(allElements);
}
protected @NonNull List<Element> getSortedCommentedElements(@NonNull Model root) {
Collection<org.eclipse.ocl.pivot.Class> oclTypes = getOclTypes(root);
Set<Element> allElements = new HashSet<Element>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof Element) && !(eObject instanceof Constraint) &&
!((eObject instanceof Property) && (((Property)eObject).getOwningClass() == null)) &&
!((eObject instanceof org.eclipse.ocl.pivot.Class) && !oclTypes.contains(eObject))) {
Element t = (Element)eObject;
if (t.getOwnedComments().size() > 0) {
allElements.add(t);
}
}
}
List<Element> sortedElements = new ArrayList<Element>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Comment> getSortedComments(@NonNull Element element) {
List<Comment> sortedElements = new ArrayList<Comment>(element.getOwnedComments());
Collections.sort(sortedElements, commentComparator);
return sortedElements;
}
protected @NonNull List<Enumeration> getSortedEnumerations(@NonNull Model root) {
Set<Enumeration> allElements = new HashSet<Enumeration>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof Enumeration) {
allElements.add((Enumeration)eObject);
}
}
List<Enumeration> sortedElements = new ArrayList<Enumeration>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Iteration> getSortedIterations(@NonNull Model root) {
Set<Iteration> allElements = new HashSet<Iteration>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof Iteration) {
allElements.add((Iteration)eObject);
}
}
List<Iteration> sortedElements = new ArrayList<Iteration>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Iteration> getSortedIterations(@NonNull org.eclipse.ocl.pivot.Class type, @NonNull List<Iteration> allIterations) {
Set<Iteration> allElements = new HashSet<Iteration>();
for (Operation operation : type.getOwnedOperations()) {
if (allIterations.contains(operation)) {
allElements.add((Iteration)operation);
}
}
List<Iteration> sortedElements = new ArrayList<Iteration>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<LambdaType> getSortedLambdaTypes(@NonNull Model root) {
Set<LambdaType> allElements = new HashSet<LambdaType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof LambdaType) {
allElements.add((LambdaType)eObject);
}
}
List<LambdaType> sortedElements = new ArrayList<LambdaType>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Library> getSortedLibraries(@NonNull Model root) {
Set<Library> allElements = new HashSet<Library>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof Library) {
allElements.add((Library)eObject);
}
}
List<Library> sortedElements = new ArrayList<Library>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<MapType> getSortedMapTypes(@NonNull Model root) {
Set<MapType> allElements = new HashSet<MapType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof MapType) {
allElements.add((MapType)eObject);
}
}
return new ArrayList<MapType>(allElements);
}
protected @NonNull List<org.eclipse.ocl.pivot.Class> getSortedOclTypes(@NonNull org.eclipse.ocl.pivot.Package pkg) {
List<org.eclipse.ocl.pivot.Class> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Class>(getOclTypes(getRootPackage(pkg)));
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Operation> getSortedOperations(@NonNull Model root) {
Set<Operation> allElements = new HashSet<Operation>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof Operation) && !(eObject instanceof Iteration) &&
!isEcoreConstraint((Operation)eObject)) {
allElements.add((Operation)eObject);
}
}
List<Operation> sortedElements = new ArrayList<Operation>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Operation> getSortedOperations(@NonNull org.eclipse.ocl.pivot.Class type, @NonNull List<Operation> allOperations) {
Set<Operation> allElements = new HashSet<Operation>();
for (Operation operation : type.getOwnedOperations()) {
if (allOperations.contains(operation)) {
allElements.add(operation);
}
}
List<Operation> sortedElements = new ArrayList<Operation>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Operation> getSortedOperationsWithPrecedence(@NonNull Model root) {
Set<Operation> allElements = new HashSet<Operation>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof Operation) && !(eObject instanceof Iteration) &&
!isEcoreConstraint((Operation)eObject)) {
Operation operation = (Operation)eObject;
if (!(operation instanceof Iteration) && !isEcoreConstraint(operation) &&
(operation.getPrecedence() != null)) {
allElements.add(operation);
}
}
}
List<Operation> sortedElements = new ArrayList<Operation>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Class> getSortedOwningTypes(@NonNull List<? extends Operation> operations) {
Set<org.eclipse.ocl.pivot.Class> allElements = new HashSet<org.eclipse.ocl.pivot.Class>();
for (Operation operation : operations) {
if (operation.getOwningClass() != null) {
allElements.add(operation.getOwningClass());
}
}
List<org.eclipse.ocl.pivot.Class> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Class>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Class> getSortedOwningTypes2(@NonNull List<? extends Property> properties) {
Set<org.eclipse.ocl.pivot.Class> allElements = new HashSet<org.eclipse.ocl.pivot.Class>();
for (Property property : properties) {
if (property.getOwningClass() != null) {
allElements.add(property.getOwningClass());
}
}
List<org.eclipse.ocl.pivot.Class> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Class>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Package> getSortedPackages(@NonNull Model root) {
Set<org.eclipse.ocl.pivot.Package> allElements = new HashSet<org.eclipse.ocl.pivot.Package>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof org.eclipse.ocl.pivot.Package) {
allElements.add((org.eclipse.ocl.pivot.Package)eObject);
}
}
List<org.eclipse.ocl.pivot.Package> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Package>(allElements);
Collections.sort(sortedElements, nameableComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Package> getSortedPackages(@NonNull org.eclipse.ocl.pivot.Package pkg) {
List<org.eclipse.ocl.pivot.Package> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Package>(pkg.getOwnedPackages());
Collections.sort(sortedElements, nameableComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Class> getSortedParameterTypes(@NonNull Model root) {
Set<org.eclipse.ocl.pivot.Class> allElements = new HashSet<org.eclipse.ocl.pivot.Class>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof org.eclipse.ocl.pivot.Class) {
org.eclipse.ocl.pivot.Class t = (org.eclipse.ocl.pivot.Class)eObject;
if (t.isTemplateParameter() != null) { // FIXME can never happen
allElements.add(t);
}
}
}
List<org.eclipse.ocl.pivot.Class> sortedElements = new ArrayList<org.eclipse.ocl.pivot.Class>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Precedence> getSortedPrecedences(@NonNull Library library) {
List<Precedence> sortedElements = new ArrayList<Precedence>(library.getOwnedPrecedences());
Collections.sort(sortedElements, nameableComparator);
return sortedElements;
}
protected @NonNull List<PrimitiveType> getSortedPrimitiveTypes(@NonNull Model root) {
Set<PrimitiveType> allElements = new HashSet<PrimitiveType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof PrimitiveType) {
allElements.add((PrimitiveType)eObject);
}
}
List<PrimitiveType> sortedElements = new ArrayList<PrimitiveType>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Property> getSortedProperties(@NonNull Model root) {
List<Property> allElements = new ArrayList<Property>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if ((eObject instanceof Property) && !(eObject.eContainer() instanceof TupleType) &&
(((Property)eObject).getOwningClass() != null)) {
allElements.add((Property)eObject);
}
}
List<Property> sortedElements = new ArrayList<Property>(allElements);
Collections.sort(sortedElements, OCLinEcoreTablesUtils.propertyComparator);
return sortedElements;
}
protected @NonNull List<Property> getSortedProperties(@NonNull org.eclipse.ocl.pivot.Class type) {
List<Property> sortedElements = new ArrayList<Property>(type.getOwnedProperties());
Collections.sort(sortedElements, OCLinEcoreTablesUtils.propertyComparator);
return sortedElements;
}
protected @NonNull List<Property> getSortedProperties(@NonNull org.eclipse.ocl.pivot.Class type, @NonNull List<Property> allProperties) {
Set<Property> allElements = new HashSet<Property>();
for (Property property : type.getOwnedProperties()) {
if (allProperties.contains(property)) {
allElements.add(property);
}
}
List<Property> sortedElements = new ArrayList<Property>(allElements);
Collections.sort(sortedElements, OCLinEcoreTablesUtils.propertyComparator);
if ("OCLExpression".equals(type.getName())) {
Collections.sort(sortedElements, OCLinEcoreTablesUtils.propertyComparator);
}
return sortedElements;
}
protected @NonNull List<TemplateParameter> getSortedTemplateParameters(@NonNull Model root) {
Set<TemplateParameter> allElements = new HashSet<TemplateParameter>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TemplateParameter) {
allElements.add((TemplateParameter)eObject);
}
}
List<TemplateParameter> sortedElements = new ArrayList<TemplateParameter>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<TemplateSignature> getSortedTemplateSignatures(@NonNull Model root) {
Set<TemplateSignature> allElements = new HashSet<TemplateSignature>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TemplateSignature) {
allElements.add((TemplateSignature)eObject);
}
}
List<TemplateSignature> sortedElements = new ArrayList<TemplateSignature>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected List<TemplateableElement> getSortedTemplateableElements(@NonNull Model root) {
Set<TemplateableElement> allElements = new HashSet<TemplateableElement>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TemplateableElement) {
TemplateableElement asTemplateableElement = (TemplateableElement)eObject;
if (asTemplateableElement.getOwnedBindings().size() > 0) {
allElements.add(asTemplateableElement);
}
}
}
List<TemplateableElement> sortedElements = new ArrayList<TemplateableElement>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<Property> getSortedTupleParts(@NonNull TupleType tupleType) {
List<Property> sortedElements = new ArrayList<Property>(tupleType.getOwnedProperties());
Collections.sort(sortedElements, nameableComparator);
return sortedElements;
}
protected @NonNull List<TupleType> getSortedTupleTypes(@NonNull Model root) {
Set<TupleType> allElements = new HashSet<TupleType>();
TreeIterator<EObject> tit = root.eAllContents();
while (tit.hasNext()) {
EObject eObject = tit.next();
if (eObject instanceof TupleType) {
allElements.add((TupleType)eObject);
}
}
List<TupleType> sortedElements = new ArrayList<TupleType>(allElements);
Collections.sort(sortedElements, monikerComparator);
return sortedElements;
}
protected @NonNull List<org.eclipse.ocl.pivot.Class> getSuperclassesInPackage(@NonNull org.eclipse.ocl.pivot.Class type) {
List<org.eclipse.ocl.pivot.Class> allElements = new ArrayList<org.eclipse.ocl.pivot.Class>();
for (org.eclipse.ocl.pivot.Class superclass : type.getSuperClasses()) {
if (getRootPackage(superclass.getOwningPackage()) == getRootPackage(type.getOwningPackage())) {
allElements.add(superclass);
}
}
return allElements;
}
protected @NonNull List<TemplateParameterSubstitution> getTemplateParameterSubstitutions(@NonNull TemplateableElement element) {
List<TemplateParameterSubstitution> allElements = new ArrayList<TemplateParameterSubstitution>();
for (TemplateBinding templateBinding : element.getOwnedBindings()) {
allElements.addAll(templateBinding.getOwnedSubstitutions());
}
return allElements;
}
protected String getSymbolName(@NonNull EObject elem) {
return NameQueries.getSymbolName(elem);
}
protected Boolean isEcoreConstraint(@NonNull Operation operation) {
for (Parameter p : operation.getOwnedParameters()) {
if (p.getName().equals("diagnostics") && p.getType().getName().equals("EDiagnosticChain")) {
return true;
}
}
return false;
}
protected @NonNull String javaName(@NonNull NamedElement element) {
return NameQueries.rawEncodeName(element.getName(), 0);
}
protected @NonNull String javaName(@Nullable Object element, @NonNull String string) {
return NameQueries.rawEncodeName(string, 0);
}
protected @NonNull String javaString(@NonNull Comment aComment) {
return Strings.convertToJavaString(aComment.getBody().trim());
}
protected @NonNull String javaString(@NonNull LanguageExpression anExpression) {
return Strings.convertToJavaString(anExpression.getBody().trim());
}
protected abstract /*@NonNull*/ String partialName(EObject element);
}