Source Code Cross Referenced for UMLOCLJavaModel.java in  » Testing » KeY » de » uka » ilkd » key » casetool » 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.casetool 
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:        //
009:
010:        package de.uka.ilkd.key.casetool;
011:
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.util.Iterator;
015:
016:        import recoder.ServiceConfiguration;
017:        import recoder.abstraction.ClassType;
018:        import recoder.abstraction.Field;
019:        import recoder.abstraction.Method;
020:
021:        import recoder.io.DefaultSourceFileRepository;
022:        import recoder.io.SourceFileRepository;
023:        import recoder.java.CompilationUnit;
024:        import recoder.java.declaration.TypeDeclaration;
025:        import recoder.list.*;
026:        import recoder.service.DefaultSourceInfo;
027:        import recoder.util.FileCollector;
028:        import tudresden.ocl.check.types.Type;
029:        import de.uka.ilkd.key.java.Services;
030:
031:        /**
032:         * @deprecated
033:         */
034:        public class UMLOCLJavaModel implements  UMLOCLModel {
035:            //debug flag
036:            private static final boolean DEBUG = false;
037:
038:            protected SourceFileRepository sfr;
039:            protected String projectRoot;
040:            protected HashMapOfClassifier classifiers;
041:            protected HashMapOfAssociations associations;
042:            protected JavaOCLTypeMap typeMap = null;
043:
044:            private UMLOCLJavaModel() {
045:            }
046:
047:            /**@deprecated */
048:            public UMLOCLJavaModel(String projectRoot) {
049:                this .projectRoot = projectRoot;
050:                this .projectRoot = new File(projectRoot).getAbsolutePath();
051:                this .classifiers = new HashMapOfClassifier();
052:                this .associations = new HashMapOfAssociations();
053:                initRecoder();
054:            }
055:
056:            public UMLOCLJavaModel(Services services, String projectRoot) {
057:                this .projectRoot = projectRoot;
058:                this .projectRoot = new File(projectRoot).getAbsolutePath();
059:                this .classifiers = new HashMapOfClassifier();
060:                this .associations = new HashMapOfAssociations();
061:                if (services != null) {
062:                    ServiceConfiguration crsc = services.getJavaInfo()
063:                            .getKeYProgModelInfo().getServConf();
064:                    sfr = crsc.getSourceFileRepository();
065:                } else {
066:                    initRecoder();
067:                }
068:            }
069:
070:            protected JavaOCLTypeMap getJavaOCLTypeMap(
071:                    HashMapOfClassifier classifier) {
072:
073:                return new JavaOCLTypeMap(classifiers);
074:            }
075:
076:            public HashMapOfClassifier getUMLOCLClassifiers() {
077:
078:                final CompilationUnitList cuList = sfr.getCompilationUnits();
079:
080:                // find classes
081:                findAllClasses(cuList);
082:
083:                if (DEBUG) {
084:                    printClasses();
085:                }
086:
087:                typeMap = getJavaOCLTypeMap(classifiers);
088:
089:                // find attributes and methods	
090:                for (int i = 0, cuListSize = cuList.size(); i < cuListSize; i++) {
091:                    final CompilationUnit unit = cuList.getCompilationUnit(i);
092:                    for (int j = 0, typeCount = unit.getTypeDeclarationCount(); j < typeCount; j++) {
093:
094:                        final TypeDeclaration td = unit.getTypeDeclarationAt(j);
095:                        findAllAttributes(td);
096:                        findAllMethods(td);
097:
098:                    }
099:                }
100:
101:                if (DEBUG) {
102:                    printTypeMembers();
103:                }
104:
105:                return classifiers;
106:            }
107:
108:            protected UMLOCLClassifier createUMLOCLClassifier(ClassType ct) {
109:                return new UMLOCLClassifier(ct.getName(), ct.getFullName());
110:            }
111:
112:            private UMLOCLClassifier ensureUMLOCLClassifier(ClassType ct) {
113:                UMLOCLClassifier cls = classifiers.getClassifier(ct.getName());
114:                if (cls == null) {
115:                    cls = createUMLOCLClassifier(ct);
116:                    classifiers.putClassifier(ct.getName(), cls);
117:                }
118:                return cls;
119:            }
120:
121:            protected void findAllClasses(CompilationUnitList cuList) {
122:                for (int i = 0, cuListSize = cuList.size(); i < cuListSize; i++) {
123:                    final CompilationUnit pa = cuList.getCompilationUnit(i);
124:
125:                    for (int j = 0, tdCount = pa.getTypeDeclarationCount(); j < tdCount; j++) {
126:                        final TypeDeclaration td = pa.getTypeDeclarationAt(j);
127:                        final UMLOCLClassifier cls = ensureUMLOCLClassifier(td);
128:                        // now find all supertypes of this class
129:                        final ClassTypeList super types = td.getAllSupertypes();
130:                        for (int k = 1, supSize = super types.size(); k < supSize; k++) {
131:                            final ClassType st = super types.getClassType(k);
132:                            cls.addSupertype(st.getName(),
133:                                    ensureUMLOCLClassifier(st));
134:                        }
135:                    }
136:                }
137:            }
138:
139:            private void findAllMethods(TypeDeclaration td) {
140:
141:                final UMLOCLClassifier cls = classifiers
142:                        .getClassifierByFullName(td.getFullName());
143:                final MethodList ml = td.getAllMethods();
144:                for (int l = 0, mlSize = ml.size(); l < mlSize; l++) {
145:                    final Method meth = ml.getMethod(l);
146:                    recoder.abstraction.Type retType = meth.getReturnType();
147:                    tudresden.ocl.check.types.Type ret2 = typeMap.getTypeFor(
148:                            retType, classifiers);
149:
150:                    if (ret2 == null) {
151:                        ret2 = new UMLOCLClassifier(retType.getName(), retType
152:                                .getFullName());
153:                        classifiers.putClassifier(retType.getName(),
154:                                (UMLOCLClassifier) ret2);
155:                    }
156:
157:                    final TypeList ctl = meth.getSignature();
158:                    final Type[] paramsArray = new Type[ctl.size()];
159:                    final StringBuffer methodSignatureStr = new StringBuffer(
160:                            meth.getName());
161:                    methodSignatureStr.append("(");
162:
163:                    for (int k = 0, ctlSize = ctl.size(); k < ctlSize; k++) {
164:                        final recoder.abstraction.Type par = ctl.getType(k);
165:                        final String parTypeFullName = par.getFullName();
166:
167:                        methodSignatureStr.append(parTypeFullName);
168:                        if (k < ctlSize - 1) {
169:                            methodSignatureStr.append(",");
170:                        }
171:
172:                        paramsArray[k] = typeMap.getTypeFor(par, classifiers);
173:                        if (paramsArray[k] == null) {
174:                            classifiers.putClassifier(par.getName(),
175:                                    new UMLOCLClassifier(par.getName(),
176:                                            parTypeFullName));
177:                            paramsArray[k] = typeMap.getTypeFor(par,
178:                                    classifiers);
179:                        }
180:                    }
181:                    methodSignatureStr.append(")");
182:                    final String name = methodSignatureStr.toString();
183:
184:                    final UMLOCLBehaviouralFeature behaviouralFeature = (retType == null) ? new UMLOCLBehaviouralFeature(
185:                            name, paramsArray)
186:                            : new UMLOCLBehaviouralFeature(name, ret2,
187:                                    paramsArray);
188:                    cls.addFeature(name, behaviouralFeature);
189:                }
190:            }
191:
192:            private void findAllAttributes(TypeDeclaration td) {
193:                final FieldList fl = td.getAllFields();
194:                final UMLOCLClassifier clf = classifiers
195:                        .getClassifierByFullName(td.getFullName());
196:                if (clf == null) {
197:                    throw new IllegalStateException("Classifier not found: "
198:                            + td.getFullName());
199:                }
200:                for (int l = 0, flSize = fl.size(); l < flSize; l++) {
201:                    final Field field = fl.getField(l);
202:                    final recoder.abstraction.Type fieldType = field.getType();
203:
204:                    Type type = typeMap.getTypeFor(fieldType, classifiers);
205:                    if (type == null) {
206:                        type = new UMLOCLClassifier(fieldType.getName(),
207:                                fieldType.getFullName());
208:                        classifiers.putClassifier(fieldType.getName(),
209:                                (UMLOCLClassifier) type);
210:                    }
211:                    clf.addFeature(field.getName(),
212:                            new UMLOCLStructuralFeature(field.getName(), type));
213:                }
214:            }
215:
216:            // replace recoder2key by pure recoder 
217:            private void initRecoder() {
218:                de.uka.ilkd.key.java.Services services = new de.uka.ilkd.key.java.Services();
219:                de.uka.ilkd.key.java.Recoder2KeY r2k = new de.uka.ilkd.key.java.Recoder2KeY(
220:                        services, new de.uka.ilkd.key.logic.NamespaceSet());
221:                // comment this if OCLDL does not needs to access the java classes	
222:                r2k.parseSpecialClasses();
223:                ServiceConfiguration crsc = services.getJavaInfo()
224:                        .getKeYProgModelInfo().getServConf();
225:                sfr = crsc.getSourceFileRepository();
226:                new DefaultSourceInfo(crsc);
227:                StringArrayList files = collectJavaFiles(projectRoot);
228:                for (int i = 0, sz = files.size(); i < sz; i++) {
229:                    final String path = files.getString(i);
230:                    if (path != null) {
231:                        try {
232:                            sfr.getCompilationUnitFromFile(path);
233:                        } catch (recoder.ParserException e) {
234:                            System.out.println("Exception occurred while "
235:                                    + "reading in Java sources: " + e);
236:                        }
237:                    }
238:                }
239:            }
240:
241:            private StringArrayList collectJavaFiles(String dir) {
242:                final FileCollector col = new FileCollector(dir);
243:                final StringArrayList list = new StringArrayList();
244:                while (col
245:                        .next(DefaultSourceFileRepository.JAVA_FILENAME_FILTER)) {
246:                    String path;
247:                    try {
248:                        path = col.getFile().getCanonicalPath();
249:                    } catch (IOException ioe) {
250:                        path = col.getFile().getAbsolutePath();
251:                    }
252:                    list.add(path);
253:                }
254:                return list;
255:            }
256:
257:            // Debugging stuff
258:            private void printClasses() {
259:                System.out.println("------------- found the following "
260:                        + "classes ------------------");
261:                Iterator it = classifiers.values().iterator();
262:                UMLOCLClassifier c;
263:                while (it.hasNext()) {
264:                    c = (UMLOCLClassifier) it.next();
265:                    System.out.println(c.getName());
266:                }
267:            }
268:
269:            private void printTypeMembers() {
270:                System.out.println("------------- found the following "
271:                        + "methods and attributes ------------------");
272:                Iterator cit = classifiers.values().iterator();
273:                UMLOCLClassifier c;
274:                while (cit.hasNext()) {
275:                    c = (UMLOCLClassifier) cit.next();
276:                    HashMapOfFeatures feat = c.features();
277:                    Iterator it = feat.values().iterator();
278:                    UMLOCLFeature f;
279:                    while (it.hasNext()) {
280:                        f = (UMLOCLFeature) it.next();
281:                        if (f instanceof  UMLOCLBehaviouralFeature)
282:                            System.out
283:                                    .println("Method    " + c.getName()
284:                                            + " :: " + f.getName() + "  "
285:                                            + f.getType());
286:                        if (f instanceof  UMLOCLStructuralFeature)
287:                            System.out.println("Attribute " + c.getName()
288:                                    + " :: " + f.getName());
289:                    }
290:                }
291:            }
292:
293:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.