Changeset View
Changeset View
Standalone View
Standalone View
completion/context.cpp
Show First 20 Lines • Show All 498 Lines • ▼ Show 20 Line(s) | 303 | switch ( lastToken.type() ) { | |||
---|---|---|---|---|---|
499 | case Parser::Token_DIV: | 499 | case Parser::Token_DIV: | ||
500 | case Parser::Token_DIV_ASSIGN: | 500 | case Parser::Token_DIV_ASSIGN: | ||
501 | case Parser::Token_DOC_COMMENT: | 501 | case Parser::Token_DOC_COMMENT: | ||
502 | case Parser::Token_DOLLAR_OPEN_CURLY_BRACES: | 502 | case Parser::Token_DOLLAR_OPEN_CURLY_BRACES: | ||
503 | case Parser::Token_DOUBLE_ARROW: | 503 | case Parser::Token_DOUBLE_ARROW: | ||
504 | case Parser::Token_DOUBLE_CAST: | 504 | case Parser::Token_DOUBLE_CAST: | ||
505 | case Parser::Token_DOUBLE_QUOTE: | 505 | case Parser::Token_DOUBLE_QUOTE: | ||
506 | case Parser::Token_ECHO: | 506 | case Parser::Token_ECHO: | ||
507 | case Parser::Token_ELLIPSIS: | ||||
507 | case Parser::Token_ENCAPSED_AND_WHITESPACE: | 508 | case Parser::Token_ENCAPSED_AND_WHITESPACE: | ||
508 | case Parser::Token_EXIT: | 509 | case Parser::Token_EXIT: | ||
509 | case Parser::Token_INC: | 510 | case Parser::Token_INC: | ||
510 | case Parser::Token_INT_CAST: | 511 | case Parser::Token_INT_CAST: | ||
511 | case Parser::Token_IS_EQUAL: | 512 | case Parser::Token_IS_EQUAL: | ||
512 | case Parser::Token_IS_GREATER: | 513 | case Parser::Token_IS_GREATER: | ||
513 | case Parser::Token_IS_GREATER_OR_EQUAL: | 514 | case Parser::Token_IS_GREATER_OR_EQUAL: | ||
514 | case Parser::Token_IS_IDENTICAL: | 515 | case Parser::Token_IS_IDENTICAL: | ||
▲ Show 20 Lines • Show All 440 Lines • ▼ Show 20 Line(s) | 954 | if ( lastToken.prependedBy(TokenList() << Parser::Token_STRING, true) == -1 ) { | |||
955 | ifDebug(qCDebug(COMPLETION) << "No real function call";) | 956 | ifDebug(qCDebug(COMPLETION) << "No real function call";) | ||
956 | return; | 957 | return; | ||
957 | } | 958 | } | ||
958 | 959 | | |||
959 | ifDebug(qCDebug(COMPLETION) << QString("Recursive function-call: creating parent context")); | 960 | ifDebug(qCDebug(COMPLETION) << QString("Recursive function-call: creating parent context")); | ||
960 | m_parentContext = new CodeCompletionContext(m_duContext, m_position, lastToken, m_depth + 1); | 961 | m_parentContext = new CodeCompletionContext(m_duContext, m_position, lastToken, m_depth + 1); | ||
961 | 962 | | |||
962 | if (!m_parentContext->isValid()) { | 963 | if (!m_parentContext->isValid()) { | ||
963 | m_parentContext = 0; | 964 | m_parentContext = nullptr; | ||
964 | m_valid = false; | 965 | m_valid = false; | ||
965 | return; | 966 | return; | ||
966 | } | 967 | } | ||
967 | } | 968 | } | ||
968 | } | 969 | } | ||
969 | 970 | | |||
970 | void CodeCompletionContext::forbidIdentifier(const QString& identifier) | 971 | void CodeCompletionContext::forbidIdentifier(const QString& identifier) | ||
971 | { | 972 | { | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 1049 | if (UnsureType::Ptr unsureType = UnsureType::Ptr::dynamicCast(m_expressionResult.type())) { | |||
1051 | } | 1052 | } | ||
1052 | } else if (ReferenceType::Ptr referencedType = ReferenceType::Ptr::dynamicCast(m_expressionResult.type()) ) { | 1053 | } else if (ReferenceType::Ptr referencedType = ReferenceType::Ptr::dynamicCast(m_expressionResult.type()) ) { | ||
1053 | types << referencedType->baseType(); | 1054 | types << referencedType->baseType(); | ||
1054 | } else { | 1055 | } else { | ||
1055 | types << expressionTarget; | 1056 | types << expressionTarget; | ||
1056 | } | 1057 | } | ||
1057 | foreach (const AbstractType::Ptr &type, types) { | 1058 | foreach (const AbstractType::Ptr &type, types) { | ||
1058 | const IdentifiedType* idType = dynamic_cast<const IdentifiedType*>(type.data()); | 1059 | const IdentifiedType* idType = dynamic_cast<const IdentifiedType*>(type.data()); | ||
1059 | Declaration* declaration = 0; | 1060 | Declaration* declaration = nullptr; | ||
1060 | if (idType) { | 1061 | if (idType) { | ||
1061 | declaration = idType->declaration(m_duContext->topContext()); | 1062 | declaration = idType->declaration(m_duContext->topContext()); | ||
1062 | } | 1063 | } | ||
1063 | DUContext* ctx = 0; | 1064 | DUContext* ctx = nullptr; | ||
1064 | if (declaration) { | 1065 | if (declaration) { | ||
1065 | ctx = declaration->logicalInternalContext(m_duContext->topContext()); | 1066 | ctx = declaration->logicalInternalContext(m_duContext->topContext()); | ||
1066 | } | 1067 | } | ||
1067 | if (ctx) { | 1068 | if (ctx) { | ||
1068 | ret << ctx; | 1069 | ret << ctx; | ||
1069 | } else if (declaration) { | 1070 | } else if (declaration) { | ||
1070 | //Print some debug-output | 1071 | //Print some debug-output | ||
1071 | qCDebug(COMPLETION) << "Could not get internal context from" << declaration->toString(); | 1072 | qCDebug(COMPLETION) << "Could not get internal context from" << declaration->toString(); | ||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Line(s) | 1265 | foreach(DeclarationDepthPair decl, ctx->allDeclarations(ctx->range().end, m_duContext->topContext(), false)) { | |||
1325 | } | 1326 | } | ||
1326 | } | 1327 | } | ||
1327 | } | 1328 | } | ||
1328 | } else { | 1329 | } else { | ||
1329 | qCDebug(COMPLETION) << "invalid owner declaration for overloadable completion"; | 1330 | qCDebug(COMPLETION) << "invalid owner declaration for overloadable completion"; | ||
1330 | } | 1331 | } | ||
1331 | } | 1332 | } | ||
1332 | } else if (m_memberAccessOperation == BackslashAccess || m_memberAccessOperation == NamespaceChoose) { | 1333 | } else if (m_memberAccessOperation == BackslashAccess || m_memberAccessOperation == NamespaceChoose) { | ||
1333 | DUContext* ctx = 0; | 1334 | DUContext* ctx = nullptr; | ||
1334 | if (m_namespace.isEmpty()) { | 1335 | if (m_namespace.isEmpty()) { | ||
1335 | ctx = m_duContext->topContext(); | 1336 | ctx = m_duContext->topContext(); | ||
1336 | } else { | 1337 | } else { | ||
1337 | foreach(Declaration* dec, m_duContext->topContext()->findDeclarations(m_namespace)) { | 1338 | foreach(Declaration* dec, m_duContext->topContext()->findDeclarations(m_namespace)) { | ||
1338 | if (dec->kind() == Declaration::Namespace) { | 1339 | if (dec->kind() == Declaration::Namespace) { | ||
1339 | ctx = dec->internalContext(); | 1340 | ctx = dec->internalContext(); | ||
1340 | break; | 1341 | break; | ||
1341 | } | 1342 | } | ||
Show All 15 Lines | 1353 | items << CompletionTreeItemPointer( | |||
1357 | ); | 1358 | ); | ||
1358 | } | 1359 | } | ||
1359 | } | 1360 | } | ||
1360 | } else if (m_expressionResult.type()) { | 1361 | } else if (m_expressionResult.type()) { | ||
1361 | QList<DUContext*> containers = memberAccessContainers(); | 1362 | QList<DUContext*> containers = memberAccessContainers(); | ||
1362 | qCDebug(COMPLETION) << "containers: " << containers.count(); | 1363 | qCDebug(COMPLETION) << "containers: " << containers.count(); | ||
1363 | if (!containers.isEmpty()) { | 1364 | if (!containers.isEmpty()) { | ||
1364 | // get the parent class when we are inside a method declaration | 1365 | // get the parent class when we are inside a method declaration | ||
1365 | ClassDeclaration* currentClass = 0; | 1366 | ClassDeclaration* currentClass = nullptr; | ||
1366 | if (m_duContext->owner() && m_duContext->owner()->isFunctionDeclaration() && | 1367 | if (m_duContext->owner() && m_duContext->owner()->isFunctionDeclaration() && | ||
1367 | m_duContext->parentContext() && m_duContext->parentContext()->owner()) { | 1368 | m_duContext->parentContext() && m_duContext->parentContext()->owner()) { | ||
1368 | currentClass = dynamic_cast<ClassDeclaration*>(m_duContext->parentContext()->owner()); | 1369 | currentClass = dynamic_cast<ClassDeclaration*>(m_duContext->parentContext()->owner()); | ||
1369 | } | 1370 | } | ||
1370 | 1371 | | |||
1371 | foreach(DUContext* ctx, containers) { | 1372 | foreach(DUContext* ctx, containers) { | ||
1372 | ClassDeclaration* accessedClass = dynamic_cast<ClassDeclaration*>(ctx->owner()); | 1373 | ClassDeclaration* accessedClass = dynamic_cast<ClassDeclaration*>(ctx->owner()); | ||
1373 | if (abort) | 1374 | if (abort) | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 1435 | } else { | |||
1471 | } | 1472 | } | ||
1472 | 1473 | | |||
1473 | foreach(QSet<IndexedString> urlSets, completionFiles()) { | 1474 | foreach(QSet<IndexedString> urlSets, completionFiles()) { | ||
1474 | foreach(const IndexedString &url, urlSets) { | 1475 | foreach(const IndexedString &url, urlSets) { | ||
1475 | if (url == m_duContext->url()) { | 1476 | if (url == m_duContext->url()) { | ||
1476 | continue; | 1477 | continue; | ||
1477 | } | 1478 | } | ||
1478 | uint count = 0; | 1479 | uint count = 0; | ||
1479 | const CodeModelItem* foundItems = 0; | 1480 | const CodeModelItem* foundItems = nullptr; | ||
1480 | CodeModel::self().items(url, count, foundItems); | 1481 | CodeModel::self().items(url, count, foundItems); | ||
1481 | for (uint i = 0; i < count; ++i) { | 1482 | for (uint i = 0; i < count; ++i) { | ||
1482 | CodeModelItem::Kind k = foundItems[i].kind; | 1483 | CodeModelItem::Kind k = foundItems[i].kind; | ||
1483 | if (((k & CodeModelItem::Function) || (k & CodeModelItem::Variable)) && !(k & CodeModelItem::ClassMember)) { | 1484 | if (((k & CodeModelItem::Function) || (k & CodeModelItem::Variable)) && !(k & CodeModelItem::ClassMember)) { | ||
1484 | foreach(const ParsingEnvironmentFilePointer &env, DUChain::self()->allEnvironmentFiles(url)) { | 1485 | foreach(const ParsingEnvironmentFilePointer &env, DUChain::self()->allEnvironmentFiles(url)) { | ||
1485 | if (env->language() != phpLangString) continue; | 1486 | if (env->language() != phpLangString) continue; | ||
1486 | TopDUContext* top = env->topContext(); | 1487 | TopDUContext* top = env->topContext(); | ||
1487 | if(!top) continue; | 1488 | if(!top) continue; | ||
Show All 23 Lines | |||||
1511 | } | 1512 | } | ||
1512 | } | 1513 | } | ||
1513 | } | 1514 | } | ||
1514 | } | 1515 | } | ||
1515 | 1516 | | |||
1516 | foreach(QSet<IndexedString> urlSets, completionFiles()) { | 1517 | foreach(QSet<IndexedString> urlSets, completionFiles()) { | ||
1517 | foreach(const IndexedString &url, urlSets) { | 1518 | foreach(const IndexedString &url, urlSets) { | ||
1518 | uint count = 0; | 1519 | uint count = 0; | ||
1519 | const CompletionCodeModelItem* foundItems = 0; | 1520 | const CompletionCodeModelItem* foundItems = nullptr; | ||
1520 | CompletionCodeModel::self().items(url, count, foundItems); | 1521 | CompletionCodeModel::self().items(url, count, foundItems); | ||
1521 | for (uint i = 0; i < count; ++i) { | 1522 | for (uint i = 0; i < count; ++i) { | ||
1522 | if (abort) return items; | 1523 | if (abort) return items; | ||
1523 | if (m_memberAccessOperation == ExceptionChoose) { | 1524 | if (m_memberAccessOperation == ExceptionChoose) { | ||
1524 | if (!(foundItems[i].kind & CompletionCodeModelItem::Exception)) continue; | 1525 | if (!(foundItems[i].kind & CompletionCodeModelItem::Exception)) continue; | ||
1525 | } | 1526 | } | ||
1526 | auto files = DUChain::self()->allEnvironmentFiles(url); | 1527 | auto files = DUChain::self()->allEnvironmentFiles(url); | ||
1527 | items.reserve(files.size()); | 1528 | items.reserve(files.size()); | ||
Show All 20 Lines | 1548 | Declaration* decl = parentContext->memberAccessContainer().allDeclarationIds().first() | |||
1548 | .getDeclaration(m_duContext->topContext()); | 1549 | .getDeclaration(m_duContext->topContext()); | ||
1549 | 1550 | | |||
1550 | if (!isValidCompletionItem(decl)) { | 1551 | if (!isValidCompletionItem(decl)) { | ||
1551 | continue; | 1552 | continue; | ||
1552 | } | 1553 | } | ||
1553 | if ( !decl->isFunctionDeclaration() ) { | 1554 | if ( !decl->isFunctionDeclaration() ) { | ||
1554 | if ( ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(decl) ) { | 1555 | if ( ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(decl) ) { | ||
1555 | // search for ctor | 1556 | // search for ctor | ||
1556 | decl = 0; | 1557 | decl = nullptr; | ||
1557 | foreach ( Declaration* dec, classDec->internalContext()->findDeclarations(Identifier("__construct")) ) { | 1558 | foreach ( Declaration* dec, classDec->internalContext()->findDeclarations(Identifier("__construct")) ) { | ||
1558 | if ( dec->isFunctionDeclaration() ) { | 1559 | if ( dec->isFunctionDeclaration() ) { | ||
1559 | decl = dec; | 1560 | decl = dec; | ||
1560 | break; | 1561 | break; | ||
1561 | } | 1562 | } | ||
1562 | } | 1563 | } | ||
1563 | if ( !decl ) { | 1564 | if ( !decl ) { | ||
1564 | foreach ( Declaration* dec, classDec->internalContext()->findDeclarations(classDec->identifier()) ) { | 1565 | foreach ( Declaration* dec, classDec->internalContext()->findDeclarations(classDec->identifier()) ) { | ||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |