use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class DesignServices method getNbDependencies.
/**
* Returns the number of dependencies between 2 namespaces
* @param source
* @param target
* @return
*/
public static int getNbDependencies(Namespace source, Namespace target) {
int count = 0;
for (Type type : source.getTypes()) {
if (type instanceof StructuredType) {
StructuredType structuredType = (StructuredType) type;
// Check inheritance
StructuredType supertype = structuredType.getSupertype();
if (supertype != null && target.equals(supertype.eContainer())) {
count += 1;
}
// Check references
for (Reference reference : structuredType.getOwnedReferences()) {
StructuredType referencedType = reference.getReferencedType();
if (referencedType != null && target.equals(referencedType.eContainer())) {
count += 1;
}
}
// Check attributes
for (Attribute attribute : structuredType.getOwnedAttributes()) {
DataType datatype = attribute.getType();
if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
count += 1;
}
}
}
}
return count;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class ReferencesService method getOppositeReferences.
public List<Reference> getOppositeReferences(DSemanticDiagram diagram) {
Collection<StructuredType> structuredTypes = DesignServices.getDisplayedStructuredTypes(diagram);
Set<Reference> references = Sets.newLinkedHashSet();
for (StructuredType structuredType : structuredTypes) {
references.addAll(structuredType.getOwnedReferences());
}
Map<String, Reference> map = new HashMap<String, Reference>();
for (Reference ref : references) {
if (ref.getOppositeOf() != null) {
String key1 = ref.getOppositeOf().hashCode() + "" + ref.hashCode();
String key2 = ref.hashCode() + "" + ref.getOppositeOf().hashCode();
if (map.get(key1) == null && map.get(key2) == null) {
map.put(key1, ref);
}
}
}
return new ArrayList<Reference>(map.values());
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllReferencedStructuredTypes.
public Collection<StructuredType> getAllReferencedStructuredTypes(Namespace namespace, DSemanticDiagram diagram) {
Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
types.retainAll(namespace.getTypes());
Collection<StructuredType> referencedTypes = new HashSet<StructuredType>();
for (StructuredType existingType : types) {
referencedTypes.add(existingType.getSupertype());
for (Reference reference : existingType.getOwnedReferences()) {
referencedTypes.add(reference.getReferencedType());
}
referencedTypes.addAll(getAllReferencingStructuredTypes(existingType));
}
referencedTypes.removeAll(namespace.getTypes());
return referencedTypes;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllStructuredTypes.
public Collection<StructuredType> getAllStructuredTypes(EObject context, String typeName) {
Collection<StructuredType> types = new ArrayList<StructuredType>();
Collection<Resource> resources = ModelServices.getAllResources(context);
for (Resource resource : resources) {
for (EObject object : resource.getContents()) {
if (object instanceof ObeoDSMObject) {
types.addAll(internalGetAllChildrenStructuredTypes((ObeoDSMObject) object, typeName));
}
}
}
return types;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllSelectableExternalStructuredTypesWithAncestors.
public Collection<EObject> getAllSelectableExternalStructuredTypesWithAncestors(Namespace namespace, DSemanticDiagram diagram, String typeName) {
Collection<EObject> result = new HashSet<EObject>();
Collection<StructuredType> selectableTypes = getAllSelectableExternalStructuredTypes(namespace, diagram, typeName);
result.addAll(selectableTypes);
for (StructuredType selectableType : selectableTypes) {
result.addAll(ModelServices.getAncestors(selectableType));
}
return result;
}
Aggregations