mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
UElementAsPsiInspection also checks casts
This commit is contained in:
+18
@@ -85,6 +85,24 @@ class KtUElementAsPsiInspectionTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
}
|
||||
|
||||
fun testCast() {
|
||||
myFixture.configureByText("UastUsage.kt", """
|
||||
import org.jetbrains.uast.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
|
||||
class UastUsage {
|
||||
|
||||
constructor(uElement: UElement){
|
||||
(<warning descr="Usage of UElement as PsiElement is not recommended">uElement</warning> as? PsiClass).toString();
|
||||
(uElement as? UClass).toString();
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent())
|
||||
myFixture.testHighlighting("UastUsage.kt")
|
||||
|
||||
}
|
||||
|
||||
fun testCallParentMethod() {
|
||||
myFixture.configureByText("UastUsage.kt", """
|
||||
import org.jetbrains.uast.UClass;
|
||||
|
||||
@@ -100,6 +100,13 @@ class UElementAsPsiInspection : DevKitUastInspectionBase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
override fun visitBinaryExpressionWithType(node: UBinaryExpressionWithType): Boolean {
|
||||
if (isUElementType(node.operand.getExpressionType()) && isPsiElementType(node.typeReference?.type)) {
|
||||
node.operand.sourcePsiElement?.let { reportedElements.add(it) }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun visitVariable(node: UVariable): Boolean {
|
||||
if (isUElementType(node.uastInitializer?.getExpressionType()) && isPsiElementType(node.type)) {
|
||||
node.uastInitializer.sourcePsiElement?.let { reportedElements.add(it) }
|
||||
|
||||
@@ -67,6 +67,30 @@ class UElementAsPsiInspectionTest : PluginModuleTestCase() {
|
||||
|
||||
}
|
||||
|
||||
fun testCast() {
|
||||
//language=JAVA
|
||||
myFixture.addClass("""
|
||||
import org.jetbrains.uast.UClass;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import org.jetbrains.uast.UElement;
|
||||
|
||||
class UastUsage {
|
||||
|
||||
public UastUsage(UElement uElement){
|
||||
if(<warning descr="Usage of UElement as PsiElement is not recommended">uElement</warning> instanceof PsiClass){
|
||||
PsiClass psiClass = (PsiClass)<warning descr="Usage of UElement as PsiElement is not recommended">uElement</warning>;
|
||||
}
|
||||
if(uElement instanceof UClass){
|
||||
UClass uClass = (UClass)uElement;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent())
|
||||
myFixture.testHighlighting("UastUsage.java")
|
||||
|
||||
}
|
||||
|
||||
fun testCallParentMethod() {
|
||||
//language=JAVA
|
||||
myFixture.addClass("""
|
||||
|
||||
Reference in New Issue
Block a user