Skip to content

Commit

Permalink
fix: Fix string concatenation in Java and bump dependencies (#558)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
PranavPurwar committed Aug 16, 2024
1 parent 5c6002e commit fcdbe69
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ lint/outputs/
lint/tmp/
# lint/reports/
/.idea/sonarlint/
/.kotlin/
Empty file.
2 changes: 1 addition & 1 deletion build-tools/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ dependencies {
implementation("io.github.Rosemoe.sora-editor:editor:0.23.4-cac2770-SNAPSHOT")
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
implementation("com.google.guava:guava:33.1.0-android")
implementation("com.android.tools:r8:8.3.37")
implementation("com.android.tools:r8:8.5.35")
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class JavaCompileTask(val project: Project) : Task {
val flags = Prefs.javacFlags

val options = listOf(
"-XDstringConcat=inline",
"-proc:none",
"-source",
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.github.rosemoe.sora.widget.CodeEditor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.cosmicide.common.Prefs
import org.cosmicide.project.Project
import java.io.File

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

private val diagnostics = DiagnosticsContainer()
private var analyzer = JavaAnalyzer(editor, project)
private var analyzer = JavaAnalyzer(
editor,
project,
if (Prefs.javacFlags.isNotEmpty()) Prefs.javacFlags.split(" ").toList() else listOf()
)

init {
analyze(editor.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.cosmicide.editor.analyzers

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

class JavaAnalyzer(
val editor: CodeEditor,
val project: Project
val project: Project,
val compilerOptions: List<String> = mutableListOf()
) {
private val args by lazy {
listOf(
"-XDstringConcat=inline",
"-XDcompilePolicy=byfile",
"-XD-Xprefer=source",
"-XDide",
Expand Down Expand Up @@ -62,8 +63,7 @@ class JavaAnalyzer(

init {
standardFileManager.setLocation(
StandardLocation.PLATFORM_CLASS_PATH,
FileUtil.classpathDir.walk().toList()
StandardLocation.PLATFORM_CLASS_PATH, FileUtil.classpathDir.walk().toList()
)
if (!project.binDir.exists()) {
project.binDir.mkdirs()
Expand All @@ -86,6 +86,7 @@ class JavaAnalyzer(
add(version.toString())
add("-target")
add(version.toString())
addAll(compilerOptions)
}

tool.getTask(System.out.writer(), standardFileManager, diagnostics, copy, null, toCompile)
Expand Down Expand Up @@ -121,7 +122,6 @@ class JavaAnalyzer(
if (it.code == "compiler.err.cant.resolve.location") {
val symbol = it.source.getCharContent(true)
.substring(it.startPosition.toInt(), it.endPosition.toInt())
Log.d("JavaAnalyzer", symbol)
CompletionProvider.symbolCacher.filterClassNames(symbol).forEach { name ->
quickFixes.add(Quickfix("Import ${name.value}", 0L) {
val lines = editor.text.lines()
Expand All @@ -130,11 +130,8 @@ class JavaAnalyzer(
firstImportLine =
lines.indexOfFirst { it.startsWith("package ") } + 1
}
Log.d("JavaAnalyzer", "index: $firstImportLine")
editor.text.insert(
firstImportLine,
0,
"import ${name.key}.${name.value};\n"
firstImportLine, 0, "import ${name.key}.${name.value};\n"
)
})
}
Expand Down Expand Up @@ -166,15 +163,11 @@ class JavaAnalyzer(
}


project.binDir
.resolve("classes")
.walk()
.filter { it.extension == "class" }
.forEach {
if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) {
classpath.add(it)
}
project.binDir.resolve("classes").walk().filter { it.extension == "class" }.forEach {
if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) {
classpath.add(it)
}
}

return classpath
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ plugins {

buildscript {
dependencies {
classpath("com.google.gms:google-services:4.4.1")
classpath("com.google.gms:google-services:4.4.2")
}
}
2 changes: 1 addition & 1 deletion datadir/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ android {
dependencies {
implementation(projects.util)
implementation("de.maxr1998:modernandroidpreferences:2.3.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
}
6 changes: 3 additions & 3 deletions feature/TreeView/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.13.0-beta01")
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
implementation("com.google.android.material:material:1.12.0-beta01")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
}
11 changes: 2 additions & 9 deletions feature/TreeView/src/main/res/drawable/outline_folder_24.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,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/>.
-->

<!--
~ This file is part of Cosmic IDE.
~ 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.
~ 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.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorControlNormal"
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" />
android:fillColor="?colorOnSurfaceVariant"
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" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<!--
~ This file is part of Cosmic IDE.
~ 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.
~ 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.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorControlNormal"
android:pathData="M14,2H6c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2H18c1.1,0 2,-0.9 2,-2V8l-6,-6zM6,20V4h7v5h5v11H6z" />
android:fillColor="?colorOnSurfaceVariant"
android:pathData="M14,2H6c-1.1,0 -2,0.9 -2,2L4,20c0,1.1 0.9,2 2,2H18c1.1,0 2,-0.9 2,-2V8l-6,-6zM6,20V4h7v5h5v11H6z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,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/>.
-->

<!--
~ This file is part of Cosmic IDE.
~ 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.
~ 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.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorControlNormal"
android:pathData="M9.29,6.71c-0.39,0.39 -0.39,1.02 0,1.41L13.17,12l-3.88,3.88c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0l4.59,-4.59c0.39,-0.39 0.39,-1.02 0,-1.41L10.7,6.7c-0.38,-0.38 -1.02,-0.38 -1.41,0.01z" />
android:fillColor="?colorOnSurfaceVariant"
android:pathData="M9.3,6.7c-0.4,0.4 -0.4,1 0,1.4L13.2,12l-3.9,3.9c-0.4,0.4 -0.4,1 0,1.4 0.4,0.4 1,0.4 1.4,0l4.6,-4.6c0.4,-0.4 0.4,-1 0,-1.4L10.7,6.7c-0.4,-0.4 -1,-0.4 -1.4,0z" />
</vector>
11 changes: 2 additions & 9 deletions feature/TreeView/src/main/res/drawable/round_expand_more_24.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,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/>.
-->

<!--
~ This file is part of Cosmic IDE.
~ 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.
~ 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.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorControlNormal"
android:pathData="M15.88,9.29L12,13.17 8.12,9.29c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41l4.59,4.59c0.39,0.39 1.02,0.39 1.41,0l4.59,-4.59c0.39,-0.39 0.39,-1.02 0,-1.41 -0.39,-0.38 -1.03,-0.39 -1.42,0z" />
android:fillColor="?colorOnSurfaceVariant"
android:pathData="M15.9,9.3L12,13.2 8.1,9.3c-0.4,-0.4 -1,-0.4 -1.4,0 -0.4,0.4 -0.4,1 0,1.4l4.6,4.6c0.4,0.4 1,0.4 1.4,0l4.6,-4.6c0.4,-0.4 0.4,-1 0,-1.4 -0.4,-0.4 -1,-0.4 -1.4,0z" />
</vector>
4 changes: 2 additions & 2 deletions feature/TreeView/src/main/res/layout/recycler_view_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingVertical="8dp">
android:paddingVertical="12dp">

<ImageView
android:id="@+id/expand"
Expand All @@ -25,7 +25,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAppearance="@style/TextAppearance.Material3.BodyMedium"
android:textAppearance="@style/TextAppearance.Material3.BodyLarge"
tools:text="Main.kt" />

</LinearLayout>
9 changes: 1 addition & 8 deletions feature/TreeView/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<!--
~ This file is part of Cosmic IDE.
~ 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.
~ 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.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<resources>
<string name="file_type">File type</string>
<string name="expand">Expand</string>
</resources>
</resources>
8 changes: 4 additions & 4 deletions feature/appwrite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ dependencies {
implementation("com.squareup.okhttp3:logging-interceptor")
implementation("com.google.code.gson:gson:2.10.1")

implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03")
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
implementation("androidx.fragment:fragment-ktx:1.7.0-beta01")
implementation("androidx.activity:activity-ktx:1.9.0-beta01")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.fragment:fragment-ktx:1.8.2")
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("androidx.browser:browser:1.8.0")
}
2 changes: 1 addition & 1 deletion feature/completion/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
implementation("com.github.Cosmic-Ide.kotlinc-android:kotlinc:2a0a6a7291")
implementation("com.google.auto.value:auto-value-annotations:1.10.4")
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
implementation("androidx.annotation:annotation:1.8.0-alpha02")
implementation("androidx.annotation:annotation:1.8.2")
implementation("com.google.code.gson:gson:2.10.1")
api("com.google.guava:guava:33.1.0-android")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ data class KotlinEnvironment(
setupIdeaStandaloneExecution()
return KotlinEnvironment(
KotlinCoreEnvironment.createForProduction(
parentDisposable = {},
{},
configFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES,
configuration =
CompilerConfiguration().apply {
Expand Down
2 changes: 1 addition & 1 deletion util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ android {
dependencies {
implementation("de.maxr1998:modernandroidpreferences:2.3.2")
implementation(projects.feature.aliuhook)
implementation("androidx.core:core-ktx:1.13.0-beta01")
implementation("androidx.core:core-ktx:1.13.1")
}

0 comments on commit fcdbe69

Please sign in to comment.