insertionpointlocator.h 3.62 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31 32

#ifndef INSERTIONPOINTLOCATOR_H
#define INSERTIONPOINTLOCATOR_H

33
#include "cpptools_global.h"
34
#include "cpprefactoringchanges.h"
35 36

namespace CppTools {
37

38
class CPPTOOLS_EXPORT InsertionLocation
39 40 41
{
public:
    InsertionLocation();
42 43 44 45 46
    InsertionLocation(const QString &fileName, const QString &prefix,
                      const QString &suffix, unsigned line, unsigned column);

    QString fileName() const
    { return m_fileName; }
47 48 49 50 51

    /// \returns The prefix to insert before any other text.
    QString prefix() const
    { return m_prefix; }

52 53 54 55
    /// \returns The suffix to insert after the other inserted text.
    QString suffix() const
    { return m_suffix; }

56
    /// \returns The line where to insert. The line number is 1-based.
57
    unsigned line() const
58 59 60
    { return m_line; }

    /// \returns The column where to insert. The column number is 1-based.
61
    unsigned column() const
62 63 64
    { return m_column; }

    bool isValid() const
65
    { return !m_fileName.isEmpty() && m_line > 0 && m_column > 0; }
66 67

private:
68
    QString m_fileName;
69
    QString m_prefix;
70
    QString m_suffix;
71 72 73 74
    unsigned m_line;
    unsigned m_column;
};

75
class CPPTOOLS_EXPORT InsertionPointLocator
76 77 78 79 80 81 82 83 84 85 86 87
{
public:
    enum AccessSpec {
        Invalid = -1,
        Signals = 0,

        Public = 1,
        Protected = 2,
        Private = 3,

        SlotBit = 1 << 2,

88
        PublicSlot    = Public    | SlotBit,
89
        ProtectedSlot = Protected | SlotBit,
90
        PrivateSlot   = Private   | SlotBit
91
    };
92
    static QString accessSpecToString(InsertionPointLocator::AccessSpec xsSpec);
93 94

public:
95
    InsertionPointLocator(const CppRefactoringChanges &refactoringChanges);
96

97
    InsertionLocation methodDeclarationInClass(const QString &fileName,
98
                                               const CPlusPlus::Class *clazz,
99 100
                                               AccessSpec xsSpec) const;

101
    QList<InsertionLocation> methodDefinition(CPlusPlus::Symbol *declaration,
102 103
                                              bool useSymbolFinder = true,
                                              const QString &destinationFile = QString()) const;
104

105
private:
106
    CppRefactoringChanges m_refactoringChanges;
107 108
};

109
} // namespace CppTools
110 111

#endif // INSERTIONPOINTLOCATOR_H