1414import org .ugp .serialx .GenericScope ;
1515import org .ugp .serialx .LogProvider ;
1616import org .ugp .serialx .Scope ;
17+ import org .ugp .serialx .Utils ;
1718import org .ugp .serialx .Utils .NULL ;
1819import org .ugp .serialx .converters .DataConverter ;
20+ import org .ugp .serialx .converters .DataParser ;
1921
2022/**
2123 * 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)
7072
7173 if (enrty .length > 1 && !objString .isEmpty ())
7274 {
73- obj = NULL . toOopNull ( myHomeRegistry .parse (objString , args ) );
75+ obj = myHomeRegistry .parse (objString , args );
7476 }
7577
7678 for (int i = 0 ; i < enrty .length -1 ; i ++)
@@ -105,12 +107,38 @@ else if (obj == VOID)
105107 }
106108 else if (arg .charAt (0 ) == '$' && !contains (arg , ' ' , '+' , '-' , '*' , '/' , '%' , '>' , '<' , '=' , '&' , '|' , '^' , '?' , '=' ))
107109 {
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+
108127 Object obj ;
109128 if ((arg = fastReplace (arg , "$" , "" )).indexOf ('.' ) > -1 )
110129 {
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.
114142 /*if (sc == null || !sc.containsVariable(tree[tree.length-1]))
115143 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!");*/
116144 }
@@ -119,9 +147,16 @@ else if (arg.charAt(0) == '$' && !contains(arg, ' ', '+', '-', '*', '/', '%', '>
119147 String str = fastReplace (fastReplace (arg , "::new" , "" ), "::class" , "" );
120148 /*if (!scope.containsVariable(str))
121149 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+ }
123156 }
124157
158+ if (obj == null || obj == VOID ) // Was not found...
159+ return null ;
125160 return arg .endsWith ("::class" ) ? obj .getClass () : arg .endsWith ("::new" ) ? Clone (obj ) : obj ;
126161 }
127162 }
0 commit comments