Package aQute.bnd.osgi.Descriptors

Examples of aQute.bnd.osgi.Descriptors.TypeRef


    if (!referred.containsKey(pack))
      referred.put(pack, new Attrs());
  }

  public void referToByBinaryName(String binaryClassName) {
    TypeRef ref = descriptors.getTypeRef(binaryClassName);
    referTo(ref);
  }
View Full Code Here


    String min = null;
    String[] optionLabels = null;
    String[] optionValues = null;
    String description = null;

    TypeRef typeRef = reporter.getTypeRefFromFQN(rtype);
    Clazz c = reporter.findClass(typeRef);
    if (c != null && c.isEnum()) {
      optionValues = parseOptionValues(c);
    }
View Full Code Here

    if (ifaces != null) {
      for (TypeRef ref : ifaces) {
        parseAndMergeInheritedMetadata(ref, child);
      }
    }
    TypeRef superClazz = child.getSuper();
    if (superClazz != null) {
      parseAndMergeInheritedMetadata(superClazz, child);
    }
  }
View Full Code Here

    final Set<Element> members = new LinkedHashSet<Element>();
    final Set<MethodDef> methods = new LinkedHashSet<MethodDef>();
    final Set<Clazz.FieldDef> fields = Create.set();
    final MultiMap<Clazz.Def,Element> annotations = new MultiMap<Clazz.Def,Element>();

    final TypeRef name = clazz.getClassName();

    final String fqn = name.getFQN();
    final String shortName = name.getShortName();

    // Check if this clazz is actually a provider or not
    // providers must be listed in the exported package in the
    // PROVIDER_TYPE directive.
    Instructions matchers = providerMatcher.get(name.getPackageRef());
    boolean p = matchers != null && matchers.matches(shortName);
    final AtomicBoolean provider = new AtomicBoolean(p);

    //
    // Check if we already had this clazz in the cache
    //

    Element before = cache.get(clazz); // for super classes
    if (before != null)
      return before;

    clazz.parseClassFileWithCollector(new ClassDataCollector() {
      boolean      memberEnd;
      Clazz.FieldDef  last;

      @Override
      public void version(int minor, int major) {
        javas.add(Clazz.JAVA.getJava(major, minor));
      }

      @Override
      public void method(MethodDef defined) {
        if ((defined.isProtected() || defined.isPublic())) {
          last = defined;
          methods.add(defined);
        } else {
          last = null;
        }
      }

      @Override
      public void deprecated() {
        if (memberEnd)
          clazz.setDeprecated(true);
        else if (last != null)
          last.setDeprecated(true);
      }

      @Override
      public void field(Clazz.FieldDef defined) {
        if (defined.isProtected() || defined.isPublic()) {
          last = defined;
          fields.add(defined);
        } else
          last = null;
      }

      @Override
      public void constant(Object o) {
        if (last != null) {
          // Must be accessible now
          last.setConstant(o);
        }
      }

      @Override
      public void extendsClass(TypeRef name) throws Exception {
        String comment = null;
        if (!clazz.isInterface())
          comment = inherit(members, name);

        Clazz c = analyzer.findClass(name);
        if ((c == null || c.isPublic()) && !name.isObject())
          members.add(new Element(Type.EXTENDS, name.getFQN(), null, MICRO, MAJOR, comment));
      }

      @Override
      public void implementsInterfaces(TypeRef names[]) throws Exception {
        // TODO is interface reordering important for binary
        // compatibility??

        for (TypeRef name : names) {

          String comment = null;
          if (clazz.isInterface() || clazz.isAbstract())
            comment = inherit(members, name);
          members.add(new Element(Type.IMPLEMENTS, name.getFQN(), null, MINOR, MAJOR, comment));
        }
      }

      /**
       * @param members
       * @param name
       * @param comment
       * @return
       */
      Set<Element>  OBJECT  = Create.set();

      public String inherit(final Set<Element> members, TypeRef name) throws Exception {
        if (name.isObject()) {
          if (OBJECT.isEmpty()) {
            Clazz c = analyzer.findClass(name);
            Element s = classElement(c);
            for (Element child : s.children) {
              if (INHERITED.contains(child.type)) {
View Full Code Here

          ad.cardinality = Integer.MIN_VALUE;
        }
      }

      ad.required = true;
      TypeRef typeRef = analyzer.getTypeRefFromFQN(rtype);
      try {
        Clazz c = analyzer.findClass(typeRef);
        if (c != null && c.isEnum()) {
          parseOptionValues(c, ad.options);
        }
View Full Code Here

  private void processAnnotationArguments(final String methodDescriptor) {
    Matcher m = LIFECYCLEARGUMENT.matcher(methodDescriptor);
    while (m.find()) {
      String type = m.group(6);
      if (type != null) {
        TypeRef typeRef = analyzer.getTypeRef(type);
        try {
          Clazz clazz = analyzer.findClass(typeRef);
          if (clazz.isAnnotation()) {
            final MultiMap<String, String> props = new MultiMap<String, String>();
            clazz.parseClassFileWithCollector(new ClassDataCollector() {

              @Override
              public void annotationDefault(Clazz.MethodDef defined) {
                Object value = defined.getConstant();
                //check type, exit with warning if annotation or annotation array
                boolean isClass = false;
                boolean isCharacter = false;
                TypeRef type = defined.getType().getClassRef();
                if (!type.isPrimitive()) {
                  if (Class.class.getName().equals(type.getFQN())) {
                    isClass = true;
                  } else {
                    try {
                      Clazz r = analyzer.findClass(type);
                      if (r.isAnnotation()) {
                        analyzer.warning("Nested annotation type found in field % s, %s", defined.getName(), type.getFQN());
                        return;
                      }
                    } catch (Exception e) {
                      analyzer.error("Exception looking at annotation type to lifecycle method with descriptor %s,  type %s", e, methodDescriptor, type);
                    }
                  }
                } else if ("char".equals(type.getFQN())) {
                  isCharacter = true;
                }
                if (value != null) {
                  String name = identifierToPropertyName(defined.getName());
                  if (value.getClass().isArray()) {
View Full Code Here

    } else {
      // We have explicit interfaces set
      component.service = new TypeRef[x.length];
      for (int i = 0; i < x.length; i++) {
        String s = (String) x[i];
        TypeRef ref = analyzer.getTypeRefFromFQN(s);
        component.service[i] = ref;
      }
    }
    Object[] refAnnotations = annotation.get("reference");
    if (refAnnotations != null) {
      for (Object o: refAnnotations) {
        Annotation refAnnotation = (Annotation)o;
        LookupReference ref = refAnnotation.getAnnotation();
        ReferenceDef refdef = new ReferenceDef();
        refdef.name = ref.name();
        refdef.service = analyzer.getTypeRef((String) refAnnotation.get("service")).getFQN();
        refdef.cardinality = ref.cardinality();
        refdef.policy = ref.policy();
        refdef.policyOption = ref.policyOption();
        refdef.target = ref.target();
        refdef.scope = ref.scope();
        component.references.put(refdef.name, refdef);
      }
    }

  }
View Full Code Here

    }
   
    //analyze the class for suitable methods.
    final Map<String, MethodDef> lifecycleMethods = new HashMap<String, MethodDef>();
    final Map<String, MethodDef> bindmethods = new HashMap<String, MethodDef>();
    TypeRef typeRef = analyzer.getTypeRefFromFQN(impl);
    Clazz clazz = analyzer.findClass(typeRef);
    boolean privateAllowed = true;
    boolean defaultAllowed = true;
    String topPackage = typeRef.getPackageRef().getFQN();
    while (clazz != null) {
      final boolean pa = privateAllowed;
      final boolean da = defaultAllowed;
      final Map<String, MethodDef> classLifecyclemethods = new HashMap<String, MethodDef>();
      final Map<String, MethodDef> classBindmethods = new HashMap<String, MethodDef>();
     
      clazz.parseClassFileWithCollector(new ClassDataCollector() {
       
        @Override
        public void method(MethodDef md) {
          Set<String> allowedParams = allowed;
          String lifecycleName = null;
         
          boolean isLifecycle = (cd.activate == null? "activate": cd.activate).equals(md.getName()) ||
            md.getName().equals(cd.modified)
          if (!isLifecycle && (cd.deactivate == null? "deactivate": cd.deactivate).equals(md.getName())) {
            isLifecycle = true;
            allowedParams = allowedDeactivate;
          }
          if (isLifecycle && !lifecycleMethods.containsKey(md.getName()) &&
              (md.isPublic() ||
                  md.isProtected() ||
                  (md.isPrivate() && pa) ||
                  (!md.isPrivate()) && da) &&
              isBetter(md, classLifecyclemethods.get(md.getName()), allowedParams)) {
            classLifecyclemethods.put(md.getName(), md);
          }
          if (!bindmethods.containsKey(md.getName()) &&
              (md.isPublic() ||
                  md.isProtected() ||
                  (md.isPrivate() && pa) ||
                  (!md.isPrivate()) && da) &&
              isBetterBind(md, classBindmethods.get(md.getName()))) {
            classBindmethods.put(md.getName(), md);
          }
        }

        private boolean isBetter(MethodDef test, MethodDef existing, Set<String> allowedParams) {
          int testRating = rateLifecycle(test, allowedParams);
          if (existing == null)
            return testRating < 6;// ignore invalid methods
          if (testRating < rateLifecycle(existing, allowedParams))
            return true;
         
          return false;
        }

        private boolean isBetterBind(MethodDef test, MethodDef existing) {
          int testRating = rateBind(test);
          if (existing == null)
            return testRating < 6;// ignore invalid methods
          if (testRating < rateBind(existing))
            return true;
         
          return false;
        }

      });
      lifecycleMethods.putAll(classLifecyclemethods);
      bindmethods.putAll(classBindmethods);
      typeRef = clazz.getSuper();
      if (typeRef == null)
        break;
      clazz = analyzer.findClass(typeRef);
      privateAllowed = false;
      defaultAllowed = defaultAllowed && topPackage.equals(typeRef.getPackageRef().getFQN());
    }
   
   
    if (cd.activate != null && !lifecycleMethods.containsKey(cd.activate)) {
      error("in component %s, activate method %s specified but not found", cd.implementation.getFQN(), cd.activate);
View Full Code Here

    if (provides != null) {
      StringTokenizer st = new StringTokenizer(provides, ",");
      List<TypeRef> provide = new ArrayList<TypeRef>();
      while (st.hasMoreTokens()) {
        String interfaceName = st.nextToken();
        TypeRef ref = analyzer.getTypeRefFromFQN(interfaceName);
        provide.add(ref);
        analyzer.referTo(ref);

        // TODO verifies the impl. class extends or implements the
        // interface
View Full Code Here

      Matcher m = REFERENCE.matcher(interfaceName);
      if (m.matches()) {
        interfaceName = m.group(1);
        target = m.group(2);
      }
      TypeRef ref = analyzer.getTypeRefFromFQN(interfaceName);
      analyzer.referTo(ref);
      ReferenceDef rd = new ReferenceDef();
      rd.name = referenceName;
      rd.service = interfaceName;
View Full Code Here

TOP

Related Classes of aQute.bnd.osgi.Descriptors.TypeRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.