@@ -26,20 +26,21 @@ public static int parseLiteralNumber(@NotNull String val) throws NumberFormatExc
26
26
}
27
27
28
28
@ Nullable
29
- public static PsiElement getNewExprFromType (PsiElement element ) {
29
+ public static PsiElement getNewExprFromType (@ NotNull PsiElement element ) {
30
+ if (element .getNode () == null ) return null ;
30
31
if (element .getNode ().getElementType () != DartTokenTypes .SIMPLE_TYPE ) return null ;
31
32
PsiElement parent = element .getParent ();
32
33
if (parent == null ) return null ;
33
34
parent = parent .getParent ();
34
- if (parent == null ) return null ;
35
+ if (parent == null || parent . getNode () == null ) return null ;
35
36
if (parent .getNode ().getElementType () != DartTokenTypes .NEW_EXPRESSION ) return null ;
36
37
return parent ;
37
38
}
38
39
39
40
@ Nullable
40
41
public static String getValueOfPositionalArgument (@ NotNull DartArguments arguments , int index ) {
41
42
final DartExpression expression = getPositionalArgument (arguments , index );
42
- if (expression == null ) return null ;
43
+ if (expression == null || expression . getNode () == null ) return null ;
43
44
if (expression .getNode ().getElementType () != DartTokenTypes .LITERAL_EXPRESSION ) return null ;
44
45
return expression .getText ();
45
46
}
@@ -56,9 +57,12 @@ public static DartExpression getPositionalArgument(@NotNull DartArguments argume
56
57
public static String getValueOfNamedArgument (@ NotNull DartArguments arguments , @ NotNull String name ) {
57
58
final PsiElement family = getNamedArgumentExpression (arguments , "fontFamily" );
58
59
if (family != null ) {
60
+ assert family .getNode () != null ;
59
61
if (family .getNode ().getElementType () == DartTokenTypes .STRING_LITERAL_EXPRESSION ) {
62
+ assert family .getText () != null ;
60
63
return DartPsiImplUtil .getUnquotedDartStringAndItsRange (family .getText ()).first ;
61
- } else {
64
+ }
65
+ else {
62
66
return "" ; // Empty string indicates arg was found but value could not be determined easily.
63
67
}
64
68
}
@@ -71,10 +75,12 @@ public static PsiElement getNamedArgumentExpression(@NotNull DartArguments argum
71
75
if (list == null ) return null ;
72
76
final List <DartNamedArgument > namedArgumentList = list .getNamedArgumentList ();
73
77
for (DartNamedArgument namedArgument : namedArgumentList ) {
78
+ assert namedArgument != null ;
74
79
final DartExpression nameExpression = namedArgument .getParameterReferenceExpression ();
80
+ assert nameExpression != null ;
75
81
final PsiElement childId = nameExpression .getFirstChild ();
76
82
final PsiElement child = nameExpression .getFirstChild ();
77
- if (name .equals (child .getText ())) {
83
+ if (name .equals (child != null ? child .getText () : "" )) {
78
84
return namedArgument .getExpression ();
79
85
}
80
86
}
@@ -84,12 +90,14 @@ public static PsiElement getNamedArgumentExpression(@NotNull DartArguments argum
84
90
@ Nullable
85
91
public static PsiElement topmostReferenceExpression (@ NotNull PsiElement element ) {
86
92
final PsiElement id = element .getParent ();
87
- if (id == null || id .getNode ().getElementType () != DartTokenTypes .ID ) return null ;
93
+ if (id == null || id .getNode () == null || id . getNode () .getElementType () != DartTokenTypes .ID ) return null ;
88
94
PsiElement refExpr = id .getParent ();
89
- if (refExpr == null || refExpr .getNode ().getElementType () != DartTokenTypes .REFERENCE_EXPRESSION ) return null ;
95
+ if (refExpr == null || refExpr .getNode () == null || refExpr .getNode ().getElementType () != DartTokenTypes .REFERENCE_EXPRESSION ) {
96
+ return null ;
97
+ }
90
98
91
99
PsiElement parent = refExpr .getParent ();
92
- while (parent != null && parent .getNode ().getElementType () == DartTokenTypes .REFERENCE_EXPRESSION ) {
100
+ while (parent != null && parent .getNode () != null && parent . getNode () .getElementType () == DartTokenTypes .REFERENCE_EXPRESSION ) {
93
101
refExpr = parent ;
94
102
parent = parent .getParent ();
95
103
}
0 commit comments