use UmpleNotice.ump;
use association_set_specialization_reqCommonCode.ump;
use association_set_specialization_reqSuperCode.ump;


namespace cruise.umple.compiler.java;

@SuppressWarnings("unused")
class JavaSpecGenerator {
    depend cruise.umple.compiler.*;
    depend cruise.umple.util.*;
    depend java.util.*;



  /*  Skeleton for the Specialization Generator
      
      This file was created to fix a "code too large" error in the 
      constructor for the JavaClassGenerator. 

      Note the lack of a getCode method -- this is the distinction
      between the Class Generators and the Spec Generator. The issue
      was with the generator implementing ILang. Since there really
      was no point to implement ILang with the desired solution
      in mind, the getCode method was dropped.

      Essentially, this Generator would contain methods that are
      called from other Generators when the inclusion of the 
      necessary strings would result in a "code too large" error.
  */

  // Add a newline to the end of the input
  private void appendln(StringBuffer buffer, String input, Object... variables)
  {
    append(buffer, input + "\n", variables);
  }  

  // This method will be used to append formatted strings
  // i.e. format("Hello {0} {1}", "andrew","forward");
  private void append(StringBuffer buffer, String input, Object... variables)
  {
    buffer.append(StringFormatter.format(input,variables));
  }

  // This method will have the JET stuff inserted into it.
  // Will not be called anywhere, but will ensure the rest of the file works
  // as expected
  private void genHere() {
  
  }

    // TODO: Replace <lastFunctionName> with the name of the function that is above this. Replace arguments as well.
        // That function can be removed
    emit <lastFunctionName>(arguments...)(JavaSpecGenerator);


    JavaSpecGenerator <<!<</*JavaSpecGenerator*/>><<@ UnitTest.UmpleNotice >>
<<#
	} // end append
	
  public void getAssociationCode_specialization_reqSuperCode(JavaGenerator gen, String includeFile, String includeFile2, String includeFile3, StringBuffer realSb, AssociationVariable av, AssociationVariable relatedAssociation,
  		String customSetPrefixCode, String customSetPostfixCode, String customAddPrefixCode, String customAddPostfixCode, String customRemovePrefixCode, String customRemovePostfixCode,
  		String customSetManyPrefixCode, String customSetManyPostfixCode, List<TraceItem> traceItemAssocRemoves, List<TraceItem> traceItemAssocAdds, UmpleClass uClass, boolean sortMethodAdded, String umpleSourceFile,
  		Map<String,UncaughtException> uncaughtExceptions, UmpleClass globalUmpleClass, boolean addNewLine, boolean mulChangedToOne, boolean relMulChangedToOne, boolean mulChangedToN, boolean reqSetCode, boolean relReqCommonCode, boolean relReqSetCode, String scName) 
  	{ 
  	this.uncaughtExceptions = uncaughtExceptions;
  	this.globalUmpleClass = globalUmpleClass;
  #>><<@ UnitTest.association_set_specialization_reqSuperCode >><<#
     }// end super code
     
  public void getAssociationCode_specialization_reqCommonCode(JavaGenerator gen, String includeFile, String includeFile2, String includeFile3, StringBuffer realSb, AssociationVariable av, AssociationVariable relatedAssociation,
  		String customSetPrefixCode, String customSetPostfixCode, String customAddPrefixCode, String customAddPostfixCode, String customRemovePrefixCode, String customRemovePostfixCode,
  		String customSetManyPrefixCode, String customSetManyPostfixCode, List<TraceItem> traceItemAssocRemoves, List<TraceItem> traceItemAssocAdds, UmpleClass uClass, boolean sortMethodAdded, String umpleSourceFile,
  		Map<String,UncaughtException> uncaughtExceptions, UmpleClass globalUmpleClass, boolean addNewLine, boolean mulChangedToOne, boolean relMulChangedToOne, boolean mulChangedToN, boolean reqSetCode, boolean relReqCommonCode, boolean relReqSetCode, String scName) 
  	{
  	 this.uncaughtExceptions = uncaughtExceptions;
  	 this.globalUmpleClass = globalUmpleClass;
  #>><<@ UnitTest.association_set_specialization_reqCommonCode >><<# 
    } // end common code
    
    java.util.regex.Pattern lineNumberPattern = java.util.regex.Pattern.compile("// line ([0|1|2|3|4|5|6|7|8|9]*) (.*)");
private void addUncaughtExceptionVariables(int javaline, String code, String methodname)
{
  String[] lines = code.split("\\n");
  java.util.regex.Matcher matcher = lineNumberPattern.matcher(lines[0]);
  if(matcher.matches())
  {
    if(!uncaughtExceptions.containsKey(methodname))
    {
      uncaughtExceptions.put(methodname,new UncaughtException(globalUmpleClass.getName(), methodname));
    }
    uncaughtExceptions.get(methodname).addUncaughtFileName(matcher.group(2));
    uncaughtExceptions.get(methodname).addUncaughtUmpleLine(Integer.parseInt(matcher.group(1))-1);
    uncaughtExceptions.get(methodname).addUncaughtJavaLine(javaline+1);
    uncaughtExceptions.get(methodname).addUncaughtLength(lines.length);
  }  
}
private void addUncaughtExceptionVariables(String methodname, String filename, int umpleline, int javaline, int length)
{
  if(!uncaughtExceptions.containsKey(methodname))
  {
    uncaughtExceptions.put(methodname,new UncaughtException(globalUmpleClass.getName(), methodname));
  }
  
  uncaughtExceptions.get(methodname).addUncaughtFileName(filename);
  uncaughtExceptions.get(methodname).addUncaughtUmpleLine(umpleline-1);
  uncaughtExceptions.get(methodname).addUncaughtJavaLine(javaline+1);
  uncaughtExceptions.get(methodname).addUncaughtLength(length);
}

private Map<String,UncaughtException> uncaughtExceptions;
private UmpleClass globalUmpleClass;

public String endAll(String realSb)
{
  GeneratorHelper.generator = null;
#>>!>>
}