KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > SourceNameReferenceTypeSpec


1 /*
2  * @(#)SourceNameReferenceTypeSpec.java 1.9 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import com.sun.jdi.*;
38
39 class SourceNameReferenceTypeSpec implements ReferenceTypeSpec {
40     final String JavaDoc sourceName;
41     final int linenumber;
42
43     SourceNameReferenceTypeSpec(String JavaDoc sourceName, int linenumber) {
44         this.sourceName = sourceName;
45         this.linenumber = linenumber;
46     }
47
48     /**
49      * Does the specified ReferenceType match this spec.
50      */

51     public boolean matches(ReferenceType refType) {
52         try {
53             if (refType.sourceName().equals(sourceName)) {
54                 try {
55                     refType.locationsOfLine(linenumber);
56                     // if we don't throw an exception then it was found
57
return true;
58                 } catch(AbsentInformationException exc) {
59                 } catch(ObjectCollectedException exc) {
60                 } catch(InvalidLineNumberException exc) {
61 // } catch(ClassNotPreparedException exc) {
62
// -- should not happen, so don't catch this ---
63
}
64             }
65         } catch(AbsentInformationException exc) {
66             // for sourceName(), fall through
67
}
68         return false;
69     }
70
71     public int hashCode() {
72         return sourceName.hashCode() + linenumber;
73     }
74
75     public boolean equals(Object JavaDoc obj) {
76         if (obj instanceof SourceNameReferenceTypeSpec) {
77             SourceNameReferenceTypeSpec spec = (SourceNameReferenceTypeSpec)obj;
78
79             return sourceName.equals(spec.sourceName) &&
80                               (linenumber == spec.linenumber);
81         } else {
82             return false;
83         }
84     }
85
86     public String JavaDoc toString() {
87         return sourceName + "@" + linenumber;
88     }
89 }
90
91
92
Popular Tags