Differential D8512 Diff 21414 kdevplatform/language/duchain/navigation/abstractdeclarationnavigationcontext.cpp
Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/duchain/navigation/abstractdeclarationnavigationcontext.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 82 | { | |||
---|---|---|---|---|---|
83 | DUChainReadLocker lock(DUChain::lock(), 300); | 83 | DUChainReadLocker lock(DUChain::lock(), 300); | ||
84 | if ( !lock.locked() ) { | 84 | if ( !lock.locked() ) { | ||
85 | return {}; | 85 | return {}; | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | clear(); | 88 | clear(); | ||
89 | AbstractNavigationContext::html(shorten); | 89 | AbstractNavigationContext::html(shorten); | ||
90 | 90 | | |||
91 | modifyHtml() += "<html><body><p>" + fontSizePrefix(shorten); | 91 | modifyHtml() += QLatin1String("<html><body><p>") + fontSizePrefix(shorten); | ||
92 | 92 | | |||
93 | addExternalHtml(prefix()); | 93 | addExternalHtml(prefix()); | ||
94 | 94 | | |||
95 | if(!d->m_declaration.data()) { | 95 | if(!d->m_declaration.data()) { | ||
96 | modifyHtml() += i18n("<br /> lost declaration <br />"); | 96 | modifyHtml() += i18n("<br /> lost declaration <br />"); | ||
97 | return currentHtml(); | 97 | return currentHtml(); | ||
98 | } | 98 | } | ||
99 | 99 | | |||
Show All 22 Lines | 114 | } else if( d->m_declaration->isTypeAlias() || d->m_declaration->type<EnumeratorType>() || d->m_declaration->kind() == Declaration::Instance ) { | |||
122 | if(d->m_declaration->isTypeAlias()) { | 122 | if(d->m_declaration->isTypeAlias()) { | ||
123 | //Do not show the own name as type of typedefs | 123 | //Do not show the own name as type of typedefs | ||
124 | if(useType.cast<TypeAliasType>()) | 124 | if(useType.cast<TypeAliasType>()) | ||
125 | useType = useType.cast<TypeAliasType>()->type(); | 125 | useType = useType.cast<TypeAliasType>()->type(); | ||
126 | } | 126 | } | ||
127 | 127 | | |||
128 | eventuallyMakeTypeLinks( useType ); | 128 | eventuallyMakeTypeLinks( useType ); | ||
129 | 129 | | |||
130 | modifyHtml() += ' ' + identifierHighlight(declarationName(d->m_declaration).toHtmlEscaped(), d->m_declaration); | 130 | modifyHtml() += QLatin1Char(' ') + identifierHighlight(declarationName(d->m_declaration).toHtmlEscaped(), d->m_declaration); | ||
131 | 131 | | |||
132 | if(auto integralType = d->m_declaration->type<ConstantIntegralType>()) { | 132 | if(auto integralType = d->m_declaration->type<ConstantIntegralType>()) { | ||
133 | const QString plainValue = integralType->valueAsString(); | 133 | const QString plainValue = integralType->valueAsString(); | ||
134 | if (!plainValue.isEmpty()) { | 134 | if (!plainValue.isEmpty()) { | ||
135 | modifyHtml() += QStringLiteral(" = ") + plainValue; | 135 | modifyHtml() += QStringLiteral(" = ") + plainValue; | ||
136 | } | 136 | } | ||
137 | } | 137 | } | ||
138 | 138 | | |||
Show All 36 Lines | 169 | for(uint a = 0; a < count; ++a) { | |||
175 | if ((static_cast<bool>(decFile) != static_cast<bool>(forwardDecFile)) || | 175 | if ((static_cast<bool>(decFile) != static_cast<bool>(forwardDecFile)) || | ||
176 | (decFile && forwardDecFile && decFile->language() != forwardDecFile->language())) | 176 | (decFile && forwardDecFile && decFile->language() != forwardDecFile->language())) | ||
177 | { | 177 | { | ||
178 | // the language of the declarations must match | 178 | // the language of the declarations must match | ||
179 | continue; | 179 | continue; | ||
180 | } | 180 | } | ||
181 | modifyHtml() += QStringLiteral("<br />"); | 181 | modifyHtml() += QStringLiteral("<br />"); | ||
182 | makeLink(i18n("possible resolution from"), DeclarationPointer(dec), NavigationAction::NavigateDeclaration); | 182 | makeLink(i18n("possible resolution from"), DeclarationPointer(dec), NavigationAction::NavigateDeclaration); | ||
183 | modifyHtml() += ' ' + dec->url().str(); | 183 | modifyHtml() += QLatin1Char(' ') + dec->url().str(); | ||
184 | } | 184 | } | ||
185 | } | 185 | } | ||
186 | } | 186 | } | ||
187 | modifyHtml() += QStringLiteral("<br />"); | 187 | modifyHtml() += QStringLiteral("<br />"); | ||
188 | } | 188 | } | ||
189 | }else{ | 189 | }else{ | ||
190 | AbstractType::Ptr showType = d->m_declaration->abstractType(); | 190 | AbstractType::Ptr showType = d->m_declaration->abstractType(); | ||
191 | if(showType && showType.cast<FunctionType>()) { | 191 | if(showType && showType.cast<FunctionType>()) { | ||
Show All 35 Lines | |||||
227 | } | 227 | } | ||
228 | 228 | | |||
229 | if( shorten && !d->m_declaration->comment().isEmpty() ) { | 229 | if( shorten && !d->m_declaration->comment().isEmpty() ) { | ||
230 | QString comment = QString::fromUtf8(d->m_declaration->comment()); | 230 | QString comment = QString::fromUtf8(d->m_declaration->comment()); | ||
231 | if( comment.length() > 60 ) { | 231 | if( comment.length() > 60 ) { | ||
232 | comment.truncate(60); | 232 | comment.truncate(60); | ||
233 | comment += QLatin1String("..."); | 233 | comment += QLatin1String("..."); | ||
234 | } | 234 | } | ||
235 | comment.replace('\n', QLatin1String(" ")); | 235 | comment.replace(QLatin1Char('\n'), QLatin1Char(' ')); | ||
236 | comment.replace(QLatin1String("<br />"), QLatin1String(" ")); | 236 | comment.replace(QLatin1String("<br />"), QLatin1String(" ")); | ||
237 | comment.replace(QLatin1String("<br/>"), QLatin1String(" ")); | 237 | comment.replace(QLatin1String("<br/>"), QLatin1String(" ")); | ||
238 | modifyHtml() += commentHighlight(comment.toHtmlEscaped()) + " "; | 238 | modifyHtml() += commentHighlight(comment.toHtmlEscaped()) + QLatin1String(" "); | ||
239 | } | 239 | } | ||
240 | 240 | | |||
241 | 241 | | |||
242 | QString access = stringFromAccess(d->m_declaration); | 242 | QString access = stringFromAccess(d->m_declaration); | ||
243 | if( !access.isEmpty() ) | 243 | if( !access.isEmpty() ) | ||
244 | modifyHtml() += labelHighlight(i18n("Access: %1 ", propertyHighlight(access.toHtmlEscaped()))); | 244 | modifyHtml() += labelHighlight(i18n("Access: %1 ", propertyHighlight(access.toHtmlEscaped()))); | ||
245 | 245 | | |||
246 | 246 | | |||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
306 | if( !shorten && (!declarationComment.isEmpty() || doc) ) { | 306 | if( !shorten && (!declarationComment.isEmpty() || doc) ) { | ||
307 | modifyHtml() += QStringLiteral("<p>"); | 307 | modifyHtml() += QStringLiteral("<p>"); | ||
308 | 308 | | |||
309 | if(doc) { | 309 | if(doc) { | ||
310 | QString comment = doc->description(); | 310 | QString comment = doc->description(); | ||
311 | connect(doc.data(), &IDocumentation::descriptionChanged, this, &AbstractDeclarationNavigationContext::contentsChanged); | 311 | connect(doc.data(), &IDocumentation::descriptionChanged, this, &AbstractDeclarationNavigationContext::contentsChanged); | ||
312 | 312 | | |||
313 | if(!comment.isEmpty()) { | 313 | if(!comment.isEmpty()) { | ||
314 | modifyHtml() += "<p>" + commentHighlight(comment) + "</p>"; | 314 | modifyHtml() += QLatin1String("<p>") + commentHighlight(comment) + QLatin1String("</p>"); | ||
315 | } | 315 | } | ||
316 | } | 316 | } | ||
317 | 317 | | |||
318 | QString comment = QString::fromUtf8(declarationComment); | 318 | QString comment = QString::fromUtf8(declarationComment); | ||
319 | if(!comment.isEmpty()) { | 319 | if(!comment.isEmpty()) { | ||
320 | // if the first paragraph does not contain a tag, we assume that this is a plain-text comment | 320 | // if the first paragraph does not contain a tag, we assume that this is a plain-text comment | ||
321 | if (!Qt::mightBeRichText(comment)) { | 321 | if (!Qt::mightBeRichText(comment)) { | ||
322 | // still might contain extra html tags for line breaks (this is the case for doxygen-style comments sometimes) | 322 | // still might contain extra html tags for line breaks (this is the case for doxygen-style comments sometimes) | ||
323 | // let's protect them from being removed completely | 323 | // let's protect them from being removed completely | ||
324 | comment.replace(QRegExp("<br */>"), QStringLiteral("\n")); | 324 | comment.replace(QRegExp(QStringLiteral("<br */>")), QStringLiteral("\n")); | ||
325 | comment = comment.toHtmlEscaped(); | 325 | comment = comment.toHtmlEscaped(); | ||
326 | comment.replace('\n', QLatin1String("<br />")); //Replicate newlines in html | 326 | comment.replace(QLatin1Char('\n'), QLatin1String("<br />")); //Replicate newlines in html | ||
327 | } | 327 | } | ||
328 | modifyHtml() += commentHighlight(comment); | 328 | modifyHtml() += commentHighlight(comment); | ||
329 | modifyHtml() += QStringLiteral("</p>"); | 329 | modifyHtml() += QStringLiteral("</p>"); | ||
330 | } | 330 | } | ||
331 | } | 331 | } | ||
332 | 332 | | |||
333 | if(!shorten && doc) { | 333 | if(!shorten && doc) { | ||
334 | modifyHtml() += "<p>" + i18n("Show documentation for "); | 334 | modifyHtml() += QLatin1String("<p>") + i18n("Show documentation for "); | ||
335 | makeLink(prettyQualifiedName(d->m_declaration), | 335 | makeLink(prettyQualifiedName(d->m_declaration), | ||
336 | d->m_declaration, NavigationAction::ShowDocumentation); | 336 | d->m_declaration, NavigationAction::ShowDocumentation); | ||
337 | modifyHtml() += QStringLiteral("</p>"); | 337 | modifyHtml() += QStringLiteral("</p>"); | ||
338 | } | 338 | } | ||
339 | 339 | | |||
340 | 340 | | |||
341 | //modifyHtml() += "<br />"; | 341 | //modifyHtml() += "<br />"; | ||
342 | 342 | | |||
343 | addExternalHtml(suffix()); | 343 | addExternalHtml(suffix()); | ||
344 | 344 | | |||
345 | modifyHtml() += fontSizeSuffix(shorten) + "</p></body></html>"; | 345 | modifyHtml() += fontSizeSuffix(shorten) + QLatin1String("</p></body></html>"); | ||
346 | 346 | | |||
347 | return currentHtml(); | 347 | return currentHtml(); | ||
348 | } | 348 | } | ||
349 | 349 | | |||
350 | AbstractType::Ptr AbstractDeclarationNavigationContext::typeToShow(AbstractType::Ptr type) { | 350 | AbstractType::Ptr AbstractDeclarationNavigationContext::typeToShow(AbstractType::Ptr type) { | ||
351 | return type; | 351 | return type; | ||
352 | } | 352 | } | ||
353 | 353 | | |||
Show All 9 Lines | 361 | if( !type ) { | |||
363 | return; | 363 | return; | ||
364 | } | 364 | } | ||
365 | 365 | | |||
366 | if( !classFunDecl || (!classFunDecl->isConstructor() && !classFunDecl->isDestructor()) ) { | 366 | if( !classFunDecl || (!classFunDecl->isConstructor() && !classFunDecl->isDestructor()) ) { | ||
367 | // only print return type for global functions and non-ctor/dtor methods | 367 | // only print return type for global functions and non-ctor/dtor methods | ||
368 | eventuallyMakeTypeLinks( type->returnType() ); | 368 | eventuallyMakeTypeLinks( type->returnType() ); | ||
369 | } | 369 | } | ||
370 | 370 | | |||
371 | modifyHtml() += ' ' + identifierHighlight(prettyIdentifier(d->m_declaration).toString().toHtmlEscaped(), d->m_declaration); | 371 | modifyHtml() += QLatin1Char(' ') + identifierHighlight(prettyIdentifier(d->m_declaration).toString().toHtmlEscaped(), d->m_declaration); | ||
372 | 372 | | |||
373 | if( type->indexedArgumentsSize() == 0 ) | 373 | if( type->indexedArgumentsSize() == 0 ) | ||
374 | { | 374 | { | ||
375 | modifyHtml() += QStringLiteral("()"); | 375 | modifyHtml() += QStringLiteral("()"); | ||
376 | } else { | 376 | } else { | ||
377 | modifyHtml() += QStringLiteral("( "); | 377 | modifyHtml() += QStringLiteral("( "); | ||
378 | 378 | | |||
379 | bool first = true; | 379 | bool first = true; | ||
380 | int firstDefaultParam = type->indexedArgumentsSize() - function->defaultParametersSize(); | 380 | int firstDefaultParam = type->indexedArgumentsSize() - function->defaultParametersSize(); | ||
381 | int currentArgNum = 0; | 381 | int currentArgNum = 0; | ||
382 | 382 | | |||
383 | QVector<Declaration*> decls; | 383 | QVector<Declaration*> decls; | ||
384 | if (DUContext* argumentContext = DUChainUtils::getArgumentContext(d->m_declaration.data())) { | 384 | if (DUContext* argumentContext = DUChainUtils::getArgumentContext(d->m_declaration.data())) { | ||
385 | decls = argumentContext->localDeclarations(topContext().data()); | 385 | decls = argumentContext->localDeclarations(topContext().data()); | ||
386 | } | 386 | } | ||
387 | foreach(const AbstractType::Ptr& argType, type->arguments()) { | 387 | foreach(const AbstractType::Ptr& argType, type->arguments()) { | ||
388 | if( !first ) | 388 | if( !first ) | ||
389 | modifyHtml() += QStringLiteral(", "); | 389 | modifyHtml() += QStringLiteral(", "); | ||
390 | first = false; | 390 | first = false; | ||
391 | 391 | | |||
392 | eventuallyMakeTypeLinks( argType ); | 392 | eventuallyMakeTypeLinks( argType ); | ||
393 | if (currentArgNum < decls.size()) { | 393 | if (currentArgNum < decls.size()) { | ||
394 | modifyHtml() += ' ' + identifierHighlight(decls[currentArgNum]->identifier().toString().toHtmlEscaped(), d->m_declaration); | 394 | modifyHtml() += QLatin1Char(' ') + identifierHighlight(decls[currentArgNum]->identifier().toString().toHtmlEscaped(), d->m_declaration); | ||
395 | } | 395 | } | ||
396 | 396 | | |||
397 | if (currentArgNum >= firstDefaultParam) { | 397 | if (currentArgNum >= firstDefaultParam) { | ||
398 | IndexedString defaultStr = function->defaultParameters()[currentArgNum - firstDefaultParam]; | 398 | IndexedString defaultStr = function->defaultParameters()[currentArgNum - firstDefaultParam]; | ||
399 | if (!defaultStr.isEmpty()) { | 399 | if (!defaultStr.isEmpty()) { | ||
400 | modifyHtml() += " = " + defaultStr.str().toHtmlEscaped(); | 400 | modifyHtml() += QLatin1String(" = ") + defaultStr.str().toHtmlEscaped(); | ||
401 | } | 401 | } | ||
402 | } | 402 | } | ||
403 | 403 | | |||
404 | ++currentArgNum; | 404 | ++currentArgNum; | ||
405 | } | 405 | } | ||
406 | 406 | | |||
407 | modifyHtml() += QStringLiteral(" )"); | 407 | modifyHtml() += QStringLiteral(" )"); | ||
408 | } | 408 | } | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 568 | case ClassDeclarationData::Trait: | |||
570 | break; | 570 | break; | ||
571 | default: | 571 | default: | ||
572 | modifyHtml() += QStringLiteral("<unknown type> "); | 572 | modifyHtml() += QStringLiteral("<unknown type> "); | ||
573 | break; | 573 | break; | ||
574 | } | 574 | } | ||
575 | eventuallyMakeTypeLinks( klass.cast<AbstractType>() ); | 575 | eventuallyMakeTypeLinks( klass.cast<AbstractType>() ); | ||
576 | 576 | | |||
577 | FOREACH_FUNCTION( const BaseClassInstance& base, classDecl->baseClasses ) { | 577 | FOREACH_FUNCTION( const BaseClassInstance& base, classDecl->baseClasses ) { | ||
578 | modifyHtml() += ", " + stringFromAccess(base.access) + " " + (base.virtualInheritance ? QStringLiteral("virtual") : QString()) + " "; | 578 | modifyHtml() += QLatin1String(", ") + stringFromAccess(base.access) + QLatin1Char(' ') + (base.virtualInheritance ? QStringLiteral("virtual") : QString()) + QLatin1Char(' '); | ||
579 | eventuallyMakeTypeLinks(base.baseClass.abstractType()); | 579 | eventuallyMakeTypeLinks(base.baseClass.abstractType()); | ||
580 | } | 580 | } | ||
581 | } else { | 581 | } else { | ||
582 | /// @todo How can we get here? and should this really be a class? | 582 | /// @todo How can we get here? and should this really be a class? | ||
583 | modifyHtml() += QStringLiteral("class "); | 583 | modifyHtml() += QStringLiteral("class "); | ||
584 | eventuallyMakeTypeLinks( klass.cast<AbstractType>() ); | 584 | eventuallyMakeTypeLinks( klass.cast<AbstractType>() ); | ||
585 | } | 585 | } | ||
586 | modifyHtml() += QStringLiteral(" "); | 586 | modifyHtml() += QStringLiteral(" "); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 639 | if( idType && idType->declaration(topContext().data()) ) { | |||
646 | 646 | | |||
647 | //We need to exchange the target type, else template-parameters may confuse this | 647 | //We need to exchange the target type, else template-parameters may confuse this | ||
648 | SimpleTypeExchanger exchangeTarget(target, AbstractType::Ptr()); | 648 | SimpleTypeExchanger exchangeTarget(target, AbstractType::Ptr()); | ||
649 | 649 | | |||
650 | AbstractType::Ptr exchanged = exchangeTarget.exchange(type); | 650 | AbstractType::Ptr exchanged = exchangeTarget.exchange(type); | ||
651 | 651 | | |||
652 | if(exchanged) { | 652 | if(exchanged) { | ||
653 | QString typeSuffixString = exchanged->toString(); | 653 | QString typeSuffixString = exchanged->toString(); | ||
654 | QRegExp suffixExp("\\&|\\*"); | 654 | QRegExp suffixExp(QStringLiteral("\\&|\\*")); | ||
655 | int suffixPos = typeSuffixString.indexOf(suffixExp); | 655 | int suffixPos = typeSuffixString.indexOf(suffixExp); | ||
656 | if(suffixPos != -1) | 656 | if(suffixPos != -1) | ||
657 | modifyHtml() += typeHighlight(typeSuffixString.mid(suffixPos)); | 657 | modifyHtml() += typeHighlight(typeSuffixString.mid(suffixPos)); | ||
658 | } | 658 | } | ||
659 | 659 | | |||
660 | } else { | 660 | } else { | ||
661 | if(idType) { | 661 | if(idType) { | ||
662 | qCDebug(LANGUAGE) << "identified type could not be resolved:" << idType->qualifiedIdentifier() << idType->declarationId().isValid() << idType->declarationId().isDirect(); | 662 | qCDebug(LANGUAGE) << "identified type could not be resolved:" << idType->qualifiedIdentifier() << idType->declarationId().isValid() << idType->declarationId().isDirect(); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 702 | { | |||
706 | } | 706 | } | ||
707 | return QString(); | 707 | return QString(); | ||
708 | } | 708 | } | ||
709 | 709 | | |||
710 | QString AbstractDeclarationNavigationContext::declarationName( const DeclarationPointer& decl ) const | 710 | QString AbstractDeclarationNavigationContext::declarationName( const DeclarationPointer& decl ) const | ||
711 | { | 711 | { | ||
712 | if( NamespaceAliasDeclaration* alias = dynamic_cast<NamespaceAliasDeclaration*>(decl.data()) ) { | 712 | if( NamespaceAliasDeclaration* alias = dynamic_cast<NamespaceAliasDeclaration*>(decl.data()) ) { | ||
713 | if( alias->identifier().isEmpty() ) | 713 | if( alias->identifier().isEmpty() ) | ||
714 | return "using namespace " + alias->importIdentifier().toString(); | 714 | return QLatin1String("using namespace ") + alias->importIdentifier().toString(); | ||
715 | else | 715 | else | ||
716 | return "namespace " + alias->identifier().toString() + " = " + alias->importIdentifier().toString(); | 716 | return QLatin1String("namespace ") + alias->identifier().toString() + QLatin1String(" = ") + alias->importIdentifier().toString(); | ||
717 | } | 717 | } | ||
718 | 718 | | |||
719 | if( !decl ) | 719 | if( !decl ) | ||
720 | return i18nc("A declaration that is unknown", "Unknown"); | 720 | return i18nc("A declaration that is unknown", "Unknown"); | ||
721 | else | 721 | else | ||
722 | return prettyIdentifier(decl).toString(); | 722 | return prettyIdentifier(decl).toString(); | ||
723 | } | 723 | } | ||
724 | 724 | | |||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |