use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class Target method testSimple.
public void testSimple() throws Exception {
Analyzer analyzer = new Analyzer();
Clazz clazz = new Clazz(analyzer, "", null);
ClassDataCollector cd = new ClassDataCollector() {
@Override
public void addReference(TypeRef token) {
}
@Override
public void annotation(Annotation annotation) {
System.err.println("Annotation " + annotation);
}
@Override
public void classBegin(int access, TypeRef name) {
System.err.println("Class " + name);
}
@Override
public void classEnd() {
System.err.println("Class end ");
}
@Override
public void extendsClass(TypeRef name) {
System.err.println("extends " + name);
}
@Override
public void implementsInterfaces(TypeRef[] name) {
System.err.println("implements " + Arrays.toString(name));
}
@Override
public void parameter(int p) {
System.err.println("parameter " + p);
}
};
clazz.parseClassFile(getClass().getResourceAsStream("Target.class"), cd);
}
use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class DescriptorsTest method testReferences.
public static void testReferences() {
Descriptors d = new Descriptors();
TypeRef r = d.getTypeRef("[B");
assertNotNull(r);
assertEquals("byte[]", r.getFQN());
assertNotNull(r.getPackageRef());
assertEquals(".", r.getPackageRef().getFQN());
PackageRef a = d.getPackageRef("a.b.c");
PackageRef b = d.getPackageRef("a/b/c");
assertTrue(a == b);
}
use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class ParseSignatureBuilder method parse.
public void parse(InputStream in) throws Exception {
Analyzer analyzer = new Analyzer();
Clazz clazz = new Clazz(analyzer, "", null);
clazz.parseClassFile(in, new ClassDataCollector() {
Scope s;
Scope enclosing;
Scope declaring;
@Override
public void classBegin(int access, TypeRef name) {
s = root.getScope(name.getBinary());
s.access = Access.modifier(access);
s.kind = Kind.CLASS;
}
@Override
public void extendsClass(TypeRef name) {
// s.setBase(new GenericType(name));
}
@Override
public void implementsInterfaces(TypeRef[] names) {
s.setParameterTypes(convert(names));
}
GenericType[] convert(TypeRef[] names) {
GenericType[] tss = new GenericType[names.length];
for (int i = 0; i < names.length; i++) {
// tss[i] = new GenericType(names[i]);
}
return tss;
}
@Override
public void method(Clazz.MethodDef defined) {
String descriptor;
Kind kind;
if (defined.isConstructor()) {
descriptor = ":" + defined.getDescriptor();
kind = Kind.CONSTRUCTOR;
} else {
descriptor = defined.getName() + ":" + defined.getDescriptor();
kind = Kind.METHOD;
}
Scope m = s.getScope(descriptor);
m.access = Access.modifier(defined.getAccess());
m.kind = kind;
m.declaring = s;
s.add(m);
}
@Override
public void field(Clazz.FieldDef defined) {
String descriptor = defined.getName() + ":" + defined.getDescriptor();
Kind kind = Kind.FIELD;
Scope m = s.getScope(descriptor);
m.access = Access.modifier(defined.getAccess());
m.kind = kind;
m.declaring = s;
s.add(m);
}
@Override
public void classEnd() {
if (enclosing != null)
s.setEnclosing(enclosing);
if (declaring != null)
s.setDeclaring(declaring);
}
@Override
public void enclosingMethod(TypeRef cName, String mName, String mDescriptor) {
enclosing = root.getScope(cName.getBinary());
if (mName != null) {
enclosing = enclosing.getScope(Scope.methodIdentity(mName, mDescriptor));
}
}
@Override
public void innerClass(TypeRef innerClass, TypeRef outerClass, String innerName, int innerClassAccessFlags) {
if (outerClass != null && innerClass != null && innerClass.getBinary().equals(s.name))
declaring = root.getScope(outerClass.getBinary());
}
});
}
use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class ComponentDef method getTag.
/**
* Returns a tag describing the component element.
*
* @return a component element
*/
Tag getTag() {
String xmlns = this.xmlns;
if (xmlns == null && !version.equals(AnnotationReader.V1_0))
xmlns = NAMESPACE_STEM + "/v" + version;
Tag component = new Tag(xmlns == null ? "component" : "scr:component");
Namespaces namespaces = null;
if (xmlns != null) {
namespaces = new Namespaces();
namespaces.registerNamespace("scr", xmlns);
addNamespaces(namespaces, xmlns);
for (ReferenceDef ref : references.values()) ref.addNamespaces(namespaces, xmlns);
namespaces.addNamespaces(component);
}
component.addAttribute("name", name);
if (configurationPolicy != null)
component.addAttribute("configuration-policy", configurationPolicy.toString().toLowerCase());
if (enabled != null)
component.addAttribute("enabled", enabled);
if (immediate != null)
component.addAttribute("immediate", immediate);
if (factory != null)
component.addAttribute("factory", factory);
if (activate != null && !version.equals(AnnotationReader.V1_0))
component.addAttribute("activate", activate);
if (deactivate != null && !version.equals(AnnotationReader.V1_0))
component.addAttribute("deactivate", deactivate);
if (modified != null)
component.addAttribute("modified", modified);
if (configurationPid != null) {
StringBuilder b = new StringBuilder();
String space = "";
for (String pid : configurationPid) {
if ("$".equals(pid))
pid = name;
b.append(space).append(pid);
space = " ";
}
component.addAttribute("configuration-pid", b.toString());
}
addAttributes(component, namespaces);
Tag impl = new Tag(component, "implementation");
impl.addAttribute("class", implementation.getFQN());
if (service != null && service.length != 0) {
Tag s = new Tag(component, "service");
if (scope != null) {
// TODO check for DEFAULT???
if (AnnotationReader.V1_3.compareTo(version) > 0) {
if (scope == ServiceScope.PROTOTYPE) {
throw new IllegalStateException("verification failed, pre 1.3 component with scope PROTOTYPE");
}
s.addAttribute("servicefactory", scope == ServiceScope.BUNDLE);
} else {
s.addAttribute("scope", scope.toString().toLowerCase());
}
}
for (TypeRef ss : service) {
Tag provide = new Tag(s, "provide");
provide.addAttribute("interface", ss.getFQN());
}
}
for (ReferenceDef ref : references.values()) {
Tag refTag = ref.getTag(namespaces);
component.addContent(refTag);
}
for (Tag tag : propertyTags) component.addContent(tag);
for (String entry : properties) {
Tag properties = new Tag(component, "properties");
properties.addAttribute("entry", entry);
}
return component;
}
use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class ComponentDef method prepare.
/**
* Called to prepare. If will look for any errors or inconsistencies in the
* setup.
*
* @param analyzer the analyzer to report errors and create references
* @throws Exception
*/
void prepare(Analyzer analyzer) throws Exception {
prepareVersion(analyzer);
if (implementation == null) {
analyzer.error("No Implementation defined for component %s", name);
return;
}
analyzer.referTo(implementation);
if (name == null)
name = implementation.getFQN();
if (service != null && service.length > 0) {
for (TypeRef interfaceName : service) analyzer.referTo(interfaceName);
} else if (scope != null && scope != ServiceScope.BUNDLE)
analyzer.warning("The servicefactory:=true directive is set but no service is provided, ignoring it");
for (Map.Entry<String, List<String>> kvs : property.entrySet()) {
Tag property = new Tag("property");
String name = kvs.getKey();
String type = propertyType.get(name);
property.addAttribute("name", name);
if (type != null) {
property.addAttribute("type", type);
}
if (kvs.getValue().size() == 1) {
String value = kvs.getValue().get(0);
value = check(type, value, analyzer);
property.addAttribute("value", value);
} else {
StringBuilder sb = new StringBuilder();
String del = "";
for (String v : kvs.getValue()) {
if (v == MARKER) {
continue;
}
sb.append(del);
v = check(type, v, analyzer);
sb.append(v);
del = "\n";
}
property.addContent(sb.toString());
}
propertyTags.add(property);
}
}
Aggregations