use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class XMLAttributeFinder method getXMLAttribute.
public synchronized XMLAttribute getXMLAttribute(Annotation a) throws Exception {
TypeRef name = a.getName();
if (annoCache.containsKey(name))
return annoCache.get(name);
Clazz clazz = analyzer.findClass(name);
if (clazz != null) {
xmlAttr = null;
clazz.parseClassFileWithCollector(this);
annoCache.put(name, xmlAttr);
return xmlAttr;
}
return null;
}
use of aQute.bnd.osgi.Descriptors.TypeRef in project bnd by bndtools.
the class ComponentAnnotationReader method annotation.
@Override
public void annotation(Annotation annotation) {
String fqn = annotation.getName().getFQN();
if (fqn.equals("aQute.bnd.annotation.component.Component")) {
if (!mismatchedAnnotations.isEmpty()) {
String componentName = annotation.get(Component.NAME);
componentName = (componentName == null) ? className.getFQN() : componentName;
for (Entry<String, List<DeclarativeServicesAnnotationError>> e : mismatchedAnnotations.entrySet()) {
for (DeclarativeServicesAnnotationError errorDetails : e.getValue()) {
if (errorDetails.fieldName != null) {
reporter.error("The DS component %s uses bnd annotations to declare it as a component, but also uses the standard DS annotation: %s on field %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.fieldName).details(errorDetails);
} else if (errorDetails.methodName != null) {
reporter.error("The DS component %s uses bnd annotations to declare it as a component, but also uses the standard DS annotation: %s on method %s with signature %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.methodName, errorDetails.methodSignature).details(errorDetails);
} else {
reporter.error("The DS component %s uses bnd annotations to declare it as a component, but also uses the standard DS annotation: %s. It is an error to mix these two types of annotations", componentName, e.getKey()).details(errorDetails);
}
}
}
return;
}
set(COMPONENT_NAME, annotation.get(Component.NAME), "<>");
set(COMPONENT_FACTORY, annotation.get(Component.FACTORY), false);
setBoolean(COMPONENT_ENABLED, annotation.get(Component.ENABLED), true);
setBoolean(COMPONENT_IMMEDIATE, annotation.get(Component.IMMEDIATE), false);
setBoolean(COMPONENT_SERVICEFACTORY, annotation.get(Component.SERVICEFACTORY), false);
if (annotation.get(Component.DESIGNATE) != null) {
TypeRef configs = annotation.get(Component.DESIGNATE);
if (configs != null) {
set(COMPONENT_DESIGNATE, configs.getFQN(), "");
}
}
if (annotation.get(Component.DESIGNATE_FACTORY) != null) {
TypeRef configs = annotation.get(Component.DESIGNATE_FACTORY);
if (configs != null) {
set(COMPONENT_DESIGNATEFACTORY, configs.getFQN(), "");
}
}
setVersion((String) annotation.get(Component.VERSION));
String configurationPolicy = annotation.get(Component.CONFIGURATION_POLICY);
if (configurationPolicy != null)
set(COMPONENT_CONFIGURATION_POLICY, configurationPolicy.toLowerCase(), "");
doProperties(annotation);
Object[] provides = (Object[]) annotation.get(Component.PROVIDE);
String[] p;
if (provides == null) {
// fqn.
if (interfaces != null) {
List<String> result = new ArrayList<String>();
for (int i = 0; i < interfaces.length; i++) {
if (!interfaces[i].getBinary().equals("scala/ScalaObject"))
result.add(interfaces[i].getFQN());
}
p = result.toArray(EMPTY);
} else
p = EMPTY;
} else {
// We have explicit interfaces set
p = new String[provides.length];
for (int i = 0; i < provides.length; i++) {
p[i] = ((TypeRef) provides[i]).getFQN();
}
}
if (p.length > 0) {
set(COMPONENT_PROVIDE, Processor.join(Arrays.asList(p)), "<>");
}
} else if (fqn.equals("aQute.bnd.annotation.component.Activate")) {
if (!checkMethod())
setVersion(V1_1);
if (!ACTIVATEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches())
reporter.error("Activate method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", className, method.getDescriptor()).details(new DeclarativeServicesAnnotationError(className.getFQN(), method.getName(), method.getDescriptor().toString(), ErrorType.ACTIVATE_SIGNATURE_ERROR));
if (method.getName().equals("activate") && OLDACTIVATEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches()) {
// this is the default!
} else {
setVersion(V1_1);
set(COMPONENT_ACTIVATE, method, "<>");
}
} else if (fqn.equals("aQute.bnd.annotation.component.Deactivate")) {
if (!checkMethod())
setVersion(V1_1);
if (!ACTIVATEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches())
reporter.error("Deactivate method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", className, method.getDescriptor()).details(new DeclarativeServicesAnnotationError(className.getFQN(), method.getName(), method.getDescriptor().toString(), ErrorType.DEACTIVATE_SIGNATURE_ERROR));
if (method.getName().equals("deactivate") && OLDACTIVATEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches()) {
// This is the default!
} else {
setVersion(V1_1);
set(COMPONENT_DEACTIVATE, method, "<>");
}
} else if (fqn.equals("aQute.bnd.annotation.component.Modified")) {
if (!ACTIVATEDESCRIPTOR.matcher(method.getDescriptor().toString()).matches())
reporter.error("Modified method for %s does not have an acceptable prototype, only Map, ComponentContext, or BundleContext is allowed. Found: %s", className, method.getDescriptor()).details(new DeclarativeServicesAnnotationError(className.getFQN(), method.getName(), method.getDescriptor().toString(), ErrorType.MODIFIED_SIGNATURE_ERROR));
set(COMPONENT_MODIFIED, method, "<>");
setVersion(V1_1);
} else if (fqn.equals("aQute.bnd.annotation.component.Reference")) {
String name = (String) annotation.get("aQute.bnd.annotation.component.Reference");
String bind = method.getName();
String unbind = null;
if (name == null) {
Matcher m = BINDMETHOD.matcher(method.getName());
if (m.matches()) {
name = m.group(2).toLowerCase() + m.group(3);
} else {
name = method.getName().toLowerCase();
}
}
String simpleName = name;
unbind = annotation.get(Reference.UNBIND);
if (bind != null) {
name = name + "/" + bind;
if (unbind != null)
name = name + "/" + unbind;
}
String service = null;
TypeRef serviceTR = annotation.get(Reference.SERVICE);
if (serviceTR != null)
service = serviceTR.getFQN();
if (service == null) {
// We have to find the type of the current method to
// link it to the referenced service.
Matcher m = BINDDESCRIPTOR.matcher(method.getDescriptor().toString());
if (m.matches()) {
service = Descriptors.binaryToFQN(m.group(1));
} else
throw new IllegalArgumentException("Cannot detect the type of a Component Reference from the descriptor: " + method.getDescriptor());
}
// Check if we have a target, this must be a filter
String target = annotation.get(Reference.TARGET);
if (target != null) {
String error = Verifier.validateFilter(target);
if (error != null) {
reporter.error("Invalid target filter %s for %s: %s", target, name, error).details(new DeclarativeServicesAnnotationError(className.getFQN(), bind, method.getDescriptor().toString(), ErrorType.INVALID_TARGET_FILTER));
}
service = service + target;
}
Integer c = annotation.get(Reference.TYPE);
if (c != null && !c.equals(0) && !c.equals((int) '1')) {
service = service + (char) c.intValue();
}
if (map.containsKey(name))
reporter.error("In component %s, Multiple references with the same name: %s. Previous def: %s, this def: %s", name, map.get(name), service, "").details(new DeclarativeServicesAnnotationError(className.getFQN(), null, null, ErrorType.MULTIPLE_REFERENCES_SAME_NAME));
map.put(name, service);
if (isTrue(annotation.get(Reference.MULTIPLE)))
multiple.add(simpleName);
if (isTrue(annotation.get(Reference.OPTIONAL)))
optional.add(simpleName);
if (isTrue(annotation.get(Reference.DYNAMIC)))
dynamic.add(simpleName);
if (!checkMethod())
setVersion(V1_1);
else if (REFERENCEBINDDESCRIPTOR.matcher(method.getDescriptor().toString()).matches() || !OLDBINDDESCRIPTOR.matcher(method.getDescriptor().toString()).matches())
setVersion(V1_1);
} else if (fqn.startsWith("org.osgi.service.component.annotations")) {
DeclarativeServicesAnnotationError errorDetails;
switch(annotation.getElementType()) {
case METHOD:
errorDetails = new DeclarativeServicesAnnotationError(className.getFQN(), method.getName(), method.getDescriptor().toString(), ErrorType.MIXED_USE_OF_DS_ANNOTATIONS_BND);
break;
case FIELD:
errorDetails = new DeclarativeServicesAnnotationError(className.getFQN(), field.getName(), ErrorType.MIXED_USE_OF_DS_ANNOTATIONS_BND);
break;
default:
errorDetails = new DeclarativeServicesAnnotationError(className.getFQN(), null, ErrorType.MIXED_USE_OF_DS_ANNOTATIONS_BND);
}
List<DeclarativeServicesAnnotationError> errors = mismatchedAnnotations.get(fqn);
if (errors == null) {
errors = new ArrayList<DeclarativeServicesAnnotationError>();
mismatchedAnnotations.put(fqn, errors);
}
errors.add(errorDetails);
}
}
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());
}
});
}
Aggregations