
    Æe                         d dl mZmZmZmZmZ d dlmZ d dlm	Z	 dddej                  fdZdej                  fdZddZ G d	 d
      Zd Zy)    )evaluate
exceptions	pyobjects
taskhandleworder)	fixsyntax)occurrencesFNc                 :   t        j                  ||      }| j                  |      }t        j                  ||      \  }	}
fd}t        j                  | ||
|||	      }|| j                         }|j                  dt        |            }t        |||      S )aM  Return a list of `Location`

    If `unsure` is `True`, possible matches are returned, too.  You
    can use `Location.unsure` to see which are unsure occurrences.
    `resources` can be a list of `rope.base.resource.File` that
    should be searched for occurrences; if `None` all python files
    in the project are searched.

    c                     S N )
occurrenceunsures    5/usr/lib/python3/dist-packages/rope/contrib/findit.pyis_matchz"find_occurrences.<locals>.is_match   s        )r   in_hierarchyinstancezFinding Occurrencescount)r   get_name_atget_pymoduler   eval_location2r	   create_finderget_python_filescreate_jobsetlen_find_locations)projectresourceoffsetr   	resourcesr   task_handlenamethis_pymoduleprimarypynamer   finderjob_sets      `          r   find_occurrencesr*      s    $ h/D((2M--mVDOGV &&!F ,,.	''(=S^'TG69g66r   c                 8   t        j                  ||      }| j                  |      }t        j                  ||      Rj                         }t        |t        j                        r|j                         dk7  r*t        j                  d      t        j                  d      d }fd}	||	t        j                  d      g}
t        j                  | ||
      }|| j                         }|j!                  dt#        |      	      }t%        |||      S )
zFind the places a given method is overridden.

    Finds the places a method is implemented.  Returns a list of
    `Location`.
    methodzNot a method!zCannot resolve the identifier!c                 &    | j                         syy NF)
is_defined)r   s    r   r/   z(find_implementations.<locals>.is_definedF   s    $$& 'r   c                 f    | j                         j                         j                         k(  ryy r.   )
get_pyname
get_object)r   r'   s    r   not_selfz&find_implementations.<locals>.not_selfJ   s/      "--/63D3D3FF Gr   T)filterszFinding Implementationsr   )r   r   r   r   eval_locationr2   
isinstancer   
PyFunctionget_kindr   BadIdentifierErrorr	   InHierarchyFilterFinderr   r   r   r   )r   r    r!   r"   r#   r$   r%   pyobjectr/   r3   r4   r(   r)   r'   s                @r   find_implementationsr=   -   s    h/D((2M##M6:F$$&8Y%9%9:  "h.//@@++,LMM 8[%B%B64%PQGw?F,,.	''(AY'XG69g66r   c                    t        j                  | |||      }|j                  |      }||j                         \  }}t	        j
                  |      j                  |      }	|r|j                  j                  |      fd}
t        j                  |      }t        j                  | |	|
|g      }|j                  |      D ]  }t        |      c S  yyy)zReturn the definition location of the python name at `offset`

    A `Location` object is returned if the definition location can be
    determined, otherwise ``None`` is returned.
    Nc                 &    | j                   k  ryy r.   )r!   )r   starts    r   check_offsetz%find_definition.<locals>.check_offsetd   s    $$u,  -r   )pymodule)r   	FixSyntax	pyname_atget_definition_locationr   Worderget_word_atlinesget_line_startr	   PyNameFilterr;   r*   Location)r   coder!   r    maxfixesfixerr'   modulelinenor$   rA   pyname_filterr(   r   r@   s                 @r   find_definitionrR   V   s     xBE__V$F779}}T"..v6LL//7E! (44V<M ''m7TUF$55v5F ,

++,  r   c                       e Zd Zd Zd Zy)rK   c                     |j                   | _         |j                         | _        | j                  d   | _        |j	                         | _        |j                  | _        y )Nr   )r    get_word_rangeregionr!   	is_unsurer   rP   )selfr   s     r   __init__zLocation.__init__o   sK    "++ //1kk!n **, ''r   c                    dj                  | j                  j                  | j                  j                  | j                  j
                  | j                  | j                  d   | j                  d   t        t        |                   S )Nz<{}.{} "{}:{} ({}-{})" at {}>r      )
format	__class__
__module____name__r    pathrP   rV   hexid)rX   s    r   __repr__zLocation.__repr__v   sd    .55NN%%NN##MMKKKKNKKN4M
 	
r   N)r_   r^   __qualname__rY   rc   r   r   r   rK   rK   n   s    (	
r   rK   c           	          g }|D ][  }|j                  |j                         |j                  t        t        | j                  |                   |j                          ] |S r   )started_jobr`   extendmaprK   r*   finished_job)r(   r"   r)   resultr    s        r   r   r      sY    F HMM*c(F$;$;H$EFG Mr   )Nr[   )	rope.baser   r   r   r   r   rope.contribr   rope.refactorr	   DEFAULT_TASK_HANDLEr*   r=   rR   rK   r   r   r   r   <module>ro      sS    I I " % ..$7V ..&7R,0
 
(r   