Wrap a function call in a trace block; designed for use in a parallel stream

@param <T>
the type of the input to the function
@param <R>
the type of the result of the function

@return
421244
public static <T, R> Function<T, R> wrap(final String id, final boolean verbose, final Function<T, R> function)
	{
		return (t) -> {
			try
			{
				Tracing.start(id, verbose);

				return function.apply(t);
			}
574608
private T nextWrapper(Iterator<T> it) {
        try {
            if (trace != null) {
                trace.add(new TraceEntry(System.nanoTime(), System.currentTimeMillis(),
                        NextOrHasNext.NEXT, debugLabels.get(it)));
            }
            return it.next();
        } catch (RuntimeException e) {
            logTrace();
            throw e;
        }
    }
292612
public <R> FluentMatchingR<T, R> get(Function3<A, B, C, R> function) {
    return get(new FluentMatchingR<>(value), function);
  }
1257137
public WsByteBuffer wrap(com.ibm.wsspi.bytebuffer.WsByteBuffer realBuffer)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "wrap", realBuffer);

      RichByteBufferImpl returnBuffer = null;
      // Ensure here that if a null realBuffer was passed in we do not wrap that in a wrapper from
      // the pool - we must also simply return null
      if (realBuffer != null)
      {
         returnBuffer = getFromPool();
         returnBuffer.reset(realBuffer, this);
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "wrap", returnBuffer);
      return returnBuffer;
   }
568984
private <T> Collection<? extends Callable<T>> wrap(Collection<? extends Callable<T>> tasks) {
        List<Callable<T>> wrappedTasks = new ArrayList<Callable<T>>();
        Iterator<? extends Callable<T>> i = tasks.iterator();
        while (i.hasNext()) {
            Callable<T> c = wrap(i.next());
            if (serverStopping)
                wrappedTasks.add(c);
            else
                wrappedTasks.add(new CallableWrapper<T>(c));
        }
        return wrappedTasks;
    }
287846
public void trace(Object message, Throwable t) {
        doLog(Level.TRACE, FQCN, message, null, t);
    }
400111
private boolean callMeetsBlockInliningRequirements(
      Reference ref, final Node fnNode, ImmutableSet<String> namesToAlias) {
    // Note: functions that contain function definitions are filtered out
    // in isCandidateFunction.

    // TODO(johnlenz): Determining if the called function contains VARs
    // or if the caller contains inner functions accounts for 20% of the
    // run-time cost of this pass.

    // Don't inline functions with var declarations into a scope with inner
    // functions as the new vars would leak into the inner function and
    // cause memory leaks.
    boolean fnContainsVars = NodeUtil.has(
        NodeUtil.getFunctionBody(fnNode),
        new NodeUtil.MatchDeclaration(),
        new NodeUtil.MatchShallowStatement());
    boolean forbidTemps = false;
    if (!ref.scope.getClosestHoistScope().isGlobal()) {
      Node fnCallerBody = ref.scope.getClosestHoistScope().getRootNode();

      // Don't allow any new vars into a scope that contains eval or one
      // that contains functions (excluding the function being inlined).
      Predicate<Node> match = new Predicate<Node>(){
        @Override
        public boolean apply(Node n) {
          if (n.isName()) {
            return n.getString().equals("eval");
          }
          if (!assumeMinimumCapture && n.isFunction()) {
            return n != fnNode;
          }
          return false;
        }
      };
      forbidTemps = NodeUtil.has(fnCallerBody, match, NodeUtil.MATCH_NOT_FUNCTION);
    }

    if (fnContainsVars && forbidTemps) {
      return false;
    }

    // If the caller contains functions or evals, verify we aren't adding any
    // additional VAR declarations because aliasing is needed.
    if (forbidTemps) {
      ImmutableMap<String, Node> args =
          FunctionArgumentInjector.getFunctionCallParameterMap(
              fnNode, ref.callNode, this.safeNameIdSupplier);
      boolean hasArgs = !args.isEmpty();
      if (hasArgs) {
        // Limit the inlining
        Set<String> allNamesToAlias = new HashSet<>(namesToAlias);
        FunctionArgumentInjector.maybeAddTempsForCallArguments(
            compiler, fnNode, args, allNamesToAlias, compiler.getCodingConvention());
        if (!allNamesToAlias.isEmpty()) {
          return false;
        }
      }
    }

    return true;
  }
1004567
def trace(f):
    
    @functools.wraps(f)
    def decorator(*args, **kwargs):
        print 'Calling ' + f.func_name + ' in ' + str(args[0])
        return f(*args, **kwargs)
    return decorator
349618
protected <T> Callable<T> wrapTask(Callable<T> task) {
    // Preserve the MDC context of the caller thread.
    Map contextMap = MDC.getCopyOfContextMap();
    if (contextMap != null) {
      return new MDCCallableAdapter(task, contextMap);
    }
    return task;
  }
