https://kotlinlang.org logo
Title
s

Smallville7123

03/29/2019, 9:45 PM
in particular i am unable to instance lexer(...) itself from inside the clone() function
b

bbaldino

03/29/2019, 10:55 PM
you're saying that in
lexer#clone
you can't create an instance of
lexer
? what error do you get?
s

Smallville7123

03/29/2019, 11:29 PM
Caused by: java.lang.NoSuchMethodError: Build_gradle$lexer.<init>(Ljava/nio/ByteBuffer;Ljava/lang/String;)V
	at Build_gradle$lexer.clone(build.gradle.kts:258)
b

bbaldino

03/29/2019, 11:32 PM
(oh, sorry, didn't notice that at the top of the paste)
i don't seem to get an error in a scratch file. could it be something about how you have them implemented that isn't in the paste?
s

Smallville7123

03/29/2019, 11:55 PM
ill attempt to make a minimal example
minimal example: a/build.gradle.kts :
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

fun fileToByteBuffer(f : File) : ByteBuffer {
    val file = RandomAccessFile(f, "r")
    val fileChannel = file.getChannel()
    var i = 0
    var buffer = ByteBuffer.allocate(fileChannel.size().toInt())
    fileChannel.read(buffer)
    buffer.flip()
    return buffer
}

val filetmp = "/sda3_partition_resize_to_size"

class lexer(stm : ByteBuffer, delimiter : String) {
    val f = stm
    val delimiters = delimiter
    fun clone() {
        val ll = lexer(fileToByteBuffer(File(filetmp)), "none")
    }
}

tasks.register("test") {
    val lex = lexer(fileToByteBuffer(File(filetmp)), "none")
    println("cloning")
    lex.clone()
    println("clone sucesfull")
}
app/build.gradle :
apply from: '../a/build.gradle.kts'

preBuild.dependsOn test
b

bbaldino

03/30/2019, 12:22 AM
i just pasted it into a quick kotlin file and changed the task to a main. i get a filenotfoundexception (since i don't have that file) but no complaint about the instantiation
s

Smallville7123

03/30/2019, 12:41 AM
u need to manually create the file lol (or change it to a file that DOES exist)
b

bbaldino

03/30/2019, 1:03 AM
did that but still runs fine
i'm on kotlin 1.3.21
s

Smallville7123

03/30/2019, 1:15 AM
no, you need to run it as a kotlin build script
also it fails even if the function is outside of the class itself
fun lexerClone(stm : ByteBuffer, tokens : String) : lexer {
    return lexer(stm, tokens)
}

class lexer ...
with the same error
the only way i can get it to work is this which is kinda annoying
val lex = lexer(fileToByteBuffer(File(src)), tokens)
    println("cloning")
    val la = lexer(lex.f.duplicate(), lex.delimiters)
    println("clone made")
    var line = lex.lex()
    var laline = la.lex()
    println("line is '$line'")
    println("laline is '$laline'")
cloning
clone made
line is '
'
laline is '
'