Skip to content

Package: EndpointReader$1

EndpointReader$1

nameinstructionbranchcomplexitylinemethod
compare(Element, Element)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.ws.test.model;
12:
13: import java.util.ArrayList;
14: import java.util.Collections;
15: import java.util.Comparator;
16: import java.util.LinkedHashSet;
17: import java.util.List;
18: import java.util.Set;
19: import javax.annotation.processing.AbstractProcessor;
20: import javax.annotation.processing.ProcessingEnvironment;
21: import javax.annotation.processing.RoundEnvironment;
22: import javax.annotation.processing.SupportedAnnotationTypes;
23: import jakarta.jws.WebService;
24: import javax.lang.model.element.Element;
25: import javax.lang.model.element.ElementKind;
26: import javax.lang.model.element.TypeElement;
27: import javax.lang.model.util.Elements;
28: import jakarta.xml.ws.WebServiceProvider;
29:
30: /**
31: *
32: * @author lukas
33: */
34: @SupportedAnnotationTypes({
35: "jakarta.jws.WebService",
36: "jakarta.xml.ws.WebServiceProvider"
37: })
38: public class EndpointReader extends AbstractProcessor {
39:
40: private Elements els;
41: private final Set<TestEndpoint> endpoints = new LinkedHashSet<TestEndpoint>();
42:
43: @Override
44: public synchronized void init(ProcessingEnvironment processingEnv) {
45: super.init(processingEnv);
46: els = processingEnv.getElementUtils();
47: }
48:
49: @Override
50: public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
51: List<Element> classes = new ArrayList<Element>();
52: for (Element e : roundEnv.getRootElements()) {
53: if (e.getKind().equals(ElementKind.INTERFACE)) {
54: continue;
55: }
56: classes.add(e);
57: }
58: Collections.sort(classes, new Comparator<Element>() {
59:
60: public int compare(Element o1, Element o2) {
61: return getClassName(o1).compareTo(getClassName(o2));
62: }
63: });
64: for (Element e : classes) {
65: String serviceName = null;
66: String portName = null;
67: // String name = null;
68: // String tns = null;
69: String fullName = getClassName(e);
70: WebService ws = e.getAnnotation(WebService.class);
71: if (ws != null) {
72: //SEI may not exist yet
73: if (serviceName == null) {
74: serviceName = ws.serviceName().isEmpty() ? e.getSimpleName().toString() + "Service" : ws.serviceName();
75: }
76: if (portName == null) {
77: portName = ws.portName().isEmpty() ? null : ws.portName();
78: }
79: } else {
80: WebServiceProvider wsp = e.getAnnotation(WebServiceProvider.class);
81: if (wsp != null) {
82: if (serviceName == null) {
83: serviceName = wsp.serviceName().isEmpty() ? e.getSimpleName().toString() + "Service" : wsp.serviceName();
84: }
85: if (portName == null) {
86: portName = wsp.portName().isEmpty() ? null : wsp.portName();
87: }
88: } else {
89: //not @WebService/Provider
90: continue;
91: }
92: }
93: endpoints.add(new TestEndpoint(serviceName, fullName, portName, e.getAnnotation(WebServiceProvider.class) != null));
94: }
95: return true;
96: }
97:
98: Set<TestEndpoint> getTestEndpoints() {
99: return endpoints;
100: }
101:
102: private String getPackageName(Element e) {
103: String pkg = els.getPackageOf(e).getQualifiedName().toString();
104: return pkg.isEmpty() ? "" : pkg + ".";
105: }
106:
107: private String getClassName(Element e) {
108: return getPackageName(e) + e.getSimpleName().toString();
109: }
110: }