Allow calling valueOf() on nullable UAST expressions appcode/172.1592
authorDmitry Jemerov <yole@jetbrains.com>
Tue, 18 Apr 2017 12:01:03 +0000 (14:01 +0200)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 18 Apr 2017 12:01:55 +0000 (14:01 +0200)
uast/uast-common/src/org/jetbrains/uast/evaluation/UEvaluationContext.kt

index daad664fcd0f030c671a5251551e78a85f097f4c..9967076d6efe768edcc42a8e94ec0a1346f2db16 100644 (file)
@@ -38,14 +38,15 @@ fun UFile.analyzeAll(context: UastContext = getUastContext(), extensions: List<U
         MapBasedEvaluationContext(context, extensions).analyzeAll(this)
 
 @JvmOverloads
         MapBasedEvaluationContext(context, extensions).analyzeAll(this)
 
 @JvmOverloads
-fun UExpression.uValueOf(extensions: List<UEvaluatorExtension> = emptyList()): UValue? {
+fun UExpression?.uValueOf(extensions: List<UEvaluatorExtension> = emptyList()): UValue? {
+    if (this == null) return null
     val declaration = getContainingDeclaration() ?: return null
     val context = declaration.getEvaluationContextWithCaching(extensions)
     context.analyze(declaration)
     return context.valueOf(this)
 }
 
     val declaration = getContainingDeclaration() ?: return null
     val context = declaration.getEvaluationContextWithCaching(extensions)
     context.analyze(declaration)
     return context.valueOf(this)
 }
 
-fun UExpression.uValueOf(vararg extensions: UEvaluatorExtension): UValue? = uValueOf(extensions.asList())
+fun UExpression?.uValueOf(vararg extensions: UEvaluatorExtension): UValue? = uValueOf(extensions.asList())
 
 fun UDeclaration.getEvaluationContextWithCaching(extensions: List<UEvaluatorExtension> = emptyList()): UEvaluationContext {
     return containingFile?.let { file ->
 
 fun UDeclaration.getEvaluationContextWithCaching(extensions: List<UEvaluatorExtension> = emptyList()): UEvaluationContext {
     return containingFile?.let { file ->