KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > engine > DefaultSourceSelection


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.engine;
21
22 import javax.lang.model.element.Element;
23 import org.netbeans.api.java.source.query.SourceSelection;
24
25 /**
26  * Provides access to a selected Java element in a source file,
27  * such as a class, method, or field.
28  */

29 public abstract class DefaultSourceSelection implements SourceSelection {
30     private final int start;
31     private final int offset;
32     private final int end;
33     private final String JavaDoc path;
34     private final Element element;
35     
36     public DefaultSourceSelection(Element element, int start,
37                            int offset, int end, String JavaDoc path) {
38         this.element = element;
39         this.start = start;
40         this.offset = offset;
41         this.end = end;
42         this.path = path;
43     }
44
45     /**
46      * Returns the Element associated with this
47      * result, such as a field, method, or class.
48      *
49      * @return the name of the Java element
50      */

51     public Element getElement() {
52         return element;
53     }
54     
55     /**
56      * Returns the starting offset of the Java element associated with this
57      * result in its source file.
58      *
59      * @return the starting offset.
60      */

61     public int getStartOffset() {
62         return start;
63     }
64     
65     /**
66      * Returns the offset of the Java element associated with this
67      * result in its source file. This may be the same as the starting
68      * offset, or may be the "reasonable" start. For example, the
69      * starting offset of a method is the start of its first modifier,
70      * while its offset is the start of the method's name. The
71      * <code>javac</code> compiler's error logger uses these offsets
72      * to set the caret indicating where an error has occurred.
73      *
74      * @return the starting offset.
75      */

76     public int getOffset() {
77         return offset;
78     }
79     
80     /**
81      * Returns the ending offset of the Java element associated with this
82      * result in its source file.
83      *
84      * @return the ending offset.
85      */

86     public int getEndOffset() {
87         return end;
88     }
89     
90     /**
91      * Returns the the source file path which defines the element
92      * of this selection. This path is the same format as <code>javac</code>
93      * stores in a classfile's <code>SourceFile</code> attribute.
94      *
95      * @return the source file name.
96      */

97     public String JavaDoc getSourceFileName() {
98         return path;
99     }
100     
101     /**
102      * Returns the source code that defines the element of this selection.
103      *
104      * @return a String containing the source code.
105      */

106     public abstract String JavaDoc getSource();
107 }
108
Popular Tags