-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: kt property needs to be member to be field
- Loading branch information
1 parent
855f106
commit ce68ffe
Showing
8 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
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
82 changes: 82 additions & 0 deletions
82
marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/service/JVMFieldTest.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,82 @@ | ||
/* | ||
* Source++, the continuous feedback platform for developers. | ||
* Copyright (C) 2022-2024 CodeBrig, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package spp.jetbrains.marker.jvm.service | ||
|
||
import com.google.common.base.CaseFormat | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.util.Computable | ||
import com.intellij.psi.PsiClass | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiJavaFile | ||
import com.intellij.psi.PsiNamedElement | ||
import com.intellij.testFramework.TestDataPath | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import kotlinx.coroutines.runBlocking | ||
import org.jetbrains.kotlin.psi.KtClass | ||
import org.jetbrains.kotlin.psi.KtFile | ||
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType | ||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile | ||
import spp.jetbrains.artifact.service.getFields | ||
import spp.jetbrains.marker.SourceMarker | ||
import spp.jetbrains.marker.jvm.JVMLanguageProvider | ||
import spp.jetbrains.marker.source.SourceFileMarker | ||
|
||
@TestDataPath("\$CONTENT_ROOT/testData/field/") | ||
class JVMFieldTest : BasePlatformTestCase() { | ||
|
||
override fun setUp() { | ||
super.setUp() | ||
ApplicationManager.getApplication().runReadAction(Computable { | ||
runBlocking { | ||
SourceMarker.getInstance(myFixture.project).clearAvailableSourceFileMarkers() | ||
} | ||
}) | ||
|
||
JVMLanguageProvider().setup(project) | ||
SourceFileMarker.SUPPORTED_FILE_TYPES.add(PsiJavaFile::class.java) | ||
SourceFileMarker.SUPPORTED_FILE_TYPES.add(KtFile::class.java) | ||
SourceFileMarker.SUPPORTED_FILE_TYPES.add(GroovyFile::class.java) | ||
} | ||
|
||
override fun getTestDataPath(): String { | ||
return "src/test/testData/field/" | ||
} | ||
|
||
fun testSingleField() { | ||
doTest<PsiClass>("java") | ||
doTest<KtClass>("kt") | ||
doTest<PsiClass>("groovy") | ||
} | ||
|
||
fun testFieldAndFunction() { | ||
doTest<PsiClass>("java") | ||
doTest<KtClass>("kt") | ||
doTest<PsiClass>("groovy") | ||
} | ||
|
||
private inline fun <reified T : PsiElement> doTest(extension: String) { | ||
val className = getTestName(false) | ||
val testDir = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_HYPHEN).convert(className) | ||
val psiFile = myFixture.configureByFile("$testDir/$className.$extension") | ||
val clazz = psiFile.findDescendantOfType<T> { true } | ||
assertNotNull(clazz) | ||
|
||
val fields = clazz!!.getFields() | ||
assertEquals(1, fields.size) | ||
assertEquals("foo", (fields[0] as PsiNamedElement).name) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
marker/jvm-marker/src/test/testData/field/field-and-function/FieldAndFunction.groovy
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,9 @@ | ||
class FieldAndFunction { | ||
def foo = 42 | ||
|
||
def add(int x, int y) { | ||
def result = x + y | ||
println "Adding $x and $y gives $result" | ||
return result | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
marker/jvm-marker/src/test/testData/field/field-and-function/FieldAndFunction.java
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,9 @@ | ||
public class FieldAndFunction { | ||
int foo = 42; | ||
|
||
public int add(int x, int y) { | ||
int result = x + y; | ||
System.out.println("Adding " + x + " and " + y + " gives " + result); | ||
return result; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
marker/jvm-marker/src/test/testData/field/field-and-function/FieldAndFunction.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,8 @@ | ||
class FieldAndFunction { | ||
val foo = 42 | ||
fun add(x: Int, y: Int): Int { | ||
val result = x + y | ||
println("Adding $x and $y gives $result") | ||
return result | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
marker/jvm-marker/src/test/testData/field/single-field/SingleField.groovy
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,3 @@ | ||
class SingleField { | ||
public def foo = 42 | ||
} |
3 changes: 3 additions & 0 deletions
3
marker/jvm-marker/src/test/testData/field/single-field/SingleField.java
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,3 @@ | ||
public class SingleField { | ||
public int foo = 42; | ||
} |
3 changes: 3 additions & 0 deletions
3
marker/jvm-marker/src/test/testData/field/single-field/SingleField.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,3 @@ | ||
class SingleField { | ||
val foo = 42 | ||
} |