forked from qt-creator/qt-creator
CPlusPlus: Add toLink method to the Symbol
Basically move it from CppTools to CPlusPlus to be able to use it there. Change-Id: I0af80f93bdc029824397ceafdf940cb86c4382b0 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
17
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
17
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "cppassert.h"
|
||||
|
||||
#include <utils/link.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -435,3 +436,19 @@ void Symbol::copy(Symbol *other)
|
||||
_isGenerated = other->_isGenerated;
|
||||
_isDeprecated = other->_isDeprecated;
|
||||
}
|
||||
|
||||
Utils::Link Symbol::toLink() const
|
||||
{
|
||||
const QString filename = QString::fromUtf8(fileName(), static_cast<int>(fileNameLength()));
|
||||
|
||||
int line = static_cast<int>(this->line());
|
||||
int column = static_cast<int>(this->column());
|
||||
|
||||
if (column)
|
||||
--column;
|
||||
|
||||
if (isGenerated())
|
||||
column = 0;
|
||||
|
||||
return Utils::Link(filename, line, column);
|
||||
}
|
||||
|
3
src/libs/3rdparty/cplusplus/Symbol.h
vendored
3
src/libs/3rdparty/cplusplus/Symbol.h
vendored
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "CPlusPlusForwardDeclarations.h"
|
||||
|
||||
namespace Utils { struct Link; }
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
@@ -197,6 +198,8 @@ public:
|
||||
/// Returns true if this Symbol is an Objective-C @property declaration.
|
||||
bool isObjCPropertyDeclaration() const;
|
||||
|
||||
Utils::Link toLink() const;
|
||||
|
||||
virtual const Scope *asScope() const { return 0; }
|
||||
virtual const Enum *asEnum() const { return 0; }
|
||||
virtual const Function *asFunction() const { return 0; }
|
||||
|
@@ -682,9 +682,10 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
// Link to function definition/declaration
|
||||
Utils::Link symbolLink;
|
||||
if (functionDeclarationSymbol) {
|
||||
symbolLink = linkToSymbol(
|
||||
d->m_modelManager->symbolFinder()
|
||||
->findMatchingDefinition(functionDeclarationSymbol, d->m_modelManager->snapshot()));
|
||||
Symbol *symbol = d->m_modelManager->symbolFinder()
|
||||
->findMatchingDefinition(functionDeclarationSymbol, d->m_modelManager->snapshot());
|
||||
if (symbol)
|
||||
symbolLink = symbol->toLink();
|
||||
} else if (functionDefinitionSymbol) {
|
||||
const Snapshot snapshot = d->m_modelManager->snapshot();
|
||||
LookupContext context(d->m_lastSemanticInfo.doc, snapshot);
|
||||
@@ -709,7 +710,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
|
||||
|
||||
if (best.isEmpty())
|
||||
return;
|
||||
symbolLink = linkToSymbol(best.first());
|
||||
symbolLink = best.first()->toLink();
|
||||
}
|
||||
|
||||
// Open Editor at link position
|
||||
|
@@ -246,7 +246,7 @@ void CppEditorOutline::gotoSymbolInEditor()
|
||||
if (!symbol)
|
||||
return;
|
||||
|
||||
const Utils::Link &link = CppTools::linkToSymbol(symbol);
|
||||
const Utils::Link &link = symbol->toLink();
|
||||
if (!link.hasValidTarget())
|
||||
return;
|
||||
|
||||
|
@@ -129,7 +129,7 @@ CppDeclarableElement::CppDeclarableElement(Symbol *declaration)
|
||||
}
|
||||
|
||||
tooltip = overview.prettyType(declaration->type(), qualifiedName);
|
||||
link = CppTools::linkToSymbol(declaration);
|
||||
link = declaration->toLink();
|
||||
helpMark = name;
|
||||
}
|
||||
|
||||
|
@@ -355,7 +355,7 @@ Link attemptFuncDeclDef(const QTextCursor &cursor, Snapshot snapshot,
|
||||
}
|
||||
|
||||
if (target) {
|
||||
result = CppTools::linkToSymbol(target);
|
||||
result = target->toLink();
|
||||
|
||||
unsigned startLine, startColumn, endLine, endColumn;
|
||||
document->translationUnit()->getTokenStartPosition(name->firstToken(), &startLine,
|
||||
@@ -762,7 +762,7 @@ Link FollowSymbolUnderCursor::findLink(
|
||||
|
||||
}
|
||||
|
||||
link = CppTools::linkToSymbol(def ? def : symbol);
|
||||
link = (def ? def : symbol)->toLink();
|
||||
link.linkTextStart = beginOfToken;
|
||||
link.linkTextEnd = endOfToken;
|
||||
return link;
|
||||
|
@@ -230,26 +230,6 @@ const Macro *findCanonicalMacro(const QTextCursor &cursor, Document::Ptr documen
|
||||
return 0;
|
||||
}
|
||||
|
||||
Utils::Link linkToSymbol(Symbol *symbol)
|
||||
{
|
||||
if (!symbol)
|
||||
return Utils::Link();
|
||||
|
||||
const QString filename = QString::fromUtf8(symbol->fileName(),
|
||||
symbol->fileNameLength());
|
||||
|
||||
unsigned line = symbol->line();
|
||||
unsigned column = symbol->column();
|
||||
|
||||
if (column)
|
||||
--column;
|
||||
|
||||
if (symbol->isGenerated())
|
||||
column = 0;
|
||||
|
||||
return Utils::Link(filename, line, column);
|
||||
}
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> codeModelSettings()
|
||||
{
|
||||
return CppTools::Internal::CppToolsPlugin::instance()->codeModelSettings();
|
||||
|
@@ -58,8 +58,6 @@ bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
|
||||
|
||||
Utils::Link CPPTOOLS_EXPORT linkToSymbol(CPlusPlus::Symbol *symbol);
|
||||
|
||||
QString CPPTOOLS_EXPORT identifierUnderCursor(QTextCursor *cursor);
|
||||
|
||||
bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
|
||||
|
@@ -173,7 +173,7 @@ private:
|
||||
|
||||
VirtualFunctionProposalItem *itemFromFunction(Function *func) const
|
||||
{
|
||||
const Utils::Link link = CppTools::linkToSymbol(maybeDefinitionFor(func));
|
||||
const Utils::Link link = maybeDefinitionFor(func)->toLink();
|
||||
QString text = m_overview.prettyName(LookupContext::fullyQualifiedName(func));
|
||||
if (func->isPureVirtual())
|
||||
text += QLatin1String(" = 0");
|
||||
|
Reference in New Issue
Block a user