LegacyString.java

/*
** Module   : LegacyString.java
** Abstract : Implementation of the builtin class.
**
** Copyright (c) 2019-2023, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 CA  20190526 First version, stubs taken by converting the skeleton using FWD.
** 002 CA  20190710 Runtime implementation of the common APIs.
** 003 IAS 20190923 Added implementation of a number of methods.
** 004 CA  20191024 Added method support levels and updated the class support level.
** 005 ME  20201005 Remove dependency on Apache StringUtils.
**     CA  20210113 Renamed trim() to trim_(), to follow NameConverter's rules.
** 006 CA  20210221 Fixed 'qualified', 'extent' and 'returns' annotations at the legacy
**                  signature.
** 007 ME  20210520 Set hashCode to return the actual string hashCode.
**     ME  20210902 Return default hashCode if unknown, fix empty static method and isNullOrEmpty to use trim.
**     ME  20210929 Fix return value on join/split methods.
**     ME  20220402 Use internal's longchar hashCode instead of that of the actual string (case sensitive, trim).
**     CA  20220923 Variable definitions (including associated with parameters) must be done always outside of 
**                  the BlockManager API
** 008 ME  20230503 Fix setter annotation for encoding.
** 009 CA  20231113 The 'execute' method must be annotated with LegacySignature Type.Execute, and also can be
**                  dropped if is a no-op.
** 010 AL2 20241030 Removed hashCode as LegacyString is mutable. Using LegacyString as a key in a map and 
**                  changing it afterwards will result in unwanted behavior.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.oo.core;

import com.goldencode.p2j.util.*;
import com.goldencode.p2j.util.BlockManager.Action;
import com.goldencode.p2j.util.BlockManager.Condition;
import com.goldencode.p2j.oo.lang.*;
import com.goldencode.p2j.security.ContextLocal;

import static com.goldencode.p2j.util.BlockManager.*;
import static com.goldencode.p2j.report.ReportConstants.*;
import static com.goldencode.p2j.util.InternalEntry.Type;
import static com.goldencode.p2j.util.character.valueOf;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Business logic (converted to Java from the 4GL source code
 * in OpenEdge/Core/String.cls).
 */
