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.api.java.source.query; 21 22 import javax.lang.model.element.Element; 23 24 /** 25 * Provides access to a selected Java element in a source file, 26 * such as a class, method, or field. 27 */ 28 public interface SourceSelection { 29 /** 30 * Returns the Element associated with this 31 * result, such as a field, method, or class. 32 * 33 * @return the name of the Java element 34 */ 35 Element getElement(); 36 37 /** 38 * Returns the starting offset of the Java element associated with this 39 * result in its source file. 40 * 41 * @return the starting offset. 42 */ 43 int getStartOffset(); 44 45 /** 46 * Returns the offset of the Java element associated with this 47 * result in its source file. This may be the same as the starting 48 * offset, or may be the "reasonable" start. For example, the 49 * starting offset of a method is the start of its first modifier, 50 * while its offset is the start of the method's name. The 51 * <code>javac</code> compiler's error logger uses these offsets 52 * to set the caret indicating where an error has occurred. 53 * 54 * @return the starting offset. 55 */ 56 int getOffset(); 57 58 /** 59 * Returns the ending offset of the Java element associated with this 60 * result in its source file. 61 * 62 * @return the ending offset. 63 */ 64 int getEndOffset(); 65 66 /** 67 * Returns the the source file path which defines the element 68 * of this selection. This path is the same format as <code>javac</code> 69 * stores in a classfile's <code>SourceFile</code> attribute. 70 * 71 * @return the source file name. 72 */ 73 String getSourceFileName(); 74 75 /** 76 * Returns the source code that defines the element of this selection. 77 * 78 * @return a String containing the source code. 79 */ 80 String getSource(); 81 } 82