Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert most of android-compiler module to kotlin #120

Merged
merged 24 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions android-compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
id 'com.android.lint'
}

Expand All @@ -8,6 +9,12 @@ java {
targetCompatibility = JavaVersion.VERSION_11
}

compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
}

dependencies {
// r8 dependency
implementation 'com.android.tools:r8:3.3.28'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.pranav.android.code.disassembler

import org.eclipse.jdt.internal.core.util.Disassembler

import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths

class EclipseDisassembler(filePath: String) {

private lateinit var classFileBytes: ByteArray

init {
classFileBytes = Files.readAllBytes(Paths.get(filePath))
}

@Throws(Throwable::class)
fun disassemble() : String {
return Disassembler().disassemble(classFileBytes, System.lineSeparator())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.pranav.android.code.disassembler

import com.sun.tools.javap.JavapTask

import java.io.StringWriter
import java.util.ArrayList

class JavapDisassembler(filePath: String) {

private val path: String

init {
path = filePath
}

@Throws(Throwable::class)
fun disassemble() : String {
// Create an arraylist for storing javap arguments
val args = listOf(
"-c",
path
)
// Create a StringWriter object that will store the output
val writer = StringWriter()
// Create a JavapTask to handle the arguments
val task = JavapTask()
task.handleOptions(args.toTypedArray())
task.setLog(writer)
task.run()
// return the disassembled file as string
return writer.toString()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pranav.android.code.formatter

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions
import org.eclipse.jface.text.Document

class EclipseJavaFormatter(code: String) {

private val source: String

init {
source = code;
}

fun format(): String {
val options = DefaultCodeFormatterOptions.getEclipseDefaultSettings()

val codeFormatter = DefaultCodeFormatter(options)

val edit =
codeFormatter.format(
DefaultCodeFormatter.K_COMPILATION_UNIT,
source,
0, // starting index
source.length, // length
0, // initial indentation
System.lineSeparator() // line separator
)

val document = Document(source)
try {
edit.apply(document)
} catch (e: Exception) {
throw IllegalStateException(e)
}
// return the formatted code
return document.get()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.pranav.android.code.formatter

import com.google.googlejavaformat.java.Formatter
import com.google.googlejavaformat.java.FormatterException
import com.google.googlejavaformat.java.JavaFormatterOptions

class GoogleJavaFormatter(input: String) {

private val source: String

init {
source = input
}

fun format(): String {
val options =
JavaFormatterOptions.builder()
.style(JavaFormatterOptions.Style.AOSP) // Use AOSP formatting style
.formatJavadoc(true) // Format Javadoc with code
.build()
val formatter = Formatter(options)
try {
return formatter.formatSourceAndFixImports(source)
} catch (e: Exception) {
e.printStackTrace()
}
return source
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.pranav.android.exception

class CompilationFailedException : Exception {
constructor(message: String?) : super(message)
constructor(e: Throwable?): super(e)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pranav.android.interfaces

import android.content.Context

interface Builder {

fun getContext() : Context

fun getClassloader() : ClassLoader
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pranav.android.interfaces;

interface Task {

fun getTaskName() : String

@Throws(Exception::class)
fun doFullTask()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pranav.android.task

import android.content.Context

import com.pranav.android.interfaces.*
import com.pranav.android.task.java.*

class JavaBuilder(context: Context, loader: ClassLoader) : Builder {

private var classloader: ClassLoader

private var mContext: Context

init {
mContext = context
classloader = loader
}

override fun getContext() : Context {
return mContext
}

override fun getClassloader() : ClassLoader {
return classloader
}
}