KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > JavaSearchTypeNameMatch


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.search;
12
13 import org.eclipse.jdt.core.*;
14 import org.eclipse.jdt.core.search.*;
15
16 /**
17  * Java Search concrete class for a type name match.
18  *
19  * @since 3.3
20  */

21 public class JavaSearchTypeNameMatch extends TypeNameMatch {
22
23 private IType type;
24 private int modifiers = -1; // store modifiers to avoid java model population
25

26 /**
27  * Creates a new Java Search type name match.
28  */

29 public JavaSearchTypeNameMatch(IType type, int modifiers) {
30     this.type = type;
31     this.modifiers = modifiers;
32 }
33
34 /* (non-Javadoc)
35  * Returns whether the matched type is equals to the given object or not.
36  * @see java.lang.Object#equals(java.lang.Object)
37  */

38 public boolean equals(Object JavaDoc obj) {
39     if (obj == this) return true; // avoid unnecessary calls for identical objects
40
if (obj instanceof TypeNameMatch) {
41         TypeNameMatch match = (TypeNameMatch) obj;
42         if (this.type == null) {
43             return match.getType() == null && match.getModifiers() == this.modifiers;
44         }
45         return this.type.equals(match.getType()) && match.getModifiers() == this.modifiers;
46     }
47     return false;
48 }
49
50 /* (non-Javadoc)
51  * @see org.eclipse.jdt.core.search.TypeNameMatch#getModifiers()
52  */

53 public int getModifiers() {
54     return this.modifiers;
55 }
56
57 /* (non-Javadoc)
58  * Note that returned handle exists as it matches a type accepted
59  * from up-to-date index file.
60  * @see org.eclipse.jdt.core.search.TypeNameMatch#getType()
61  */

62 public IType getType() {
63     return this.type;
64 }
65
66 /* (non-Javadoc)
67  * Returns the hash code of the matched type.
68  * @see java.lang.Object#hashCode()
69  */

70 public int hashCode() {
71     if (this.type == null) return this.modifiers;
72     return this.type.hashCode();
73 }
74
75 /**
76  * Set modifiers of the matched type.
77  *
78  * @param modifiers the modifiers of the matched type.
79  */

80 public void setModifiers(int modifiers) {
81     this.modifiers = modifiers;
82 }
83
84 /**
85  * Set matched type.
86  *
87  * @param type the matched type.
88  */

89 public void setType(IType type) {
90     this.type = type;
91 }
92
93 /* (non-Javadoc)
94  * Returns the string of the matched type.
95  * @see java.lang.Object#toString()
96  */

97 public String JavaDoc toString() {
98     if (this.type == null) return super.toString();
99     return this.type.toString();
100 }
101 }
102
Popular Tags