<s> from robotide . utils import highlightmatcher , html_escape <EOL> class CellInfo ( object ) : <EOL> def __init__ ( self , cell_content , cell_position , for_loop = False ) : <EOL> self . _cell_content = cell_content <EOL> self . _cell_position = cell_position <EOL> self . for_loop = for_loop <EOL> @ property <EOL> def content_type ( self ) : <EOL> return self . _cell_content . type <EOL> @ property <EOL> def cell_type ( self ) : <EOL> return self . _cell_position . type <EOL> @ property <EOL> def source ( self ) : <EOL> return self . _cell_content . source <EOL> @ property <EOL> def arg_name ( self ) : <EOL> return self . _cell_position . argument_name <EOL> def has_error ( self ) : <EOL> return self . argument_missing ( ) or self . too_many_arguments ( ) <EOL> def argument_missing ( self ) : <EOL> return self . cell_type == CellType . MANDATORY and self . content_type in [ ContentType . EMPTY , ContentType . COMMENTED ] <EOL> def too_many_arguments ( self ) : <EOL> return self . cell_type == CellType . MUST_BE_EMPTY and self . content_type not in [ ContentType . EMPTY , ContentType . COMMENTED ] <EOL> def matches ( self , value ) : <EOL> return highlightmatcher . highlight_matcher ( value , <EOL> self . _cell_content . value ) <EOL> def TipMessage ( cell ) : <EOL> if not cell : <EOL> return '<STR_LIT>' <EOL> tip = _TooltipMessage ( cell ) if not cell . for_loop else _ForLoopTooltipMessage ( cell ) <EOL> return html_escape ( unicode ( tip ) ) <EOL> class _TooltipMessage ( object ) : <EOL> TOO_MANY_ARGUMENTS = "<STR_LIT>" <EOL> KEYWORD_NOT_FOUND = "<STR_LIT>" <EOL> VARIABLE_ASSIGMENT = "<STR_LIT>" <EOL> UNKNOWN_VARIABLE = "<STR_LIT>" <EOL> ARGUMENT = "<STR_LIT>" <EOL> OPTIONAL_ARGUMENT = "<STR_LIT>" <EOL> MISSING_ARGUMENT = "<STR_LIT>" <EOL> KEYWORD = "<STR_LIT>" <EOL> def __init__ ( self , cell ) : <EOL> self . message = self . _get_message ( cell ) <EOL> def _get_message ( self , cell ) : <EOL> message = '<STR_LIT>' if cell . content_type != ContentType . UNKNOWN_VARIABLE else self . UNKNOWN_VARIABLE <EOL> handlers = { <EOL> CellType . ASSIGN : self . _assign , <EOL> CellType . KEYWORD : self . _keyword , <EOL> CellType . MANDATORY : self . _mandatory , <EOL> CellType . OPTIONAL : self . _optional , <EOL> CellType . MUST_BE_EMPTY : self . _must_be_empty , <EOL> CellType . UNKNOWN : self . _unknown , <EOL> } <EOL> return ( handlers [ cell . cell_type ] ( cell ) + message ) . strip ( ) <EOL> def _must_be_empty ( self , cell ) : <EOL> if cell . too_many_arguments ( ) : <EOL> return self . TOO_MANY_ARGUMENTS <EOL> return '<STR_LIT>' <EOL> def _mandatory ( self , cell ) : <EOL> if cell . argument_missing ( ) : <EOL> return self . MISSING_ARGUMENT % cell . arg_name <EOL> return self . ARGUMENT % cell . arg_name <EOL> def _optional ( self , cell ) : <EOL> return self . OPTIONAL_ARGUMENT % cell . arg_name <EOL> def _keyword ( self , cell ) : <EOL> if cell . content_type == ContentType . STRING : <EOL> return self . KEYWORD_NOT_FOUND <EOL> if cell . content_type in ContentType . KEYWORDS : <EOL> return self . KEYWORD % cell . source <EOL> return '<STR_LIT>' <EOL> def _assign ( self , cell ) : <EOL> return self . VARIABLE_ASSIGMENT <EOL> def _unknown ( self , cell ) : <EOL> return '<STR_LIT>' <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . message ) <EOL> def __str__ ( self ) : <EOL> return self . message <EOL> class _ForLoopTooltipMessage ( _TooltipMessage ) : <EOL> TOO_MANY_ARGUMENTS = "<STR_LIT>" <EOL> def _get_message ( self , cell ) : <EOL> if cell . too_many_arguments ( ) : <EOL> return self . TOO_MANY_ARGUMENTS <EOL> return '<STR_LIT>' <EOL> class CellContent ( object ) : <EOL> def __init__ ( self , type , value , source = None ) : <EOL> self . type = type <EOL> self . value = value <EOL> self . source = source <EOL> class CellPosition ( object ) : <EOL> def __init__ ( self , type , argument_name ) : <EOL> self . type = type <EOL> self . argument_name = argument_name <EOL> class ContentType : <EOL> USER_KEYWORD = '<STR_LIT>' <EOL> LIBRARY_KEYWORD = '<STR_LIT>' <EOL> KEYWORDS = ( USER_KEYWORD , LIBRARY_KEYWORD ) <EOL> VARIABLE = '<STR_LIT>' <EOL> UNKNOWN_VARIABLE = '<STR_LIT>' <EOL> COMMENTED = '<STR_LIT>' <EOL> STRING = '<STR_LIT>' <EOL> EMPTY = '<STR_LIT>' <EOL> class CellType : <EOL> ASSIGN = '<STR_LIT>' <EOL> KEYWORD = '<STR_LIT>' <EOL> MANDATORY = '<STR_LIT>' <EOL> OPTIONAL = '<STR_LIT>' <EOL> MUST_BE_EMPTY = '<STR_LIT>' <EOL> UNKNOWN = '<STR_LIT>' </s>
