14
14
import org .ugp .serialx .GenericScope ;
15
15
import org .ugp .serialx .LogProvider ;
16
16
import org .ugp .serialx .Scope ;
17
+ import org .ugp .serialx .Utils ;
17
18
import org .ugp .serialx .Utils .NULL ;
18
19
import org .ugp .serialx .converters .DataConverter ;
20
+ import org .ugp .serialx .converters .DataParser ;
19
21
20
22
/**
21
23
* This converter is capable of converting {@link Map.Entry} and reading variables from {@link Scope} via "$"!
@@ -70,7 +72,7 @@ public Object parse(ParserRegistry myHomeRegistry, String arg, Object... args)
70
72
71
73
if (enrty .length > 1 && !objString .isEmpty ())
72
74
{
73
- obj = NULL . toOopNull ( myHomeRegistry .parse (objString , args ) );
75
+ obj = myHomeRegistry .parse (objString , args );
74
76
}
75
77
76
78
for (int i = 0 ; i < enrty .length -1 ; i ++)
@@ -105,12 +107,38 @@ else if (obj == VOID)
105
107
}
106
108
else if (arg .charAt (0 ) == '$' && !contains (arg , ' ' , '+' , '-' , '*' , '/' , '%' , '>' , '<' , '=' , '&' , '|' , '^' , '?' , '=' ))
107
109
{
110
+ // Object obj;
111
+ // if ((arg = fastReplace(arg, "$", "")).indexOf('.') > -1)
112
+ // {
113
+ // Object[] path = splitValues(fastReplace(fastReplace(arg, "::new", ""), "::class", ""), '.');
114
+ // GenericScope<Object, Object> sc = (GenericScope<Object, Object>) scope.getGenericScope(Arrays.copyOfRange(path, 0, path.length-1)); //TODO: Prevent neccesity of scope parent inheritance.
115
+ // obj = sc == null ? null : sc.variables().get(path[path.length-1]);
116
+ // /*if (sc == null || !sc.containsVariable(tree[tree.length-1]))
117
+ // LogProvider.instance.logErr("Variable \"" + tree[tree.length-1] + "\" was not declared in \"" + arg.substring(0, arg.length() - tree[tree.length-1].length() - 1) + "\"! Defaulting to null!");*/
118
+ // }
119
+ // else
120
+ // {
121
+ // String str = fastReplace(fastReplace(arg, "::new", ""), "::class", "");
122
+ // /*if (!scope.containsVariable(str))
123
+ // LogProvider.instance.logErr("Variable \"" + str + "\" was not declared! Defaulting to null!");*/
124
+ // obj = scope.variables().get(str);
125
+ // }
126
+
108
127
Object obj ;
109
128
if ((arg = fastReplace (arg , "$" , "" )).indexOf ('.' ) > -1 )
110
129
{
111
- Object [] tree = splitValues (fastReplace (fastReplace (arg , "::new" , "" ), "::class" , "" ), '.' );
112
- GenericScope <Object , Object > sc = (GenericScope <Object , Object >) scope .getGenericScope (Arrays .copyOfRange (tree , 0 , tree .length -1 )); //TODO: Prevent neccesity of scope parent inheritance.
113
- obj = sc == null ? null : sc .variables ().get (tree [tree .length -1 ]);
130
+ Object [] path = splitValues (fastReplace (fastReplace (arg , "::new" , "" ), "::class" , "" ), '.' );
131
+ if ((obj = scope .get (path )) == null && !scope .variables ().containsKey (path [0 ]))
132
+ {
133
+ for (GenericScope <Object , Object > parent = scope .getParent (); parent != null ; parent = parent .getParent ())
134
+ if (parent .variables ().containsKey (path [0 ]))
135
+ {
136
+ obj = parent .get (path );
137
+ break ;
138
+ }
139
+ }
140
+
141
+ // GenericScope<Object, Object> sc = (GenericScope<Object, Object>) scope.getGenericScope(Arrays.copyOfRange(path, 0, path.length-1)); //TODO: Prevent neccesity of scope parent inheritance.
114
142
/*if (sc == null || !sc.containsVariable(tree[tree.length-1]))
115
143
LogProvider.instance.logErr("Variable \"" + tree[tree.length-1] + "\" was not declared in \"" + arg.substring(0, arg.length() - tree[tree.length-1].length() - 1) + "\"! Defaulting to null!");*/
116
144
}
@@ -119,9 +147,16 @@ else if (arg.charAt(0) == '$' && !contains(arg, ' ', '+', '-', '*', '/', '%', '>
119
147
String str = fastReplace (fastReplace (arg , "::new" , "" ), "::class" , "" );
120
148
/*if (!scope.containsVariable(str))
121
149
LogProvider.instance.logErr("Variable \"" + str + "\" was not declared! Defaulting to null!");*/
122
- obj = scope .variables ().get (str );
150
+ if ((obj = scope .variables ().getOrDefault (str , VOID )) == VOID )
151
+ {
152
+ for (GenericScope <Object , Object > parent = scope .getParent (); parent != null ; parent = parent .getParent ())
153
+ if ((obj = parent .variables ().getOrDefault (str , VOID )) != VOID )
154
+ break ;
155
+ }
123
156
}
124
157
158
+ if (obj == null || obj == VOID ) // Was not found...
159
+ return null ;
125
160
return arg .endsWith ("::class" ) ? obj .getClass () : arg .endsWith ("::new" ) ? Clone (obj ) : obj ;
126
161
}
127
162
}
0 commit comments