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

« back to all changes in this revision

Viewing changes to completion/context.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-03-14 10:19:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100314101934-d24i8t1niai087ul
Tags: 1.0.0~beta4-1
New upstream release. (Closes: #573811)

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <util/pushvalue.h>
45
45
#include <language/duchain/codemodel.h>
46
46
#include <language/duchain/classdeclaration.h>
 
47
#include <language/codecompletion/codecompletion.h>
47
48
 
48
49
#include "declarations/classmethoddeclaration.h"
49
50
#include "types/structuretype.h"
54
55
#include <project/projectmodel.h>
55
56
#include <language/duchain/types/unsuretype.h>
56
57
#include <language/duchain/parsingenvironment.h>
57
 
 
58
58
#include <language/util/includeitem.h>
 
59
 
59
60
#include "includefileitem.h"
 
61
#include "../duchain/completioncodemodel.h"
 
62
#include "codemodelitem.h"
60
63
 
61
64
#define LOCKDUCHAIN     DUChainReadLocker lock(DUChain::lock())
62
65
 
63
66
#define ifDebug(x)
64
 
#include <language/codecompletion/codecompletion.h>
65
67
 
66
68
using namespace KDevelop;
67
69
 
743
745
 
744
746
    if ( m_memberAccessOperation == FunctionCallAccess ) {
745
747
        Q_ASSERT(lastToken.type() == Parser::Token_LPAREN);
 
748
        openLParen = 1;
746
749
        // check ctor call
747
750
        qint64 pos = lastToken.prependedBy(TokenList() << Parser::Token_STRING << Parser::Token_NEW, true);
748
751
        if ( pos != -1 ) {
755
758
        }
756
759
    }
757
760
 
 
761
    static const QList<int> defaultStopTokens = QList<int>()
 
762
            << Parser::Token_SEMICOLON << Parser::Token_INVALID << Parser::Token_OPEN_TAG
 
763
            << Parser::Token_OPEN_TAG_WITH_ECHO << Parser::Token_LBRACE << Parser::Token_RBRACE
 
764
            << Parser::Token_IF << Parser::Token_WHILE << Parser::Token_FOR << Parser::Token_FOREACH
 
765
            << Parser::Token_SWITCH << Parser::Token_ELSEIF;
 
766
 
 
767
 
758
768
    // find expression start
759
 
    while ( lastToken.typeAt(startPos) != Parser::Token_COMMA &&
760
 
            lastToken.typeAt(startPos) != Parser::Token_SEMICOLON &&
761
 
            lastToken.typeAt(startPos) != Parser::Token_INVALID &&
762
 
            lastToken.typeAt(startPos) != Parser::Token_OPEN_TAG &&
763
 
            lastToken.typeAt(startPos) != Parser::Token_OPEN_TAG_WITH_ECHO &&
764
 
            lastToken.typeAt(startPos) != Parser::Token_LBRACE &&
765
 
            lastToken.typeAt(startPos) != Parser::Token_RBRACE &&
766
 
            lastToken.typeAt(startPos) != Parser::Token_COMMENT &&
767
 
            lastToken.typeAt(startPos) != Parser::Token_DOC_COMMENT )
 
769
    while ( !defaultStopTokens.contains(lastToken.typeAt(startPos)) &&
 
770
            (m_memberAccessOperation == FunctionCallAccess || lastToken.typeAt(startPos) != Parser::Token_COMMA) )
768
771
    {
769
772
        if ( lastToken.typeAt(startPos) == Parser::Token_LPAREN ) {
 
773
            ++openLParen;
 
774
            if ( m_memberAccessOperation != FunctionCallAccess && openLParen > 0 ) {
 
775
                break;
 
776
            }
 
777
        } else if ( lastToken.typeAt(startPos) == Parser::Token_RPAREN ) {
770
778
            --openLParen;
771
 
            if ( openLParen <= 0 ) {
772
 
                break;
773
 
            }
774
 
        } else if ( lastToken.typeAt(startPos) == Parser::Token_RPAREN ) {
775
 
            ++openLParen;
776
779
        }
777
780
        --startPos;
778
781
    }
779
782
 
 
783
    if ( openLParen < 0 ) {
 
784
        ifDebug(kDebug() << "too many closed parenthesis";)
 
785
        m_valid = false;
 
786
        return;
 
787
    }
 
788
 
780
789
    // we actually incorporate the not-wanted token, hence move forward
781
790
    ++startPos;
782
791
 
848
857
 
849
858
        m_expression = m_expression.trimmed();
850
859
 
851
 
        if ( m_memberAccessOperation == FunctionCallAccess ) {
852
 
            // make sure the expression is valid
853
 
            Q_ASSERT(m_expression.endsWith('('));
 
860
        // make sure the expression is valid
 
861
        for ( int i = openLParen; i > 0; --i ) {
854
862
            m_expression.append(')');
855
863
        }
856
864
 
1382
1390
                        )
1383
1391
                    );
1384
1392
        }
1385
 
        uint count = 0;
1386
 
        const CodeModelItem* foundItems = 0;
 
1393
 
1387
1394
        foreach(QSet<IndexedString> urlSets, completionFiles()) {
1388
1395
            foreach(const IndexedString &url, urlSets) {
 
1396
                uint count = 0;
 
1397
                const CodeModelItem* foundItems = 0;
1389
1398
                CodeModel::self().items(url, count, foundItems);
1390
1399
                for (uint i = 0; i < count; ++i) {
1391
 
                    if (foundItems[i].kind == CodeModelItem::Class || foundItems[i].kind == CodeModelItem::Function
1392
 
                            || foundItems[i].kind == CodeModelItem::Variable) {
 
1400
                    CodeModelItem::Kind k = foundItems[i].kind;
 
1401
                    if (((k & CodeModelItem::Function) || (k & CodeModelItem::Variable)) && !(k & CodeModelItem::ClassMember)) {
1393
1402
                        foreach(const ParsingEnvironmentFilePointer &env, DUChain::self()->allEnvironmentFiles(url)) {
1394
1403
                            if (env->language() != IndexedString("Php")) continue;
1395
1404
                            TopDUContext* top = env->topContext();
1421
1430
                }
1422
1431
            }
1423
1432
        }
 
1433
 
 
1434
        foreach(QSet<IndexedString> urlSets, completionFiles()) {
 
1435
            foreach(const IndexedString &url, urlSets) {
 
1436
                uint count = 0;
 
1437
                const CompletionCodeModelItem* foundItems = 0;
 
1438
                CompletionCodeModel::self().items(url, count, foundItems);
 
1439
                for (uint i = 0; i < count; ++i) {
 
1440
                    if (abort) return items;
 
1441
                    if (m_memberAccessOperation == ExceptionChoose) {
 
1442
                        if (!(foundItems[i].kind & CompletionCodeModelItem::Exception)) continue;
 
1443
                    }
 
1444
                    foreach(const ParsingEnvironmentFilePointer &env, DUChain::self()->allEnvironmentFiles(url)) {
 
1445
                        Q_ASSERT(env->language() == IndexedString("Php"));
 
1446
                        items << CompletionTreeItemPointer ( new CodeModelCompletionItem(env, foundItems[i]));
 
1447
                    }
 
1448
                }
 
1449
            }
 
1450
        }
1424
1451
    }
1425
1452
 
1426
1453
    ///Find all recursive function-calls that should be shown as call-tips