1
/***************************************************************************
2
* This file is part of KDevelop *
3
* Copyright 2008 Niko Sams <niko.sams@gmail.com> *
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. *
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. *
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
***************************************************************************/
22
#include "includebuilder.h"
24
#include "editorintegrator.h"
25
#include "parsesession.h"
29
using namespace KDevelop;
31
IncludeBuilder::IncludeBuilder(EditorIntegrator* editor)
35
QMap< Php::AstNode*, KDevelop::IndexedString > IncludeBuilder::includes()
40
QMap< Php::AstNode*, QString > IncludeBuilder::badIncludes()
45
void IncludeBuilder::build(const IndexedString &document, AstNode *ast)
47
m_document = document;
51
void IncludeBuilder::visitUnaryExpression(UnaryExpressionAst* node)
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;
67
m_badIncludes[node] = str;