KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > TextSourceLocation


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.*;
28
29 import java.util.*;
30 import java.io.File JavaDoc;
31
32 public class TextSourceLocation extends SourceLocation {
33     protected int startPosition = -1;
34     protected int endPosition = -1;
35     protected CompilationUnit compilationUnit;
36
37     // multiple comments form a linked list
38
protected Comment comment;
39
40     public String JavaDoc toString() {
41         return "TextSourceLocation(" + getSourceFileName() + ":" +
42             getBeginLine() + ":" + getBeginColumn() + ")";
43     }
44
45
46     public TextSourceLocation(CompilationUnit compilationUnit, int start, int end) {
47         this.compilationUnit = compilationUnit;
48         this.startPosition = start;
49         this.endPosition = end;
50     }
51
52     public JavaCompiler getCompiler() { return getCompilationUnit().getCompiler(); }
53
54     public int getStartPosition() { return startPosition; }
55     public int getEndPosition() { return endPosition; }
56
57     public int getBeginLine() {
58         if (startPosition == -1) return -1;
59         return getCompilationUnit().getLine(startPosition);
60     }
61
62     public int getEndLine() {
63         if (endPosition == -1) return -1;
64         return getCompilationUnit().getLine(endPosition);
65     }
66
67     public int getBeginColumn() {
68         if (startPosition == -1) return -1;
69         return getCompilationUnit().getColumn(startPosition);
70     }
71
72     public int getEndColumn() {
73         if (endPosition == -1) return -1;
74         return getCompilationUnit().getColumn(endPosition);
75     }
76
77     public Comment getComment() {
78         return comment;
79     }
80
81     public void addComment(Comment _comment) {
82         if (comment == null) {
83             comment = _comment;
84         } else {
85             comment.addComment(_comment);
86         }
87     }
88
89     public void clearComment() {
90         comment = null;
91     }
92
93     public void setFormalComment(String JavaDoc comment) {
94         //System.out.println("adding formal comment: " + comment + " to " + this.getDefaultDisplayName());
95
addComment(new FormalComment(comment));
96     }
97
98     public String JavaDoc getFormalComment() {
99         if (comment == null) return "";
100         return comment.getFormalComment();
101     }
102
103     public CompilationUnit getCompilationUnit() {
104         return compilationUnit;
105     }
106
107     public java.io.File JavaDoc getSourceFile() {
108         return getCompilationUnit().getSourceFile();
109     }
110
111     public String JavaDoc getSourceFileName() {
112         return getCompilationUnit().getSourceCanonicalPath();
113     }
114
115     public String JavaDoc getSourceDirectoryName() {
116         return getCompilationUnit().getSourceDirectory();
117     }
118
119     public boolean isSynthetic() {
120         return false;
121     }
122
123     public boolean hasSource() {
124         return getCompilationUnit().getSourceFile() != null;
125     }
126     public boolean fromSource() {
127         return hasSource() && getCompilationUnit().getDecs() != null;
128     }
129 }
130
Popular Tags