001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.api;
027:
028: import com.sun.mirror.apt.AnnotationProcessorEnvironment;
029: import com.sun.mirror.declaration.Declaration;
030: import com.sun.mirror.declaration.MethodDeclaration;
031: import com.sun.mirror.declaration.ParameterDeclaration;
032: import com.sun.mirror.declaration.TypeDeclaration;
033: import com.sun.mirror.type.TypeMirror;
034: import com.sun.mirror.util.SourcePosition;
035:
036: /**
037: * Reference to a JAXB type (from JAX-RPC.)
038: *
039: * <p>
040: * A reference is a Java type (represented as a {@link TypeMirror})
041: * and a set of annotations (represented as a {@link Declaration}).
042: * Together they describe a root reference to a JAXB type binding.
043: *
044: * <p>
045: * Those two values can be supplied independently, or you can use
046: * other convenience constructors to supply two values at once.
047: *
048: *
049: * @author Kohsuke Kawaguchi
050: */
051: public final class Reference {
052: /**
053: * The JAXB type being referenced. Must not be null.
054: */
055: public final TypeMirror type;
056: /**
057: * The declaration from which annotations for the {@link #type} is read.
058: * Must not be null.
059: */
060: public final Declaration annotations;
061:
062: /**
063: * Creates a reference from the return type of the method
064: * and annotations on the method.
065: */
066: public Reference(MethodDeclaration method) {
067: this (method.getReturnType(), method);
068: }
069:
070: /**
071: * Creates a reference from the parameter type
072: * and annotations on the parameter.
073: */
074: public Reference(ParameterDeclaration param) {
075: this (param.getType(), param);
076: }
077:
078: /**
079: * Creates a reference from a class declaration and its annotations.
080: */
081: public Reference(TypeDeclaration type,
082: AnnotationProcessorEnvironment env) {
083: this (env.getTypeUtils().getDeclaredType(type), type);
084: }
085:
086: /**
087: * Creates a reference by providing two values independently.
088: */
089: public Reference(TypeMirror type, Declaration annotations) {
090: if (type == null || annotations == null)
091: throw new IllegalArgumentException();
092: this .type = type;
093: this .annotations = annotations;
094: }
095:
096: /**
097: * Gets the source location that can be used to report error messages regarding
098: * this reference.
099: */
100: public SourcePosition getPosition() {
101: return annotations.getPosition();
102: }
103:
104: public boolean equals(Object o) {
105: if (this == o)
106: return true;
107: if (!(o instanceof Reference))
108: return false;
109:
110: final Reference that = (Reference) o;
111:
112: return annotations.equals(that.annotations)
113: && type.equals(that.type);
114: }
115:
116: public int hashCode() {
117: return 29 * type.hashCode() + annotations.hashCode();
118: }
119: }
|