Skip to content
Snippets Groups Projects
Commit 8eb1a9bc authored by Luca Cristoforetti's avatar Luca Cristoforetti
Browse files

Further refinement of API

parent e4c209a6
No related branches found
No related tags found
No related merge requests found
......@@ -23,17 +23,7 @@ public class ModelAccessUtil {
rootcontent = element.eContents();
}
if (filter != null) {
Collection<EObject> filtered = new ArrayList<EObject>();
for (EObject object : rootcontent) {
if (filter.test(object)) {
filtered.add(object);
}
}
return filtered;
} else {
return rootcontent;
}
return applyFilterOnList(rootcontent, filter);
}
throw new Exception("Root element does not exist.");
}
......@@ -75,7 +65,6 @@ public class ModelAccessUtil {
}
return element;
}
}
package org.polarsys.chess.contracts.profile.chesscontract.ModelUtil;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Stereotype;
import org.polarsys.chess.contracts.profile.chesscontract.util.EntityUtil;
public class SpecificElementUtil {
public SpecificElementUtil() {
// TODO Auto-generated constructor stub
}
public static Collection<EObject> getOrderedEnumerations(Package owner, boolean recursive) throws Exception {
return UmlElementAccessUtil.getEnumerations(owner, recursive, new OrderedEnumerations());
}
}
class OrderedEnumerations implements Filter {
@Override
public boolean test(Object o) {
if (o instanceof Enumeration) {
final Enumeration enumeration = (Enumeration) o;
/*
Stereotype enumStereotype = EntityUtil.getInstance().findStereotype(enumeration.getNearestPackage(), CATEGORIZED_ENUM);
CategorizedEnum categorizedEnum = (CategorizedEnum) enumeration.getStereotypeApplication(enumStereotype);
if (categorizedEnum != null && categorizedEnum.getCategory() = EnumKind.ORDERED) {
return true;
}
*/
}
return false;
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ import org.eclipse.uml2.uml.Type;
public class UmlElementAccessUtil {
// Solution based on ECore
public Collection<EObject> getEnumerations(Package owner, boolean recursive, Filter filter) throws Exception {
public static Collection<EObject> getEnumerations(Package owner, boolean recursive, Filter filter) throws Exception {
Collection<EObject> enumerations = ModelAccessUtil.getElementChildren(owner, recursive, new EnumerationsFilter());
......@@ -23,7 +23,7 @@ public class UmlElementAccessUtil {
}
// Solution based on UML API
public Collection<EObject> getEnumerationsUML(Package owner, boolean recursive, Filter filter) throws Exception {
public static Collection<EObject> getEnumerationsUML(Package owner, boolean recursive, Filter filter) throws Exception {
final Collection<EObject> enumerations = new ArrayList<EObject>();
if (recursive) {
......@@ -46,19 +46,19 @@ public class UmlElementAccessUtil {
}
// Solution based on UML API
public Operation getOperation(Class owner, String name, boolean ignoreCase, Filter filter) {
public static Operation getOperation(Class owner, String name, boolean ignoreCase, Filter filter) {
final Operation operation = owner.getOperation(name, null, null, ignoreCase);
return ModelAccessUtil.applyFilterOnElement(operation, filter);
}
// Implementation using generic isElement()
public boolean isOperation(Element element) {
public static boolean isOperation(Element element) {
return ModelAccessUtil.isElement(element, new OperationsFilter());
}
// Alternative Implementation
public boolean isEnumeration(Element element) {
public static boolean isEnumeration(Element element) {
return (ModelAccessUtil.applyFilterOnElement(element, new EnumerationsFilter()) != null);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment