<commit_before>//////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, <NAME> - All Rights Reserved                /
//                                                                                       /
// Licensed under the GNU General Public License v3;                                     /
// you may not use this file except in compliance with the License.                      /
//                                                                                       /
// You may obtain a copy of the License at                                               /
//     http://www.gnu.org/licenses/gpl.html                                              /
//                                                                                       /
// Unless required by applicable law or agreed to in writing, software                   /
// distributed under the License is distributed on an "AS IS" BASIS,                     /
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.              /
// See the License for the specific language governing permissions and                   /
// limitations under the License.                                                        /
//                                                                                       /
// Written by <NAME> <<EMAIL>>, March 2016           /
// https://www.github.com/BloodShura                                                     /
//////////////////////////////////////////////////////////////////////////////////////////

package br.shura.venus.resultor;

import br.shura.venus.exception.runtime.InvalidArrayAccessException;
import br.shura.venus.exception.runtime.ScriptRuntimeException;
import br.shura.venus.executor.Context;
import br.shura.venus.value.ArrayValue;
import br.shura.venus.value.IntegerValue;
import br.shura.venus.value.Value;
import br.shura.venus.value.ValueType;

/**
 * ArrayAccess.java
 *
 * @author <a href="https://www.github.com/BloodShura">BloodShura</a> (<NAME>)
 * @contact <EMAIL>
 * @date 22/05/16 - 02:02
 * @since GAMMA - 0x3
 */
public class ArrayAccess implements Resultor {
  private final Variable array;
  private final Resultor index;

  public ArrayAccess(Variable array, Resultor index) {
    this.array = array;
    this.index = index;
  }

  public Variable getArray() {
    return array;
  }

  public Resultor getIndex() {
    return index;
  }

  @Override
  public Value resolve(Context context) throws ScriptRuntimeException {
    Value value = getArray().resolve(context);

    if (value instanceof ArrayValue) {
      ArrayValue array = (ArrayValue) value;
      Value index = getIndex().resolve(context);

      if (index instanceof IntegerValue) {
        IntegerValue intIndex = (IntegerValue) index;

        return array.get(context, intIndex.value().intValue());
      }

      throw new InvalidArrayAccessException(context, "Index \"" + index + "\" is of type " +
        index.getType() + "; expected to be an " + ValueType.INTEGER);
    }

    throw new InvalidArrayAccessException(context, "Variable \"" + getArray().getName() + "\" is of type " +
      value.getType() + "; expected to be an " + ValueType.ARRAY);
  }

  @Override
  public String toString() {
    return "arr(" + getArray().getName() + '[' + getIndex() + "])";
  }
}
<commit_msg>ArrayAccess now holds a String attribute instead of Variable for indicating the variable to access (part of #11)<commit_after>//////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, <NAME> - All Rights Reserved                /
//                                                                                       /
// Licensed under the GNU General Public License v3;                                     /
// you may not use this file except in compliance with the License.                      /
//                                                                                       /
// You may obtain a copy of the License at                                               /
//     http://www.gnu.org/licenses/gpl.html                                              /
//                                                                                       /
// Unless required by applicable law or agreed to in writing, software                   /
// distributed under the License is distributed on an "AS IS" BASIS,                     /
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.              /
// See the License for the specific language governing permissions and                   /
// limitations under the License.                                                        /
//                                                                                       /
// Written by <NAME> <<EMAIL>>, March 2016           /
// https://www.github.com/BloodShura                                                     /
//////////////////////////////////////////////////////////////////////////////////////////

package br.shura.venus.resultor;

import br.shura.venus.exception.runtime.InvalidArrayAccessException;
import br.shura.venus.exception.runtime.ScriptRuntimeException;
import br.shura.venus.executor.Context;
import br.shura.venus.value.ArrayValue;
import br.shura.venus.value.IntegerValue;
import br.shura.venus.value.Value;
import br.shura.venus.value.ValueType;

/**
 * ArrayAccess.java
 *
 * @author <a href="https://www.github.com/BloodShura">BloodShura</a> (<NAME>)
 * @contact <EMAIL>
 * @date 22/05/16 - 02:02
 * @since GAMMA - 0x3
 */
public class ArrayAccess implements Resultor {
  private final Resultor index;
  private final String name;

  public ArrayAccess(String name, Resultor index) {
    this.index = index;
    this.name = name;
  }

  public Resultor getIndex() {
    return index;
  }

  public String getName() {
    return name;
  }

  @Override
  public Value resolve(Context context) throws ScriptRuntimeException {
    Value value = context.getVar(getName());

    if (value instanceof ArrayValue) {
      ArrayValue array = (ArrayValue) value;
      Value index = getIndex().resolve(context);

      if (index instanceof IntegerValue) {
        IntegerValue intIndex = (IntegerValue) index;

        return array.get(context, intIndex.value().intValue());
      }

      throw new InvalidArrayAccessException(context, "Index \"" + index + "\" is of type " +
        index.getType() + "; expected to be an " + ValueType.INTEGER);
    }

    throw new InvalidArrayAccessException(context, "Variable \"" + getName() + "\" is of type " +
      value.getType() + "; expected to be an " + ValueType.ARRAY);
  }

  @Override
  public String toString() {
    return "arr(" + getName() + '[' + getIndex() + "])";
  }
}

{'fraction_non_alphanumeric': 0.1460377911234803, 'fraction_numerical': 0.006444997802841658, 'mean_word_length': 1.3240299523485364, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1205669', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1502, 'n_words': 459}