822259
public boolean wrap(T t) {
		@SuppressWarnings("unchecked")
		W wrap = (W)this.wrapFactory.wrap(t);
		return add(wrap);
	}
262549
public <R> FluentMatchingR<T, R> get(Function<A, R> function) {
    return get(new FluentMatchingR<>(value), function);
  }
283310
public static <T, R, E extends Exception> Function<T, R> sneaked(
      SneakyFunction<T, R, E> function) {
    return t -> {
      @SuppressWarnings("unchecked")
      SneakyFunction<T, R, RuntimeException> f1 = (SneakyFunction<T, R, RuntimeException>) function;
      return f1.apply(t);
    };
  }
526816
public static Throwable unwrap(@Nullable Throwable t) {
		if (t instanceof UncheckedException || t instanceof java.util.concurrent.ExecutionException
				|| t instanceof java.lang.reflect.InvocationTargetException
				|| t instanceof UndeclaredThrowableException) {
			return t.getCause();
		}

		return t;
	}
25221
@SuppressWarnings("unchecked")
	public static <T extends Throwable> T wrap(Throwable throwable, Class<T> wrapThrowable) {
		if (wrapThrowable.isInstance(throwable)) {
			return (T) throwable;
		}
		return ReflectUtil.newInstance(wrapThrowable, throwable);
	}
926366
def trace(function, *args, **k) :
	""""""

	if doTrace : print ("> "+function.__name__, args, k)
	result = function(*args, **k)
	if doTrace : print ("< "+function.__name__, args, k, "->", result)
	return result
807467
private void visitImplicitReturnExpression(NodeTraversal t, Node exprNode) {
    Node enclosingFunction = t.getEnclosingFunction();
    JSType jsType = getJSType(enclosingFunction);
    if (jsType.isFunctionType()) {
      FunctionType functionType = jsType.toMaybeFunctionType();

      JSType expectedReturnType = functionType.getReturnType();
      // if no return type is specified, undefined must be returned
      // (it's a void function)
      if (expectedReturnType == null) {
        expectedReturnType = getNativeType(VOID_TYPE);
      } else if (enclosingFunction.isAsyncFunction()) {
        // Unwrap the async function's declared return type.
        expectedReturnType = Promises.createAsyncReturnableType(typeRegistry, expectedReturnType);
      }

      // Fetch the returned value's type
      JSType actualReturnType = getJSType(exprNode);

      validator.expectCanAssignTo(
          exprNode, actualReturnType, expectedReturnType, "inconsistent return type");
    }
  }
994200
public RayTraceResult trace()
	{
		RayTraceResult mop = null, firstHit = null;
		double tX, tY, tZ, min;
		int count = 0;
		boolean ret = false;

		int currentX = blockSrc.getX();
		int currentY = blockSrc.getY();
		int currentZ = blockSrc.getZ();

		while (!ret && count++ <= MAX_BLOCKS)
		{
			tX = ray.intersectX(currentX + (ray.direction.x > 0 ? 1 : 0));
			tY = ray.intersectY(currentY + (ray.direction.y > 0 ? 1 : 0));
			tZ = ray.intersectZ(currentZ + (ray.direction.z > 0 ? 1 : 0));

			min = getMin(tX, tY, tZ);

			// do not trace first block
			if (count != 1 || !hasOption(Options.IGNORE_FIRST_BLOCK))
				mop = rayTraceBlock(new BlockPos(currentX, currentY, currentZ), ray.getPointAt(min));
			if (firstHit == null)
				firstHit = mop;
			if (hasOption(Options.LOG_BLOCK_PASSED))
				blockPassed.put(new BlockPos(currentX, currentY, currentZ), mop);

			if (dest != null && currentX == blockDest.getX() && currentY == blockDest.getY() && currentZ == blockDest.getZ())
				ret = true;

			if (!ret)
			{
				if (min == tX)
					currentX += step.x;
				if (min == tY)
					currentY += step.y;
				if (min == tZ)
					currentZ += step.z;
			}

			if (dest != null && dest.equals(ray.getPointAt(min)))
				ret = true;

		}

		if (firstHit == null && dest != null)
			firstHit = new RayTraceResult(RayTraceResult.Type.MISS, dest.toVec3d(), null, new BlockPos(currentX, currentY, currentZ));

		firstHit = ChunkCollision.get().getRayTraceResult(	world,
															Pair.of(src, dest),
															firstHit,
															hasOption(Options.HIT_LIQUIDS),
															hasOption(Options.CHECK_COLLISION),
															true);

		if (!ret)
			MalisisCore.message("Trace fail : " + MAX_BLOCKS + " blocks passed (" + currentX + "," + currentY + "," + currentZ + ")");
		return firstHit;
	}