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.java.declaration;
012:
013: import de.uka.ilkd.key.java.*;
014: import de.uka.ilkd.key.java.abstraction.*;
015: import de.uka.ilkd.key.java.expression.Literal;
016: import de.uka.ilkd.key.java.expression.literal.NullLiteral;
017: import de.uka.ilkd.key.logic.ProgramElementName;
018: import de.uka.ilkd.key.util.ExtList;
019:
020: /**
021: * Type declaration.
022: * taken from COMPOST and changed to achieve an immutable structure
023: */
024: public abstract class TypeDeclaration extends JavaDeclaration implements
025: NamedProgramElement, MemberDeclaration,
026: TypeDeclarationContainer, ClassType, VariableScope, TypeScope {
027:
028: /**
029: * Name.
030: */
031:
032: protected final ProgramElementName name;
033:
034: /**
035: * Full name.
036: */
037: protected final ProgramElementName fullName;
038:
039: /**
040: * Members.
041: */
042: protected final ArrayOfMemberDeclaration members;
043:
044: protected final boolean parentIsInterfaceDeclaration;
045:
046: protected final boolean isLibrary;
047:
048: /**
049: * Type declaration.
050: */
051:
052: public TypeDeclaration() {
053: this .name = null;
054: this .fullName = null;
055: this .members = null;
056: this .parentIsInterfaceDeclaration = false;
057: this .isLibrary = false;
058: }
059:
060: /**
061: * Type declaration.
062: * @param mods a modifier array.
063: * @param name ProgramElementName of the type
064: * @param members an array containing the memberdeclarations of
065: * this type
066: */
067:
068: public TypeDeclaration(Modifier[] mods, ProgramElementName name,
069: ProgramElementName fullName, MemberDeclaration[] members,
070: boolean parentIsInterfaceDeclaration, boolean isLibrary) {
071: super (mods);
072: this .name = name;
073: this .fullName = fullName;
074: this .members = new ArrayOfMemberDeclaration(members);
075: this .parentIsInterfaceDeclaration = parentIsInterfaceDeclaration;
076: this .isLibrary = isLibrary;
077: }
078:
079: /**
080: * @param children an ExtList of children.
081: * @param name the ProgramElementName of the type
082: * May contain:
083: * several MemberDeclaration (as members of the type),
084: * a parentIsInterfaceDeclaration (indicating if parent is interface),
085: * several Modifier (as modifiers of the type decl),
086: * Comments
087: */
088: public TypeDeclaration(ExtList children, ProgramElementName name,
089: ProgramElementName fullName, boolean isLibrary) {
090: super (children);
091: this .name = name;
092: this .fullName = fullName;
093: this .members = new ArrayOfMemberDeclaration(
094: (MemberDeclaration[]) children
095: .collect(MemberDeclaration.class));
096: ParentIsInterfaceDeclaration piid = (ParentIsInterfaceDeclaration) children
097: .get(ParentIsInterfaceDeclaration.class);
098: if (piid != null) {
099: this .parentIsInterfaceDeclaration = (piid).getValue();
100: } else {
101: this .parentIsInterfaceDeclaration = false;
102: }
103: this .isLibrary = isLibrary;
104: }
105:
106: /**
107: * @param children an ExtList of children.
108: * May contain:
109: * a ProgramElementName (as name),
110: * several MemberDeclaration (as members of the type),
111: * a parentIsInterfaceDeclaration (indicating if parent is interface),
112: * several Modifier (as modifiers of the type decl),
113: * Comments
114: */
115: public TypeDeclaration(ExtList children,
116: ProgramElementName fullName, boolean isLibrary) {
117: this (children, (ProgramElementName) children
118: .get(ProgramElementName.class), fullName, isLibrary);
119: }
120:
121: public SourceElement getFirstElement() {
122: if (modArray != null && (modArray.size() > 0)) {
123: return modArray.getModifier(0);
124: } else {
125: return this ;
126: }
127: }
128:
129: public SourceElement getLastElement() {
130: // end of member block
131: return this ;
132: }
133:
134: /**
135: * Get name.
136: * @return the string.
137: */
138:
139: public final String getName() {
140: return (name == null) ? ((fullName == null) ? null : fullName
141: .toString()) : name.toString();
142: }
143:
144: public String getFullName() {
145: return (fullName == null) ? getName() : fullName.toString();
146: }
147:
148: /**
149: * returns the default value of the given type
150: * according to JLS 4.5.5
151: * @return the default value of the given type
152: * according to JLS 4.5.5
153: */
154: public Literal getDefaultValue() {
155: return NullLiteral.NULL;
156: }
157:
158: /**
159: * Get ProgramElementName.
160: * @return the ProgramElementName.
161: */
162:
163: public ProgramElementName getProgramElementName() {
164: return name;
165: }
166:
167: /**
168: * Get members.
169: * @return the member declaration array.
170: */
171:
172: public ArrayOfMemberDeclaration getMembers() {
173: return members;
174: }
175:
176: public boolean isLibraryClass() {
177: return isLibrary;
178: }
179:
180: /** TO BE IMPLEMENTED
181: */
182: public de.uka.ilkd.key.java.abstraction.Package getPackage(
183: Services s) {
184: System.err
185: .println("Method in class TypeDeclaration not implemented.");
186: return null;
187: }
188:
189: /**
190: * returns the local declared supertypes
191: */
192: public abstract ListOfKeYJavaType getSupertypes();
193:
194: /**
195: * TO BE IMPLEMENTED
196: */
197: public ListOfClassType getAllSupertypes(Services services) {
198: System.err
199: .println("Method in class TypeDeclaration not implemented.");
200: return null;
201: }
202:
203: /** TO BE IMPLEMENTED
204: */
205: public ListOfField getFields(Services services) {
206: System.err
207: .println("Method in class TypeDeclaration not implemented.");
208: return null;
209: }
210:
211: /** TO BE IMPLEMENTED
212: */
213: public ListOfField getAllFields(Services services) {
214: System.err
215: .println("Method in class TypeDeclaration not implemented.");
216: return null;
217: }
218:
219: /** TO BE IMPLEMENTED
220: */
221: public ListOfMethod getMethods(Services services) {
222: System.err
223: .println("Method in class TypeDeclaration not implemented.");
224: return null;
225: }
226:
227: /** TO BE IMPLEMENTED
228: */
229: public ListOfMethod getAllMethods(Services services) {
230: System.err
231: .println("Method in class TypeDeclaration not implemented.");
232: return null;
233: }
234:
235: /** TO BE IMPLEMENTED
236: */
237: public ListOfConstructor getConstructors(Services services) {
238: System.err
239: .println("Method in class TypeDeclaration not implemented.");
240: return null;
241: }
242:
243: /** TO BE IMPLEMENTED
244: */
245: public ListOfClassType getTypes(Services services) {
246: System.err
247: .println("Method in class TypeDeclaration not implemented.");
248: return null;
249: }
250:
251: /** TO BE IMPLEMENTED
252: */
253: public ListOfClassType getAllTypes(Services services) {
254: System.err
255: .println("Method in class TypeDeclaration not implemented.");
256: return null;
257: }
258:
259: /**
260: * Get the number of type declarations in this container.
261: * @return the number of type declarations.
262: */
263:
264: public int getTypeDeclarationCount() {
265: int count = 0;
266: if (members != null) {
267: for (int i = members.size() - 1; i >= 0; i -= 1) {
268: if (members.getMemberDeclaration(i) instanceof TypeDeclaration) {
269: count += 1;
270: }
271: }
272: }
273: return count;
274: }
275:
276: /*
277: Return the type declaration at the specified index in this node's
278: "virtual" type declaration array.
279: @param index an index for a type declaration.
280: @return the type declaration with the given index.
281: @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
282: of bounds.
283: */
284:
285: public TypeDeclaration getTypeDeclarationAt(int index) {
286: if (members != null) {
287: int s = members.size();
288: for (int i = 0; i < s && index >= 0; i += 1) {
289: MemberDeclaration md = members.getMemberDeclaration(i);
290: if (md instanceof TypeDeclaration) {
291: if (index == 0) {
292: return (TypeDeclaration) md;
293: }
294: index -= 1;
295: }
296: }
297: }
298: throw new ArrayIndexOutOfBoundsException();
299: }
300:
301: /**
302: * Test whether the declaration is final.
303: */
304:
305: public boolean isFinal() {
306: return super .isFinal();
307: }
308:
309: /**
310: * Test whether the declaration is private.
311: */
312:
313: public boolean isPrivate() {
314: return super .isPrivate();
315: }
316:
317: /**
318: * Test whether the declaration is protected.
319: */
320:
321: public boolean isProtected() {
322: return super .isProtected();
323: }
324:
325: /**
326: * Test whether the declaration is public.
327: */
328:
329: public boolean isPublic() {
330: return parentIsInterfaceDeclaration || super .isPublic();
331: }
332:
333: /**
334: * Test whether the declaration is static.
335: */
336:
337: public boolean isStatic() {
338: return parentIsInterfaceDeclaration || super .isStatic();
339: }
340:
341: /**
342: * Test whether the declaration is strictfp.
343: */
344:
345: public boolean isStrictFp() {
346: return super .isStrictFp();
347: }
348:
349: /**
350: * Test whether the declaration is abstract.
351: */
352:
353: public boolean isAbstract() {
354: return super.isAbstract();
355: }
356:
357: }
|