/** * 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; }
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 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; } }
@Override public void annotation(Annotation annotation) throws Exception { String fqn = annotation.getName() .getFQN(); if (fqn.equals("org.osgi.service.cdi.annotations.Beans")) { Object[] beanClasses = annotation.get("value"); if (beanClasses != null && beanClasses.length > 0) { marked = new Instruction(Arrays.stream(beanClasses) .map(Object::toString) .collect(Collectors.joining(","))); } else { marked = new Instruction("*"); } } } }
private void doDesignate(Annotation annotation) { if (TRUE.equals(annotation.get("factory")) && (component.configurationPolicy == null)) { component.configurationPolicy = ConfigurationPolicy.REQUIRE; } }
@Override public void annotation(Annotation annotation) throws Exception { String fqn = annotation.getName() .getFQN(); if (fqn.equals("org.osgi.service.cdi.annotations.Beans")) { Object[] beanClasses = annotation.get("value"); if (beanClasses != null && beanClasses.length > 0) { marked = new Instruction(Arrays.stream(beanClasses) .map(Object::toString) .collect(Collectors.joining(","))); } else { marked = new Instruction("*"); } } } }
private void doProperties(aQute.bnd.osgi.Annotation annotation) { Object[] properties = annotation.get(Component.PROPERTIES); if (properties != null) { for (Object o : properties) { String p = (String) o; Matcher m = PROPERTY_PATTERN.matcher(p); if (m.matches()) this.properties.add(m.group(1)+"="+m.group(2)); else throw new IllegalArgumentException("Malformed property '" + p + "' on: " + annotation.get(Component.NAME)); } } }
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); }
private void doProperties(aQute.bnd.osgi.Annotation annotation) { Object[] properties = annotation.get(Component.PROPERTIES); if (properties != null) { for (Object o : properties) { String p = (String) o; Matcher m = PROPERTY_PATTERN.matcher(p); if (m.matches()) this.properties.add(m.group(1)+"="+m.group(2)); else throw new IllegalArgumentException("Malformed property '" + p + "' on: " + annotation.get(Component.NAME)); } } }
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); }
private void doProperties(aQute.bnd.osgi.Annotation annotation) { Object[] properties = annotation.get(Component.PROPERTIES); if (properties != null) { for (Object o : properties) { String p = (String) o; Matcher m = PROPERTY_PATTERN.matcher(p); if (m.matches()) this.properties.add(m.group(1)+"="+m.group(2)); else throw new IllegalArgumentException("Malformed property '" + p + "' on: " + annotation.get(Component.NAME)); } } }
public <T> Stream<T> stream(String key, Class<? extends T> type) { Object v = get(key); if (v == null) { return Stream.empty(); } if (v.getClass() .isArray()) { return Arrays.stream((Object[]) v) .map(type::cast); } return Stream.of(v) .map(type::cast); }
public <T> Stream<T> stream(String key, Class<? extends T> type) { Object v = get(key); if (v == null) { return Stream.empty(); } if (v.getClass() .isArray()) { return Arrays.stream((Object[]) v) .map(type::cast); } return Stream.of(v) .map(type::cast); }
/** * Parse the name of a given dependency. * @param writer The writer where to write the dependency name * @param annotation the dependency to be parsed */ private void parseDependencyName(EntryWriter writer, Annotation annotation) { String name = annotation.get(EntryParam.name.toString()); if (name != null) { if(! m_dependencyNames.add(name)) { throw new IllegalArgumentException("Duplicate dependency name " + name + " in Dependency " + annotation + " from class " + m_currentClassName); } writer.put(EntryParam.name, name); } }
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); } }
/** * Get a String attribute value from an annotation and write it into this descriptor entry. */ public String putString(Annotation annotation, EntryParam param, String def) { checkType(param.toString()); Object value = annotation.get(param.toString()); if (value == null && def != null) { value = def; } if (value != null) { put(param, value.toString()); } return value == null ? null : value.toString(); }
/** * Get a class attribute value from an annotation and write it into this descriptor entry. */ public void putClass(Annotation annotation, EntryParam param) { checkType(param.toString()); String value = AnnotationCollector.parseClassAttrValue(annotation.get(param.toString())); if (value != null) { put(param, value); } }
private void doOCD(ObjectClassDefinition o, Annotation annotation) { ocd = new OCDDef(); ocd.id = o.id() == null? name.getFQN(): o.id(); ocd.name = o.name() == null? space(ocd.id): o.name(); ocd.description = o.description() == null? "": o.description(); ocd.localization = o.localization() == null? "OSGI-INF/l10n/" + name.getFQN(): o.localization(); if (annotation.get("pid") != null ) { String[] pids = o.pid(); designates(pids, false); } if (annotation.get("factoryPid") != null ) { String[] pids = o.factoryPid(); designates(pids, true); } if (annotation.get("icon") != null) { Icon[] icons = o.icon(); for (Icon icon: icons) { ocd.icons.add(new IconDef(icon.resource(), icon.size())); } } }
private void parseBundleDependencyAnnotation(Annotation annotation) { checkDependencyAlreadyDeclaredInChild(annotation, m_method, true); EntryWriter writer = new EntryWriter(EntryType.BundleDependency); m_writers.add(writer); String filter = annotation.get(EntryParam.filter.toString()); if (filter != null) { Verifier.verifyFilter(filter, 0); writer.put(EntryParam.filter, filter); } writer.putString(annotation, EntryParam.added, m_method); writer.putString(annotation, EntryParam.changed, null); writer.putString(annotation, EntryParam.removed, null); writer.putString(annotation, EntryParam.required, null); writer.putString(annotation, EntryParam.stateMask, null); writer.putString(annotation, EntryParam.propagate, null); parseDependencyName(writer, annotation); }