01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.logic.op.oclop;
12:
13: import de.uka.ilkd.key.logic.Name;
14: import de.uka.ilkd.key.logic.Term;
15: import de.uka.ilkd.key.logic.op.TermSymbol;
16: import de.uka.ilkd.key.logic.sort.Sort;
17: import de.uka.ilkd.key.logic.sort.oclsort.CollectionSort;
18: import de.uka.ilkd.key.logic.sort.oclsort.OclSort;
19:
20: /**
21: * Represents the OCL operations: asSet(), asBag(), asSequence()
22: */
23: public class OclCollectionConversion extends TermSymbol {
24:
25: private int collectionKind;
26:
27: public OclCollectionConversion(Name name, int collectionKind) {
28: super (name, OclSort.COLLECTION_OF_OCLANY);
29: this .collectionKind = collectionKind;
30: }
31:
32: /** @return arity of the Function as int */
33: public int arity() {
34: return 1;
35: }
36:
37: /*
38: * checks if the given term is syntactically valid at its top
39: * level assumed the top level operator were this, i.e. if the
40: * direct subterms can be subterms of a term with this top level
41: * operator, the method returns true. Furthermore, it is checked
42: * that no variables are bound for none of the subterms.
43: * @param the Term to be checked.
44: * @return true iff the given term has
45: * subterms that are suitable for this function.
46: */
47: public boolean validTopLevel(Term term) {
48: if (term.arity() != arity()) {
49: return false;
50: }
51: if (!(term.sub(0).sort() instanceof CollectionSort)) {
52: return false;
53: }
54: return true;
55: }
56:
57: public Sort sort(Term[] subTerm) {
58: if (subTerm.length != arity()) {
59: throw new IllegalArgumentException(
60: "Cannot determine sort of "
61: + "invalid term (Wrong arity).");
62: }
63: if (!(subTerm[0].sort() instanceof CollectionSort)) {
64: throw new IllegalArgumentException(
65: "Cannot determine sort of "
66: + "invalid term (First argument must be a Collection).");
67: }
68:
69: OclSort elemSort = ((CollectionSort) subTerm[0].sort())
70: .getElemSort();
71: return CollectionSort.getCollectionSort(this .collectionKind,
72: elemSort);
73: }
74:
75: public String toString() {
76: return (name() + ":" + OclSort.COLLECTION_OF_OCLANY);
77: }
78:
79: public String proofToString() {
80: String s = OclSort.COLLECTION_OF_OCLANY + " " + name();
81: s += "(" + OclSort.COLLECTION_OF_OCLANY;
82: s += ");\n";
83: return s;
84: }
85: }
|