package ruke.vrj.util;

import ruke.vrj.Symbol;
import ruke.vrj.SymbolFlag;

/**
 * MIT License
 *
 * Copyright (c) 2017 Franco Montenegro
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
public class NameGenerator {

  public static String to(final Symbol symbol) {
    final Symbol parent = symbol.parent;

    if (parent != null) {
      final boolean mustUsePrefix =
          parent.flags.contains(SymbolFlag.STRUCT) ||
          parent.flags.contains(SymbolFlag.LIBRARY) ||
          parent.flags.contains(SymbolFlag.SCOPE);

      if (mustUsePrefix) {
        return String.format("%s_%s", parent.name, symbol.name);
      }
    }

    return symbol.name;
  }

}

@@ -15,19 +15,17 @@
 rj.util;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -40,17 +40,16 @@
 .Symbol;
-%0D
 %0Aimport 
@@ -72,16 +72,13 @@
 lag;
-%0D%0A%0D
+%0A
 %0A/**
-%0D
 %0A * 
@@ -88,21 +88,19 @@
  License
-%0D
 %0A *
-%0D
 %0A * Copy
@@ -131,21 +131,19 @@
 ntenegro
-%0D
 %0A *
-%0D
 %0A * Perm
@@ -214,17 +214,16 @@
 g a copy
-%0D
 %0A * of t
@@ -295,17 +295,16 @@
  to deal
-%0D
 %0A * in t
@@ -375,17 +375,16 @@
 e rights
-%0D
 %0A * to u
@@ -452,17 +452,16 @@
 /or sell
-%0D
 %0A * copi
@@ -525,17 +525,16 @@
 tware is
-%0D
 %0A * furn
@@ -585,21 +585,19 @@
 ditions:
-%0D
 %0A *
-%0D
 %0A * The 
@@ -670,17 +670,16 @@
 d in all
-%0D
 %0A * copi
@@ -725,13 +725,11 @@
 are.
-%0D
 %0A *
-%0D
 %0A * 
@@ -802,17 +802,16 @@
 PRESS OR
-%0D
 %0A * IMPL
@@ -878,17 +878,16 @@
 ABILITY,
-%0D
 %0A * FITN
@@ -953,25 +953,24 @@
 NT SHALL THE
-%0D
 %0A * AUTHORS 
@@ -1031,17 +1031,16 @@
 OR OTHER
-%0D
 %0A * LIAB
@@ -1112,17 +1112,16 @@
 NG FROM,
-%0D
 %0A * OUT 
@@ -1193,17 +1193,16 @@
 S IN THE
-%0D
 %0A * SOFT
@@ -1210,14 +1210,12 @@
 ARE.
-%0D
 %0A */
-%0D
 %0Apub
@@ -1239,19 +1239,17 @@
 erator %7B
-%0D%0A%0D
+%0A
 %0A  publi
@@ -1285,25 +1285,24 @@
 ol symbol) %7B
-%0D
 %0A    final S
@@ -1330,19 +1330,17 @@
 .parent;
-%0D%0A%0D
+%0A
 %0A    if 
@@ -1357,17 +1357,16 @@
  null) %7B
-%0D
 %0A      f
@@ -1393,17 +1393,16 @@
 Prefix =
-%0D
 %0A       
@@ -1443,25 +1443,24 @@
 g.STRUCT) %7C%7C
-%0D
 %0A          p
@@ -1502,17 +1502,16 @@
 RARY) %7C%7C
-%0D
 %0A       
@@ -1553,19 +1553,17 @@
 .SCOPE);
-%0D%0A%0D
+%0A
 %0A      i
@@ -1581,17 +1581,16 @@
 refix) %7B
-%0D
 %0A       
@@ -1624,19 +1624,32 @@
 s%22, 
-parent.name
+NameGenerator.to(parent)
 , sy
@@ -1663,17 +1663,16 @@
 me);
-%0D
 %0A      %7D
 %0D%0A  
@@ -1671,18 +1671,15 @@
    %7D
-%0D
 %0A    %7D
-%0D%0A%0D
+%0A
 %0A   
@@ -1702,16 +1702,12 @@
 ame;
-%0D
 %0A  %7D
-%0D%0A%0D
+%0A
 %0A%7D
-%0D
 %0A

Make NameGenerator recursive