5
5
*/
6
6
package io .flutter .editor ;
7
7
8
+ import org .jetbrains .annotations .Nullable ;
9
+
8
10
import java .awt .*;
9
11
10
12
public class ExpressionParsingUtils {
11
- public static Integer parseNumberFromCallParam (String callText , String prefix ) {
12
- if (callText .startsWith (prefix ) && callText .endsWith (")" )) {
13
+ public static @ Nullable Integer parseNumberFromCallParam (String callText , String prefix ) {
14
+ if (prefix == null ) {
15
+ return null ;
16
+ }
17
+ if (callText != null && callText .startsWith (prefix ) && callText .endsWith (")" )) {
13
18
String val = callText .substring (prefix .length (), callText .length () - 1 ).trim ();
14
19
final int index = val .indexOf (',' );
15
20
if (index != -1 ) {
@@ -23,32 +28,40 @@ public static Integer parseNumberFromCallParam(String callText, String prefix) {
23
28
catch (NumberFormatException ignored ) {
24
29
}
25
30
}
26
-
27
31
return null ;
28
32
}
29
33
30
- public static Color parseColor (String text ) {
34
+ public static @ Nullable Color parseColor (String text ) {
35
+ if (text == null ) {
36
+ return null ;
37
+ }
31
38
final Color color = parseColor (text , "const Color(" );
32
39
if (color != null ) return color ;
33
40
34
41
return parseColor (text , "Color(" );
35
42
}
36
43
37
- public static Color parseColor (String text , String colorText ) {
44
+ public static @ Nullable Color parseColor (String text , String colorText ) {
45
+ if (text == null || colorText == null ) {
46
+ return null ;
47
+ }
38
48
final Integer val = parseNumberFromCallParam (text , colorText );
39
49
if (val == null ) return null ;
40
50
41
51
try {
42
52
final int value = val ;
43
53
//noinspection UseJBColor
44
- return new Color ((int )( value >> 16 ) & 0xFF , (int )( value >> 8 ) & 0xFF , ( int ) value & 0xFF , ( int ) (value >> 24 ) & 0xFF );
54
+ return new Color ((value >> 16 ) & 0xFF , (value >> 8 ) & 0xFF , value & 0xFF , (value >> 24 ) & 0xFF );
45
55
}
46
56
catch (IllegalArgumentException e ) {
47
57
return null ;
48
58
}
49
59
}
50
60
51
- public static Color parseColorComponents (String callText , String prefix , boolean isARGB ) {
61
+ public static @ Nullable Color parseColorComponents (String callText , String prefix , boolean isARGB ) {
62
+ if (callText == null || prefix == null ) {
63
+ return null ;
64
+ }
52
65
if (callText .startsWith (prefix ) && callText .endsWith (")" )) {
53
66
final String colorString = callText .substring (prefix .length (), callText .length () - 1 ).trim ();
54
67
final String [] maybeNumbers = colorString .split ("," );
@@ -60,8 +73,8 @@ public static Color parseColorComponents(String callText, String prefix, boolean
60
73
return null ;
61
74
}
62
75
63
- private static Color parseARGBColorComponents (String [] maybeNumbers ) {
64
- if (maybeNumbers .length < 4 ) {
76
+ private static @ Nullable Color parseARGBColorComponents (String [] maybeNumbers ) {
77
+ if (maybeNumbers == null || maybeNumbers .length < 4 ) {
65
78
return null ;
66
79
}
67
80
@@ -90,7 +103,10 @@ private static Color parseARGBColorComponents(String[] maybeNumbers) {
90
103
}
91
104
}
92
105
93
- private static Color parseRGBOColorComponents (String [] maybeNumbers ) {
106
+ private static @ Nullable Color parseRGBOColorComponents (String [] maybeNumbers ) {
107
+ if (maybeNumbers == null ) {
108
+ return null ;
109
+ }
94
110
final float [] rgbo = new float [4 ];
95
111
for (int i = 0 ; i < 4 ; ++i ) {
96
112
final String maybeNumber = maybeNumbers [i ].trim ();
0 commit comments