diff --git a/NeoLang/build.gradle b/NeoLang/build.gradle index b8ccbda..133ec64 100644 --- a/NeoLang/build.gradle +++ b/NeoLang/build.gradle @@ -30,3 +30,7 @@ compileTestKotlin { jvmTarget = "1.8" } } + +dependencies { + testCompile 'junit:junit:4.12' +} diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangBlockNode.kt b/NeoLang/src/main/java/io/neolang/ast/NeoLangBlockNode.kt deleted file mode 100644 index 4318d05..0000000 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangBlockNode.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.neolang.ast - -import io.neolang.ast.base.NeoLangAstBaseNode -import io.neolang.ast.typed.NeoLangAstTypedNode - -/** - * @author kiva - */ -class NeoLangBlockNode(ast: NeoLangAstBaseNode) : NeoLangAstTypedNode(ast) { - companion object { - fun emptyNode() :NeoLangBlockNode { - return NeoLangBlockNode(NeoLangDummyNode()) - } - } -} \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangDummyNode.kt b/NeoLang/src/main/java/io/neolang/ast/NeoLangDummyNode.kt deleted file mode 100644 index c9b510e..0000000 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangDummyNode.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.neolang.ast - -import io.neolang.ast.base.NeoLangAstBaseNode - -/** - * @author kiva - */ -class NeoLangDummyNode : NeoLangAstBaseNode() \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangNumberNode.kt b/NeoLang/src/main/java/io/neolang/ast/NeoLangNumberNode.kt deleted file mode 100644 index 8279f1f..0000000 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangNumberNode.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.neolang.ast - -import io.neolang.ast.typed.NeoLangTokenTypedNode - -/** - * @author kiva - */ -class NeoLangNumberNode(token: NeoLangToken) : NeoLangTokenTypedNode(token) \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangStringNode.kt b/NeoLang/src/main/java/io/neolang/ast/NeoLangStringNode.kt deleted file mode 100644 index 358ec67..0000000 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangStringNode.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.neolang.ast - -import io.neolang.ast.typed.NeoLangTokenTypedNode - -/** - * @author kiva - */ -class NeoLangStringNode(token: NeoLangToken) : NeoLangTokenTypedNode(token) \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangTokenValue.kt b/NeoLang/src/main/java/io/neolang/ast/NeoLangTokenValue.kt index 1d1ccd7..b8e9f42 100644 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangTokenValue.kt +++ b/NeoLang/src/main/java/io/neolang/ast/NeoLangTokenValue.kt @@ -1,28 +1,30 @@ package io.neolang.ast +import io.neolang.runtime.type.NeoLangValue + /** * @author kiva */ -class NeoLangTokenValue(val value: String) { +class NeoLangTokenValue(val value: NeoLangValue) { override fun toString(): String { - return value + return value.asString() } companion object { - val COLON = NeoLangTokenValue(":") - val BRACKET_START = NeoLangTokenValue("{") - val BRACKET_END = NeoLangTokenValue("}") - val QUOTE = NeoLangTokenValue("\"") - val EOF = NeoLangTokenValue("") + val COLON = NeoLangTokenValue(NeoLangValue(":")) + val BRACKET_START = NeoLangTokenValue(NeoLangValue("{")) + val BRACKET_END = NeoLangTokenValue(NeoLangValue("}")) + val QUOTE = NeoLangTokenValue(NeoLangValue("\"")) + val EOF = NeoLangTokenValue(NeoLangValue("")) fun wrap(tokenText: String): NeoLangTokenValue { return when (tokenText) { - COLON.value -> COLON - BRACKET_START.value -> BRACKET_START - BRACKET_END.value -> BRACKET_END - QUOTE.value -> QUOTE - else -> NeoLangTokenValue(tokenText) + COLON.value.asString() -> COLON + BRACKET_START.value.asString() -> BRACKET_START + BRACKET_END.value.asString() -> BRACKET_END + QUOTE.value.asString() -> QUOTE + else -> NeoLangTokenValue(NeoLangValue(tokenText)) } } } diff --git a/NeoLang/src/main/java/io/neolang/ast/typed/NeoLangAstTypedNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangAstBasedNode.kt similarity index 67% rename from NeoLang/src/main/java/io/neolang/ast/typed/NeoLangAstTypedNode.kt rename to NeoLang/src/main/java/io/neolang/ast/node/NeoLangAstBasedNode.kt index 3b2a341..a442d64 100644 --- a/NeoLang/src/main/java/io/neolang/ast/typed/NeoLangAstTypedNode.kt +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangAstBasedNode.kt @@ -1,11 +1,11 @@ -package io.neolang.ast.typed +package io.neolang.ast.node import io.neolang.ast.base.NeoLangAstBaseNode /** * @author kiva */ -open class NeoLangAstTypedNode(val ast: NeoLangAstBaseNode) : NeoLangAstBaseNode() { +open class NeoLangAstBasedNode(val ast: NeoLangAstBaseNode) : NeoLangAstBaseNode() { override fun toString(): String { return "${javaClass.simpleName} { ast: $ast }" } diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangAttributeNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangAttributeNode.kt similarity index 56% rename from NeoLang/src/main/java/io/neolang/ast/NeoLangAttributeNode.kt rename to NeoLang/src/main/java/io/neolang/ast/node/NeoLangAttributeNode.kt index 9827c50..5c197fd 100644 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangAttributeNode.kt +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangAttributeNode.kt @@ -1,11 +1,11 @@ -package io.neolang.ast +package io.neolang.ast.node import io.neolang.ast.base.NeoLangAstBaseNode /** * @author kiva */ -class NeoLangAttributeNode(private val stringNode: NeoLangStringNode, private val blockNode: NeoLangBlockNode) : NeoLangAstBaseNode() { +class NeoLangAttributeNode(val stringNode: NeoLangStringNode, val blockNode: NeoLangBlockNode) : NeoLangAstBaseNode() { override fun toString(): String { return "NeoLangAttributeNode { stringNode: $stringNode, block: $blockNode }" diff --git a/NeoLang/src/main/java/io/neolang/ast/node/NeoLangBlockNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangBlockNode.kt new file mode 100644 index 0000000..96cbaaf --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangBlockNode.kt @@ -0,0 +1,14 @@ +package io.neolang.ast.node + +import io.neolang.ast.base.NeoLangAstBaseNode + +/** + * @author kiva + */ +class NeoLangBlockNode(blockElement: NeoLangAstBaseNode) : NeoLangAstBasedNode(blockElement) { + companion object { + fun emptyNode() : NeoLangBlockNode { + return NeoLangBlockNode(NeoLangDummyNode()) + } + } +} \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/node/NeoLangDummyNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangDummyNode.kt new file mode 100644 index 0000000..798d229 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangDummyNode.kt @@ -0,0 +1,8 @@ +package io.neolang.ast.node + +import io.neolang.ast.base.NeoLangAstBaseNode + +/** + * @author kiva + */ +class NeoLangDummyNode : NeoLangAstBaseNode() \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangGroupNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangGroupNode.kt similarity index 58% rename from NeoLang/src/main/java/io/neolang/ast/NeoLangGroupNode.kt rename to NeoLang/src/main/java/io/neolang/ast/node/NeoLangGroupNode.kt index 94070e8..93d7cd6 100644 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangGroupNode.kt +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangGroupNode.kt @@ -1,11 +1,11 @@ -package io.neolang.ast +package io.neolang.ast.node import io.neolang.ast.base.NeoLangAstBaseNode /** * @author kiva */ -class NeoLangGroupNode(private val attributes: List) : NeoLangAstBaseNode() { +class NeoLangGroupNode(val attributes: List) : NeoLangAstBaseNode() { override fun toString(): String { return "NeoLangGroupNode { attrs: $attributes }" diff --git a/NeoLang/src/main/java/io/neolang/ast/node/NeoLangNumberNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangNumberNode.kt new file mode 100644 index 0000000..106c333 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangNumberNode.kt @@ -0,0 +1,8 @@ +package io.neolang.ast.node + +import io.neolang.ast.NeoLangToken + +/** + * @author kiva + */ +class NeoLangNumberNode(token: NeoLangToken) : NeoLangTokenBasedNode(token) \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/NeoLangProgramNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangProgramNode.kt similarity index 72% rename from NeoLang/src/main/java/io/neolang/ast/NeoLangProgramNode.kt rename to NeoLang/src/main/java/io/neolang/ast/node/NeoLangProgramNode.kt index 3d163d0..1887d81 100644 --- a/NeoLang/src/main/java/io/neolang/ast/NeoLangProgramNode.kt +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangProgramNode.kt @@ -1,4 +1,4 @@ -package io.neolang.ast +package io.neolang.ast.node import io.neolang.ast.base.NeoLangAstBaseNode @@ -6,7 +6,7 @@ import io.neolang.ast.base.NeoLangAstBaseNode * @author kiva */ -class NeoLangProgramNode(private val groups: List) : NeoLangAstBaseNode() { +class NeoLangProgramNode(val groups: List) : NeoLangAstBaseNode() { override fun toString(): String { return "NeoLangProgramNode { groups: $groups }" diff --git a/NeoLang/src/main/java/io/neolang/ast/node/NeoLangStringNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangStringNode.kt new file mode 100644 index 0000000..5d89e49 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangStringNode.kt @@ -0,0 +1,8 @@ +package io.neolang.ast.node + +import io.neolang.ast.NeoLangToken + +/** + * @author kiva + */ +class NeoLangStringNode(token: NeoLangToken) : NeoLangTokenBasedNode(token) \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/typed/NeoLangTokenTypedNode.kt b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangTokenBasedNode.kt similarity index 51% rename from NeoLang/src/main/java/io/neolang/ast/typed/NeoLangTokenTypedNode.kt rename to NeoLang/src/main/java/io/neolang/ast/node/NeoLangTokenBasedNode.kt index 4d057dd..c6ebf64 100644 --- a/NeoLang/src/main/java/io/neolang/ast/typed/NeoLangTokenTypedNode.kt +++ b/NeoLang/src/main/java/io/neolang/ast/node/NeoLangTokenBasedNode.kt @@ -1,13 +1,18 @@ -package io.neolang.ast.typed +package io.neolang.ast.node import io.neolang.ast.base.NeoLangAstBaseNode import io.neolang.ast.NeoLangToken +import io.neolang.runtime.type.NeoLangValue /** * @author kiva */ -open class NeoLangTokenTypedNode(val token: NeoLangToken) : NeoLangAstBaseNode() { +open class NeoLangTokenBasedNode(val token: NeoLangToken) : NeoLangAstBaseNode() { override fun toString(): String { return "${javaClass.simpleName} { token: $token }" } + + fun eval() :NeoLangValue { + return token.tokenValue.value + } } \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitor.kt b/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitor.kt index 755861f..31d1c65 100644 --- a/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitor.kt +++ b/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitor.kt @@ -7,6 +7,6 @@ import io.neolang.ast.base.NeoLangAst */ class AstVisitor(private val ast: NeoLangAst, private val visitorCallback: IVisitorCallback) { fun start() { - // TODO visitor + AstVisitorImpl.visitStartAst(ast, visitorCallback) } -} \ No newline at end of file +} diff --git a/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitorImpl.kt b/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitorImpl.kt new file mode 100644 index 0000000..c2c37e1 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/ast/visitor/AstVisitorImpl.kt @@ -0,0 +1,62 @@ +package io.neolang.ast.visitor + +import io.neolang.ast.base.NeoLangAst +import io.neolang.ast.node.* + +/** + * grammar: [ + * program: group (group)* + * group: attribute (attribute)* + * attribute: ID COLON block + * block: STRING | NUMBER | (BRACKET_START group BRACKET_END) + * ] + */ + +/** + * @author kiva + */ +internal object AstVisitorImpl { + fun visitProgram(ast: NeoLangProgramNode, visitorCallback: IVisitorCallback) { + visitorCallback.onStart() + ast.groups.forEach { visitGroup(it, visitorCallback) } + visitorCallback.onFinish() + } + + fun visitGroup(ast: NeoLangGroupNode, visitorCallback: IVisitorCallback) { + ast.attributes.forEach { + visitAttribute(it, visitorCallback) + } + } + + fun visitAttribute(ast: NeoLangAttributeNode, visitorCallback: IVisitorCallback) { + visitBlock(ast.blockNode, ast.stringNode.eval().asString(), visitorCallback) + } + + fun visitBlock(ast: NeoLangBlockNode, blockName: String, visitorCallback: IVisitorCallback) { + val visitingNode = ast.ast + when (visitingNode) { + is NeoLangGroupNode -> { + // is a sub block, e.g. + // block: { sub-block: {} } + visitorCallback.onEnterContext(blockName) + AstVisitorImpl.visitGroup(visitingNode, visitorCallback) + visitorCallback.onExitContext() + } + is NeoLangStringNode -> { + // block: { node: "hello" } + visitorCallback.getCurrentContext().defineAttribute(blockName, visitingNode.eval()) + } + is NeoLangNumberNode -> { + // block: { node: 123.456 } + visitorCallback.getCurrentContext().defineAttribute(blockName, visitingNode.eval()) + } + } + } + + fun visitStartAst(ast: NeoLangAst, visitorCallback: IVisitorCallback) { + when (ast) { + is NeoLangProgramNode -> AstVisitorImpl.visitProgram(ast, visitorCallback) + is NeoLangGroupNode -> AstVisitorImpl.visitGroup(ast, visitorCallback) + } + } +} diff --git a/NeoLang/src/main/java/io/neolang/ast/visitor/IVisitorCallback.kt b/NeoLang/src/main/java/io/neolang/ast/visitor/IVisitorCallback.kt index fc5fa2c..d5d71c0 100644 --- a/NeoLang/src/main/java/io/neolang/ast/visitor/IVisitorCallback.kt +++ b/NeoLang/src/main/java/io/neolang/ast/visitor/IVisitorCallback.kt @@ -1,7 +1,18 @@ package io.neolang.ast.visitor +import io.neolang.runtime.context.NeoLangContext + /** * @author kiva */ interface IVisitorCallback { -} \ No newline at end of file + fun onStart() + + fun onFinish() + + fun onEnterContext(contextName: String) + + fun onExitContext() + + fun getCurrentContext() : NeoLangContext +} diff --git a/NeoLang/src/main/java/io/neolang/main/DisplayAstVisitor.kt b/NeoLang/src/main/java/io/neolang/main/DisplayAstVisitor.kt deleted file mode 100644 index 01a308e..0000000 --- a/NeoLang/src/main/java/io/neolang/main/DisplayAstVisitor.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.neolang.main - -import io.neolang.ast.visitor.IVisitorCallback - -/** - * @author kiva - */ -class DisplayAstVisitor : IVisitorCallback { -} \ No newline at end of file diff --git a/NeoLang/src/main/java/io/neolang/main/DisplayProcessVisitor.kt b/NeoLang/src/main/java/io/neolang/main/DisplayProcessVisitor.kt new file mode 100644 index 0000000..ab60722 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/main/DisplayProcessVisitor.kt @@ -0,0 +1,39 @@ +package io.neolang.main + +import io.neolang.ast.visitor.IVisitorCallback +import io.neolang.runtime.context.NeoLangContext +import java.util.* + +/** + * @author kiva + */ +class DisplayProcessVisitor : IVisitorCallback { + private val contextStack = Stack() + + override fun onStart() { + println(">>> Start") + onEnterContext("global") + } + + override fun onFinish() { + while (contextStack.isNotEmpty()) { + onExitContext() + } + println(">>> Finish") + } + + override fun onEnterContext(contextName: String) { + val context = NeoLangContext(contextName) + contextStack.push(context) + println(">>> Entering Context `$contextName'") + } + + override fun onExitContext() { + val context = contextStack.pop() + println(">>> Exiting Context ${context.contextName}") + } + + override fun getCurrentContext(): NeoLangContext { + return contextStack.peek() + } +} diff --git a/NeoLang/src/main/java/io/neolang/main/Main.kt b/NeoLang/src/main/java/io/neolang/main/Main.kt index 0fa4089..3441cf7 100644 --- a/NeoLang/src/main/java/io/neolang/main/Main.kt +++ b/NeoLang/src/main/java/io/neolang/main/Main.kt @@ -20,12 +20,10 @@ class Main { val programCode = readFully(it) parser.setInputSource(programCode) val ast = parser.parse() - - val visitor = ast.visit().getVisitor(DisplayAstVisitor::class.java) - if (visitor != null) { - println("Compile `$it' -> $ast") - visitor.start() - } + println("Compile `$it'") + ast.visit() + .getVisitor(DisplayProcessVisitor::class.java) + ?.start() } return } diff --git a/NeoLang/src/main/java/io/neolang/parser/NeoLangLexer.kt b/NeoLang/src/main/java/io/neolang/parser/NeoLangLexer.kt index d643694..4a9dbca 100755 --- a/NeoLang/src/main/java/io/neolang/parser/NeoLangLexer.kt +++ b/NeoLang/src/main/java/io/neolang/parser/NeoLangLexer.kt @@ -8,10 +8,10 @@ import java.util.* /** * grammar: [ - * prog: group (group)* + * program: group (group)* * group: attribute (attribute)* - * attribute: TEXT COLON block - * block: NUMBER | TEXT | (BRACKET_START group BRACKET_END) + * attribute: ID COLON block + * block: STRING | NUMBER | (BRACKET_START group BRACKET_END) * ] */ @@ -122,7 +122,7 @@ class NeoLangLexer { val builder = StringBuilder() var loop = true - while (loop && currentChar != NeoLangTokenValue.QUOTE.value[0]) { + while (loop && currentChar != NeoLangTokenValue.QUOTE.value.asString()[0]) { // Skip escaped char if (currentChar == '\\') { builder.append('\\') diff --git a/NeoLang/src/main/java/io/neolang/parser/NeoLangParser.kt b/NeoLang/src/main/java/io/neolang/parser/NeoLangParser.kt index c69e342..b3efd02 100755 --- a/NeoLang/src/main/java/io/neolang/parser/NeoLangParser.kt +++ b/NeoLang/src/main/java/io/neolang/parser/NeoLangParser.kt @@ -2,6 +2,7 @@ package io.neolang.parser import io.neolang.ast.* import io.neolang.ast.base.NeoLangAst +import io.neolang.ast.node.* /** * @author kiva diff --git a/NeoLang/src/main/java/io/neolang/runtime/context/IContextMaker.kt b/NeoLang/src/main/java/io/neolang/runtime/context/IContextMaker.kt new file mode 100644 index 0000000..26b2608 --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/runtime/context/IContextMaker.kt @@ -0,0 +1,8 @@ +package io.neolang.runtime.context + +/** + * @author kiva + */ +interface IContextMaker { + fun makeContext() +} diff --git a/NeoLang/src/main/java/io/neolang/runtime/context/NeoLangContext.kt b/NeoLang/src/main/java/io/neolang/runtime/context/NeoLangContext.kt new file mode 100644 index 0000000..b5034ad --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/runtime/context/NeoLangContext.kt @@ -0,0 +1,18 @@ +package io.neolang.runtime.context + +import io.neolang.runtime.type.NeoLangValue + +/** + * @author kiva + */ +class NeoLangContext(val contextName: String) { + private val attributes = mutableMapOf() + + fun defineAttribute(attributeName: String, attributeValue: NeoLangValue) { + attributes[attributeName] = attributeValue + } + + fun getAttribute(attributeName: String) : NeoLangValue { + return attributes[attributeName] ?: NeoLangValue.UNDEFINED + } +} diff --git a/NeoLang/src/main/java/io/neolang/runtime/type/NeoLangValue.kt b/NeoLang/src/main/java/io/neolang/runtime/type/NeoLangValue.kt new file mode 100644 index 0000000..5024ecc --- /dev/null +++ b/NeoLang/src/main/java/io/neolang/runtime/type/NeoLangValue.kt @@ -0,0 +1,22 @@ +package io.neolang.runtime.type + +/** + * @author kiva + */ +class NeoLangValue(private val rawValue: Any) { + fun asString() : String { + return rawValue.toString() + } + + fun asNumber() : Double { + try { + return asString().toDouble() + } catch (e: NumberFormatException) { + return 0.0 + } + } + + companion object { + val UNDEFINED = NeoLangValue("") + } +} \ No newline at end of file diff --git a/app/src/test/java/io/neoterm/NeoLangTest.kt b/NeoLang/src/test/java/io/neolang/NeoLangTest.kt similarity index 94% rename from app/src/test/java/io/neoterm/NeoLangTest.kt rename to NeoLang/src/test/java/io/neolang/NeoLangTest.kt index 613b50f..b5adf69 100644 --- a/app/src/test/java/io/neoterm/NeoLangTest.kt +++ b/NeoLang/src/test/java/io/neolang/NeoLangTest.kt @@ -1,4 +1,4 @@ -package io.neoterm +package io.neolang import io.neolang.main.Main import org.junit.Test diff --git a/app/src/androidTest/java/io/neoterm/ExampleInstrumentedTest.kt b/app/src/androidTest/java/io/neoterm/ExampleInstrumentedTest.kt deleted file mode 100644 index b183e81..0000000 --- a/app/src/androidTest/java/io/neoterm/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.neoterm - -import android.support.test.InstrumentationRegistry -import android.support.test.runner.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see [Testing documentation](http://d.android.com/tools/testing) - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - @Throws(Exception::class) - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getTargetContext() - assertEquals("io.neoterm", appContext.packageName) - } -} diff --git a/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt index 5dd4847..beb6b23 100644 --- a/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt +++ b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt @@ -4,7 +4,7 @@ import android.app.AlertDialog import android.content.Context import android.content.DialogInterface import io.neoterm.backend.TerminalSession -import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.tinyclient.BasicSessionCallback import io.neoterm.frontend.tinyclient.BasicViewClient import io.neoterm.utils.TerminalUtils diff --git a/app/src/main/java/io/neoterm/frontend/service/ServiceDuplicateException.kt b/app/src/main/java/io/neoterm/frontend/service/ServiceDuplicateException.kt new file mode 100644 index 0000000..e449ef2 --- /dev/null +++ b/app/src/main/java/io/neoterm/frontend/service/ServiceDuplicateException.kt @@ -0,0 +1,6 @@ +package io.neoterm.frontend.service + +/** + * @author kiva + */ +class ServiceDuplicateException(serviceName: String) : RuntimeException("Service $serviceName duplicate") \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/frontend/service/ServiceManager.kt b/app/src/main/java/io/neoterm/frontend/service/ServiceManager.kt index f4eff74..2d9e6c1 100644 --- a/app/src/main/java/io/neoterm/frontend/service/ServiceManager.kt +++ b/app/src/main/java/io/neoterm/frontend/service/ServiceManager.kt @@ -10,9 +10,12 @@ object ServiceManager { val THROW_WHEN_SERVICE_NOT_FOUND = true val SERVICE_CACHE = ConcurrentHashMap, NeoService>() - fun registerService(serviceInterface: Class) { - val service = createServiceInstance(serviceInterface) - SERVICE_CACHE.put(serviceInterface, service) + fun registerService(serviceClass: Class) { + if (SERVICE_CACHE.containsKey(serviceClass)) { + throw ServiceDuplicateException(serviceClass.simpleName) + } + val service = createServiceInstance(serviceClass) + SERVICE_CACHE.put(serviceClass, service) service.onServiceInit() } @@ -24,7 +27,6 @@ object ServiceManager { } } - @Suppress("UNCHECKED_CAST") inline fun getService(): T { Log.e("NeoTerm", SERVICE_CACHE.keys.toString()) val serviceInterface = T::class.java diff --git a/app/src/main/java/io/neoterm/frontend/ShellParameter.kt b/app/src/main/java/io/neoterm/frontend/shell/ShellParameter.kt similarity index 97% rename from app/src/main/java/io/neoterm/frontend/ShellParameter.kt rename to app/src/main/java/io/neoterm/frontend/shell/ShellParameter.kt index 5bd863b..f18e1ea 100644 --- a/app/src/main/java/io/neoterm/frontend/ShellParameter.kt +++ b/app/src/main/java/io/neoterm/frontend/shell/ShellParameter.kt @@ -1,4 +1,4 @@ -package io.neoterm.frontend +package io.neoterm.frontend.shell import io.neoterm.backend.TerminalSession diff --git a/app/src/main/java/io/neoterm/frontend/ShellTermSession.kt b/app/src/main/java/io/neoterm/frontend/shell/ShellTermSession.kt similarity index 99% rename from app/src/main/java/io/neoterm/frontend/ShellTermSession.kt rename to app/src/main/java/io/neoterm/frontend/shell/ShellTermSession.kt index 455d935..2571322 100644 --- a/app/src/main/java/io/neoterm/frontend/ShellTermSession.kt +++ b/app/src/main/java/io/neoterm/frontend/shell/ShellTermSession.kt @@ -1,4 +1,4 @@ -package io.neoterm.frontend +package io.neoterm.frontend.shell import android.content.Context import io.neoterm.R diff --git a/app/src/main/java/io/neoterm/services/NeoTermService.kt b/app/src/main/java/io/neoterm/services/NeoTermService.kt index 0ca432d..c9bc8e3 100644 --- a/app/src/main/java/io/neoterm/services/NeoTermService.kt +++ b/app/src/main/java/io/neoterm/services/NeoTermService.kt @@ -15,7 +15,7 @@ import android.support.v4.content.WakefulBroadcastReceiver import io.neoterm.R import io.neoterm.backend.EmulatorDebug import io.neoterm.backend.TerminalSession -import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.ui.term.NeoTermActivity import io.neoterm.utils.TerminalUtils import java.util.* diff --git a/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt b/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt index 32415b1..da67157 100644 --- a/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt +++ b/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt @@ -13,7 +13,7 @@ import io.neoterm.backend.TerminalSession import io.neoterm.customize.color.ColorSchemeManager import io.neoterm.preference.NeoTermPath import io.neoterm.customize.font.FontManager -import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.service.ServiceManager import io.neoterm.utils.FileUtils import io.neoterm.utils.MediaUtils diff --git a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt index 5175e58..d3dc3f7 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermActivity.kt @@ -22,14 +22,10 @@ import android.widget.Toast import de.mrapp.android.tabswitcher.* import io.neoterm.R import io.neoterm.backend.TerminalSession -import io.neoterm.customize.color.ColorSchemeManager -import io.neoterm.customize.eks.ExtraKeysManager -import io.neoterm.customize.font.FontManager import io.neoterm.customize.setup.BaseFileInstaller -import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.client.TermSessionCallback import io.neoterm.frontend.client.TermViewClient -import io.neoterm.frontend.service.ServiceManager import io.neoterm.preference.NeoPermission import io.neoterm.preference.NeoPreference import io.neoterm.services.NeoTermService @@ -309,7 +305,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference } private fun floatTabUp(tab: TermTab) { - + Toast.makeText(this, "In Progress", Toast.LENGTH_SHORT).show() } private fun forceAddSystemSession() { diff --git a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt index 17d4171..baa7ab1 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt @@ -16,14 +16,13 @@ import android.widget.Toast import io.neoterm.R import io.neoterm.customize.script.UserScript import io.neoterm.customize.script.UserScriptManager -import io.neoterm.frontend.ShellParameter +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.client.TermSessionCallback import io.neoterm.preference.NeoPreference import io.neoterm.services.NeoTermService import io.neoterm.utils.TerminalUtils import java.io.File import android.content.Intent.ShortcutIconResource -import android.os.Parcelable import io.neoterm.frontend.service.ServiceManager diff --git a/app/src/main/java/io/neoterm/utils/CrashHandler.kt b/app/src/main/java/io/neoterm/utils/CrashHandler.kt index c17ed90..c8648b0 100644 --- a/app/src/main/java/io/neoterm/utils/CrashHandler.kt +++ b/app/src/main/java/io/neoterm/utils/CrashHandler.kt @@ -23,6 +23,6 @@ object CrashHandler : Thread.UncaughtExceptionHandler { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra("exception", e) App.get().startActivity(intent) - Process.killProcess(Process.myPid()) + defaultHandler.uncaughtException(t, e) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt index fc55a7a..6e66b2f 100644 --- a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt +++ b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt @@ -4,8 +4,8 @@ import android.content.Context import io.neoterm.R import io.neoterm.backend.TerminalSession import io.neoterm.customize.font.FontManager -import io.neoterm.frontend.ShellParameter -import io.neoterm.frontend.ShellTermSession +import io.neoterm.frontend.shell.ShellParameter +import io.neoterm.frontend.shell.ShellTermSession import io.neoterm.frontend.service.ServiceManager import io.neoterm.preference.NeoPreference import io.neoterm.view.eks.ExtraKeysView diff --git a/build.gradle b/build.gradle index cc108e3..8486154 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-alpha8' + classpath 'com.android.tools.build:gradle:3.0.0-alpha9' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 91ad85c..f3fd93e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jul 03 20:26:42 CST 2017 +#Thu Aug 03 22:06:45 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip