Package aQute.bnd.osgi.Clazz

Examples of aQute.bnd.osgi.Clazz.MethodDef


        return;
      }
    }
    for (String lifecycle: LIFECYCLE_METHODS) {
      //lifecycle methods were not specified.... check for non 1.0 signatures.
      MethodDef test = descriptors.get(lifecycle);
      if (descriptors.containsKey(lifecycle) && (!(test.isPublic() || test.isProtected()) ||
          rateLifecycle(test, "deactivate".equals(lifecycle)? allowedDeactivate: allowed) > 1)) {
        cd.updateVersion(AnnotationReader.V1_1);
        return;
      }
    }
View Full Code Here


    // We must do this in the correct order so please
    // keep the linked hashset in place!

    Set<MethodDef> synthetic = new LinkedHashSet<MethodDef>();
    for (Iterator<MethodDef> i = methods.iterator(); i.hasNext();) {
      MethodDef m = i.next();
      if (m.isSynthetic()) {
        synthetic.add(m);
        i.remove();
      }
    }

    //System.out.println("methods/synthetic " + clazz+ " " + methods + " " + synthetic);
    for (MethodDef m : methods) {
     
      Collection<Element> children = annotations.get(m);
      if (children == null)
        children = new HashSet<Element>();

      access(children, m.getAccess(), m.isDeprecated());

      // A final class cannot be extended, ergo,
      // all methods defined in it are by definition
      // final. However, marking them final (either
      // on the method or inheriting it from the class)
      // will create superfluous changes if we
      // override a method from a super class that was not
      // final. So we actually remove the final for methods
      // in a final class.
      if (clazz.isFinal())
        children.remove(FINAL);

      // for covariant types we need to add the return types
      // and all the implemented and extended types. This is already
      // do for us when we get the element of the return type.


      getCovariantReturns(children, m.getType(), m.getGenericReturnType());

      /**
       * No longer includes synthetic methods in the tree
       */
//      for (Iterator<MethodDef> i = synthetic.iterator(); i.hasNext();) {
//        MethodDef s = i.next();
//        if (s.getName().equals(m.getName()) && Arrays.equals(s.getPrototype(), m.getPrototype())) {
//          i.remove();
//          getCovariantReturns(children, s.getType());
//        }
//      }

      String signature = m.getSignature();
      Matcher matcher;
      if (signature !=null && (matcher = PARAMETERS_P.matcher(signature)).matches()) {
        signature = matcher.group(1);
      } else
        signature = toString(m.getPrototype());
     
      Element member = new Element(Type.METHOD, m.getName() + signature, children, add, remove,
          null);

      if (!members.add(member)) {
        members.remove(member);
        members.add(member);
View Full Code Here

    // Remove all synthetic methods, we need
    // to treat them special for the covariant returns

    Set<MethodDef> synthetic = Create.set();
    for (Iterator<MethodDef> i = methods.iterator(); i.hasNext();) {
      MethodDef m = i.next();
      if (m.isSynthetic()) {
        synthetic.add(m);
        i.remove();
      }
    }

    for (MethodDef m : methods) {
      List<Element> children = annotations.get(m);
      if (children == null)
        children = new ArrayList<Element>();

      access(children, m.getAccess(), m.isDeprecated());

      // A final class cannot be extended, ergo,
      // all methods defined in it are by definition
      // final. However, marking them final (either
      // on the method or inheriting it from the class)
      // will create superfluous changes if we
      // override a method from a super class that was not
      // final. So we actually remove the final for methods
      // in a final class.
      if (clazz.isFinal())
        children.remove(FINAL);

      // for covariant types we need to add the return types
      // and all the implemented and extended types. This is already
      // do for us when we get the element of the return type.

      getCovariantReturns(children, m.getType());

      for (Iterator<MethodDef> i = synthetic.iterator(); i.hasNext();) {
        MethodDef s = i.next();
        if (s.getName().equals(m.getName()) && Arrays.equals(s.getPrototype(), m.getPrototype())) {
          i.remove();
          getCovariantReturns(children, s.getType());
        }
      }

      Element member = new Element(Type.METHOD, m.getName() + toString(m.getPrototype()), children, add, remove,
          null);
View Full Code Here

        return;
      }
    }
    for (String lifecycle: LIFECYCLE_METHODS) {
      //lifecycle methods were not specified.... check for non 1.0 signatures.
      MethodDef test = descriptors.get(lifecycle);
      if (descriptors.containsKey(lifecycle) && (!(test.isPublic() || test.isProtected()) ||
          rateLifecycle(test, "deactivate".equals(lifecycle)? allowedDeactivate: allowed) > 1)) {
        cd.updateVersion(AnnotationReader.V1_1);
        return;
      }
    }
View Full Code Here

      Set.class.getName() + "|" +
      List.class.getName() + "|" +
      Iterable.class.getName() + ")|(.*))<(L.+;)>");
  private void doMethods() throws Exception {
    for (Map.Entry<MethodDef,Pair> entry: methods.entrySet()) {
      MethodDef defined = entry.getKey();
      if (defined.isConstructor()) {
        analyzer.error(
            "Constructor %s for %s.%s found; only interfaces and annotations allowed for OCDs",
            defined.getName(), clazz.getClassName().getFQN(), defined.getName())

      }
      if (defined.getPrototype().length > 0) {
        analyzer.error(
            "Element %s for %s.%s has parameters; only no-parameter elements in an OCD interface allowed",
            defined.getName(), clazz.getClassName().getFQN(), defined.getName())
        continue;
      }
      ADDef ad = new ADDef();
      ocd.attributes.add(ad);
      ad.id = fixup(defined.getName());
      ad.name = space(defined.getName());
      ad.description = "";
      String rtype = defined.getGenericReturnType();
      if (rtype.endsWith("[]")) {
        ad.cardinality = Integer.MAX_VALUE;
        rtype = rtype.substring(0, rtype.length() - 2);
      }
      Matcher m = GENERIC.matcher(rtype);
      if (m.matches()) {
        boolean knownCollection = m.group(2) != null;
        boolean collection = knownCollection || identifiableCollection(m.group(3), false, true);
        if (collection) {
          if (ad.cardinality != 0)
            analyzer.error(
                "AD for %s.%s uses an array of collections in return type (%s), Metatype allows either Vector or array",
                clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN());
          rtype = Clazz.objectDescriptorToFQN(m.group(4));
          ad.cardinality = Integer.MIN_VALUE;
        }
      }
      if (rtype.indexOf('<') > 0) {
        rtype = rtype.substring(0, rtype.indexOf('<'));
      }
      ad.type = getType(rtype);

      ad.required = true;
      TypeRef typeRef = analyzer.getTypeRefFromFQN(rtype);
      try {
        Clazz c = analyzer.findClass(typeRef);
        if (c != null && c.isEnum()) {
          parseOptionValues(c, ad.options);
        }
      }
      catch (Exception e) {
        analyzer.error(
            "AD for %s.%s Can not parse option values from type (%s), %s",
            clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN(), e.getMessage());
      }
      if (entry.getValue() != null) {
        doAD(ad, entry.getValue());
      }
      if (ad.defaults == null && clazz.isAnnotation() && defined.getConstant() != null) {
        //defaults from annotation default
        Object value = defined.getConstant();
        boolean isClass = 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 default for element with descriptor %s,  type %s", e, defined, type);
            }
View Full Code Here

      clazz.parseClassFileWithCollector(new ClassDataCollector() {
//        MethodDef  source;

        @Override
        public void implementsInterfaces(TypeRef names[]) {
          MethodDef def = clazz.getMethodDef(0, "<implements>", "()V");
          // TODO
          for (TypeRef interfaceName : names) {
            for (Map.Entry<MethodDef,List<MethodDef>> entry : catalog.entrySet()) {
              String catalogClass = entry.getKey().getContainingClass().getFQN();
              List<MethodDef> references = entry.getValue();
View Full Code Here

    // We must do this in the correct order so please
    // keep the linked hashset in place!

    Set<MethodDef> synthetic = new LinkedHashSet<MethodDef>();
    for (Iterator<MethodDef> i = methods.iterator(); i.hasNext();) {
      MethodDef m = i.next();
      if (m.isSynthetic()) {
        synthetic.add(m);
        i.remove();
      }
    }

    //System.out.println("methods/synthetic " + clazz+ " " + methods + " " + synthetic);
    for (MethodDef m : methods) {
     
      Collection<Element> children = annotations.get(m);
      if (children == null)
        children = new HashSet<Element>();

      access(children, m.getAccess(), m.isDeprecated());

      // A final class cannot be extended, ergo,
      // all methods defined in it are by definition
      // final. However, marking them final (either
      // on the method or inheriting it from the class)
      // will create superfluous changes if we
      // override a method from a super class that was not
      // final. So we actually remove the final for methods
      // in a final class.
      if (clazz.isFinal())
        children.remove(FINAL);

      // for covariant types we need to add the return types
      // and all the implemented and extended types. This is already
      // do for us when we get the element of the return type.


      getCovariantReturns(children, m.getType(), m.getGenericReturnType());

      /**
       * No longer includes synthetic methods in the tree
       */
//      for (Iterator<MethodDef> i = synthetic.iterator(); i.hasNext();) {
//        MethodDef s = i.next();
//        if (s.getName().equals(m.getName()) && Arrays.equals(s.getPrototype(), m.getPrototype())) {
//          i.remove();
//          getCovariantReturns(children, s.getType());
//        }
//      }

      String signature = m.getSignature();
      Matcher matcher;
      if (signature !=null && (matcher = PARAMETERS_P.matcher(signature)).matches()) {
        signature = matcher.group(1);
      } else
        signature = toString(m.getPrototype());

      //
      // Java default methods are concrete implementations of methods
      // on an interface.
      //
     
      if ( clazz.isInterface() && !m.isAbstract()) {
       
        //
        // We have a Java 8 default method!
        // Such a method is always a minor update
        //
       
        add = MINOR;
      }
     
      Element member = new Element(Type.METHOD, m.getName() + signature, children, add, remove,
          null);

      if (!members.add(member)) {
        members.remove(member);
        members.add(member);
View Full Code Here

  }
 
  static Pattern  COLLECTION  = Pattern.compile("(.*(Collection|Set|List|Queue|Stack|Deque))<(L.+;)>");
  private void doMethods() throws Exception {
    for (Map.Entry<MethodDef,Pair> entry: methods.entrySet()) {
      MethodDef defined = entry.getKey();
      ADDef ad = new ADDef();
      ocd.attributes.add(ad);
      ad.id = fixup(defined.getName());
      ad.name = space(defined.getName());
      ad.description = "";
      String rtype = defined.getGenericReturnType();
      ad.type = getType(rtype);
      if (rtype.endsWith("[]")) {
        ad.cardinality = Integer.MAX_VALUE;
        rtype = rtype.substring(0, rtype.length() - 2);
      }
      if (rtype.indexOf('<') > 0) {
        if (ad.cardinality != 0)
          analyzer.error(
              "AD for %s.%s uses an array of collections in return type (%s), Metatype allows either Vector or array",
              clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN());
        Matcher m = COLLECTION.matcher(rtype);
        if (m.matches()) {
          rtype = Clazz.objectDescriptorToFQN(m.group(3));
          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);
        }
      }
      catch (Exception e) {
        analyzer.error(
            "AD for %s.%s Can not parse option values from type (%s), %s",
            clazz.getClassName().getFQN(), defined.getName(), defined.getType().getFQN(), e.getMessage());
      }
      if (entry.getValue() != null) {
        doAD(ad, entry.getValue());
      }
    }
View Full Code Here

        return;
      }
    }
    for (String lifecycle: LIFECYCLE_METHODS) {
      //lifecycle methods were not specified.... check for non 1.0 signatures.
      MethodDef test = descriptors.get(lifecycle);
      if (descriptors.containsKey(lifecycle) && (!(test.isPublic() || test.isProtected()) ||
          rateLifecycle(test, "deactivate".equals(lifecycle)? allowedDeactivate: allowed) > 1)) {
        cd.updateVersion(AnnotationReader.V1_1);
        return;
      }
    }
View Full Code Here

    // We must do this in the correct order so please
    // keep the linked hashset in place!

    Set<MethodDef> synthetic = new LinkedHashSet<MethodDef>();
    for (Iterator<MethodDef> i = methods.iterator(); i.hasNext();) {
      MethodDef m = i.next();
      if (m.isSynthetic()) {
        synthetic.add(m);
        i.remove();
      }
    }

    //System.out.println("methods/synthetic " + clazz+ " " + methods + " " + synthetic);
    for (MethodDef m : methods) {
     
      Collection<Element> children = annotations.get(m);
      if (children == null)
        children = new HashSet<Element>();

      access(children, m.getAccess(), m.isDeprecated());

      // A final class cannot be extended, ergo,
      // all methods defined in it are by definition
      // final. However, marking them final (either
      // on the method or inheriting it from the class)
      // will create superfluous changes if we
      // override a method from a super class that was not
      // final. So we actually remove the final for methods
      // in a final class.
      if (clazz.isFinal())
        children.remove(FINAL);

      // for covariant types we need to add the return types
      // and all the implemented and extended types. This is already
      // do for us when we get the element of the return type.

      getCovariantReturns(children, m.getType());

      /**
       * No longer includes synthetic methods in the tree
       */
//      for (Iterator<MethodDef> i = synthetic.iterator(); i.hasNext();) {
//        MethodDef s = i.next();
//        if (s.getName().equals(m.getName()) && Arrays.equals(s.getPrototype(), m.getPrototype())) {
//          i.remove();
//          getCovariantReturns(children, s.getType());
//        }
//      }

      Element member = new Element(Type.METHOD, m.getName() + toString(m.getPrototype()), children, add, remove,
          null);

      if (!members.add(member)) {
        members.remove(member);
        members.add(member);
View Full Code Here

TOP

Related Classes of aQute.bnd.osgi.Clazz.MethodDef

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.