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: package de.uka.ilkd.key.java;
11:
12: import recoder.java.declaration.ClassDeclaration;
13: import recoder.java.declaration.TypeDeclaration;
14: import recoder.list.ImportArrayList;
15: import recoder.list.TypeDeclarationArrayList;
16: import recoder.list.TypeDeclarationMutableList;
17: import de.uka.ilkd.key.java.recoderext.ImplicitIdentifier;
18: import de.uka.ilkd.key.java.recoderext.KeYCrossReferenceServiceConfiguration;
19:
20: /** this class stores recoder related contextinformation used to parse
21: * in program parts in which non-declared variables are used
22: */
23: class Context {
24:
25: private recoder.java.CompilationUnit compilationUnitContext;
26: private ClassDeclaration classContext;
27: public static final String PARSING_CONTEXT_CLASS_NAME = "<KeYSpecialParsing>";
28:
29: /** creates a new context object
30: * @param compilationUnitContext a
31: * recoder.java.CompilationUnit
32: * @param classContext a recoder.java.declaration.ClassDeclaration
33: */
34: public Context(KeYCrossReferenceServiceConfiguration servConf,
35: recoder.java.CompilationUnit compilationUnitContext,
36: ClassDeclaration classContext) {
37: this .compilationUnitContext = compilationUnitContext;
38: this .classContext = classContext;
39: }
40:
41: /** creates a new context object
42: * @param compilationUnitContext a
43: * recoder.java.declaration.CompilationUnit
44: */
45: public Context(KeYCrossReferenceServiceConfiguration servConf,
46: recoder.java.CompilationUnit compilationUnitContext) {
47: this (servConf, compilationUnitContext,
48: createClassDecl(servConf));
49: }
50:
51: /** creates a new context object
52: * @param classContext a recoder.java.declaration.ClassDeclaration
53: */
54: public Context(KeYCrossReferenceServiceConfiguration servConf,
55: ClassDeclaration classContext) {
56: this (servConf, createCompUnit(classContext), classContext);
57: }
58:
59: private static recoder.java.CompilationUnit createCompUnit(
60: ClassDeclaration classContext) {
61: recoder.java.CompilationUnit cu = new recoder.java.CompilationUnit(
62: null, new ImportArrayList(0), inList(classContext));
63: // cu.setDataLocation(new ContextDataLocation("tmp"+counter++));
64: return cu;
65: }
66:
67: public static TypeDeclarationMutableList inList(TypeDeclaration td) {
68: TypeDeclarationMutableList tdml = new TypeDeclarationArrayList();
69: tdml.add(td);
70: return tdml;
71: }
72:
73: /** returns the compilation context */
74: public recoder.java.CompilationUnit getCompilationUnitContext() {
75: return compilationUnitContext;
76: }
77:
78: /** returns the compilation context */
79: public ClassDeclaration getClassContext() {
80: return classContext;
81: }
82:
83: private static recoder.java.declaration.ClassDeclaration createClassDecl(
84: KeYCrossReferenceServiceConfiguration servConf) {
85: return servConf.getProgramFactory().createClassDeclaration(
86: null,
87: new ImplicitIdentifier(PARSING_CONTEXT_CLASS_NAME),
88: null, null, null);
89: }
90:
91: }
|