001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.core.search;
011:
012: import org.eclipse.jdt.core.*;
013: import org.eclipse.jdt.core.search.*;
014:
015: /**
016: * Java Search concrete class for a type name match.
017: *
018: * @since 3.3
019: */
020: public class JavaSearchTypeNameMatch extends TypeNameMatch {
021:
022: private IType type;
023: private int modifiers = -1; // store modifiers to avoid java model population
024:
025: /**
026: * Creates a new Java Search type name match.
027: */
028: public JavaSearchTypeNameMatch(IType type, int modifiers) {
029: this .type = type;
030: this .modifiers = modifiers;
031: }
032:
033: /* (non-Javadoc)
034: * Returns whether the matched type is equals to the given object or not.
035: * @see java.lang.Object#equals(java.lang.Object)
036: */
037: public boolean equals(Object obj) {
038: if (obj == this )
039: return true; // avoid unnecessary calls for identical objects
040: if (obj instanceof TypeNameMatch) {
041: TypeNameMatch match = (TypeNameMatch) obj;
042: if (this .type == null) {
043: return match.getType() == null
044: && match.getModifiers() == this .modifiers;
045: }
046: return this .type.equals(match.getType())
047: && match.getModifiers() == this .modifiers;
048: }
049: return false;
050: }
051:
052: /* (non-Javadoc)
053: * @see org.eclipse.jdt.core.search.TypeNameMatch#getModifiers()
054: */
055: public int getModifiers() {
056: return this .modifiers;
057: }
058:
059: /* (non-Javadoc)
060: * Note that returned handle exists as it matches a type accepted
061: * from up-to-date index file.
062: * @see org.eclipse.jdt.core.search.TypeNameMatch#getType()
063: */
064: public IType getType() {
065: return this .type;
066: }
067:
068: /* (non-Javadoc)
069: * Returns the hash code of the matched type.
070: * @see java.lang.Object#hashCode()
071: */
072: public int hashCode() {
073: if (this .type == null)
074: return this .modifiers;
075: return this .type.hashCode();
076: }
077:
078: /**
079: * Set modifiers of the matched type.
080: *
081: * @param modifiers the modifiers of the matched type.
082: */
083: public void setModifiers(int modifiers) {
084: this .modifiers = modifiers;
085: }
086:
087: /**
088: * Set matched type.
089: *
090: * @param type the matched type.
091: */
092: public void setType(IType type) {
093: this .type = type;
094: }
095:
096: /* (non-Javadoc)
097: * Returns the string of the matched type.
098: * @see java.lang.Object#toString()
099: */
100: public String toString() {
101: if (this.type == null)
102: return super.toString();
103: return this.type.toString();
104: }
105: }
|