File: editorintegrator.h

package info (click to toggle)
kdevelop-php 24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,616 kB
  • sloc: cpp: 20,858; php: 15,243; xml: 136; sh: 58; makefile: 10
file content (115 lines) | stat: -rw-r--r-- 2,841 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#ifndef PHPEDITORINTEGRATOR_H
#define PHPEDITORINTEGRATOR_H

#include <language/editor/rangeinrevision.h>

#include "phpduchainexport.h"

#include "kdev-pg-token-stream.h"

namespace Php
{

class ParseSession;
struct AstNode;


/**
 * Provides facilities for easy integration of a text editor component with
 * the information parsed from a source file.
 *
 * Uses a disguised singleton + stateful design.
 *
 * \todo introduce stacks for the state?
 */
class KDEVPHPDUCHAIN_EXPORT EditorIntegrator
{
public:
    EditorIntegrator(ParseSession* session);

    ParseSession* parseSession() const;

    enum Edge {
        FrontEdge,
        BackEdge
    };

    enum RangeEdge {
        InnerEdge,
        OuterEdge
    };

    /**
     * Finds the location and \a file where the given \a token was parsed from.
     *
     * \param token token to locate
     * \param edge set to FrontEdge to return the start position of the token, BackEdge to return the end position.
     *
     * \returns the requested cursor relating to the start or end of the given token.
     */
    KDevelop::CursorInRevision findPosition(const KDevPG::TokenStream::Token& token, Edge edge = BackEdge) const;

    /**
     * Finds the location and \a file where the given \a token was parsed from.
     *
     * \param token token to locate
     * \param edge set to FrontEdge to return the start position of the token, BackEdge to return the end position.
     *
     * \returns the requested cursor relating to the start or end of the given token.
     */
    KDevelop::CursorInRevision findPosition(qint64 token, Edge edge = BackEdge) const;

    /**
     * Create a range encompassing the given AstNode \a node.
     *
     * \overload
     */
    KDevelop::RangeInRevision findRange(AstNode* node, RangeEdge = OuterEdge) const;

    /**
     * Create a range encompassing the given AstNode \a nodes.
     *
     * \overload
     */
    KDevelop::RangeInRevision findRange(AstNode* from, AstNode* to) const;

    /**
     * Create a range encompassing the given AstNode \a token.
     *
     * \overload
     */
    KDevelop::RangeInRevision findRange(const KDevPG::TokenStream::Token& token) const;

    /**
     * Create a range encompassing the given AstNode \a token.
     *
     * \overload
     */
    KDevelop::RangeInRevision findRange(qint64 token) const;

    /**
     * Create a range encompassing the given AstNode \a tokens.
     *
     * \overload
     */
    KDevelop::RangeInRevision findRange(qint64 start_token, qint64 end_token) const;

    /**
     * Retrieve the string represented by a token.
     */
    QString tokenToString(qint64 token) const;

private:
    ParseSession* m_session;
};

}

#endif // PHPEDITORINTEGRATOR_H