~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to duchain/includebuilder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-01-17 17:10:22 UTC
  • Revision ID: james.westby@ubuntu.com-20100117171022-q2xlgd9ekewo2ijx
Tags: upstream-1.0.0~beta2
ImportĀ upstreamĀ versionĀ 1.0.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   This file is part of KDevelop                                         *
 
3
 *   Copyright 2008 Niko Sams <niko.sams@gmail.com>                        *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU Library General Public License as       *
 
7
 *   published by the Free Software Foundation; either version 2 of the    *
 
8
 *   License, or (at your option) any later version.                       *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU Library General Public     *
 
16
 *   License along with this program; if not, write to the                 *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 
19
 ***************************************************************************/
 
20
 
 
21
 
 
22
#include "includebuilder.h"
 
23
#include "helper.h"
 
24
#include "editorintegrator.h"
 
25
#include "parsesession.h"
 
26
 
 
27
namespace Php
 
28
{
 
29
using namespace KDevelop;
 
30
 
 
31
IncludeBuilder::IncludeBuilder(EditorIntegrator* editor)
 
32
        : m_editor(editor)
 
33
{}
 
34
 
 
35
QMap< Php::AstNode*, KDevelop::IndexedString > IncludeBuilder::includes()
 
36
{
 
37
    return m_includes;
 
38
}
 
39
 
 
40
QMap< Php::AstNode*, QString > IncludeBuilder::badIncludes()
 
41
{
 
42
    return m_badIncludes;
 
43
}
 
44
 
 
45
void IncludeBuilder::build(const IndexedString &document, AstNode *ast)
 
46
{
 
47
    m_document = document;
 
48
    visitNode(ast);
 
49
}
 
50
 
 
51
void IncludeBuilder::visitUnaryExpression(UnaryExpressionAst* node)
 
52
{
 
53
    DefaultVisitor::visitUnaryExpression(node);
 
54
    if (node->includeExpression) {
 
55
        //find name of the constant (first argument of the function call)
 
56
        CommonScalarAst* scalar = findCommonScalar(node->includeExpression);
 
57
        if (scalar && scalar->string != -1) {
 
58
            QString str = m_editor->parseSession()->symbol(scalar->string);
 
59
            str = str.mid(1, str.length() - 2);
 
60
            if ( str != "." && str != ".." && !str.endsWith('/') ) {
 
61
                IndexedString includeFile = findIncludeFileUrl(str, m_document.toUrl());
 
62
                if (!includeFile.isEmpty()) {
 
63
                    m_includes[node] = includeFile;
 
64
                    return;
 
65
                }
 
66
            }
 
67
            m_badIncludes[node] = str;
 
68
        }
 
69
    }
 
70
}
 
71
 
 
72
}