Lines 48-53
Link Here
|
48 |
import java.io.OutputStreamWriter; |
48 |
import java.io.OutputStreamWriter; |
49 |
import java.io.PrintWriter; |
49 |
import java.io.PrintWriter; |
50 |
import java.lang.annotation.Annotation; |
50 |
import java.lang.annotation.Annotation; |
|
|
51 |
import java.net.URLStreamHandler; |
51 |
import java.util.ArrayList; |
52 |
import java.util.ArrayList; |
52 |
import java.util.Collection; |
53 |
import java.util.Collection; |
53 |
import java.util.Collections; |
54 |
import java.util.Collections; |
Lines 75-87
Link Here
|
75 |
import javax.tools.Diagnostic.Kind; |
76 |
import javax.tools.Diagnostic.Kind; |
76 |
import javax.tools.FileObject; |
77 |
import javax.tools.FileObject; |
77 |
import javax.tools.StandardLocation; |
78 |
import javax.tools.StandardLocation; |
|
|
79 |
import org.openide.util.URLStreamHandlerRegistration; |
78 |
import org.openide.util.lookup.ServiceProvider; |
80 |
import org.openide.util.lookup.ServiceProvider; |
79 |
import org.openide.util.lookup.ServiceProviders; |
81 |
import org.openide.util.lookup.ServiceProviders; |
80 |
|
82 |
|
81 |
@SupportedSourceVersion(SourceVersion.RELEASE_6) |
83 |
@SupportedSourceVersion(SourceVersion.RELEASE_6) |
82 |
@SupportedAnnotationTypes({"org.openide.util.lookup.ServiceProvider", "org.openide.util.lookup.ServiceProviders"}) |
84 |
@SupportedAnnotationTypes({ |
|
|
85 |
"org.openide.util.lookup.ServiceProvider", |
86 |
"org.openide.util.lookup.ServiceProviders", |
87 |
"org.openide.util.URLStreamHandlerRegistration" |
88 |
}) |
83 |
public class ServiceProviderProcessor extends AbstractProcessor { |
89 |
public class ServiceProviderProcessor extends AbstractProcessor { |
84 |
|
90 |
|
|
|
91 |
public static final String URL_STREAM_HANDLER_REGISTRATION_PREFIX = "URLStreamHandler/"; // NOI18N |
92 |
|
85 |
/** public for ServiceLoader */ |
93 |
/** public for ServiceLoader */ |
86 |
public ServiceProviderProcessor() {} |
94 |
public ServiceProviderProcessor() {} |
87 |
|
95 |
|
Lines 115-133
Link Here
|
115 |
register(clazz, sp); |
123 |
register(clazz, sp); |
116 |
} |
124 |
} |
117 |
} |
125 |
} |
|
|
126 |
for (Element el : roundEnv.getElementsAnnotatedWith(URLStreamHandlerRegistration.class)) { |
127 |
TypeElement clazz = (TypeElement) el; |
128 |
if (!verifyServiceProviderSignature(clazz)) { |
129 |
continue; |
130 |
} |
131 |
URLStreamHandlerRegistration r = clazz.getAnnotation(URLStreamHandlerRegistration.class); |
132 |
TypeMirror type = processingEnv.getTypeUtils().getDeclaredType( |
133 |
processingEnv.getElementUtils().getTypeElement(URLStreamHandler.class.getName())); |
134 |
for (String protocol : r.protocol()) { |
135 |
register(clazz, type, URL_STREAM_HANDLER_REGISTRATION_PREFIX + protocol, r.position(), new String[0]); |
136 |
} |
137 |
} |
118 |
return true; |
138 |
return true; |
119 |
} |
139 |
} |
120 |
} |
140 |
} |
121 |
|
141 |
|
122 |
private void register(TypeElement clazz, ServiceProvider svc) { |
142 |
private void register(TypeElement clazz, ServiceProvider svc) { |
123 |
TypeMirror type; |
|
|
124 |
try { |
143 |
try { |
125 |
svc.service(); |
144 |
svc.service(); |
126 |
assert false; |
145 |
assert false; |
127 |
return; |
146 |
return; |
128 |
} catch (MirroredTypeException e) { |
147 |
} catch (MirroredTypeException e) { |
129 |
type = e.getTypeMirror(); |
148 |
register(clazz, e.getTypeMirror(), svc.path(), svc.position(), svc.supersedes()); |
130 |
} |
149 |
} |
|
|
150 |
} |
151 |
|
152 |
private void register(TypeElement clazz, TypeMirror type, String path, int position, String[] supersedes) { |
131 |
String impl = processingEnv.getElementUtils().getBinaryName(clazz).toString(); |
153 |
String impl = processingEnv.getElementUtils().getBinaryName(clazz).toString(); |
132 |
String xface = processingEnv.getElementUtils().getBinaryName((TypeElement) processingEnv.getTypeUtils().asElement(type)).toString(); |
154 |
String xface = processingEnv.getElementUtils().getBinaryName((TypeElement) processingEnv.getTypeUtils().asElement(type)).toString(); |
133 |
if (!processingEnv.getTypeUtils().isAssignable(clazz.asType(), type)) { |
155 |
if (!processingEnv.getTypeUtils().isAssignable(clazz.asType(), type)) { |
Lines 136-143
Link Here
|
136 |
clazz, ann, findAnnotationValue(ann, "service")); |
158 |
clazz, ann, findAnnotationValue(ann, "service")); |
137 |
return; |
159 |
return; |
138 |
} |
160 |
} |
139 |
processingEnv.getMessager().printMessage(Kind.NOTE, impl + " to be registered as a " + xface); |
161 |
processingEnv.getMessager().printMessage(Kind.NOTE, |
140 |
String rsrc = (svc.path().length() > 0 ? "META-INF/namedservices/" + svc.path() + "/" : "META-INF/services/") + xface; |
162 |
impl + " to be registered as a " + xface + (path.length() > 0 ? " under " + path : "")); |
|
|
163 |
String rsrc = (path.length() > 0 ? "META-INF/namedservices/" + path + "/" : "META-INF/services/") + xface; |
141 |
{ |
164 |
{ |
142 |
List<Element> origEls = originatingElements.get(rsrc); |
165 |
List<Element> origEls = originatingElements.get(rsrc); |
143 |
if (origEls == null) { |
166 |
if (origEls == null) { |
Lines 188-197
Link Here
|
188 |
} |
211 |
} |
189 |
} |
212 |
} |
190 |
lines.add(impl); |
213 |
lines.add(impl); |
191 |
if (svc.position() != Integer.MAX_VALUE) { |
214 |
if (position != Integer.MAX_VALUE) { |
192 |
lines.add("#position=" + svc.position()); |
215 |
lines.add("#position=" + position); |
193 |
} |
216 |
} |
194 |
for (String exclude : svc.supersedes()) { |
217 |
for (String exclude : supersedes) { |
195 |
lines.add("#-" + exclude); |
218 |
lines.add("#-" + exclude); |
196 |
} |
219 |
} |
197 |
} |
220 |
} |