Skip to content

Commit 236a580

Browse files
committed
JSON: Find and highlight usages of the same property key in a file. Hide Schema selector widget.
1 parent 55b47a8 commit 236a580

File tree

20 files changed

+297
-37
lines changed

20 files changed

+297
-37
lines changed

gen/com/gmail/blueboxware/libgdxplugin/filetypes/json/psi/GdxJsonElementVisitor.java

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/com/gmail/blueboxware/libgdxplugin/filetypes/json/psi/GdxJsonProperty.java

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/LibGDXStartupActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.intellij.psi.PsiManager
2424
* See the License for the specific language governing permissions and
2525
* limitations under the License.
2626
*/
27-
class LibGDXStartupActivity: StartupActivity.DumbAware {
27+
class LibGDXStartupActivity: StartupActivity {
2828

2929
override fun runActivity(project: Project) {
3030
PsiManager.getInstance(project).addPsiTreeChangeListener(

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/filetypes/json/GdxJson.bnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
implements("jobject|array|value|property") = "com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonElement"
1616
implements("string") = "com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonLiteral"
1717
implements("property_name") = "com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonString"
18+
implements("property") = "com.intellij.psi.PsiNamedElement"
1819

1920
name("jobject") = 'object'
2021
name("property_name") = 'property name'

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/filetypes/json/GdxJsonElementFactory.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.intellij.openapi.util.text.StringUtil
99
import com.intellij.psi.PsiElement
1010
import com.intellij.psi.PsiFileFactory
1111
import com.intellij.psi.PsiWhiteSpace
12-
import kotlin.text.Typography.quote
1312

1413

1514
/*
@@ -30,11 +29,12 @@ import kotlin.text.Typography.quote
3029
class GdxJsonElementFactory(private val project: Project) {
3130

3231
fun createQuotedValueString(value: String): GdxJsonValue? {
33-
val content = "$quote${StringUtil.escapeStringCharacters(value)}$quote"
32+
val content = "\"${StringUtil.escapeStringCharacters(value)}\""
3433
return createElement(content)
3534
}
3635

37-
fun createQuotedPropertyName(name: String): GdxJsonPropertyName? {
36+
fun createPropertyName(name: String, doQuote: Boolean): GdxJsonPropertyName? {
37+
val quote = if (doQuote) "\"" else ""
3838
val content = "{ $quote${StringUtil.escapeStringCharacters(name)}$quote: bar }"
3939
return createElement(content)
4040
}

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/filetypes/json/GdxJsonParserUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.intellij.psi.TokenType
2525
object GdxJsonParserUtil: GeneratedParserUtilBase() {
2626

2727
@JvmStatic
28-
fun no_comment_or_newline(builder: PsiBuilder, level: Int): Boolean {
28+
fun no_comment_or_newline(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean {
2929
var i = 1
3030

3131
while (builder.rawTokenIndex() - i >= 0) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.gmail.blueboxware.libgdxplugin.filetypes.json.editor
2+
3+
import com.gmail.blueboxware.libgdxplugin.filetypes.json.LibGDXJsonLanuage
4+
import com.intellij.lang.LanguageUtil
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.vfs.VirtualFile
7+
import com.jetbrains.jsonSchema.extension.JsonWidgetSuppressor
8+
9+
10+
/*
11+
* Copyright 2021 Blue Box Ware
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
class GdxJsonSchemaWidgetSuppressor: JsonWidgetSuppressor {
26+
27+
override fun suppressSwitcherWidget(file: VirtualFile, project: Project): Boolean =
28+
LanguageUtil.getLanguageForPsi(project, file) == LibGDXJsonLanuage.INSTANCE
29+
30+
}

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/filetypes/json/intentions/GdxJsonAddQuotesIntention.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GdxJsonAddQuotesIntention: GdxJsonBaseIntention() {
3636

3737
(element.parent as? GdxJsonPropertyName)?.let { propertyName ->
3838
val oldString = propertyName.getValue()
39-
val newString = GdxJsonElementFactory(project).createQuotedPropertyName(oldString) ?: return
39+
val newString = GdxJsonElementFactory(project).createPropertyName(oldString, true) ?: return
4040
propertyName.replace(newString)
4141
return
4242
}

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/filetypes/json/psi/impl/mixins/GdxJsonPropertyMixin.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.impl.mixins
22

3+
import com.gmail.blueboxware.libgdxplugin.filetypes.json.GdxJsonElementFactory
34
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonArray
45
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonJobject
56
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonProperty
67
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonString
78
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.impl.GdxJsonElementImpl
9+
import com.gmail.blueboxware.libgdxplugin.filetypes.json.references.GdxJsonPropertyNameReference
810
import com.intellij.icons.AllIcons
911
import com.intellij.lang.ASTNode
1012
import com.intellij.navigation.ItemPresentation
13+
import com.intellij.psi.PsiElement
14+
import com.intellij.psi.PsiReference
1115
import com.intellij.util.PlatformIcons
1216
import javax.swing.Icon
1317

@@ -31,6 +35,13 @@ abstract class GdxJsonPropertyMixin(node: ASTNode): GdxJsonProperty, GdxJsonElem
3135

3236
override fun getName(): String? = propertyName.getValue()
3337

38+
override fun setName(name: String): PsiElement? =
39+
GdxJsonElementFactory(project).createPropertyName(name, propertyName.isQuoted)?.let {
40+
propertyName.replace(it)
41+
}
42+
43+
override fun getReference(): PsiReference? = GdxJsonPropertyNameReference(this)
44+
3445
override fun getPresentation(): ItemPresentation? = object: ItemPresentation {
3546

3647
override fun getLocationString(): String? = (value?.value as? GdxJsonString)?.getValue()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.gmail.blueboxware.libgdxplugin.filetypes.json.references
2+
3+
import com.gmail.blueboxware.libgdxplugin.filetypes.json.psi.GdxJsonProperty
4+
import com.intellij.lang.findUsages.FindUsagesProvider
5+
import com.intellij.psi.PsiElement
6+
import com.intellij.psi.PsiNamedElement
7+
8+
9+
/*
10+
* Copyright 2021 Blue Box Ware
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
class GdxJsonFindUsagesProvider: FindUsagesProvider {
25+
26+
override fun canFindUsagesFor(psiElement: PsiElement): Boolean =
27+
psiElement is PsiNamedElement
28+
29+
override fun getHelpId(psiElement: PsiElement): String? = null
30+
31+
override fun getType(element: PsiElement): String =
32+
if (element is GdxJsonProperty) {
33+
"property"
34+
} else {
35+
""
36+
}
37+
38+
override fun getDescriptiveName(element: PsiElement): String =
39+
(element as? PsiNamedElement)?.name ?: ""
40+
41+
override fun getNodeText(element: PsiElement, useFullName: Boolean): String =
42+
getDescriptiveName(element)
43+
44+
}

0 commit comments

Comments
 (0)