generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devin-lang): add DevInCompilerTest and DevInCompiler classes to …
…support DevInFile compilation and testing. #101 These new classes provide a foundation for compiling and testing DevInFile content, ensuring that the language features are correctly interpreted and processed. The DevInCompilerTest class includes a test case for normal string compilation, verifying the correct output. The DevInCompiler class is responsible for compiling a DevInFile, handling different element types within the file and providing a StringBuilder output. This commit lays the groundwork for further development and testing of the DevInFile compiler.
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInCompiler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cc.unitmesh.devti.language.compiler | ||
|
||
import cc.unitmesh.devti.language.psi.DevInFile | ||
import cc.unitmesh.devti.language.psi.DevInTypes | ||
import cc.unitmesh.devti.language.psi.DevInUsed | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.util.elementType | ||
|
||
class DevInCompiler(val project: Project, val file: DevInFile, val editor: Editor) { | ||
private val logger = logger<DevInCompiler>() | ||
private val output: StringBuilder = StringBuilder() | ||
|
||
fun compile(): String { | ||
file.children.forEach { | ||
when (it.elementType) { | ||
DevInTypes.TEXT_SEGMENT -> output.append(it.text) | ||
DevInTypes.NEWLINE -> output.append("\n") | ||
DevInTypes.CODE -> { | ||
output.append(it.text) | ||
} | ||
|
||
DevInTypes.USED -> { | ||
processUsed(it as DevInUsed) | ||
} | ||
|
||
else -> { | ||
output.append(it.text) | ||
logger.warn("Unknown element type: ${it.elementType}") | ||
} | ||
} | ||
} | ||
|
||
return output.toString() | ||
} | ||
|
||
private fun processUsed(used: DevInUsed) { | ||
|
||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
exts/devin-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cc.unitmesh.devti.language.compiler | ||
|
||
import cc.unitmesh.devti.language.psi.DevInFile | ||
import com.intellij.openapi.project.guessProjectDir | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.testFramework.VfsTestUtil | ||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture | ||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase | ||
|
||
class DevInCompilerTest : LightJavaCodeInsightFixtureTestCase() { | ||
fun testNormalString() { | ||
val code = "Normal String /" | ||
val file = myFixture.configureByText("test.devin", code) | ||
|
||
val compile = DevInCompiler(project, file as DevInFile, myFixture.editor).compile() | ||
assertEquals("Normal String /", compile) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters