Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/usebuilder.cpp
Context not available. | |||||
236 | } | 236 | } | ||
---|---|---|---|---|---|
237 | } | 237 | } | ||
238 | 238 | | |||
239 | void UseBuilder::visitUseStatement(UseStatementAst* node) | 239 | void UseBuilder::visitUseNamespaceOrUseGroupedNamespace(UseNamespaceOrUseGroupedNamespaceAst* node) | ||
240 | { | 240 | { | ||
241 | if ( node->useFunction != -1 ) | 241 | if (node->compoundNamespace) { | ||
242 | { | 242 | QualifiedIdentifier identifier = identifierForNamespace(node->identifier, m_editor, false); | ||
243 | m_useNamespaceType = FunctionDeclarationType; | 243 | buildNamespaceUses( | ||
244 | identifier, | ||||
245 | nullptr, | ||||
246 | node->identifier->namespaceNameSequence, | ||||
247 | NamespaceDeclarationType); | ||||
248 | m_compoundNamespacePrefix = node->identifier; | ||||
249 | visitCompoundNamespace(node->compoundNamespace); | ||||
250 | } else { | ||||
251 | buildNamespaceUses(node->identifier, node->useImportType); | ||||
244 | } | 252 | } | ||
245 | else if ( node->useConst != -1 ) | 253 | } | ||
246 | { | 254 | | ||
247 | m_useNamespaceType = ConstantDeclarationType; | 255 | void UseBuilder::visitInnerUseNamespace(InnerUseNamespaceAst* node) | ||
248 | } | 256 | { | ||
249 | else | 257 | Php::DeclarationType lastType; | ||
250 | { | 258 | if (node->useImportType == ConstantImport) { | ||
251 | m_useNamespaceType = NamespaceDeclarationType; | 259 | lastType = ConstantDeclarationType; | ||
260 | } else if (node->useImportType == FunctionImport) { | ||||
261 | lastType = FunctionDeclarationType; | ||||
262 | } else { | ||||
263 | lastType = NamespaceDeclarationType; | ||||
252 | } | 264 | } | ||
253 | UseBuilderBase::visitUseStatement(node); | 265 | | ||
266 | QualifiedIdentifier identifier = identifierForNamespace( | ||||
267 | m_compoundNamespacePrefix, | ||||
268 | node, | ||||
269 | m_editor, | ||||
270 | node->useImportType == ConstantImport); | ||||
271 | buildNamespaceUses( | ||||
272 | identifier, | ||||
273 | m_compoundNamespacePrefix->namespaceNameSequence, | ||||
274 | node->namespaceNameSequence, | ||||
275 | lastType); | ||||
254 | } | 276 | } | ||
255 | 277 | | |||
256 | void UseBuilder::visitUseNamespace(UseNamespaceAst* node) | 278 | void UseBuilder::buildNamespaceUses(NamespacedIdentifierBeforeGroupedNamespaceAst* node, UseImportType useImportType) | ||
257 | { | 279 | { | ||
258 | buildNamespaceUses(node->identifier, m_useNamespaceType); | 280 | Php::DeclarationType lastType; | ||
281 | if (useImportType == ConstantImport) { | ||||
282 | lastType = ConstantDeclarationType; | ||||
283 | } else if (useImportType == FunctionImport) { | ||||
284 | lastType = FunctionDeclarationType; | ||||
285 | } else { | ||||
286 | lastType = NamespaceDeclarationType; | ||||
287 | } | ||||
288 | | ||||
289 | QualifiedIdentifier identifier = identifierForNamespace(node, m_editor, useImportType == ConstantImport); | ||||
290 | buildNamespaceUses(identifier, nullptr, node->namespaceNameSequence, lastType); | ||||
259 | } | 291 | } | ||
260 | 292 | | |||
261 | void UseBuilder::buildNamespaceUses(NamespacedIdentifierAst* node, DeclarationType lastType) | 293 | void UseBuilder::buildNamespaceUses(NamespacedIdentifierAst* node, DeclarationType lastType) | ||
262 | { | 294 | { | ||
263 | QualifiedIdentifier identifier = identifierForNamespace(node, m_editor, lastType == ConstantDeclarationType); | 295 | QualifiedIdentifier identifier = identifierForNamespace(node, m_editor, lastType == ConstantDeclarationType); | ||
296 | buildNamespaceUses(identifier, nullptr, node->namespaceNameSequence, lastType); | ||||
297 | } | ||||
264 | 298 | | |||
299 | void UseBuilder::buildNamespaceUses( | ||||
300 | KDevelop::QualifiedIdentifier identifier, | ||||
301 | const KDevPG::ListNode<IdentifierAst *>* prefixNamespaceNameSequence, | ||||
302 | const KDevPG::ListNode<IdentifierAst *>* namespaceNameSequence, | ||||
303 | Php::DeclarationType lastType) | ||||
304 | { | ||||
265 | QualifiedIdentifier curId; | 305 | QualifiedIdentifier curId; | ||
266 | 306 | | |||
267 | // check if we need to resolve the namespaced identifier globally or locally | 307 | // check if we need to resolve the namespaced identifier globally or locally | ||
Context not available. | |||||
287 | } | 327 | } | ||
288 | 328 | | |||
289 | curId.setExplicitlyGlobal(identifier.explicitlyGlobal()); | 329 | curId.setExplicitlyGlobal(identifier.explicitlyGlobal()); | ||
290 | Q_ASSERT(identifier.count() == node->namespaceNameSequence->count()); | 330 | int prefixCount = prefixNamespaceNameSequence == nullptr ? 0 : prefixNamespaceNameSequence->count(); | ||
331 | Q_ASSERT(identifier.count() == prefixCount + namespaceNameSequence->count()); | ||||
291 | for ( int i = 0; i < identifier.count() - 1; ++i ) { | 332 | for ( int i = 0; i < identifier.count() - 1; ++i ) { | ||
292 | curId.push(identifier.at(i)); | 333 | curId.push(identifier.at(i)); | ||
293 | AstNode* n = node->namespaceNameSequence->at(i)->element; | 334 | if (i>=prefixCount) { | ||
294 | DeclarationPointer dec = findDeclarationImport(NamespaceDeclarationType, curId); | 335 | AstNode* n = namespaceNameSequence->at(i)->element; | ||
295 | if (!dec || dec->range() != editorFindRange(n, n)) { | 336 | DeclarationPointer dec = findDeclarationImport(NamespaceDeclarationType, curId); | ||
296 | newCheckedUse(n, dec, true); | 337 | if (!dec || dec->range() != editorFindRange(n, n)) { | ||
338 | newCheckedUse(n, dec, true); | ||||
339 | } | ||||
297 | } | 340 | } | ||
298 | } | 341 | } | ||
299 | newCheckedUse(node->namespaceNameSequence->back()->element, | 342 | bool reportNotFound = lastType == ClassDeclarationType | ||
300 | findDeclarationImport(lastType, identifier), | 343 | || lastType == ConstantDeclarationType | ||
301 | lastType == ClassDeclarationType || lastType == ConstantDeclarationType | 344 | || lastType == FunctionDeclarationType | ||
302 | || lastType == FunctionDeclarationType || lastType == NamespaceDeclarationType); | 345 | || lastType == NamespaceDeclarationType; | ||
346 | newCheckedUse(namespaceNameSequence->back()->element, findDeclarationImport(lastType, identifier), reportNotFound); | ||||
303 | } | 347 | } | ||
304 | 348 | | |||
305 | void UseBuilder::openNamespace(NamespaceDeclarationStatementAst* parent, IdentifierAst* node, | 349 | void UseBuilder::openNamespace(NamespaceDeclarationStatementAst* parent, IdentifierAst* node, | ||
Context not available. |