File: refactorengine.h

package info (click to toggle)
codelite 10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 71,364 kB
  • sloc: cpp: 415,397; ansic: 18,277; php: 9,547; lex: 4,181; yacc: 2,820; python: 2,294; sh: 383; makefile: 51; xml: 13
file content (159 lines) | stat: -rw-r--r-- 5,537 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2009 by Eran Ifrah
// file name            : refactorengine.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef REFACTORENGINE_H
#define REFACTORENGINE_H

#include <wx/event.h>
#include <wx/filename.h>
#include <vector>
#include <list>
#include "entry.h"
#include "cppwordscanner.h"
#include "cpptoken.h"
#include "codelite_exports.h"
#include "refactoring_storage.h"

class clProgressDlg;

//----------------------------------------------------------------------------------

struct RefactorSource {
    wxString name;
    wxString scope;
    bool isClass;

    RefactorSource()
        : name(wxEmptyString)
        , scope(wxEmptyString)
        , isClass(false)
    {
    }

    void Reset()
    {
        name.clear();
        scope.clear();
        isClass = false;
    }
};

//-----------------------------------------------------------------------------------
extern WXDLLIMPEXP_CL const wxEventType wxEVT_REFACTORING_ENGINE_CACHE_INITIALIZING;

class WXDLLIMPEXP_CL RefactoringEngine
{
    std::list<CppToken> m_candidates;
    std::list<CppToken> m_possibleCandidates;
    wxEvtHandler* m_evtHandler;
    RefactoringStorage m_storage;

public:
    static RefactoringEngine* Instance();

protected:
    clProgressDlg* CreateProgressDialog(const wxString& title, int maxValue);
    void DoFindReferences(const wxString& symname,
                          const wxFileName& fn,
                          int line,
                          int pos,
                          const wxFileList_t& files,
                          bool onlyDefiniteMatches);

private:
    RefactoringEngine();
    ~RefactoringEngine();
    bool DoResolveWord(TextStatesPtr states,
                       const wxFileName& fn,
                       int pos,
                       int line,
                       const wxString& word,
                       RefactorSource* rs);

public:
    void InitializeCache(const wxFileList_t& files) { m_storage.InitializeCache(files); }
    bool IsCacheInitialized() const;
    void SetCandidates(const std::list<CppToken>& candidates) { this->m_candidates = candidates; }
    void SetPossibleCandidates(const std::list<CppToken>& possibleCandidates)
    {
        this->m_possibleCandidates = possibleCandidates;
    }
    const std::list<CppToken>& GetCandidates() const { return m_candidates; }
    const std::list<CppToken>& GetPossibleCandidates() const { return m_possibleCandidates; }
    wxString GetExpression(int pos, TextStatesPtr states);

    void Clear();
    /**
     * @brief rename global symbol. Global Symbol can be one of:
     * <li>member
     * <li>global variable
     * <li>class
     * <li>struct
     * <li>union
     * <li>namespace
     * <li>function
     * <li>prototype
     * <li>typedef
     * @param symname the name of the symbol
     * @param fn current file
     * @param line the symbol is loacted in this file
     * @param pos at that position
     * @param files perform the refactoring on these files
     */
    void
    RenameGlobalSymbol(const wxString& symname, const wxFileName& fn, int line, int pos, const wxFileList_t& files);

    /**
     * @param rename local variable
     * @param symname symbol we want to rename
     * @param fn the current file name (full path)
     * @param line the line where our symbol appears
     * @param pos the position of the symbol (this should be pointing to the *start* of the symbol)
     */
    void RenameLocalSymbol(const wxString& symname, const wxFileName& fn, int line, int pos);

    /**
     * @brief find usages of given symbol in a list of files
     * @param symname symbol to search for
     * @param fn active file open which holds the context of the symbol
     * @param line the line where the symbol exists
     * @param pos the position of the symbol (this should be pointing to the *start* of the symbol)
     * @param files list of files to search in
     */
    void FindReferences(const wxString& symname, const wxFileName& fn, int line, int pos, const wxFileList_t& files);

    /**
     * @brief given a location (file:line:pos) use the current location function signature
     * and return the propsed counter-part tag
     */
    TagEntryPtr SyncSignature(const wxFileName& fn,
                              int line,
                              int pos,
                              const wxString& word,
                              const wxString& text,
                              const wxString& expr);
};

#endif // REFACTORENGINE_H