Package com.github.mustachejava.util

Examples of com.github.mustachejava.util.Wrapper


*/
public class IndyObjectHandler extends CodegenObjectHandler {

  @Override
  public Wrapper find(String name, Object[] scopes) {
    Wrapper wrapper = super.find(name, scopes);
    if (wrapper instanceof CodegenReflectionWrapper) {
      CodegenReflectionWrapper rw = (CodegenReflectionWrapper) wrapper;
      return IndyWrapper.create(rw);
    } else {
      return wrapper;
View Full Code Here


  }
 
  @SuppressWarnings("unchecked")
  @Override
  public Wrapper find(String name, final Object[] scopes) {
    Wrapper wrapper = null;
    final int length = scopes.length;
    List<Guard> guards = new ArrayList<Guard>(scopes.length);
    // Simple guard to break if the number of scopes at this call site have changed
    guards.add(createDepthGuard(length));
    NEXT:
    for (int i = length - 1; i >= 0; i--) {
      Object scope = scopes[i];
      if (scope == null) continue;
      // Make sure that the current scope is the same class
      guards.add(createClassGuard(i, scope));
      List<Wrapper> wrappers = null;
      int dotIndex;
      String subname = name;
      // Try and find a wrapper using the simple name
      wrapper = findWrapper(i, null, guards, scope, subname);
      if (wrapper != null) {
        break;
      }
      // If there is dot notation, start evaluating it
      while ((dotIndex = subname.indexOf('.')) != -1) {
        final String lookup = subname.substring(0, dotIndex);
        subname = subname.substring(dotIndex + 1);
        // This is used for lookups but otherwise always succeeds
        guards.add(createDotGuard(i, scope, lookup));
        List<Guard> wrapperGuard = new ArrayList<Guard>(1);
        wrapperGuard.add(createClassGuard(0, scope));
        wrapper = findWrapper(0, null, wrapperGuard, scope, lookup);
        if (wrappers == null) wrappers = new ArrayList<Wrapper>();
        if (wrapper != null) {
          // We need to dig into a scope when dot notation shows up
          wrappers.add(wrapper);
          try {
            // Pull out the next level
            scope = coerce(wrapper.call(new Object[]{scope}));
          } catch (GuardException e) {
            throw new AssertionError(e);
          }
        } else {
          // Failed to find a wrapper for the next dot
View Full Code Here

      public Wrapper find(String name, Object[] scopes) {
        // Worst expression parser ever written follows
        String[] split = name.split("[*]");
        if (split.length > 1) {
          final double multiplier = Double.parseDouble(split[1].trim());
          final Wrapper wrapper = super.find(split[0].trim(), scopes);
          return new Wrapper() {
            @Override
            public Object call(Object[] scopes) throws GuardException {
              Object value = wrapper.call(scopes);
              if (value instanceof Number) {
                value = ((Number) value).doubleValue();
              } else {
                value = value == null ? 0d : Double.parseDouble(value.toString());
              }
View Full Code Here

       * @param name       the name in the scope
       * @return null if not found, otherwise a wrapper for this scope and name
       */
      @Override
      protected Wrapper findWrapper(int scopeIndex, Wrapper[] wrappers, List<Guard> guards, Object scope, String name) {
        Wrapper wrapper = super.findWrapper(scopeIndex, wrappers, guards, scope, name);
        if (wrapper == null) {
          // Now check to see if there is a method that takes a string
          return getWrapper(scopeIndex, wrappers, guards, scope, name, scope.getClass());
        }
        return wrapper;
View Full Code Here

      @Override
      public Binding createBinding(String name, final TemplateContext tc, Code code) {
        return new GuardedBinding(this, name, tc, code) {
          @Override
          protected synchronized Wrapper getWrapper(String name, Object[] scopes) {
            Wrapper wrapper = super.getWrapper(name, scopes);
            if (wrapper instanceof MissingWrapper) {
              throw new MustacheException(name + " not found in " + tc);
            }
            return wrapper;
          }
View Full Code Here

TOP

Related Classes of com.github.mustachejava.util.Wrapper

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.