1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
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.ws.processor.modeler.annotation;
27
28 import javax.annotation.processing.ProcessingEnvironment;
29 import javax.lang.model.element.ElementKind;
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.DeclaredType;
34 import javax.lang.model.type.TypeKind;
35 import javax.lang.model.type.TypeMirror;
36 import javax.lang.model.util.ElementFilter;
37 import java.util.Collection;
38
39 /**
40 * @author WS Development Team
41 */
42 final class TypeModeler {
43
44 private TypeModeler() {
45 }
46
47 public static TypeElement getDeclaration(TypeMirror typeMirror) {
48 if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED))
49 return (TypeElement) ((DeclaredType) typeMirror).asElement();
50 return null;
51 }
52
53 public static TypeElement getDeclaringClassMethod(TypeMirror theClass, String methodName, TypeMirror[] args) {
54 return getDeclaringClassMethod(getDeclaration(theClass), methodName, args);
55 }
56
57 public static TypeElement getDeclaringClassMethod(TypeElement theClass, String methodName, TypeMirror[] args) {
58
59 TypeElement retClass = null;
60 if (theClass.getKind().equals(ElementKind.CLASS)) {
61 TypeMirror superClass = theClass.getSuperclass();
62 if (!superClass.getKind().equals(TypeKind.NONE))
63 retClass = getDeclaringClassMethod(superClass, methodName, args);
143 if (!superClass.getKind().equals(TypeKind.NONE)) {
144 superClassDecl = (TypeElement) ((DeclaredType) superClass).asElement();
145 if (superClassDecl.equals(d2))
146 return true;
147 }
148 }
149 for (TypeMirror superIntf : d1.getInterfaces()) {
150 DeclaredType declaredSuperIntf = (DeclaredType) superIntf;
151 if (declaredSuperIntf.asElement().equals(d2)) {
152 return true;
153 }
154 if (isSubElement((TypeElement) declaredSuperIntf.asElement(), d2)) {
155 return true;
156 } else if (superClassDecl != null && isSubElement(superClassDecl, d2)) {
157 return true;
158 }
159 }
160 return false;
161 }
162
163 }
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
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.ws.processor.modeler.annotation;
27
28 import javax.annotation.processing.ProcessingEnvironment;
29 import javax.lang.model.element.ElementKind;
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.DeclaredType;
34 import javax.lang.model.type.TypeKind;
35 import javax.lang.model.type.TypeMirror;
36 import javax.lang.model.util.ElementFilter;
37 import java.util.Collection;
38 import javax.lang.model.element.Element;
39
40 /**
41 * @author WS Development Team
42 */
43 final class TypeModeler {
44
45 private static final String REMOTE = "java.rmi.Remote";
46 private static final String REMOTE_EXCEPTION = "java.rmi.RemoteException";
47
48 private TypeModeler() {
49 }
50
51 public static TypeElement getDeclaration(TypeMirror typeMirror) {
52 if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED))
53 return (TypeElement) ((DeclaredType) typeMirror).asElement();
54 return null;
55 }
56
57 public static TypeElement getDeclaringClassMethod(TypeMirror theClass, String methodName, TypeMirror[] args) {
58 return getDeclaringClassMethod(getDeclaration(theClass), methodName, args);
59 }
60
61 public static TypeElement getDeclaringClassMethod(TypeElement theClass, String methodName, TypeMirror[] args) {
62
63 TypeElement retClass = null;
64 if (theClass.getKind().equals(ElementKind.CLASS)) {
65 TypeMirror superClass = theClass.getSuperclass();
66 if (!superClass.getKind().equals(TypeKind.NONE))
67 retClass = getDeclaringClassMethod(superClass, methodName, args);
147 if (!superClass.getKind().equals(TypeKind.NONE)) {
148 superClassDecl = (TypeElement) ((DeclaredType) superClass).asElement();
149 if (superClassDecl.equals(d2))
150 return true;
151 }
152 }
153 for (TypeMirror superIntf : d1.getInterfaces()) {
154 DeclaredType declaredSuperIntf = (DeclaredType) superIntf;
155 if (declaredSuperIntf.asElement().equals(d2)) {
156 return true;
157 }
158 if (isSubElement((TypeElement) declaredSuperIntf.asElement(), d2)) {
159 return true;
160 } else if (superClassDecl != null && isSubElement(superClassDecl, d2)) {
161 return true;
162 }
163 }
164 return false;
165 }
166
167 public static boolean isRemoteException(ProcessingEnvironment env, TypeMirror typeMirror) {
168 Element element = env.getTypeUtils().asElement(typeMirror);
169 if (element.getKind() == ElementKind.CLASS) {
170 TypeElement te = (TypeElement) element;
171 TypeKind tk = typeMirror.getKind();
172 while (tk != TypeKind.NONE && !te.getQualifiedName().contentEquals(REMOTE_EXCEPTION)) {
173 TypeMirror superType = te.getSuperclass();
174 te = (TypeElement) env.getTypeUtils().asElement(superType);
175 tk = superType.getKind();
176 }
177 return tk != TypeKind.NONE;
178 }
179 return false;
180 }
181
182 public static boolean isRemote(/*@NotNull*/ TypeElement typeElement) {
183 for (TypeMirror superType : typeElement.getInterfaces()) {
184 TypeElement name = (TypeElement) ((DeclaredType) superType).asElement();
185 if (name.getQualifiedName().contentEquals(REMOTE)) {
186 return true;
187 }
188 isRemote(name);
189 }
190 return false;
191 }
192 }
|