File: Method.cpp

package info (click to toggle)
bluez-qt 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: cpp: 16,676; xml: 554; ansic: 337; sh: 13; makefile: 8
file content (99 lines) | stat: -rw-r--r-- 2,454 bytes parent folder | download | duplicates (6)
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
/*
 * BluezQt - Asynchronous BlueZ wrapper library
 *
 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

#include <QRegularExpression>

#include "Method.h"

Method::Method()
{
}

bool Method::finalize()
{
    for (const auto &tag : m_stringTags) {
        m_tags.isOptional |= tag.contains(QLatin1String("optional"), Qt::CaseInsensitive);
        m_tags.isDeprecated |= tag.contains(QLatin1String("deprecated"), Qt::CaseInsensitive);
        m_tags.isExperimental |= tag.contains(QLatin1String("experimental"), Qt::CaseInsensitive);
    }

    bool success = true;
    success &= m_comment.finalize();

    for (const auto &inParam : m_inParameterStrings) {
        m_inParameters.push_back(Parameter::fromString(inParam));
    }

    m_outParameterStrings.removeOne(QStringLiteral("void"));
    if (m_outParameterStrings.isEmpty()) {
        m_outParameter = Parameter::fromString(QStringLiteral("void unnamend"));
        return true;
    }

    // Guess out parameter name from method name
    QString paramName = guessOutParameterName();
    if (!paramName.isEmpty()) {
        m_outParameterStrings.front() += QLatin1Char(' ') + paramName;
        m_outParameter = Parameter::fromString(m_outParameterStrings.front());
    } else {
        for (int i = 0; i < m_outParameterStrings.size(); ++i) {
            m_outParameterStrings[i] += QLatin1String(" value") + QString::number(i);
        }
    }

    for (const auto &outParam : m_outParameterStrings) {
        m_outParameters.push_back(Parameter::fromString(outParam));
    }

    return success;
}

QString Method::name() const
{
    return m_name;
}

QList<Parameter> Method::inParameters() const
{
    return m_inParameters;
}

QList<Parameter> Method::outParameters() const
{
    return m_outParameters;
}

Parameter Method::outParameter() const
{
    return m_outParameter;
}

Method::Tags Method::tags() const
{
    return m_tags;
}

QStringList Method::comment() const
{
    return m_comment;
}

QString Method::guessOutParameterName() const
{
    if (m_outParameterStrings.size() != 1) {
        return QString();
    }

    const QRegularExpression rx(QStringLiteral("([A-Z][a-z0-9]+)+"));
    QRegularExpressionMatch match = rx.match(m_name, 1);
    if (!match.hasMatch()) {
        return QStringLiteral("value");
    }

    return match.captured(1).toLower();
}