SharedMethodInfo.java

  1. /*
  2.  * Copyright (c) 2013, 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.truffle.runtime.methods;

  11. import com.oracle.truffle.api.source.SourceSection;
  12. import org.jruby.truffle.runtime.LexicalScope;

  13. /**
  14.  * {@link RubyMethod} objects are copied as properties such as visibility are changed. {@link SharedMethodInfo} stores
  15.  * the state that does not change, such as where the method was defined.
  16.  */
  17. public class SharedMethodInfo {

  18.     private final SourceSection sourceSection;
  19.     private final LexicalScope lexicalScope;
  20.     private final String name;
  21.     private final boolean isBlock;
  22.     private final org.jruby.ast.Node parseTree;
  23.     private final boolean alwaysSplit;

  24.     public SharedMethodInfo(SourceSection sourceSection, LexicalScope lexicalScope, String name, boolean isBlock, org.jruby.ast.Node parseTree, boolean alwaysSplit) {
  25.         assert sourceSection != null;
  26.         assert name != null;

  27.         this.sourceSection = sourceSection;
  28.         this.lexicalScope = lexicalScope;
  29.         this.name = name;
  30.         this.isBlock = isBlock;
  31.         this.parseTree = parseTree;
  32.         this.alwaysSplit = alwaysSplit;
  33.     }

  34.     public SourceSection getSourceSection() {
  35.         return sourceSection;
  36.     }

  37.     public LexicalScope getLexicalScope() {
  38.         return lexicalScope;
  39.     }

  40.     public String getName() {
  41.         return name;
  42.     }

  43.     public boolean isBlock() {
  44.         return isBlock;
  45.     }

  46.     public org.jruby.ast.Node getParseTree() {
  47.         return parseTree;
  48.     }

  49.     public boolean shouldAlwaysSplit() {
  50.         return alwaysSplit;
  51.     }

  52.     @Override
  53.     public String toString() {
  54.         final StringBuilder builder = new StringBuilder();

  55.         if (isBlock) {
  56.             builder.append("block in ");
  57.         }

  58.         builder.append(name);
  59.         builder.append(":");
  60.         builder.append(sourceSection.getShortDescription());

  61.         return builder.toString();
  62.     }

  63. }