Adapt changes from main repo:
Detect @NotNull fields Detect @NotNull reference in call chains Enum constants are non-nullable by Andrey Ponomarev
This commit is contained in:
committed by
Pavel V. Talanov
parent
aceeebdcfd
commit
01a1c75588
@@ -13,6 +13,7 @@ import java.util.Collections
|
||||
import com.intellij.psi.CommonClassNames.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType
|
||||
import org.jetbrains.jet.j2k.isAnnotatedAsNotNull
|
||||
|
||||
public open class ExpressionVisitor(converter: Converter): StatementVisitor(converter) {
|
||||
{
|
||||
@@ -219,7 +220,8 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression)
|
||||
val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor
|
||||
val isThis: Boolean = isThisExpression(expression)
|
||||
val isNullable: Boolean = getConverter().typeToType(expression.getType()).nullable
|
||||
val notNull = isResolvedToNotNull(expression)
|
||||
val isNullable: Boolean = getConverter().typeToType(expression.getType(), notNull).nullable
|
||||
val className: String = getClassNameWithConstructor(expression)
|
||||
val referencedName = expression.getReferenceName()!!
|
||||
var identifier: Expression = Identifier(referencedName, isNullable)
|
||||
@@ -262,6 +264,17 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
myResult = CallChainExpression(getConverter().expressionToExpression(qualifier), identifier)
|
||||
}
|
||||
|
||||
private fun isResolvedToNotNull(expression: PsiReference): Boolean {
|
||||
val target = expression.resolve()
|
||||
if (target is PsiEnumConstant) {
|
||||
return true;
|
||||
}
|
||||
if (target is PsiModifierListOwner) {
|
||||
return isAnnotatedAsNotNull(target.getModifierList());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit {
|
||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||
myResult = SuperExpression((if (qualifier != null)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class Foo {
|
||||
void execute() {}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
@NotNull
|
||||
Foo fooNotNull = Foo();
|
||||
Foo fooNullable = null;
|
||||
}
|
||||
|
||||
class Test {
|
||||
public void test(@NotNull Bar barNotNull, Bar barNullable) {
|
||||
barNotNull.fooNotNull.execute();
|
||||
barNotNull.fooNullable.execute();
|
||||
barNullable.fooNotNull.execute();
|
||||
barNullable.fooNullable.execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
open class Foo() {
|
||||
open fun execute() : Unit {
|
||||
}
|
||||
}
|
||||
open class Bar() {
|
||||
var fooNotNull : Foo = Foo()
|
||||
var fooNullable : Foo? = null
|
||||
}
|
||||
open class Test() {
|
||||
public open fun test(barNotNull : Bar, barNullable : Bar?) : Unit {
|
||||
barNotNull.fooNotNull.execute()
|
||||
barNotNull.fooNullable?.execute()
|
||||
barNullable?.fooNotNull?.execute()
|
||||
barNullable?.fooNullable?.execute()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
enum E {
|
||||
FOO;
|
||||
|
||||
void foo() {
|
||||
FOO.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
enum class E {
|
||||
FOO
|
||||
fun foo() : Unit {
|
||||
FOO.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user