aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/android/javaparser.cpp
blob: a6b6146f1d2df9245f91139f0a21aa6e87c22414 (plain)
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
// Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "javaparser.h"

#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/task.h>

#include <QRegularExpression>

using namespace ProjectExplorer;
using namespace Utils;

namespace Android::Internal {

JavaParser::JavaParser()
{ }

void JavaParser::setProjectFileList(const FilePaths &fileList)
{
    m_fileList = fileList;
}

void JavaParser::setBuildDirectory(const FilePath &buildDirectory)
{
    m_buildDirectory = buildDirectory;
}

void JavaParser::setSourceDirectory(const FilePath &sourceDirectory)
{
    m_sourceDirectory = sourceDirectory;
}

OutputLineParser::Result JavaParser::handleLine(const QString &line, OutputFormat type)
{
    Q_UNUSED(type);
    static const QRegularExpression javaRegExp("^(.*\\[javac\\]\\s)(.*\\.java):(\\d+):(.*)$");

    const QRegularExpressionMatch match = javaRegExp.match(line);
    if (!match.hasMatch())
        return Status::NotHandled;

    bool ok;
    int lineno = match.captured(3).toInt(&ok);
    if (!ok)
        lineno = -1;
    FilePath file = FilePath::fromUserInput(match.captured(2));
    if (file.isChildOf(m_buildDirectory)) {
        FilePath relativePath = file.relativeChildPath(m_buildDirectory);
        file = m_sourceDirectory.resolvePath(relativePath);
    }
    if (file.toFileInfo().isRelative()) {
        for (int i = 0; i < m_fileList.size(); i++)
            if (m_fileList[i].endsWith(file.path())) {
                file = m_fileList[i];
                break;
            }
    }

    CompileTask task(Task::Error,
                     match.captured(4).trimmed(),
                     absoluteFilePath(file),
                     lineno);
    LinkSpecs linkSpecs;
    addLinkSpecForAbsoluteFilePath(linkSpecs, task.file, task.line, task.column, match, 2);
    scheduleTask(task, 1);
    return {Status::Done, linkSpecs};
}

} // Android::Internal