Examples of VirtualMethodVisitor


Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

    }

    // verify has no public methods (ignore those belonging to
    // java.lang.Object)
    final List<Method> publicMethods = new ArrayList<Method>();
    final VirtualMethodVisitor methodFinder = new VirtualMethodVisitor() {
      @Override
      protected boolean visit(final Method method) {
        publicMethods.add(method);
        return false;
      }

      @Override
      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    methodFinder.start(type);
    if (false == publicMethods.isEmpty()) {
      throwBeanFactoryInterfaceHasPublicMethods(type, publicMethods.size());
    }
  }
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

      final Value value = property.getValue();
      this.prepareValue(value);

      final List<Method> matchingSetters = new ArrayList<Method>();

      final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {
        protected boolean visit(final Method method) {

          while (true) {
            // names dont match
            if (false == method.getName().equals(setterName)) {
              break;
            }
            // return type must be void
            if (false == method.getReturnType().equals(voidType)) {
              break;
            }
            // parameter types must be compatible...
            final List<MethodParameter> parameters = method.getParameters();
            if (parameters.size() != 1) {
              break;
            }

            final MethodParameter parameter = (MethodParameter) parameters.get(0);
            final Type propertyType = parameter.getType();
            if (false == value.isCompatibleWith(propertyType)) {
              break;
            }

            value.setPropertyType(propertyType);
            matchingSetters.add(method);
            break;
          }

          return false;
        }

        protected boolean skipJavaLangObjectMethods() {
          return true;
        }
      };

      visitor.start(beanType);
      if (matchingSetters.isEmpty()) {
        this.throwUnableToFindSetter(bean, property);
      }
      if (matchingSetters.size() != 1) {
        this.throwTooManySettersFound(bean, property);
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

    context.debug("Discovering methods that match: " + matcher + " against " + type);

    final List<Method> matchedMethods = new ArrayList<Method>();
    final Type object = context.getObject();

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {

      @Override
      protected boolean visit(final Method method) {
        while (true) {
          if (method.isFinal()) {
            if (false == method.getEnclosingType().equals(object)) {
              BeanFactoryGenerator.this.throwTargetMethodIsFinal(method);
            }
          }
          break;
        }

        if (method.getVisibility() == Visibility.PUBLIC && matcher.matches(method)) {
          matchedMethods.add(method);
          context.debug(method.toString());
        }
        return false;
      }

      @Override
      protected boolean skipJavaLangObjectMethods() {
        return false;
      }
    };
    visitor.start(type);

    if (matchedMethods.isEmpty()) {
      throwNoMatchedMethods(aspect);
    }
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

    field.setValue(EmptyCodeBlock.INSTANCE);
    field.setVisibility(Visibility.PUBLIC);

    final List<Aspect> aspects = bean.getAspects();

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {

      @Override
      protected boolean visit(final Method method) {

        while (true) {
          if (method.isFinal()) {
            break;
          }

          if (method.getVisibility() != Visibility.PUBLIC) {
            break;
          }

          // dont proxy getClass()
          if (method.getName().equals("getClass") && method.getParameters().isEmpty()) {
            break;
          }

          // the public methods remain...
          final List<Aspect> matched = BeanFactoryGenerator.this.findMatchingAdvices(method, aspects);
          if (matched.isEmpty()) {
            BeanFactoryGenerator.this.createProxyMethod(proxy, method);
            break;
          }

          BeanFactoryGenerator.this.createProxyMethodWithInterceptors(proxy, method, matched);
          break;
        }
        return false;
      }

      @Override
      protected boolean skipJavaLangObjectMethods() {
        return false;
      }
    };
    visitor.start(targetBeanType);

    return proxy;
  }
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

    final Type voidType = this.getGeneratorContext().getVoid();

    final List<Method> methods = new ArrayList<Method>();

    // find and add public methods that start with test
    final VirtualMethodVisitor testMethodFinder = new VirtualMethodVisitor() {

      protected boolean visit(final Method method) {

        while (true) {
          if (method.getVisibility() != Visibility.PUBLIC) {
            break;
          }
          if (false == method.getName().startsWith(Constants.TEST_METHOD_NAME_PREFIX)) {
            context.debug("Ignoring method " + method + " because it doesnt start with public.");
            break;
          }

          // test method must return void
          final Type returnType = method.getReturnType();
          if (returnType != voidType) {
            throwTestMethodDoesntReturnVoid(method);
          }

          // test method must have no parameters.
          final List<MethodParameter> parameters = method.getParameters();
          if (false == parameters.isEmpty()) {
            throwTestMethodHasParameters(method);
          }

          // public void test*() method found...
          methods.add(method);
          break;
        }

        return false;
      }

      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    testMethodFinder.start(webPageTestRunner);

    Collections.sort(methods, new Comparator<Method>() {
      public int compare(final Method method, final Method otherMethod) {
        return TestBuilderGenerator.this.getOrder( method) - TestBuilderGenerator.this.getOrder(otherMethod);
      }
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

    // methods
    // in
    // alphabetical
    // order

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {
      protected boolean visit(final Method method) {
        context.debug(method.getName());
        ImageFactoryGenerator.this.checkMethod(method);
        methods.add(method);
        return false; // continue visiting other methods.
      }

      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    visitor.start(type);

    context.unbranch();
    return methods;
  }
View Full Code Here

Examples of rocket.generator.rebind.visitor.VirtualMethodVisitor

   */
  protected void implementInterfaceMethods(final Type interfacee, final NewConcreteType newType) {
    Checker.notNull("parameter:interface", interfacee);
    Checker.notNull("parameter:newType", newType);

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {
      protected boolean visit(final Method method) {
        if (method.getVisibility() == Visibility.PUBLIC) {
          HtmlTemplateFactoryGenerator.this.implementMethod(method, newType);
        }
        return false;
      }

      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    visitor.start(interfacee);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.