* Return a "more useful" declaration that documentation providers can look-up * * @code * QPoint point; * ^-- cursor here * @endcode * * In this case, this method returns a Declaration pointer to the *type* * instead of a pointer to the instance, which is more useful when looking for help * * @return A more appropriate Declaration pointer or the given parameter @p decl */
| 53 | * @return A more appropriate Declaration pointer or the given parameter @p decl |
| 54 | */ |
| 55 | Declaration* usefulDeclaration(Declaration* decl) |
| 56 | { |
| 57 | if (!decl) |
| 58 | return nullptr; |
| 59 | |
| 60 | // First: Attempt to find the declaration of a definition |
| 61 | decl = DUChainUtils::declarationForDefinition(decl); |
| 62 | |
| 63 | // Convenience feature: Retrieve the type declaration of instances, |
| 64 | // it makes no sense to pass the declaration pointer of instances of types |
| 65 | if (decl->kind() == Declaration::Instance) { |
| 66 | AbstractType::Ptr type = TypeUtils::targetTypeKeepAliases(decl->abstractType(), decl->topContext()); |
| 67 | auto* idType = dynamic_cast<IdentifiedType*>(type.data()); |
| 68 | Declaration* idDecl = idType ? idType->declaration(decl->topContext()) : nullptr; |
| 69 | if (idDecl) { |
| 70 | decl = idDecl; |
| 71 | } |
| 72 | } |
| 73 | return decl; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |
no test coverage detected