author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.internal.xjc.api; |
|
27 |
||
28 |
import javax.annotation.processing.ProcessingEnvironment; |
|
29 |
import javax.lang.model.element.Element; |
|
30 |
import javax.lang.model.element.ExecutableElement; |
|
31 |
import javax.lang.model.element.TypeElement; |
|
32 |
import javax.lang.model.element.VariableElement; |
|
33 |
import javax.lang.model.type.TypeMirror; |
|
34 |
||
35 |
/** |
|
36 |
* Reference to a JAXB type (from JAX-RPC.) |
|
37 |
* |
|
38 |
* <p> |
|
39 |
* A reference is a Java type (represented as a {@link javax.lang.model.type.TypeMirror}) |
|
40 |
* and a set of annotations (represented as a {@link javax.lang.model.element.Element}). |
|
41 |
* Together they describe a root reference to a JAXB type binding. |
|
42 |
* |
|
43 |
* <p> |
|
44 |
* Those two values can be supplied independently, or you can use |
|
45 |
* other convenience constructors to supply two values at once. |
|
46 |
* |
|
47 |
* |
|
48 |
* @author Kohsuke Kawaguchi |
|
49 |
*/ |
|
50 |
public final class Reference { |
|
51 |
/** |
|
52 |
* The JAXB type being referenced. Must not be null. |
|
53 |
*/ |
|
54 |
public final TypeMirror type; |
|
55 |
/** |
|
56 |
* The declaration from which annotations for the {@link #type} is read. |
|
57 |
* Must not be null. |
|
58 |
*/ |
|
59 |
public final Element annotations; |
|
60 |
||
61 |
/** |
|
62 |
* Creates a reference from the return type of the method |
|
63 |
* and annotations on the method. |
|
64 |
*/ |
|
65 |
public Reference(ExecutableElement method) { |
|
66 |
this(method.getReturnType(),method); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Creates a reference from the parameter type |
|
71 |
* and annotations on the parameter. |
|
72 |
*/ |
|
73 |
public Reference(VariableElement param) { |
|
74 |
this(param.asType(), param); |
|
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Creates a reference from a class declaration and its annotations. |
|
79 |
*/ |
|
80 |
public Reference(TypeElement type, ProcessingEnvironment env) { |
|
81 |
this(env.getTypeUtils().getDeclaredType(type),type); |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Creates a reference by providing two values independently. |
|
86 |
*/ |
|
87 |
public Reference(TypeMirror type, Element annotations) { |
|
88 |
if(type==null || annotations==null) |
|
89 |
throw new IllegalArgumentException(); |
|
90 |
this.type = type; |
|
91 |
this.annotations = annotations; |
|
92 |
} |
|
93 |
||
94 |
public boolean equals(Object o) { |
|
95 |
if (this == o) return true; |
|
96 |
if (!(o instanceof Reference)) return false; |
|
97 |
||
98 |
final Reference that = (Reference) o; |
|
99 |
||
100 |
return annotations.equals(that.annotations) && type.equals(that.type); |
|
101 |
} |
|
102 |
||
103 |
public int hashCode() { |
|
104 |
return 29 * type.hashCode() + annotations.hashCode(); |
|
105 |
} |
|
106 |
} |