-- Classes used by the IDE
local projectClass = luajava.bindClass("com.intellij.openapi.project.Project")
local projectManagerClass = luajava.bindClass("com.intellij.openapi.project.ProjectManager")
local fileTemplateManagerClass = luajava.bindClass("com.intellij.ide.fileTemplates.FileTemplateManager")
local fileTemplateUtilClass = luajava.bindClass("com.intellij.ide.fileTemplates.FileTemplateUtil")
local createFromTemplateHandlerClass = luajava.bindClass("com.intellij.ide.fileTemplates.CreateFromTemplateHandler")
local projectRootManagerClass = luajava.bindClass("com.intellij.openapi.roots.ProjectRootManager")
local psiFileClass = luajava.bindClass("com.intellij.psi.PsiFile")
local psiManagerClass = luajava.bindClass("com.intellij.psi.PsiManager")

-- Get the current project and other details for it
local project = projectManagerClass:getInstance():getOpenProjects()[1]
local projectRoot = projectRootManagerClass:getInstance(project)
local fileTemplateManager = fileTemplateManagerClass:getInstance(project)
local psiManager = psiManagerClass:getInstance(project)

-- Get the SquirrelJME Test template instance
local testTemplate = fileTemplateManager:getTemplate("SquirrelJME Test")

local contentRoot = projectRoot:getContentRoots()[1]
local testRoot = contentRoot:findChild("tests")
local psiTestDir = psiManager:findDirectory(testRoot)

-- All the files we want
local files = {"testByteCodeAALoad",
               "testByteCodeAAStore",
               "testByteCodeAConstNull",
               "testByteCodeANewArray",
               "testByteCodeAReturn",
               "testByteCodeArrayLength",
               "testByteCodeAThrow",
               "testByteCodeBALoad",
               "testByteCodeBAStore",
               "testByteCodeBIPush",
               "testByteCodeCALoad",
               "testByteCodeCAStore",
               "testByteCodeCheckCast",
               "testByteCodeD2F",
               "testByteCodeD2I",
               "testByteCodeD2L",
               "testByteCodeDAdd",
               "testByteCodeDALoad",
               "testByteCodeDAStore",
               "testByteCodeDCmpG",
               "testByteCodeDCmpL",
               "testByteCodeDDiv",
               "testByteCodeDMul",
               "testByteCodeDNeg",
               "testByteCodeDRem",
               "testByteCodeDReturn",
               "testByteCodeDSub",
               "testByteCodeDup",
               "testByteCodeDup2",
               "testByteCodeDup2X1",
               "testByteCodeDup2X2",
               "testByteCodeDupX1",
               "testByteCodeDupX2",
               "testByteCodeF2D",
               "testByteCodeF2I",
               "testByteCodeF2L",
               "testByteCodeFAdd",
               "testByteCodeFALoad",
               "testByteCodeFAStore",
               "testByteCodeFCmpG",
               "testByteCodeFCmpL",
               "testByteCodeFDiv",
               "testByteCodeFLoad",
               "testByteCodeFMul",
               "testByteCodeFNeg",
               "testByteCodeFRem",
               "testByteCodeFReturn",
               "testByteCodeFSub",
               "testByteCodeGetField",
               "testByteCodeGetStatic",
               "testByteCodeI2B",
               "testByteCodeI2C",
               "testByteCodeI2D",
               "testByteCodeI2F",
               "testByteCodeI2L",
               "testByteCodeI2S",
               "testByteCodeIAdd",
               "testByteCodeIALoad",
               "testByteCodeIAnd",
               "testByteCodeIAStore",
               "testByteCodeIDiv",
               "testByteCodeIfACmpEq",
               "testByteCodeIfACmpNe",
               "testByteCodeIfICmpEq",
               "testByteCodeIfICmpGe",
               "testByteCodeIfICmpGt",
               "testByteCodeIfICmpLe",
               "testByteCodeIfICmpLt",
               "testByteCodeIfICmpNe",
               "testByteCodeIfEq",
               "testByteCodeIfGe",
               "testByteCodeIfGt",
               "testByteCodeIfLe",
               "testByteCodeIfLt",
               "testByteCodeIfNe",
               "testByteCodeIfNonNull",
               "testByteCodeIfNull",
               "testByteCodeIMul",
               "testByteCodeINeg",
               "testByteCodeInstanceOf",
               "testByteCodeInvokeInterface",
               "testByteCodeInvokeSpecial",
               "testByteCodeInvokeStatic",
               "testByteCodeInvokeVirtual",
               "testByteCodeIOr",
               "testByteCodeIRem",
               "testByteCodeIReturn",
               "testByteCodeIShl",
               "testByteCodeIShr",
               "testByteCodeISub",
               "testByteCodeIUShr",
               "testByteCodeIXor",
               "testByteCodeL2D",
               "testByteCodeL2F",
               "testByteCodeL2I",
               "testByteCodeLAdd",
               "testByteCodeLALoad",
               "testByteCodeLAnd",
               "testByteCodeLAStore",
               "testByteCodeLCmp",
               "testByteCodeLdc2W",
               "testByteCodeLdcW",
               "testByteCodeLDiv",
               "testByteCodeLMul",
               "testByteCodeLNeg",
               "testByteCodeLookupSwitch",
               "testByteCodeLOr",
               "testByteCodeLRem",
               "testByteCodeLReturn",
               "testByteCodeLShl",
               "testByteCodeLShr",
               "testByteCodeLSub",
               "testByteCodeLUShr",
               "testByteCodeLXor",
               "testByteCodeMonitorEnter",
               "testByteCodeMonitorExit",
               "testByteCodeMultiANewArray",
               "testByteCodeNew",
               "testByteCodeNewArray",
               "testByteCodeNop",
               "testByteCodePop",
               "testByteCodePop2",
               "testByteCodePutField",
               "testByteCodePutStatic",
               "testByteCodeReturn",
               "testByteCodeSALoad",
               "testByteCodeSAStore",
               "testByteCodeSIPush",
               "testByteCodeSwap",
               "testByteCodeTableSwitch",
               "testByteCodeWideALoad",
               "testByteCodeWideAStore",
               "testByteCodeWideDLoad",
               "testByteCodeWideDStore",
               "testByteCodeWideFLoad",
               "testByteCodeWideFStore",
               "testByteCodeWideIInc",
               "testByteCodeWideILoad",
               "testByteCodeWideIStore",
               "testByteCodeWideLLoad",
               "testByteCodeWideLStore"}

-- Create using this template
for _,fileName in ipairs(files) do
    fileTemplateUtilClass:createFromTemplate(testTemplate,
            fileName,
            nil,
            psiTestDir)
end
