Source Code Cross Referenced for FormulaBoolConverter.java in  » Testing » KeY » de » uka » ilkd » key » parser » ocl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » KeY » de.uka.ilkd.key.parser.ocl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        //This file is part of KeY - Integrated Deductive Software Design
009:        //Copyright (C) 2001-2005 Universitaet Karlsruhe, Germany
010:        //                      Universitaet Koblenz-Landau, Germany
011:        //                      Chalmers University of Technology, Sweden
012:        //
013:        //The KeY system is protected by the GNU General Public License. 
014:        //See LICENSE.TXT for details.
015:        //
016:        //
017:
018:        package de.uka.ilkd.key.parser.ocl;
019:
020:        import de.uka.ilkd.key.java.Services;
021:        import de.uka.ilkd.key.java.abstraction.PrimitiveType;
022:        import de.uka.ilkd.key.java.expression.literal.BooleanLiteral;
023:        import de.uka.ilkd.key.logic.*;
024:        import de.uka.ilkd.key.logic.op.ListOfLogicVariable;
025:        import de.uka.ilkd.key.logic.op.LogicVariable;
026:        import de.uka.ilkd.key.logic.op.SLListOfLogicVariable;
027:        import de.uka.ilkd.key.logic.sort.Sort;
028:
029:        /**
030:         * Converts between formulas and boolean terms.
031:         */
032:        class FormulaBoolConverter {
033:            private static final String VARNAME_PREFIX = "_oclFBC";
034:            private static final TermBuilder tb = TermBuilder.DF;
035:
036:            private final NamespaceSet nss;
037:            private final Term trueLitTerm;
038:            private final Sort boolSort;
039:
040:            private int varCounter = 0;
041:            private ListOfTerm termsToAdd = SLListOfTerm.EMPTY_LIST;
042:            private ListOfLogicVariable introducedVars = SLListOfLogicVariable.EMPTY_LIST;
043:
044:            /**
045:             * @param serv used for adding the created variables to the 
046:             * appropriate namespace
047:             * 
048:             */
049:            public FormulaBoolConverter(Services serv, NamespaceSet nss) {
050:                this .nss = nss;
051:                trueLitTerm = serv.getTypeConverter().convertToLogicElement(
052:                        BooleanLiteral.TRUE);
053:                boolSort = serv.getJavaInfo().getKeYJavaType(
054:                        PrimitiveType.JAVA_BOOLEAN).getSort();
055:            }
056:
057:            /**
058:             * Sets the counter which is used for naming the introduced variables.
059:             */
060:            public void setVariableCounter(int value) {
061:                varCounter = value;
062:            }
063:
064:            /**
065:             * Returns the current value of the counter which is used for naming the 
066:             * introduced variables.
067:             */
068:            public int getVariableCounter() {
069:                return varCounter;
070:            }
071:
072:            /**
073:             * Adds axiomatisations for all variables which have been introduced so far 
074:             * to a term. 
075:             * 
076:             */
077:            public Term addAxioms(Term term) {
078:                Term result = term;
079:
080:                Term termToAdd = null;
081:                if (termsToAdd.size() == 1) {
082:                    termToAdd = termsToAdd.head();
083:                } else if (termsToAdd.size() > 1) {
084:                    termToAdd = tb.and(termsToAdd.toArray());
085:                }
086:
087:                if (termToAdd != null) {
088:                    Term impTerm = tb.imp(termToAdd, result);
089:                    result = tb.all(introducedVars.toArray(), impTerm);
090:                }
091:
092:                return result;
093:            }
094:
095:            /**
096:             * Converts a term to a formula, if it is boolean; otherwise, just returns 
097:             * the term unchanged.
098:             */
099:            public Term convertBoolToFormula(Term term) {
100:                Term result = term;
101:
102:                if (term != null && term.sort() == boolSort) {
103:                    result = tb.equals(term, trueLitTerm);
104:                }
105:
106:                return result;
107:            }
108:
109:            /**
110:             * Converts a term to a boolean term, if it is a formula; otherwise, just 
111:             * returns the term unchanged. For the conversion, a logic variable is
112:             * introduced, which must later be axiomatised by calling addAxioms(). 
113:             */
114:            public Term convertFormulaToBool(Term term) {
115:                Term result = term;
116:
117:                if (term != null && term.sort() == Sort.FORMULA) {
118:                    Name name = new Name(VARNAME_PREFIX + varCounter++);
119:                    LogicVariable var = new LogicVariable(name, boolSort);
120:
121:                    nss.variables().add(var);
122:                    introducedVars = introducedVars.prepend(var);
123:
124:                    Term varTerm = tb.var(var);
125:                    Term varTrueTerm = tb.equals(varTerm, trueLitTerm);
126:                    Term termToAdd = tb.equiv(term, varTrueTerm);
127:
128:                    termsToAdd = termsToAdd.append(termToAdd);
129:
130:                    result = varTerm;
131:                }
132:
133:                return result;
134:            }
135:
136:            /**
137:             * Converts those terms in a list which are formulas to boolean 
138:             * terms, and leaves the others unchanged.
139:             */
140:            public ListOfTerm convertFormulasToBool(ListOfTerm list) {
141:                ListOfTerm result = SLListOfTerm.EMPTY_LIST;
142:
143:                IteratorOfTerm it = list.iterator();
144:                while (it.hasNext()) {
145:                    result = result.append(convertFormulaToBool(it.next()));
146:                }
147:
148:                return result;
149:            }
150:
151:            /**
152:             * Converts those terms in a list of OCLEntities which are formulas 
153:             * to boolean terms, and leaves the others unchanged.
154:             */
155:            public ListOfTerm convertFormulasToBool(ListOfOCLEntity list) {
156:                ListOfTerm result = SLListOfTerm.EMPTY_LIST;
157:
158:                IteratorOfOCLEntity it = list.iterator();
159:                while (it.hasNext()) {
160:                    result = result.append(it.next().getTerm());
161:                }
162:
163:                return convertFormulasToBool(result);
164:            }
165:
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.