Location.java 9.3 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
10 11 12 13 14 15 16 17 18 19 20
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
 */

package com.sun.jdi;

import java.util.List;

/**
 * A point within the executing code of the target VM.
 * Locations are used to identify the current position of
 * a suspended thread (analogous to an instruction pointer or
 * program counter register in native programs). They are also used
 * to identify the position at which to set a breakpoint.
 * <p>
 * The availability of a line number for a location will
 * depend on the level of debugging information available from the
 * target VM.
 * <p>
 * Several mirror interfaces have locations. Each such mirror
 * extends a {@link Locatable} interface.
 * <p>
 * <a name="strata"><b>Strata</b></a>
 * <p>
 * The source information for a Location is dependent on the
 * <i>stratum</i> which is used. A stratum is a source code
 * level within a sequence of translations.  For example,
 * say the baz program is written in the programming language
 * "Foo" then translated to the language "Bar" and finally
 * translated into the Java programming language.  The
 * Java programming language stratum is named
 * <code>"Java"</code>, let's say the other strata are named
 * "Foo" and "Bar".  A given location (as viewed by the
 * {@link #sourceName()} and {@link #lineNumber()} methods)
 * might be at line 14 of "baz.foo" in the <code>"Foo"</code>
 * stratum, line 23 of "baz.bar" in the <code>"Bar"</code>
 * stratum and line 71 of the <code>"Java"</code> stratum.
 * Note that while the Java programming language may have
 * only one source file for a reference type, this restriction
 * does not apply to other strata - thus each Location should
 * be consulted to determine its source path.
 * Queries which do not specify a stratum
 * ({@link #sourceName()}, {@link #sourcePath()} and
 * {@link #lineNumber()}) use the VM's default stratum
 * ({@link VirtualMachine#getDefaultStratum()}).
 * If the specified stratum (whether explicitly specified
 * by a method parameter or implicitly as the VM's default)
 * is <code>null</code> or is not available in the declaring
 * type, the declaring type's default stratum is used
 * ({@link #declaringType()}.{@link ReferenceType#defaultStratum()
 * defaultStratum()}).  Note that in the normal case, of code
 * that originates as Java programming language source, there
 * will be only one stratum (<code>"Java"</code>) and it will be
 * returned as the default.  To determine the available strata
 * use {@link ReferenceType#availableStrata()}.
 *
 * @see com.sun.jdi.request.EventRequestManager
 * @see StackFrame
 * @see com.sun.jdi.event.BreakpointEvent
 * @see com.sun.jdi.event.ExceptionEvent
 * @see Locatable
 *
 * @author Robert Field
 * @author Gordon Hirsch
 * @author James McIlree
 * @since 1.3
 */
89
@jdk.Exported
D
duke 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
public interface Location extends Mirror, Comparable<Location> {

    /**
     * Gets the type to which this Location belongs. Normally
     * the declaring type is a {@link ClassType}, but executable
     * locations also may exist within the static initializer of an
     * {@link InterfaceType}.
     *
     * @return the {@link ReferenceType} containing this Location.
     */
    ReferenceType declaringType();

    /**
     * Gets the method containing this Location.
     *
     * @return the location's {@link Method}.
     */
    Method method();

    /**
     * Gets the code position within this location's method.
     *
     * @return the long representing the position within the method
     * or -1 if location is within a native method.
     */
    long codeIndex();

    /**
     * Gets an identifing name for the source corresponding to
     * this location.
     * <P>
     * This method is equivalent to
     * <code>sourceName(vm.getDefaultStratum())</code> -
     * see {@link #sourceName(String)}
     * for more information.
     *
     * @return a string specifying the source
     * @throws AbsentInformationException if the source name is not
     * known
     */
    String sourceName() throws AbsentInformationException;


    /**
     * Gets an identifing name for the source corresponding to
     * this location. Interpretation of this string is the
     * responsibility of the source repository mechanism.
     * <P>
     * Returned name is for the specified <i>stratum</i>
     * (see the {@link Location class comment} for a
     * description of strata).
     * <P>
     * The returned string is the unqualified name of the source
     * file for this Location.  For example,
     * <CODE>java.lang.Thread</CODE> would return
     * <CODE>"Thread.java"</CODE>.
     *
     * @param stratum The stratum to retrieve information from
     * or <code>null</code> for the declaring type's
     * default stratum.
     *
     * @return a string specifying the source
     *
     * @throws AbsentInformationException if the source name is not
     * known
     *
     * @since 1.4
     */
    String sourceName(String stratum)
                        throws AbsentInformationException;

    /**
     * Gets the path to the source corresponding to this
     * location.
     * <P>
     * This method is equivalent to
     * <code>sourcePath(vm.getDefaultStratum())</code> -
     * see {@link #sourcePath(String)}
     * for more information.
     *
     * @return a string specifying the source
     *
     * @throws AbsentInformationException if the source name is not
     * known
     */
    String sourcePath() throws AbsentInformationException;


    /**
     * Gets the path to the source corresponding to this
     * location. Interpretation of this string is the
     * responsibility of the source repository mechanism.
     * <P>
     * Returned path is for the specified <i>stratum</i>
     * (see the {@link Location class comment} for a
     * description of strata).
     * <P>
     * In the reference implementation, for strata which
     * do not explicitly specify source path (the Java
     * programming language stratum never does), the returned
     * string is the package name of {@link #declaringType()}
     * converted to a platform dependent path followed by the
     * unqualified name of the source file for this Location
     * ({@link #sourceName sourceName(stratum)}).
     * For example, on a
     * Windows platform, <CODE>java.lang.Thread</CODE>
     * would return
     * <CODE>"java\lang\Thread.java"</CODE>.
     *
     * @param stratum The stratum to retrieve information from
     * or <code>null</code> for the declaring type's
     * default stratum.
     *
     * @return a string specifying the source
     *
     * @throws AbsentInformationException if the source name is not
     * known
     *
     * @since 1.4
     */
    String sourcePath(String stratum)
                         throws AbsentInformationException;

    /**
     * Gets the line number of this Location.
     * <P>
     * This method is equivalent to
     * <code>lineNumber(vm.getDefaultStratum())</code> -
     * see {@link #lineNumber(String)}
     * for more information.
     *
     * @return an int specifying the line in the source, returns
     * -1 if the information is not available; specifically, always
     * returns -1 for native methods.
     */
    int lineNumber();

    /**
     * The line number of this Location.  The line number is
     * relative to the source specified by
     * {@link #sourceName(String) sourceName(stratum)}.
     * <P>
     * Returned line number is for the specified <i>stratum</i>
     * (see the {@link Location class comment} for a
     * description of strata).
     *
     * @param stratum The stratum to retrieve information from
     * or <code>null</code> for the declaring type's
     * default stratum.
     *
     * @return an int specifying the line in the source, returns
     * -1 if the information is not available; specifically, always
     * returns -1 for native methods.
     *
     * @since 1.4
     */
    int lineNumber(String stratum);

    /**
     * Compares the specified Object with this Location for equality.
     *
     * @return true if the Object is a Location and if it refers to
     * the same point in the same VM as this Location.
     */
    boolean equals(Object obj);

    /**
     * Returns the hash code value for this Location.
     *
     * @return the integer hash code
     */
    int hashCode();
}