Skip to content

Commit bd542c0

Browse files
committed
Address new deprecations in 2018.3
1 parent 97cf964 commit bd542c0

File tree

12 files changed

+80
-28
lines changed

12 files changed

+80
-28
lines changed

src/main/kotlin/com/demonwav/mcdev/buildsystem/gradle/GradleBuildSystem.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ class GradleBuildSystem : BuildSystem() {
326326
private fun requestCreateForgeRunConfigs(project: Project, rootModule: Module, configurations: Collection<ProjectConfiguration>) {
327327
runWriteTaskLater {
328328
// Basically mark this as a newly created project
329-
val gradleDir = VfsUtil.createDirectoryIfMissing(project.baseDir, ".gradle")
330-
val hello = gradleDir.findOrCreateChildData(this, HELLO)
329+
val basePath = project.basePath ?: return@runWriteTaskLater // If this is null there's not much we can do
330+
val gradleDir = VfsUtil.createDirectoryIfMissing("$basePath/.gradle")
331+
val hello = gradleDir?.findOrCreateChildData(this, HELLO) ?: return@runWriteTaskLater
331332

332333
hello.setBinaryContent((rootModule.name + "\n" + configurations.size).toByteArray(Charsets.UTF_8))
333334
}

src/main/kotlin/com/demonwav/mcdev/i18n/lang/I18nCompletionContributor.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ import com.intellij.psi.PsiElement
3131
import com.intellij.psi.util.PsiUtilCore
3232

3333
class I18nCompletionContributor : CompletionContributor() {
34-
override fun invokeAutoPopup(position: PsiElement, typeChar: Char): Boolean {
35-
if (typeChar == '.') {
36-
return true
37-
}
38-
return super.invokeAutoPopup(position, typeChar)
39-
}
4034

4135
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
4236
if (parameters.completionType != CompletionType.BASIC) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Minecraft Dev for IntelliJ
3+
*
4+
* https://minecraftdev.org
5+
*
6+
* Copyright (c) 2018 minecraft-dev
7+
*
8+
* MIT License
9+
*/
10+
11+
package com.demonwav.mcdev.i18n.lang
12+
13+
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
14+
import com.intellij.openapi.editor.Editor
15+
import com.intellij.openapi.project.Project
16+
import com.intellij.psi.PsiFile
17+
18+
class I18nTypedHandlerDelegate : TypedHandlerDelegate() {
19+
override fun checkAutoPopup(charTyped: Char, project: Project, editor: Editor, file: PsiFile): Result {
20+
if (file.language != I18nLanguage && charTyped == '.') {
21+
return Result.CONTINUE
22+
}
23+
return super.checkAutoPopup(charTyped, project, editor, file)
24+
}
25+
}

src/main/kotlin/com/demonwav/mcdev/platform/forge/gradle/ForgeRunConfigDataService.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsPr
2626
import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService
2727
import com.intellij.openapi.module.ModuleManager
2828
import com.intellij.openapi.project.Project
29+
import com.intellij.openapi.vfs.LocalFileSystem
2930
import com.intellij.openapi.vfs.VfsUtil
3031
import org.jetbrains.plugins.gradle.util.GradleConstants
3132
import java.io.File
@@ -43,7 +44,9 @@ class ForgeRunConfigDataService : AbstractProjectDataService<ProjectData, Projec
4344
return
4445
}
4546

46-
val hello = VfsUtil.findRelativeFile(project.baseDir, ".gradle", GradleBuildSystem.HELLO) ?: return
47+
val basePath = project.basePath ?: return
48+
val baseDir = LocalFileSystem.getInstance().findFileByPath(basePath)
49+
val hello = VfsUtil.findRelativeFile(baseDir, ".gradle", GradleBuildSystem.HELLO) ?: return
4750
if (!hello.exists()) {
4851
return
4952
}
@@ -86,7 +89,7 @@ class ForgeRunConfigDataService : AbstractProjectDataService<ProjectData, Projec
8689
}
8790

8891
runClientConfiguration.workingDirectory = project.basePath + File.separator + "run"
89-
runClientConfiguration.setMainClassName("GradleStart")
92+
runClientConfiguration.mainClassName = "GradleStart"
9093

9194
if (size == 1) {
9295
runClientConfiguration.setModule(mainModule ?: rootModule)
@@ -114,7 +117,7 @@ class ForgeRunConfigDataService : AbstractProjectDataService<ProjectData, Projec
114117
ApplicationConfigurationType.getInstance()
115118
)
116119

117-
runServerConfiguration.setMainClassName("GradleStartServer")
120+
runServerConfiguration.mainClassName = "GradleStartServer"
118121
runServerConfiguration.programParameters = "nogui"
119122
runServerConfiguration.workingDirectory = project.basePath + File.separator + "run"
120123

src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/completion/AtCompletionContributor.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ import com.intellij.util.PlatformIcons
4848

4949
class AtCompletionContributor : CompletionContributor() {
5050

51-
override fun invokeAutoPopup(position: PsiElement, typeChar: Char): Boolean {
52-
if (typeChar == '$') {
53-
return true
54-
}
55-
return super.invokeAutoPopup(position, typeChar)
56-
}
57-
5851
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
5952
if (parameters.completionType != CompletionType.BASIC) {
6053
return
@@ -67,7 +60,11 @@ class AtCompletionContributor : CompletionContributor() {
6760

6861
val parent = position.parent
6962

70-
val text = parent.text.let { it.substring(0, it.length - CompletionUtil.DUMMY_IDENTIFIER.length) }
63+
val parentText = parent.text ?: return
64+
if (parentText.length < CompletionUtil.DUMMY_IDENTIFIER.length) {
65+
return
66+
}
67+
val text = parentText.substring(0, parentText.length - CompletionUtil.DUMMY_IDENTIFIER.length)
7168

7269
when {
7370
AFTER_KEYWORD.accepts(parent) -> handleAtClassName(text, parent, result)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Minecraft Dev for IntelliJ
3+
*
4+
* https://minecraftdev.org
5+
*
6+
* Copyright (c) 2018 minecraft-dev
7+
*
8+
* MIT License
9+
*/
10+
11+
package com.demonwav.mcdev.platform.mcp.at.completion
12+
13+
import com.demonwav.mcdev.platform.mcp.at.AtLanguage
14+
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
15+
import com.intellij.openapi.editor.Editor
16+
import com.intellij.openapi.project.Project
17+
import com.intellij.psi.PsiFile
18+
19+
class AtTypedHandlerDelegate : TypedHandlerDelegate() {
20+
override fun checkAutoPopup(charTyped: Char, project: Project, editor: Editor, file: PsiFile): Result {
21+
if (file.language == AtLanguage && charTyped == '$') {
22+
return Result.CONTINUE
23+
}
24+
return super.checkAutoPopup(charTyped, project, editor, file)
25+
}
26+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
</intentionAction>
133133
<codeFoldingOptionsProvider instance="com.demonwav.mcdev.i18n.I18nCodeFoldingOptionsProvider"/>
134134
<applicationService serviceImplementation="com.demonwav.mcdev.i18n.I18nFoldingSettings"/>
135+
<typedHandler implementation="com.demonwav.mcdev.i18n.lang.I18nTypedHandlerDelegate" />
135136
<completion.contributor language="I18n" implementationClass="com.demonwav.mcdev.i18n.lang.I18nCompletionContributor" />
136137
<completion.confidence language="JAVA" implementationClass="com.demonwav.mcdev.i18n.reference.I18nReferenceCompletionConfidence"
137138
order="before javaSkipAutopopupInStrings"/>
@@ -209,6 +210,7 @@
209210
<lang.syntaxHighlighterFactory language="Access Transformers" implementationClass="com.demonwav.mcdev.platform.mcp.at.AtSyntaxHighlighterFactory"/>
210211
<colorSettingsPage implementation="com.demonwav.mcdev.platform.mcp.at.AtColorSettingsPage" />
211212
<lang.commenter language="Access Transformers" implementationClass="com.demonwav.mcdev.platform.mcp.at.AtCommenter" />
213+
<typedHandler implementation="com.demonwav.mcdev.platform.mcp.at.completion.AtTypedHandlerDelegate" />
212214
<completion.contributor language="Access Transformers" implementationClass="com.demonwav.mcdev.platform.mcp.at.completion.AtCompletionContributor" />
213215
<gotoDeclarationHandler implementation="com.demonwav.mcdev.platform.mcp.at.AtGotoDeclarationHandler" />
214216
<annotator language="Access Transformers" implementationClass="com.demonwav.mcdev.platform.mcp.at.AtAnnotator"/>

src/test/kotlin/com/demonwav/mcdev/framework/ProjectBuilder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ProjectBuilder(fixture: JavaCodeInsightTestFixture) {
4141
private val project
4242
get() = fixture.project
4343
private val root
44-
get() = fixture.project.baseDir
44+
get() = fixture.project.baseDirPath
4545

4646
var intermediatePath = ""
4747

@@ -85,8 +85,8 @@ class ProjectBuilder(fixture: JavaCodeInsightTestFixture) {
8585
runWriteAction {
8686
VfsUtil.markDirtyAndRefresh(false, true, true, root)
8787
// Make sure to always add the module content root
88-
if (fixture.module.rootManager.contentEntries.none { it.file == project.baseDir }) {
89-
ModuleRootModificationUtil.addContentRoot(fixture.module, project.baseDir)
88+
if (fixture.module.rootManager.contentEntries.none { it.file == project.baseDirPath }) {
89+
ModuleRootModificationUtil.addContentRoot(fixture.module, project.baseDirPath)
9090
}
9191

9292
builder()

src/test/kotlin/com/demonwav/mcdev/framework/ProjectBuilderTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ abstract class ProjectBuilderTest : LightCodeInsightFixtureTestCase() {
2020
protected fun buildProject(builder: ProjectBuilder.() -> Unit) = ProjectBuilder(myFixture).build(builder)
2121

2222
fun ProjectBuilder.src(block: ProjectBuilder.() -> Unit) {
23-
val srcFolder = VfsUtil.createDirectoryIfMissing(project.baseDir, "src")
24-
val entry = myFixture.module.rootManager.contentEntries.first { it.file == project.baseDir }
23+
val srcFolder = VfsUtil.createDirectoryIfMissing(project.baseDirPath, "src")
24+
val entry = myFixture.module.rootManager.contentEntries.first { it.file == project.baseDirPath }
2525
if (!entry.sourceFolderFiles.contains(srcFolder)) {
2626
ModuleRootModificationUtil.updateModel(myFixture.module) { model ->
27-
model.contentEntries.first { it.file == project.baseDir }.addSourceFolder(srcFolder, false)
27+
model.contentEntries.first { it.file == project.baseDirPath }.addSourceFolder(srcFolder, false)
2828
}
2929
}
3030

@@ -33,7 +33,7 @@ abstract class ProjectBuilderTest : LightCodeInsightFixtureTestCase() {
3333

3434
override fun tearDown() {
3535
ModuleRootModificationUtil.updateModel(myFixture.module) { model ->
36-
model.removeContentEntry(model.contentEntries.first { it.file == project.baseDir })
36+
model.removeContentEntry(model.contentEntries.first { it.file == project.baseDirPath })
3737
}
3838

3939
super.tearDown()

src/test/kotlin/com/demonwav/mcdev/framework/TestUtil.kt renamed to src/test/kotlin/com/demonwav/mcdev/framework/test-util.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.intellij.openapi.roots.libraries.Library
1717
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
1818
import com.intellij.openapi.util.io.FileUtil
1919
import com.intellij.openapi.vfs.JarFileSystem
20+
import com.intellij.openapi.vfs.LocalFileSystem
2021
import com.intellij.openapi.vfs.StandardFileSystems
2122

2223
val mockJdk by lazy {
@@ -41,5 +42,8 @@ fun createLibrary(project: Project, name: String): Library {
4142
}
4243
}
4344

45+
val Project.baseDirPath
46+
get() = LocalFileSystem.getInstance().findFileByPath(this.basePath!!)!!
47+
4448
fun String.toSnakeCase(postFix: String = "") =
4549
replace(" ", "_") + postFix

0 commit comments

Comments
 (0)