@LegacyResource(resource = "OpenEdge.Core.String")
@LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_PARTIAL)
public class LegacyString
extends BaseObject
implements com.goldencode.p2j.oo.common.support.IlongcharHolder,
           com.goldencode.p2j.oo.core.ISupportEncoding
{
   private longchar value = TypeFactory.longchar();
   private character encoding = TypeFactory.character();

   private static ContextLocal<object<? extends LegacyString>> empty = new ContextLocal<object<? extends LegacyString>>()
   {
      protected object<? extends LegacyString> initialValue()
      {
         object<? extends LegacyString> empty = TypeFactory.object(LegacyString.class);
         // can't use ObjectOps as will fail to initialise the class
         // empty.assign(ObjectOps.newInstance(LegacyString.class));

         return empty;
      }
   };

   @LegacySignature(type = Type.EXECUTE)
   public void __core_LegacyString_execute__()
   {
      onBlockLevel(Condition.ERROR, Action.THROW);
   }

   @LegacySignature(returns = "CHARACTER", type = Type.GETTER, name = "Encoding")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public character getEncoding()
   {
      return function(this, "Encoding", character.class, new Block((Body) () ->
      {
         returnNormal(encoding);
      }));
   }

   @LegacySignature(type = Type.SETTER, name = "Encoding", parameters = {
            @LegacyParameter(name = "pcEncoding", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   @Override
   public void setEncoding(character _pcEncoding)
   {
      character pcEncoding = TypeFactory.initInput(_pcEncoding);
      internalProcedure(this, "Encoding", new Block((Body) () ->
      {
         encoding = pcEncoding;
      }));
   }

   @LegacySignature(returns = "INT64", type = Type.GETTER, name = "Size")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public int64 getSize()
   {
      return function(this, "Size", int64.class, new Block((Body) () ->
      {
         returnNormal(value.isUnknown() ? new int64() : new int64(value.getSize()));
      }));
   }

   @LegacySignature(returns = "LONGCHAR", type = Type.GETTER, name = "Value")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public longchar getValue()
   {
      longchar val = TypeFactory.longchar();

      return function(this, "Value", longchar.class, new Block((Body) () ->
      {
         if ("utf-8".equalsIgnoreCase(encoding.getValue())) 
         {
            val.fixCodePage(getEncoding());
            val.assign(value);
         }
         else 
         {
            val.assign(TextOps.codePageConvert(value, getEncoding()));
         }
         
         returnNormal(val);
      }));
   }

   @LegacySignature(type = Type.CONSTRUCTOR)
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public static void __core_LegacyString_constructor__static__()
   {
      externalProcedure(LegacyString.class, new Block((Body) () ->
      {
         onBlockLevel(Condition.ERROR, Action.THROW);
      }));
   }

   @LegacySignature(type = Type.CONSTRUCTOR)
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void __core_LegacyString_constructor__()
   {
      internalProcedure(this, "__core_LegacyString_constructor__", new Block((Body) () ->
      {
         __lang_BaseObject_constructor__();

         value.fixCodePage("UTF-8");
         value.assign("");
         encoding.assign(I18nOps.getCPInternal());

      }));
   }

   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
            @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void __core_LegacyString_constructor__(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "__core_LegacyString_constructor__", new Block((Body) () ->
      {
         __core_LegacyString_constructor__();
         value.assign(p1);
      }));
   }

   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void __core_LegacyString_constructor__(final longchar _p1)
   {
      longchar p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "__core_LegacyString_constructor__", new Block((Body) () ->
      {
         __core_LegacyString_constructor__();
         value.assign(p1);
         encoding.assign(p1._getCodePage());
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Append", parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void append(final longchar _p1)
   {
      longchar p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "Append", new Block((Body) () ->
      {
         if (!this.equals(LegacyString.empty().ref()) && !value.isUnknown())
         {
            if (p1.isUnknown())
               value.setUnknown();
            else
               value.assign(value.getValue().concat(p1.getValue()));
         }
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Append", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "openedge.core.string", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void append(final object<? extends com.goldencode.p2j.oo.core.LegacyString> _p1)
   {
      object<? extends com.goldencode.p2j.oo.core.LegacyString> p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "Append", new Block((Body) () ->
      {
         if (!this.equals(LegacyString.empty().ref()) && !value.isUnknown())
         {
            // 4GL does not check for valid object, it just let the error throw
            append(p1.ref().getValue());
         }
      }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Empty", qualified = "openedge.core.string")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public static object<? extends com.goldencode.p2j.oo.core.LegacyString> empty()
   {
      return function(LegacyString.class, "Empty", object.class, new Block((Body) () ->
      {
         // can't get a valid reference within the static context initial value
         if (empty.get().isUnknown())
            empty.get().assign(new object(ObjectOps.newInstance(LegacyString.class)));

         returnNormal(empty.get());
      }));
   }

   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "Equals", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "progress.lang.object", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public logical legacyEquals(
            final object<? extends com.goldencode.p2j.oo.lang._BaseObject_> _p1)
   {
      object<? extends com.goldencode.p2j.oo.lang._BaseObject_> p1 = TypeFactory.initInput(_p1);

      return function(this, "Equals", logical.class, new Block((Body) () ->
      {
         if (!p1.isUnknown() && p1.ref() instanceof LegacyString)
         {
            returnNormal(CompareOps.equals(this.value, ((LegacyString) p1.ref()).getValue()));
         }
         else
         {
            returnNormal(super.legacyEquals(p1));
         }
      }));
   }

   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "IsNullOrEmpty")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public logical isNullOrEmpty()
   {
      return function(this, "IsNullOrEmpty", logical.class, new Block((Body) () ->
      {
         returnNormal(LegacyString.isNullOrEmpty(value));
      }));
   }

   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "IsNullOrEmpty", parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public static logical isNullOrEmpty(final longchar _p1)
   {
      longchar p1 = TypeFactory.initInput(_p1);

      return function(LegacyString.class, "IsNullOrEmpty", logical.class, new Block((Body) () ->
      {
         boolean _empty = true;
         
         if (!p1.isUnknown()) 
         {
            long rlen = TextOps.byteLength(p1).getValue();
            
            if (rlen > 0) 
            {
               long len = TextOps.length(p1).getValue();
               _empty = len == rlen && TextOps.isEmpty(TextOps.trim(p1));
            }
         } 
         
         returnNormal(new logical(_empty));
      }));
   }

   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "IsQuoted", parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static logical isQuoted(final longchar _p1)
   {
      longchar p1 = TypeFactory.initInput(_p1);

      return function(LegacyString.class, "IsQuoted", logical.class, new Block((Body) () ->
      {
         logical ret = isQuoted(p1, new character("\""));

         if (ret.booleanValue())
         {
            returnNormal(ret);
         }
         else
         {
            returnNormal(isQuoted(p1, new character("'")));
         }
      }));
   }

   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "IsQuoted", parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static logical isQuoted(final longchar _p1, final character _p2)
   {
      longchar p1 = TypeFactory.initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);

      return function(LegacyString.class, "IsQuoted", logical.class, new Block((Body) () ->
      {
         Assert.notNull(_p2, new character("Quote character"));

         if (p1.isUnknown() || p1.getValue().trim().length() < 2 || p2.getValue().length() > 1)
         {
            returnNormal(new logical(false));
         }

         else
         {
            Assert.notEmpty(_p2, new character("Quote character"));

            // the 4GL implementation only consider a single quote character
            // last index of should be equal to the length, no point to even search for it
            returnNormal(new logical(
                      p1.getValue().startsWith(p2.getValue())
                              && p1.getValue().endsWith(p2.getValue())));
         }
      }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Join", qualified = "openedge.core.string", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "openedge.core.collections.array", mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static object<? extends com.goldencode.p2j.oo.core.LegacyString> join(
            final object<? extends com.goldencode.p2j.oo.core.collections.Array> _p1,
            final character _p2)
   {
      object<? extends com.goldencode.p2j.oo.core.collections.Array> p1 = TypeFactory
               .initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);
      object<? extends LegacyString> poRet = TypeFactory.object(LegacyString.class);

      return function(LegacyString.class, "Join", object.class, new Block((Body) () -> {
         object<? extends LegacyClass> clsString = ObjectOps.getLegacyClass(LegacyString.class);

         if (!p2.isUnknown() && !p1.isUnknown())
         {
            List<String> entries = new ArrayList<String>();
            boolean hasUnknown = false;

            for (int i = 1; i <= p1.ref().getSize().intValue(); i++)
            {
               object<? extends _BaseObject_> c = p1.ref().getValue(new integer(i));
               if (c.isUnknown())
               {
                  hasUnknown = true;
                  break;
               }

               Assert.isType(c, clsString);

               entries.add(ObjectOps.cast(c, LegacyString.class).ref().getValue().getValue());
            }

            if (!hasUnknown) {
               String join = entries.stream().collect(Collectors.joining(p2.getValue()));
   
               poRet.assign(ObjectOps.newInstance(LegacyString.class, "I", join));
            }
         }

         returnNormal(poRet);

      }));
   }

   @LegacySignature(returns = "LONGCHAR", type = Type.METHOD, name = "Join", parameters = {
            @LegacyParameter(name = "p1", type = "CHARACTER", extent = -1, mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static longchar join(final character[] _p1, final character _p2)
   {
      character[] p1 = TypeFactory.initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);

      return function(LegacyString.class, "Join", longchar.class, new Block((Body) () ->
      {

         if (p2.isUnknown())
         {
            returnNormal(new longchar());
         }
         else
         {
            for (character c : p1)
            {
               if (c.isUnknown())
               {
                  returnNormal(new longchar());
                  return;
               }
            }

            List<String> entries = Arrays.stream(p1).map(c -> c.getValue())
                     .collect(Collectors.toList());

            returnNormal(new longchar(entries.stream().collect(Collectors.joining(p2.getValue()))));
         }
      }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Join", qualified = "openedge.core.string", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", extent = -1, qualified = "openedge.core.string", mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static object<? extends com.goldencode.p2j.oo.core.LegacyString> join_1(
            final object<? extends com.goldencode.p2j.oo.core.LegacyString>[] _p1,
            final character _p2)
   {
      object<? extends com.goldencode.p2j.oo.core.LegacyString>[] p1 = TypeFactory.initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);
      object<? extends LegacyString> poRet = TypeFactory.object(LegacyString.class);
      
      return function(LegacyString.class, "Join", object.class, new Block((Body) () -> {
         // indeterminate array or null delimiter 
         if (p1.length > 0 && !p2.isUnknown())
         {
            boolean hasUnknown = false;
            
            for (object<? extends com.goldencode.p2j.oo.core.LegacyString> s : p1)
            {
               // OE does not check for valid objects in array (will throw error)
               // if any of the strings has a null value the result is always null
               if (!s.isUnknown() && s.ref().getValue().isUnknown())
               {
                  hasUnknown = true;
                  break;
               }
            }

            poRet.assign(ObjectOps.newInstance(LegacyString.class, "I",
                        hasUnknown ? new character() : Arrays.stream(p1).map(s -> s.ref().getValue().getValue())
                              .collect(Collectors.joining(p2.getValue()))));
         }
         else 
         {
            poRet.assign(ObjectOps.newInstance(LegacyString.class, "I", new character("")));
         }
            
         
         returnNormal(poRet);
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Prepend", parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void prepend(final longchar _p1)
   {
      longchar p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "Prepend", new Block((Body) () ->
      {
         if (!this.equals(LegacyString.empty().ref()) && !value.isUnknown())
         {
            if (p1.isUnknown())
               value.setUnknown();
            else
               value.assign(p1.getValue().concat(value.getValue()));
         }
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Prepend", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "openedge.core.string", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void prepend(final object<? extends com.goldencode.p2j.oo.core.LegacyString> _p1)
   {
      object<? extends com.goldencode.p2j.oo.core.LegacyString> p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "Prepend", new Block((Body) () ->
      {
         if (!this.equals(LegacyString.empty().ref()) && !value.isUnknown())
         {
            // 4GL does not check for valid object, it just let the error throw
            prepend(p1.ref().getValue());
         }
      }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Split", qualified = "openedge.core.collections.array")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public object<? extends com.goldencode.p2j.oo.core.collections.Array> split()
   {
      return LegacyString.split(new object<>(this));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Split", qualified = "openedge.core.collections.array", parameters = {
            @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public object<? extends com.goldencode.p2j.oo.core.collections.Array> split(
            final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);

      return function(this, "Split", object.class, new Block((Body) () ->
      {
         returnNormal(split(new object<>(this), p1));
      }));
   }

   @LegacySignature(returns = "CHARACTER", type = Type.METHOD, name = "Split", extent = -1, parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static character[] split(final longchar _p1)
   {
      return extentFunction(LegacyString.class, "Split", character.class, 0,
               new Block((Body) () ->
               {
                  returnExtentNormal(LegacyString.split(_p1, new character(",")));
               }));
   }

   @LegacySignature(returns = "CHARACTER", type = Type.METHOD, name = "Split", extent = -1, parameters = {
            @LegacyParameter(name = "p1", type = "LONGCHAR", mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static character[] split(final longchar _p1, final character _p2)
   {
      longchar p1 = TypeFactory.initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);
      ObjectOps.load(LegacyString.class);
      character[][] res = { TypeFactory.characterExtent() };
      
      return extentFunction(LegacyString.class, "Split", character.class, 0,
               new Block((Body) () ->
               {
                  if (p1.isUnknown() || p2.isUnknown())
                  {
                     returnExtentNormal(res[0]);
                  }
                  else
                  {
                     String[] entries = TextOps.entries(p1.getValue(), p2.getValue());
                     res[0] = ArrayAssigner.resize(res[0], entries.length);
                     for (int i = 0; i < entries.length; i++)
                     {
                        res[0][i].assign(entries[i]);
                     }
                     returnExtentNormal(res[0]);
                  }
               }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Split", qualified = "openedge.core.collections.array", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "openedge.core.string", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static object<? extends com.goldencode.p2j.oo.core.collections.Array> split(
            final object<? extends com.goldencode.p2j.oo.core.LegacyString> _p1)
   {
      return function(LegacyString.class, "Split", object.class, new Block((Body) () ->
      {
         returnNormal(LegacyString.split(_p1, new character(",")));
      }));
   }

   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "Split", qualified = "openedge.core.collections.array", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "openedge.core.string", mode = "INPUT"),
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public static object<? extends com.goldencode.p2j.oo.core.collections.Array> split(
            final object<? extends com.goldencode.p2j.oo.core.LegacyString> _p1,
            final character _p2)
   {
      object<? extends com.goldencode.p2j.oo.core.LegacyString> p1 = TypeFactory.initInput(_p1);
      character p2 = TypeFactory.initInput(_p2);
      object<? extends com.goldencode.p2j.oo.core.collections.Array> poRet = TypeFactory
               .object(com.goldencode.p2j.oo.core.collections.Array.class);

      return function(LegacyString.class, "Split", object.class, new Block((Body) () -> {

         if (!p1.isUnknown() && (p2.isUnknown() || p1.ref().getValue().isUnknown()))
         {
            // num-entries is unknown, this will throw assert error
            poRet.assign(ObjectOps.newInstance(com.goldencode.p2j.oo.core.collections.Array.class,
                     "I", new integer()));
         }
         else
         {
            // 4GL does not test the string object, 3135 system error will be thrown if null
            String[] entries = TextOps.entries(p1.ref().getValue().getValue(), p2.getValue());
            poRet.assign(ObjectOps.newInstance(com.goldencode.p2j.oo.core.collections.Array.class,
                     "I", entries.length));

            for (int i = 0; i < entries.length; i++)
            {
               poRet.ref()
                        .setValue(ObjectOps.newInstance(
                                 com.goldencode.p2j.oo.core.LegacyString.class, "I", entries[i]),
                                 new integer(i + 1));
            }

         }

         returnNormal(poRet);
      }));
   }

   @LegacySignature(returns = "CHARACTER", type = Type.METHOD, name = "ToString")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public character toLegacyString()
   {
      return function(this, "ToString", character.class, new Block((Body) () ->
      {
         if (!value.isUnknown() && value.getValue().length() >= 30000) {
            returnNormal(new character(value.getValue().substring(0, 29985) + " <<...MORE...>>"));
         } else {
            returnNormal(valueOf(value));
         }
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Trim")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void trim_()
   {
      internalProcedure(this, "Trim", new Block((Body) () ->
      {
         value.assign(TextOps.trim(value));
      }));
   }

   @LegacySignature(type = Type.METHOD, name = "Trim", parameters = {
            @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
   public void trim_(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);

      internalProcedure(this, "Trim", new Block((Body) () ->
      {
         value.assign(TextOps.trim(value, p1));
      }));
   }   
}