Skip to content
This repository was archived by the owner on Jun 14, 2025. It is now read-only.

Commit fcdbe69

Browse files
committed
fix: Fix string concatenation in Java and bump dependencies (#558)
Bumped several dependencies to their latest versions, including: - com.android.tools:r8 to 8. 5.35 - androidx.lifecycle:lifecycle-runtime-ktx to 2.8.4 - androidx.appcompat:appcompat to 1.7.0 - androidx.fragment:fragment-ktx to 1.8.2 - androidx.activity:activity-ktx to 1.9.1 - androidx.core:core-ktx to 1.13.1 - com.google.android.material:material to 1.12.0 - androidx.annotation:annotation to 1.8.2 - com.google.gms:google-services to 4.4.2 Updated JavaAnalyzer to support custom compiler options, allowing users to pass flags like "-XDstringConcat=inline" to the Java compiler. Also, removed unnecessary license headers and cleaned up some code. Signed-off-by: Pranav Purwar <[email protected]>
1 parent 5c6002e commit fcdbe69

File tree

19 files changed

+42
-77
lines changed

19 files changed

+42
-77
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ lint/outputs/
8686
lint/tmp/
8787
# lint/reports/
8888
/.idea/sonarlint/
89+
/.kotlin/

.kotlin/sessions/kotlin-compiler-8214769348286012165.salive

Whitespace-only changes.

build-tools/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ dependencies {
5656
implementation("io.github.Rosemoe.sora-editor:editor:0.23.4-cac2770-SNAPSHOT")
5757
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
5858
implementation("com.google.guava:guava:33.1.0-android")
59-
implementation("com.android.tools:r8:8.3.37")
59+
implementation("com.android.tools:r8:8.5.35")
6060
}

build-tools/src/main/java/org/cosmicide/build/java/JavaCompileTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class JavaCompileTask(val project: Project) : Task {
6868
val flags = Prefs.javacFlags
6969

7070
val options = listOf(
71+
"-XDstringConcat=inline",
7172
"-proc:none",
7273
"-source",
7374
version,

build-tools/src/main/java/org/cosmicide/editor/analyzers/EditorDiagnosticsMarker.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.github.rosemoe.sora.widget.CodeEditor
1616
import kotlinx.coroutines.CoroutineScope
1717
import kotlinx.coroutines.Dispatchers
1818
import kotlinx.coroutines.launch
19+
import org.cosmicide.common.Prefs
1920
import org.cosmicide.project.Project
2021
import java.io.File
2122

@@ -26,7 +27,11 @@ class EditorDiagnosticsMarker(
2627
) : EventReceiver<ContentChangeEvent> {
2728

2829
private val diagnostics = DiagnosticsContainer()
29-
private var analyzer = JavaAnalyzer(editor, project)
30+
private var analyzer = JavaAnalyzer(
31+
editor,
32+
project,
33+
if (Prefs.javacFlags.isNotEmpty()) Prefs.javacFlags.split(" ").toList() else listOf()
34+
)
3035

3136
init {
3237
analyze(editor.text)

build-tools/src/main/java/org/cosmicide/editor/analyzers/JavaAnalyzer.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.cosmicide.editor.analyzers
99

10-
import android.util.Log
1110
import com.sun.tools.javac.api.JavacTool
1211
import com.sun.tools.javac.file.JavacFileManager
1312
import io.github.rosemoe.sora.lang.diagnostic.DiagnosticDetail
@@ -28,10 +27,12 @@ import javax.tools.StandardLocation
2827

2928
class JavaAnalyzer(
3029
val editor: CodeEditor,
31-
val project: Project
30+
val project: Project,
31+
val compilerOptions: List<String> = mutableListOf()
3232
) {
3333
private val args by lazy {
3434
listOf(
35+
"-XDstringConcat=inline",
3536
"-XDcompilePolicy=byfile",
3637
"-XD-Xprefer=source",
3738
"-XDide",
@@ -62,8 +63,7 @@ class JavaAnalyzer(
6263

6364
init {
6465
standardFileManager.setLocation(
65-
StandardLocation.PLATFORM_CLASS_PATH,
66-
FileUtil.classpathDir.walk().toList()
66+
StandardLocation.PLATFORM_CLASS_PATH, FileUtil.classpathDir.walk().toList()
6767
)
6868
if (!project.binDir.exists()) {
6969
project.binDir.mkdirs()
@@ -86,6 +86,7 @@ class JavaAnalyzer(
8686
add(version.toString())
8787
add("-target")
8888
add(version.toString())
89+
addAll(compilerOptions)
8990
}
9091

9192
tool.getTask(System.out.writer(), standardFileManager, diagnostics, copy, null, toCompile)
@@ -121,7 +122,6 @@ class JavaAnalyzer(
121122
if (it.code == "compiler.err.cant.resolve.location") {
122123
val symbol = it.source.getCharContent(true)
123124
.substring(it.startPosition.toInt(), it.endPosition.toInt())
124-
Log.d("JavaAnalyzer", symbol)
125125
CompletionProvider.symbolCacher.filterClassNames(symbol).forEach { name ->
126126
quickFixes.add(Quickfix("Import ${name.value}", 0L) {
127127
val lines = editor.text.lines()
@@ -130,11 +130,8 @@ class JavaAnalyzer(
130130
firstImportLine =
131131
lines.indexOfFirst { it.startsWith("package ") } + 1
132132
}
133-
Log.d("JavaAnalyzer", "index: $firstImportLine")
134133
editor.text.insert(
135-
firstImportLine,
136-
0,
137-
"import ${name.key}.${name.value};\n"
134+
firstImportLine, 0, "import ${name.key}.${name.value};\n"
138135
)
139136
})
140137
}
@@ -166,15 +163,11 @@ class JavaAnalyzer(
166163
}
167164

168165

169-
project.binDir
170-
.resolve("classes")
171-
.walk()
172-
.filter { it.extension == "class" }
173-
.forEach {
174-
if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) {
175-
classpath.add(it)
176-
}
166+
project.binDir.resolve("classes").walk().filter { it.extension == "class" }.forEach {
167+
if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) {
168+
classpath.add(it)
177169
}
170+
}
178171

179172
return classpath
180173
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ plugins {
1616

1717
buildscript {
1818
dependencies {
19-
classpath("com.google.gms:google-services:4.4.1")
19+
classpath("com.google.gms:google-services:4.4.2")
2020
}
2121
}

datadir/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ android {
3333
dependencies {
3434
implementation(projects.util)
3535
implementation("de.maxr1998:modernandroidpreferences:2.3.2")
36-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03")
36+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
3737
}

feature/TreeView/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ android {
4040
}
4141

4242
dependencies {
43-
implementation("androidx.core:core-ktx:1.13.0-beta01")
44-
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
45-
implementation("com.google.android.material:material:1.12.0-beta01")
43+
implementation("androidx.core:core-ktx:1.13.1")
44+
implementation("androidx.appcompat:appcompat:1.7.0")
45+
implementation("com.google.android.material:material:1.12.0")
4646
}

feature/TreeView/src/main/res/drawable/outline_folder_24.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
66
-->
77

8-
<!--
9-
~ This file is part of Cosmic IDE.
10-
~ Cosmic IDE is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11-
~ Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12-
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
13-
-->
14-
158
<vector xmlns:android="http://schemas.android.com/apk/res/android"
169
android:width="24dp"
1710
android:height="24dp"
1811
android:viewportWidth="24"
1912
android:viewportHeight="24">
2013
<path
21-
android:fillColor="?colorControlNormal"
22-
android:pathData="M9.17,6l2,2H20v10H4V6h5.17M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z" />
14+
android:fillColor="?colorOnSurfaceVariant"
15+
android:pathData="M9.2,6l2,2H20v10H4V6h5.2M10,4H4c-1.1,0 -2,0.9 -2,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z" />
2316
</vector>

0 commit comments

Comments
 (0)