@SuppressWarnings("unchecked") public InhabitantIntrospectionScanner(ParsingContext context) { types = context.getTypes(); AnnotationType am = types.getBy(AnnotationType.class, InhabitantAnnotation.class.getName()); if (am==null) { inhabitantAnnotations = Collections.EMPTY_LIST.iterator(); } else { Collection<AnnotatedElement> ccc = am.allAnnotatedTypes(); inhabitantAnnotations = ccc.iterator(); } fetch(); }
Collection<Type> allTypes = types.getAllTypes(); Collection<AnnotationModel> annotations = null; Map<String, List<ScannedAnnotation>> classesByAnnotation =
@SuppressWarnings("unchecked") public InhabitantIntrospectionScanner(ParsingContext context) { types = context.getTypes(); AnnotationType am = types.getBy(AnnotationType.class, InhabitantAnnotation.class.getName()); if (am==null) { inhabitantAnnotations = Collections.EMPTY_LIST.iterator(); } else { Collection<AnnotatedElement> ccc = am.allAnnotatedTypes(); inhabitantAnnotations = ccc.iterator(); } fetch(); }
/** * Given the set of annotations that comprise Hk2, as well as the provided classpath / files to * introspect, return the set of URIs that actually reference something of "significant value" * pertaining to habitat creation. */ private Set<URI> getSignificantURIReferences() { LinkedHashSet<URI> result = new LinkedHashSet<URI>(); Types types = context.getTypes(); for (String annotation : context.getConfig().getTypesOfInterest()) { AnnotationType atype = (AnnotationType) types.getBy(annotation); if (null != atype) { Collection<AnnotatedElement> coll = atype.allAnnotatedTypes(); for (AnnotatedElement ae : coll) { Type type = types.getBy(ae.getName()); if (null != type) { for (URI uri : type.getDefiningURIs()) { try { result.add(new File(uri).getCanonicalFile().toURI()); } catch (IOException e) { throw new RuntimeException(e); } } } } } } return Collections.unmodifiableSet(result); }
/** * Given the set of annotations that comprise Hk2, as well as the provided classpath / files to * introspect, return the set of URIs that actually reference something of "significant value" * pertaining to habitat creation. */ private Set<URI> getSignificantURIReferences() { LinkedHashSet<URI> result = new LinkedHashSet<URI>(); Types types = context.getTypes(); for (String annotation : context.getConfig().getTypesOfInterest()) { AnnotationType atype = (AnnotationType) types.getBy(annotation); if (null != atype) { Collection<AnnotatedElement> coll = atype.allAnnotatedTypes(); for (AnnotatedElement ae : coll) { Type type = types.getBy(ae.getName()); if (null != type) { for (URI uri : type.getDefiningURIs()) { try { result.add(new File(uri).getCanonicalFile().toURI()); } catch (IOException e) { throw new RuntimeException(e); } } } } } } return Collections.unmodifiableSet(result); }
Type type = classInfo.getBy(c.getName()); if (type==null) continue;
@Override public void parse(ParsingContext context, Holder<ClassLoader> loader) { this.context = context; AnnotationType configured = (AnnotationType) context.getTypes().getBy(Configured.class.getName()); if (configured==null) return; for (AnnotatedElement ae : configured.allAnnotatedTypes()) { if (!(ae instanceof ExtensibleType)) { continue; } MultiMap<String,String> metadata = new MultiMap<String,String>(); parse((ExtensibleType<?>) ae, metadata); AnnotationModel c = ae.getAnnotation(Configured.class.getName()); String elementName = (String) c.getValues().get("value"); if(elementName==null || elementName.length()==0) { // infer default elementName = Dom.convertName(ae.getName().substring(ae.getName().lastIndexOf('.')+1)); } metadata.add(ConfigMetadata.TARGET, ae.getName()); // register the injector. LazyInhabitant inhabitant = new LazyInhabitant(habitat, loader, NoopConfigInjector.class.getName(), metadata); habitat.addIndex(inhabitant, InjectionTarget.class.getName(), ae.getName()); habitat.addIndex(inhabitant, ConfigInjector.class.getName(), elementName); } }
@Override public void parse(ParsingContext context, Holder<ClassLoader> loader) { this.context = context; AnnotationType configured = (AnnotationType) context.getTypes().getBy(Configured.class.getName()); if (configured==null) return; for (AnnotatedElement ae : configured.allAnnotatedTypes()) { if (!(ae instanceof ExtensibleType)) { continue; } MultiMap<String,String> metadata = new MultiMap<String,String>(); parse((ExtensibleType<?>) ae, metadata); AnnotationModel c = ae.getAnnotation(Configured.class.getName()); String elementName = (String) c.getValues().get("value"); if(elementName==null || elementName.length()==0) { // infer default elementName = Dom.convertName(ae.getName().substring(ae.getName().lastIndexOf('.')+1)); } metadata.add(ConfigMetadata.TARGET, ae.getName()); // register the injector. LazyInhabitant inhabitant = new LazyInhabitant(habitat, loader, NoopConfigInjector.class.getName(), metadata); habitat.addIndex(inhabitant, InjectionTarget.class.getName(), ae.getName()); habitat.addIndex(inhabitant, ConfigInjector.class.getName(), elementName); } }
for (String annotationName : annotationNames) { if (types != null) { Type type = types.getBy(annotationName); if (type instanceof AnnotationType) { Collection<AnnotatedElement> elements = ((AnnotationType) type).allAnnotatedTypes();
ParsingContext context = classParser.getContext(); for (Class ejbAnnotation: ejbAnnotations) { Type type = context.getTypes().getBy(ejbAnnotation.getName()); if (type != null && type instanceof AnnotationType) { AnnotationType at = (AnnotationType) type;
public void findContracts(ClassModel cm, Set<String> interfaces, Set<String> annotationTypeInterfaces) { // It is questionable that the indexes will contain the fully qualified // parameterized type as well as the raw type but it's safer for // backward compatibility. for (ParameterizedInterfaceModel pim : cm.getParameterizedInterfaces()) { if (isContract(pim.getRawInterface())) { interfaces.add(pim.getName()); } } for (InterfaceModel im : cm.getInterfaces()) { getAllContractInterfaces(im, interfaces); } findContractsFromAnnotations(cm, interfaces, annotationTypeInterfaces); // walk parent chain too ClassModel parent = cm.getParent(); if (null == parent) { // at this point, we check all interfaces to see if they have super interfaces Set<String> newIfaces = new LinkedHashSet<String>(); for (String ifaceName : interfaces) { InterfaceModel iface = types.getBy(InterfaceModel.class, ifaceName); getAllContractInterfaces(iface, newIfaces); } interfaces.addAll(newIfaces); } else if (!parent.getName().equals(Object.class.getName())) { findContracts(parent, interfaces, annotationTypeInterfaces); } }
private void generateElement(AnnotationModel element, MethodModel m, MultiMap<String, String> metadata) { String name = Dom.convertName(m.getName()); String xmlTokenName = "<" + name + ">"; String[] arguments = m.getArgumentTypes(); String refTypeAsString; if (arguments.length==0) { refTypeAsString = m.getReturnType(); } else { if (arguments.length!=1) { throw new RuntimeException("@Element method cannot have more than 1 argument " + m.getSignature()); } refTypeAsString = arguments[0]; } boolean isCollection = refTypeAsString.startsWith("java.util.List<L"); if (isCollection) { refTypeAsString = refTypeAsString.substring("java.util.List<L".length()); } Boolean isReference = (Boolean) element.getValues().get("reference"); Type refType = context.getTypes().getBy(refTypeAsString); if (refType==null || (isReference!=null && isReference)) { // leaf metadata.add(xmlTokenName, makeCollectionIfNecessary(isCollection, "leaf")); if (isReference!=null && isReference) { metadata.add(xmlTokenName, "reference"); } } else { // node metadata.add(xmlTokenName, makeCollectionIfNecessary(isCollection, refTypeAsString)); } }
ParsingContext context = classParser.getContext(); for (String annotation: defaultScanner.getAnnotations()) { Type type = context.getTypes().getBy(annotation);
private void generateElement(AnnotationModel element, MethodModel m, MultiMap<String, String> metadata) { String name = Dom.convertName(m.getName()); String xmlTokenName = "<" + name + ">"; String[] arguments = m.getArgumentTypes(); String refTypeAsString; if (arguments.length==0) { refTypeAsString = m.getReturnType(); } else { if (arguments.length!=1) { throw new RuntimeException("@Element method cannot have more than 1 argument " + m.getSignature()); } refTypeAsString = arguments[0]; } boolean isCollection = refTypeAsString.startsWith("java.util.List<L"); if (isCollection) { refTypeAsString = refTypeAsString.substring("java.util.List<L".length()); } Boolean isReference = (Boolean) element.getValues().get("reference"); Type refType = context.getTypes().getBy(refTypeAsString); if (refType==null || (isReference!=null && isReference)) { // leaf metadata.add(xmlTokenName, makeCollectionIfNecessary(isCollection, "leaf")); if (isReference!=null && isReference) { metadata.add(xmlTokenName, "reference"); } } else { // node metadata.add(xmlTokenName, makeCollectionIfNecessary(isCollection, refTypeAsString)); } }
Type type = types.getBy(annotationType);
InterfaceModel iface = types.getBy(InterfaceModel.class, ifaceName); getAllContractInterfaces(iface, newIfaces);
Type type = types.getBy(annotationType);
Type refType = context.getTypes().getBy(refTypeAsString); Boolean isReference = (Boolean) attribute.getValues().get("reference"); if (refType==null || (isReference!=null &&isReference)) {
Type refType = context.getTypes().getBy(refTypeAsString); Boolean isReference = (Boolean) attribute.getValues().get("reference"); if (refType==null || (isReference!=null &&isReference)) {
Type type = context.getTypes().getBy(annotation);