<s> import sublime <EOL> import sublime_plugin <EOL> import sys <EOL> from imp import reload <EOL> import hashlib <EOL> from . . parser . GrammarParser import GrammarParser <EOL> from . . core import ( <EOL> ActionHistory , <EOL> JavaStructure , <EOL> JSONPanel , <EOL> Logger , <EOL> StatusManager <EOL> ) <EOL> from . . utils import ( <EOL> Constant , <EOL> Downloader <EOL> ) <EOL> class JavatarUtilsCommand ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def on_done ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> Logger ( ) . none ( str ( sublime . encode_value ( obj ) ) ) <EOL> def on_cancel ( self ) : <EOL> """<STR_LIT>""" <EOL> Logger ( ) . none ( "<STR_LIT>" ) <EOL> def run ( self , edit , util_type = "<STR_LIT>" , text = "<STR_LIT>" , region = None , dest = None ) : <EOL> """<STR_LIT>""" <EOL> if util_type == "<STR_LIT>" : <EOL> self . view . insert ( edit , <NUM_LIT:0> , text ) <EOL> elif util_type == "<STR_LIT>" : <EOL> self . view . insert ( edit , self . view . size ( ) , text ) <EOL> elif util_type == "<STR_LIT:replace>" : <EOL> if isinstance ( region , list ) or isinstance ( region , tuple ) : <EOL> region = sublime . Region ( region [ <NUM_LIT:0> ] , region [ <NUM_LIT:1> ] ) <EOL> self . view . replace ( edit , region , text ) <EOL> elif util_type == "<STR_LIT>" : <EOL> self . view . erase ( edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) <EOL> elif util_type == "<STR_LIT>" : <EOL> self . view . set_read_only ( True ) <EOL> elif util_type == "<STR_LIT>" : <EOL> self . view . set_read_only ( False ) <EOL> elif util_type == "<STR_LIT>" and Constant . is_debug ( ) : <EOL> for cl in JavaStructure ( ) . classes_in_file ( self . view . file_name ( ) ) : <EOL> print ( "<STR_LIT>" + cl [ "<STR_LIT:name>" ] ) <EOL> for ctor in JavaStructure ( ) . constructors_in_class ( cl ) : <EOL> params = [ ] <EOL> for param in ctor [ "<STR_LIT>" ] : <EOL> params . append ( param [ "<STR_LIT:type>" ] + "<STR_LIT:U+0020>" + param [ "<STR_LIT:name>" ] ) <EOL> print ( "<STR_LIT>" + ctor [ "<STR_LIT:name>" ] + "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( params ) + "<STR_LIT:)>" ) <EOL> for field in JavaStructure ( ) . fields_in_class ( cl ) : <EOL> print ( "<STR_LIT>" + field [ "<STR_LIT:type>" ] + "<STR_LIT:U+0020>" + field [ "<STR_LIT:name>" ] ) <EOL> for method in JavaStructure ( ) . methods_in_class ( cl ) : <EOL> params = [ ] <EOL> for param in method [ "<STR_LIT>" ] : <EOL> params . append ( param [ "<STR_LIT:type>" ] + "<STR_LIT:U+0020>" + param [ "<STR_LIT:name>" ] ) <EOL> print ( "<STR_LIT>" + method [ "<STR_LIT>" ] + "<STR_LIT:U+0020>" + method [ "<STR_LIT:name>" ] + "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( params ) + "<STR_LIT:)>" ) <EOL> elif util_type == "<STR_LIT>" : <EOL> sublime . active_window ( ) . show_input_panel ( <EOL> "<STR_LIT>" , "<STR_LIT>" , self . remote_hash , None , None <EOL> ) <EOL> elif util_type == "<STR_LIT>" : <EOL> Logger ( ) . none ( <EOL> hashlib . sha256 ( <EOL> self . view . substr ( <EOL> sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) <EOL> ) . encode ( "<STR_LIT:utf-8>" ) <EOL> ) . hexdigest ( ) <EOL> ) <EOL> elif util_type == "<STR_LIT>" : <EOL> jsonObj = sublime . decode_value ( <EOL> self . view . substr ( sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) <EOL> ) <EOL> self . view . replace ( <EOL> edit , <EOL> sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) , <EOL> sublime . encode_value ( jsonObj , True ) <EOL> ) <EOL> elif util_type == "<STR_LIT>" and Constant . is_debug ( ) : <EOL> panel = JSONPanel ( <EOL> window = self . view . window ( ) , <EOL> on_done = self . on_done , <EOL> on_cancel = self . on_cancel <EOL> ) <EOL> view = panel . open ( "<STR_LIT>" ) <EOL> sublime . set_timeout ( <EOL> lambda : view . run_command ( <EOL> "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:text>" : "<STR_LIT>" } <EOL> ) , <EOL> <NUM_LIT:50> <EOL> ) <EOL> elif util_type == "<STR_LIT>" : <EOL> sublime . active_window ( ) . show_input_panel ( <EOL> "<STR_LIT>" , "<STR_LIT>" , self . parse_code , None , None <EOL> ) <EOL> elif util_type == "<STR_LIT>" and Constant . is_debug ( ) : <EOL> ActionHistory ( ) . add_action ( <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ) <EOL> Logger ( ) . info ( "<STR_LIT>" ) <EOL> Constant . reset ( ) <EOL> for mod in tuple ( sys . modules . keys ( ) ) : <EOL> if mod . lower ( ) . startswith ( "<STR_LIT>" ) : <EOL> Logger ( ) . info ( "<STR_LIT>" + mod + "<STR_LIT>" ) <EOL> reload ( sys . modules [ mod ] ) <EOL> from . . Javatar import plugin_loaded <EOL> plugin_loaded ( ) <EOL> def parse_code ( self , selector ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> scope = GrammarParser ( sublime . decode_value ( sublime . load_resource ( <EOL> "<STR_LIT>" <EOL> ) ) ) <EOL> parse_output = scope . parse_grammar ( self . view . substr ( <EOL> sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) <EOL> ) ) <EOL> status_text = "<STR_LIT>" <EOL> if parse_output [ "<STR_LIT:success>" ] : <EOL> if selector == "<STR_LIT>" : <EOL> nodes = scope . find_all ( ) <EOL> elif selector == "<STR_LIT:#>" : <EOL> selections = self . view . sel ( ) <EOL> nodes = scope . find_by_region ( [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> if selections : <EOL> first_sel = selections [ <NUM_LIT:0> ] <EOL> if first_sel . empty ( ) : <EOL> nodes = scope . find_by_region ( <EOL> [ first_sel . begin ( ) , first_sel . end ( ) ] <EOL> ) <EOL> else : <EOL> nodes = scope . find_inside_region ( <EOL> [ first_sel . begin ( ) , first_sel . end ( ) ] <EOL> ) <EOL> else : <EOL> nodes = scope . find_by_selectors ( selector ) <EOL> if selector != "<STR_LIT:#>" : <EOL> status_text = "<STR_LIT>" . format ( len ( nodes ) ) <EOL> for node in nodes : <EOL> if selector == "<STR_LIT:#>" : <EOL> if status_text == "<STR_LIT>" : <EOL> status_text += node [ "<STR_LIT:name>" ] <EOL> else : <EOL> status_text += "<STR_LIT:U+0020>" + node [ "<STR_LIT:name>" ] <EOL> else : <EOL> Logger ( ) . none ( <EOL> "<STR_LIT>" . format_map ( node ) <EOL> ) <EOL> Logger ( ) . none ( <EOL> "<STR_LIT>" . format_map ( node ) <EOL> ) <EOL> Logger ( ) . none ( "<STR_LIT>" . format ( len ( nodes ) ) ) <EOL> if selector != "<STR_LIT:#>" : <EOL> if ( status_text != "<STR_LIT>" and <EOL> str ( parse_output [ "<STR_LIT:end>" ] ) == str ( self . view . size ( ) ) ) : <EOL> status_text += "<STR_LIT>" . format ( <EOL> elapse_time = scope . get_elapse_time ( ) <EOL> ) <EOL> else : <EOL> status_text = "<STR_LIT>" % ( <EOL> parse_output [ "<STR_LIT:end>" ] , <EOL> self . view . size ( ) , <EOL> scope . get_elapse_time ( ) <EOL> ) <EOL> Logger ( ) . none ( <EOL> "<STR_LIT>" % ( parse_output [ "<STR_LIT:end>" ] , self . view . size ( ) ) <EOL> ) <EOL> Logger ( ) . none ( <EOL> "<STR_LIT>" . format ( <EOL> elapse_time = scope . get_elapse_time ( ) <EOL> ) <EOL> ) <EOL> StatusManager ( ) . show_status ( status_text ) <EOL> except Exception as e : <EOL> ActionHistory ( ) . add_action ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> e <EOL> ) <EOL> def remote_hash ( self , url ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> data = Downloader . download ( url ) <EOL> datahash = hashlib . sha256 ( data ) . hexdigest ( ) <EOL> Logger ( ) . none ( "<STR_LIT>" + datahash ) <EOL> except Exception as e : <EOL> ActionHistory ( ) . add_action ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> e <EOL> ) <EOL> def nothing ( self , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def description ( self , util_type = "<STR_LIT>" , text = "<STR_LIT>" , region = None , dest = None ) : <EOL> """<STR_LIT>""" <EOL> return dest <EOL> class JavatarViewCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> group , index = self . window . get_view_index ( self . window . active_view ( ) ) <EOL> if index < <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" % ( group ) ) <EOL> else : <EOL> print ( "<STR_LIT>" % ( index ) ) <EOL> print ( "<STR_LIT>" % ( group ) ) </s>
