private Element annotatedToElement(Annotation annotation) { Collection<Element> properties = Create.set(); for (String key : annotation.keySet()) { addAnnotationMember(properties, key, annotation.get(key)); } return new Element(Type.ANNOTATED, annotation.getName().getFQN(), properties, CHANGED, CHANGED, null); }
@Override public void annotation(Annotation annotation) throws Exception { String fqn = annotation.getName() .getFQN(); if (fqn.equals("aQute.bnd.annotation.xml.XMLAttribute")) { xmlAttr = annotation.getAnnotation(XMLAttribute.class); } }
@Override public void annotation(Annotation annotation) { try { Meta.OCD ocd = annotation.getAnnotation(Meta.OCD.class); Meta.AD ad = annotation.getAnnotation(Meta.AD.class); if (ocd != null) { MetaTypeReader.this.ocdAnnotation = annotation; } if (ad != null) { assert method != null; // Fixup required since it is default true // but we have no access to these defaults. // i.e. the defaults are implemented in the code // thus here try { if (annotation.get("required") == null) annotation.put("required", true); } catch (Exception e) { // can fail ... see #514 } methods.put(method, ad); } } catch (Exception e) { reporter.error("Error during annotation parsing %s : %s", clazz, e); e.printStackTrace(); } }
private ComponentPropertyTypeDataCollector(Annotation componentPropertyAnnotation, EntryWriter componentWriter) { m_componentWriter = componentWriter; // Add in the defined attributes for (String key : componentPropertyAnnotation.keySet()) { Object value = componentPropertyAnnotation.get(key); m_logger.debug("ComponentPropertyTypeDataCollector: handle value %s %s", key, value); handleValue(key, value, value instanceof TypeRef, null); } }
private void handleAttributeOrDirective(Annotation a) { Object o = annotation.get(lastMethodSeen); if (o != null) { String attributeName = a.get("value"); if (attributeName == null) { attributeName = lastMethodSeen; } if (STD_DIRECTIVE.equals(a.getName() .getFQN())) { attributeName += ":"; } if (!attributesAndDirectives.containsKey(attributeName)) { attributesAndDirectives.putTyped(attributeName, o); } } }
/** * Get an annotation attribute, and return a default value if its not present. * @param <T> the type of the variable which is assigned to the return value of this method. * @param annotation The annotation we are parsing * @param name the attribute name to get from the annotation * @param defaultValue the default value to return if the attribute is not found in the annotation * @return the annotation attribute value, or the defaultValue if not found */ @SuppressWarnings("unchecked") private <T> T get(Annotation annotation, String name, T defaultValue) { T value = (T) annotation.get(name); return value != null ? value : defaultValue; }
public <T extends java.lang.annotation.Annotation> T getAnnotation() throws Exception { return getAnnotation(getClass().getClassLoader()); }
private void mergeAttributesAndDirectives(Annotation a) { String fqn = a.getName() .getFQN(); switch (fqn) { case STD_CAPABILITIES : case STD_REQUIREMENTS : Object[] annotations = a.get("value"); for (int i = 0; i < annotations.length; i++) { mergeAttributesAndDirectives((Annotation) annotations[i]); } break; default : if (!attributesAndDirectives.isEmpty()) { Object[] original = a.get("attribute"); int length = (original != null) ? original.length : 0; Object[] updated = new Object[length + attributesAndDirectives.size()]; if (length > 0) { System.arraycopy(original, 0, updated, 0, length); } for (String key : attributesAndDirectives.keySet()) { updated[length++] = attributesAndDirectives.toString(key); } a.put("attribute", updated); } break; } }
public Map<String, String> getDefaults(Annotation a) { TypeRef name = a.getName(); Map<String, String> defaults = defaultsCache.get(name); if (defaults == null) defaults = extractDefaults(name, analyzer); if (defaults == null) return new LinkedHashMap<>(); return new LinkedHashMap<>(defaults); }
String componentName = annotation.containsKey("name") ? comp.name() : className.getFQN(); if (annotation.get("factory") != null) { component.factory = comp.factory(); if (annotation.get("configurationPolicy") != null) { component.configurationPolicy = comp.configurationPolicy(); if (annotation.get("enabled") != null) { component.enabled = comp.enabled(); if (annotation.get("factory") != null) { component.factory = comp.factory(); if (annotation.get("immediate") != null) { component.immediate = comp.immediate(); if (annotation.get("servicefactory") != null) { @SuppressWarnings("deprecation") boolean servicefactory = comp.servicefactory(); component.scope = servicefactory ? ServiceScope.BUNDLE : ServiceScope.SINGLETON; if (annotation.get("scope") != null && comp.scope() != ServiceScope.DEFAULT) { component.scope = comp.scope(); if (comp.scope() == ServiceScope.PROTOTYPE) { if (annotation.get("configurationPid") != null) { component.configurationPid = comp.configurationPid(); if (component.configurationPid.length > 1) {
private void doAD(ADDef ad, Pair pair) throws Exception { AttributeDefinition a = pair.getAd(); Annotation annotation = pair.getA(); if (a.name() != null) { ad.name = a.name(); } ad.description = a.description(); if (a.type() != null) { ad.type = a.type().toString(); } ad.cardinality = a.cardinality(); ad.max = a.max(); ad.min = a.min(); ad.defaults = a.defaultValue(); if (annotation.get("required") != null) { ad.required = a.required(); } if (annotation.get("options") != null) { ad.options.clear(); for (Object o : (Object[])annotation.get("options")) { Option opt = ((Annotation)o).getAnnotation(); ad.options.add(new OptionDef(opt.label(), opt.value())); } } }
@Override public void annotation(Annotation a) throws Exception { String fqn = a.getName() .getFQN(); switch (fqn) { a.merge(annotation); a.addDefaults(c); AnnotationHeaders.this.annotation(a); break; Set<String> processed = new HashSet<>(this.processed); processed.add(c.getFQN()); doAnnotatedAnnotation(a, a.getName(), processed, attributesAndDirectives); break;
private Element annotatedToElement(Annotation annotation) { Collection<Element> properties = Create.set(); for (Entry<String, Object> entry : annotation.entrySet()) { addAnnotationMember(properties, entry.getKey(), entry.getValue()); } return new Element(ANNOTATED, annotation.getName() .getFQN(), properties, CHANGED, CHANGED, null); }
return new Annotation(name, elements, member, policy); return null;
if (a.containsKey("name")) { cap.append(';') .append(annotation.namespace()) if (a.containsKey("version")) { try { Version.parseVersion(annotation.version()); if (a.containsKey("uses")) { cap.append(a.stream("uses", TypeRef.class) // .map(TypeRef::getPackageRef) .map(PackageRef::getFQN) if (a.containsKey("effective")) { cap.append(";effective:="); escape(cap, annotation.effective());
void doComponent(Annotation a, Component c) { pids = a.containsKey("configurationPid") ? c.configurationPid() : null; if (pids != null) { pid = pids[0]; } if (pids == null || "$".equals(pid)) { pid = a.containsKey("name") ? c.name() : clazz.getClassName() .getFQN(); } }
ComponentPropertyTypeDataCollector(String propertyDefKey, Annotation componentPropertyAnnotation, DeclarativeServicesAnnotationError details) { this.propertyDefKey = requireNonNull(propertyDefKey); // Component Property annotations added in 1.4, but they just map to // normal DS properties, so there's not really a need to require DS // 1.4. Therefore we just leave the required version as is this.memberDescriptor = null; this.details = details; // Add in the defined attributes for (Entry<String, Object> entry : componentPropertyAnnotation.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); handleValue(key, value, value instanceof TypeRef, null); } }
private void handleAttributeOrDirective(Annotation a) { Object o = annotation.get(lastMethodSeen); if (o != null) { String attributeName = a.get("value"); if (attributeName == null) { attributeName = lastMethodSeen; } if (STD_DIRECTIVE.equals(a.getName() .getFQN())) { attributeName += ":"; } if (!attributesAndDirectives.containsKey(attributeName)) { attributesAndDirectives.putTyped(attributeName, o); } } }
private void doDesignate(Annotation annotation) { if (TRUE.equals(annotation.get("factory")) && (component.configurationPolicy == null)) { component.configurationPolicy = ConfigurationPolicy.REQUIRE; } }
public <T extends java.lang.annotation.Annotation> T getAnnotation() throws Exception { return getAnnotation(getClass().getClassLoader()); }