001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.xjc.api;
038:
039: import com.sun.mirror.apt.AnnotationProcessorEnvironment;
040: import com.sun.mirror.declaration.Declaration;
041: import com.sun.mirror.declaration.MethodDeclaration;
042: import com.sun.mirror.declaration.ParameterDeclaration;
043: import com.sun.mirror.declaration.TypeDeclaration;
044: import com.sun.mirror.type.TypeMirror;
045: import com.sun.mirror.util.SourcePosition;
046:
047: /**
048: * Reference to a JAXB type (from JAX-RPC.)
049: *
050: * <p>
051: * A reference is a Java type (represented as a {@link TypeMirror})
052: * and a set of annotations (represented as a {@link Declaration}).
053: * Together they describe a root reference to a JAXB type binding.
054: *
055: * <p>
056: * Those two values can be supplied independently, or you can use
057: * other convenience constructors to supply two values at once.
058: *
059: *
060: * @author Kohsuke Kawaguchi
061: */
062: public final class Reference {
063: /**
064: * The JAXB type being referenced. Must not be null.
065: */
066: public final TypeMirror type;
067: /**
068: * The declaration from which annotations for the {@link #type} is read.
069: * Must not be null.
070: */
071: public final Declaration annotations;
072:
073: /**
074: * Creates a reference from the return type of the method
075: * and annotations on the method.
076: */
077: public Reference(MethodDeclaration method) {
078: this (method.getReturnType(), method);
079: }
080:
081: /**
082: * Creates a reference from the parameter type
083: * and annotations on the parameter.
084: */
085: public Reference(ParameterDeclaration param) {
086: this (param.getType(), param);
087: }
088:
089: /**
090: * Creates a reference from a class declaration and its annotations.
091: */
092: public Reference(TypeDeclaration type,
093: AnnotationProcessorEnvironment env) {
094: this (env.getTypeUtils().getDeclaredType(type), type);
095: }
096:
097: /**
098: * Creates a reference by providing two values independently.
099: */
100: public Reference(TypeMirror type, Declaration annotations) {
101: if (type == null || annotations == null)
102: throw new IllegalArgumentException();
103: this .type = type;
104: this .annotations = annotations;
105: }
106:
107: /**
108: * Gets the source location that can be used to report error messages regarding
109: * this reference.
110: */
111: public SourcePosition getPosition() {
112: return annotations.getPosition();
113: }
114:
115: public boolean equals(Object o) {
116: if (this == o)
117: return true;
118: if (!(o instanceof Reference))
119: return false;
120:
121: final Reference that = (Reference) o;
122:
123: return annotations.equals(that.annotations)
124: && type.equals(that.type);
125: }
126:
127: public int hashCode() {
128: return 29 * type.hashCode() + annotations.hashCode();
129: }
130: }
|