001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.casetool;
012:
013: import de.uka.ilkd.key.java.JavaInfo;
014: import de.uka.ilkd.key.java.Services;
015: import de.uka.ilkd.key.java.abstraction.KeYJavaType;
016:
017: public class UMLInfo {
018: private final Services services;
019: private final ListOfAssociation allAssociations;
020:
021: public UMLInfo(Services services, ListOfAssociation allAssociations) {
022: this .services = services;
023: this .allAssociations = allAssociations;
024: }
025:
026: /**
027: * Returns all associations with at least one end in the passed type
028: * or one of its supertypes.
029: */
030: public ListOfAssociation getAssociations(KeYJavaType kjt) {
031: assert kjt != null;
032: ListOfAssociation result = SLListOfAssociation.EMPTY_LIST;
033:
034: IteratorOfAssociation it = allAssociations.iterator();
035: while (it.hasNext()) {
036: Association assoc = it.next();
037:
038: IteratorOfAssociationEnd it2 = assoc.getEnds().iterator();
039: while (it2.hasNext()) {
040: AssociationEnd end = it2.next();
041: String endClassName = end.getModelClass()
042: .getFullClassName();
043: KeYJavaType endKjt = services.getJavaInfo()
044: .getKeYJavaTypeByClassName(endClassName);
045:
046: if (services.getJavaInfo().isSubtype(kjt, endKjt)) {
047: result = result.prepend(assoc);
048: break;
049: }
050: }
051: }
052:
053: return result;
054: }
055:
056: /**
057: * Returns all binary associations with at least one end in the passed type,
058: * and whose role name on the other side is the passed string.
059: */
060: public ListOfAssociation getAssociations(KeYJavaType kjt,
061: String qualifier) {
062: ListOfAssociation result = SLListOfAssociation.EMPTY_LIST;
063:
064: //iterate over all associations for the desired class
065: ListOfAssociation classAssocs = getAssociations(kjt);
066: IteratorOfAssociation it = classAssocs.iterator();
067: while (it.hasNext()) {
068: Association assoc = it.next();
069:
070: ListOfAssociationEnd ends = assoc.getEnds();
071: if (ends.size() != 2) {
072: continue;
073: }
074:
075: //identify possible "other side" ends
076: JavaInfo javaInfo = services.getJavaInfo();
077: String end1ClassName = ends.head().getModelClass()
078: .getFullClassName();
079: String end2ClassName = ends.tail().head().getModelClass()
080: .getFullClassName();
081: KeYJavaType end1Kjt = javaInfo
082: .getTypeByClassName(end1ClassName);
083: KeYJavaType end2Kjt = javaInfo
084: .getTypeByClassName(end2ClassName);
085: ListOfAssociationEnd targetEnds = SLListOfAssociationEnd.EMPTY_LIST;
086: if (javaInfo.isSubtype(kjt, end1Kjt)) {
087: targetEnds = targetEnds.prepend(ends.tail().head());
088: }
089: if (javaInfo.isSubtype(kjt, end2Kjt)) {
090: targetEnds = targetEnds.prepend(ends.head());
091: }
092: assert !targetEnds.isEmpty();
093:
094: //check if one of those ends has the desired role name
095: IteratorOfAssociationEnd it2 = targetEnds.iterator();
096: while (it2.hasNext()) {
097: AssociationEnd end = it2.next();
098: if (end.getRoleName().toString().equals(qualifier)) {
099: result = result.prepend(assoc);
100: break;
101: }
102: }
103: }
104:
105: return result;
106: }
107: }
|