<commit_before>package fitnesse.wikitext.parser;

import util.Maybe;

public class VariableFinder implements VariableSource {
    private ParsingPage page;

    public VariableFinder(ParsingPage page) {
        this.page = page;
    }

    public Maybe<String> findVariable(String name) {
        Maybe<String> result = page.getSpecialVariableValue(name);
        if (!result.isNothing()) return result;

        result = findVariableInPages(name);
        if (!result.isNothing()) return result;

        String value = System.getenv(name);
        if (value != null) return new Maybe<String>(value);

        value = System.getProperty(name);
        if (value != null) return new Maybe<String>(value);

        return Maybe.noString;
    }

    private Maybe<String> findVariableInPages(String name) {
        Maybe<String> localVariable = page.findVariable(name);
        if (!localVariable.isNothing()) return new Maybe<String>(localVariable.getValue());
        return lookInParentPages(name);
    }

    private Maybe<String> lookInParentPages(String name) {
        for (SourcePage sourcePage: page.getPage().getAncestors()) {
            if (!page.inCache(sourcePage)) {
                Parser.make(page.copyForPage(sourcePage), sourcePage.getContent()).parse();
                // todo: make this a method on ParsingPage
                page.putVariable(sourcePage, "", Maybe.noString);
            }
            Maybe<String> result = page.findVariable(sourcePage, name);
            if (!result.isNothing()) return result;
            //page.putVariable(sourcePage, name, result);
        }
        return Maybe.noString;
    }
}<commit_msg>Reformat VariableFinder<commit_after>package fitnesse.wikitext.parser;

import util.Maybe;

public class VariableFinder implements VariableSource {
  private ParsingPage page;

  public VariableFinder(ParsingPage page) {
    this.page = page;
  }

  public Maybe<String> findVariable(String name) {
    Maybe<String> result = page.getSpecialVariableValue(name);
    if (!result.isNothing()) return result;

    result = findVariableInPages(name);
    if (!result.isNothing()) return result;

    String value = System.getenv(name);
    if (value != null) return new Maybe<String>(value);

    value = System.getProperty(name);
    if (value != null) return new Maybe<String>(value);

    return Maybe.noString;
  }

  private Maybe<String> findVariableInPages(String name) {
    Maybe<String> localVariable = page.findVariable(name);
    if (!localVariable.isNothing()) return new Maybe<String>(localVariable.getValue());
    return lookInParentPages(name);
  }

  private Maybe<String> lookInParentPages(String name) {
    for (SourcePage sourcePage : page.getPage().getAncestors()) {
      if (!page.inCache(sourcePage)) {
        Parser.make(page.copyForPage(sourcePage), sourcePage.getContent()).parse();
        // todo: make this a method on ParsingPage
        page.putVariable(sourcePage, "", Maybe.noString);
      }
      Maybe<String> result = page.findVariable(sourcePage, name);
      if (!result.isNothing()) return result;
      //page.putVariable(sourcePage, name, result);
    }
    return Maybe.noString;
  }
}
{'fraction_non_alphanumeric': 0.11631562401760452, 'fraction_numerical': 0.0, 'mean_word_length': 3.294197031039136, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4885156', 'n_tokens_mistral': 892, 'n_tokens_neox': 869, 'n_words': 203}