6969import org .python .indexer .types .NModuleType ;
7070import org .scijava .ui .swing .script .autocompletion .CompletionText ;
7171
72- public class JythonScriptParser {
73-
74- /** Controls whether debugging statements print to stdout. */
75- static public boolean DEBUG = false ;
76-
72+ public class JythonScriptParser
73+ {
7774 /**
7875 * Parse valid jython code.
7976 *
@@ -88,7 +85,7 @@ static public Scope parseAST(final String code) {
8885 final mod m = ParserFacade .parse (code , CompileMode .exec , "<none>" , new CompilerFlags ());
8986 return parseNode (m .getChildren (), null , null );
9087 } catch (Throwable t ) {
91- t .printStackTrace ();
88+ if ( JythonAutocompletionProvider . debug >= 2 ) t .printStackTrace ();
9289 return new Scope (null );
9390 }
9491 }
@@ -171,7 +168,7 @@ static public Map<String, DotAutocompletions> parseImportStatement(final Import
171168 }
172169
173170 static private DotAutocompletions maybeStaticToDot (final PythonTree node , final DotAutocompletions da ) {
174- System . out . println ("children count:" + node .getChildCount () + ", children: " + (null != node .getChildren () ? node .getChildren ().stream ().map (c -> c .toString ()).collect (Collectors .toList ()) : "" ));
171+ print ("children count:" + node .getChildCount () + ", children: " + (null != node .getChildren () ? node .getChildren ().stream ().map (c -> c .toString ()).collect (Collectors .toList ()) : "" ));
175172 if (node .getChildCount () > 0 && da instanceof StaticDotAutocompletions ) {
176173 // It's a right expression (a constructor invocation assigned to a variable on the left) so the left is an instance of the class
177174 return new VarDotAutocompletions (da .getClassname ());
@@ -198,7 +195,7 @@ static public Map<String, DotAutocompletions> parseAssignStatement(final Assign
198195 for (int i =0 ; i <right .getChildren ().size (); ++i ) {
199196 final CommonTree ct = left .getChildren ().get (i ).getNode ();
200197 if (null == ct ) {
201- System . out . println ("null for left: '" + left + "'" + " at child node " + i );
198+ print ("null for left: '" + left + "'" + " at child node " + i );
202199 continue ;
203200 }
204201 final String name = ct .toString ();
@@ -400,6 +397,6 @@ static public DotAutocompletions parseRight(final PyObject right, final Scope sc
400397 }
401398
402399 static public final void print (Object s ) {
403- if (DEBUG ) System .out .println (s );
400+ if (JythonAutocompletionProvider . debug >= 2 ) System .out .println (s );
404401 }
405402}
0 commit comments