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.java;
12:
13: import de.uka.ilkd.key.java.visitor.Visitor;
14:
15: public class Comment extends JavaSourceElement {
16:
17: private final String text;
18:
19: public Comment() {
20: this .text = null;
21: }
22:
23: public Comment(String text) {
24: this .text = text;
25: }
26:
27: public boolean isPrefixed() {
28: return false;
29: }
30:
31: public void prettyPrint(PrettyPrinter w) {
32: }
33:
34: /** calls the corresponding method of a visitor in order to
35: * perform some action/transformation on this element
36: * @param v the Visitor
37: */
38: public void visit(Visitor v) {
39: }
40:
41: public String getText() {
42: return text;
43: }
44:
45: public boolean containsJMLSpec() {
46: if (text == null) {
47: return false;
48: }
49: return text.trim().startsWith("/*@")
50: || text.trim().startsWith("//@")
51: || text.trim().startsWith("/*+@")
52: || text.trim().startsWith("/*-@")
53: || text.indexOf("<jml>") != -1
54: && text.indexOf("</jml>") != -1;
55: }
56:
57: public String getJMLSpec() {
58: if (!containsJMLSpec())
59: return null;
60: if (text.trim().startsWith("/*@")) {
61: return text.trim().substring(3, text.length() - 3);
62: }
63: if (text.trim().startsWith("/*+@")) {
64: return text.trim().substring(4, text.length() - 3);
65: }
66: if (text.trim().startsWith("/*-@")) {
67: return text.trim().substring(4, text.length() - 3);
68: }
69: if (text.trim().startsWith("//@")) {
70: return text.trim().substring(3);
71: }
72: int start = text.indexOf("<jml>") + 5;
73: return text.substring(start, text.indexOf("</jml>", start));
74: }
75:
76: /** comments can be ignored
77: */
78: public boolean equalsModRenaming(SourceElement se,
79: NameAbstractionTable nat) {
80: return true;
81: }
82:
83: public int hashCode() {
84: int result = 17;
85: result = 37 * result + getText().hashCode();
86: return result;
87: }
88:
89: public boolean equals(Object o) {
90: if (o == this )
91: return true;
92: if (!(o instanceof Comment))
93: return false;
94: Comment cmp = (Comment) o;
95: return (getText().equals(cmp.getText()));
96: }
97:
98: }
|