MethodNodes.java

  1. /*
  2.  * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
  3.  * code is released under a tri EPL/GPL/LGPL license. You can use it,
  4.  * redistribute it and/or modify it under the terms of the:
  5.  *
  6.  * Eclipse Public License version 1.0
  7.  * GNU General Public License version 2
  8.  * GNU Lesser General Public License version 2.1
  9.  */
  10. package org.jruby.internal.runtime.methods;

  11. import org.jruby.ast.ArgsNode;
  12. import org.jruby.ast.Node;

  13. import java.util.Map;
  14. import java.util.concurrent.ConcurrentHashMap;

  15. public class MethodNodes {

  16.     // TODO(CS): MethodNodes will never leave this cache
  17.     private final static Map<String, MethodNodes> cache = new ConcurrentHashMap<>();

  18.     private final ArgsNode argsNode;
  19.     private final Node bodyNode;

  20.     public MethodNodes(ArgsNode argsNode, Node bodyNode) {
  21.         assert argsNode != null;
  22.         assert bodyNode != null;

  23.         this.argsNode = argsNode;
  24.         this.bodyNode = bodyNode;
  25.     }

  26.     public ArgsNode getArgsNode() {
  27.         return argsNode;
  28.     }

  29.     public Node getBodyNode() {
  30.         return bodyNode;
  31.     }

  32.     public static void cache(String methodJavaName, MethodNodes nodes) {
  33.         cache.put(methodJavaName, nodes);
  34.     }

  35.     public static MethodNodes lookup(String methodJavaName) {
  36.         return cache.get(methodJavaName);
  37.     }


  38. }