Commit 58f101cb authored by hjk's avatar hjk
Browse files

CppEditor: Direct element access, less symbols.



Change-Id: Id79b69b271ad90c742a3884f8b818a7ee7f26a5b
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 6dfe3207
...@@ -237,171 +237,82 @@ void CppEditor::Internal::CppElementEvaluator::clear() ...@@ -237,171 +237,82 @@ void CppEditor::Internal::CppElementEvaluator::clear()
} }
// CppElement // CppElement
CppElement::CppElement() : m_helpCategory(TextEditor::HelpItem::Unknown) CppElement::CppElement() : helpCategory(TextEditor::HelpItem::Unknown)
{} {}
CppElement::~CppElement() CppElement::~CppElement()
{} {}
void CppElement::setHelpCategory(const TextEditor::HelpItem::Category &cat)
{ m_helpCategory = cat; }
const TextEditor::HelpItem::Category &CppElement::helpCategory() const
{ return m_helpCategory; }
void CppElement::setHelpIdCandidates(const QStringList &candidates)
{ m_helpIdCandidates = candidates; }
void CppElement::addHelpIdCandidate(const QString &candidate)
{ m_helpIdCandidates.append(candidate); }
const QStringList &CppElement::helpIdCandidates() const
{ return m_helpIdCandidates; }
void CppElement::setHelpMark(const QString &mark)
{ m_helpMark = mark; }
const QString &CppElement::helpMark() const
{ return m_helpMark; }
void CppElement::setLink(const CPPEditorWidget::Link &link)
{ m_link = link; }
const CPPEditorWidget::Link &CppElement::link() const
{ return m_link; }
void CppElement::setTooltip(const QString &tooltip)
{ m_tooltip = tooltip; }
const QString &CppElement::tooltip() const
{ return m_tooltip; }
// Unknown // Unknown
Unknown::Unknown(const QString &type) : CppElement(), m_type(type) Unknown::Unknown(const QString &type) : type(type)
{ {
setTooltip(m_type); tooltip = type;
} }
Unknown::~Unknown()
{}
const QString &Unknown::type() const
{ return m_type; }
// CppInclude // CppInclude
CppInclude::~CppInclude()
{}
CppInclude::CppInclude(const Document::Include &includeFile) : CppInclude::CppInclude(const Document::Include &includeFile) :
CppElement(), path(QDir::toNativeSeparators(includeFile.fileName())),
m_path(QDir::toNativeSeparators(includeFile.fileName())), fileName(QFileInfo(includeFile.fileName()).fileName())
m_fileName(QFileInfo(includeFile.fileName()).fileName())
{ {
setHelpCategory(TextEditor::HelpItem::Brief); helpCategory = TextEditor::HelpItem::Brief;
setHelpIdCandidates(QStringList(m_fileName)); helpIdCandidates = QStringList(fileName);
setHelpMark(m_fileName); helpMark = fileName;
setLink(CPPEditorWidget::Link(m_path)); link = CPPEditorWidget::Link(path);
setTooltip(m_path); tooltip = path;
} }
const QString &CppInclude::path() const
{ return m_path; }
const QString &CppInclude::fileName() const
{ return m_fileName; }
// CppMacro // CppMacro
CppMacro::CppMacro(const Macro &macro) : CppElement() CppMacro::CppMacro(const Macro &macro)
{ {
setHelpCategory(TextEditor::HelpItem::Macro); helpCategory = TextEditor::HelpItem::Macro;
const QString macroName = QLatin1String(macro.name()); const QString macroName = QLatin1String(macro.name());
setHelpIdCandidates(QStringList(macroName)); helpIdCandidates = QStringList(macroName);
setHelpMark(macroName); helpMark = macroName;
setLink(CPPEditorWidget::Link(macro.fileName(), macro.line())); link = CPPEditorWidget::Link(macro.fileName(), macro.line());
setTooltip(macro.toStringWithLineBreaks()); tooltip = macro.toStringWithLineBreaks();
} }
CppMacro::~CppMacro()
{}
// CppDeclarableElement // CppDeclarableElement
CppDeclarableElement::CppDeclarableElement()
{}
CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement() CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement()
{ {
m_icon = Icons().iconForSymbol(declaration); icon = Icons().iconForSymbol(declaration);
Overview overview; Overview overview;
overview.showArgumentNames = true; overview.showArgumentNames = true;
overview.showReturnTypes = true; overview.showReturnTypes = true;
m_name = overview.prettyName(declaration->name()); name = overview.prettyName(declaration->name());
if (declaration->enclosingScope()->isClass() || if (declaration->enclosingScope()->isClass() ||
declaration->enclosingScope()->isNamespace() || declaration->enclosingScope()->isNamespace() ||
declaration->enclosingScope()->isEnum()) { declaration->enclosingScope()->isEnum()) {
m_qualifiedName = overview.prettyName(LookupContext::fullyQualifiedName(declaration)); qualifiedName = overview.prettyName(LookupContext::fullyQualifiedName(declaration));
setHelpIdCandidates(stripName(m_qualifiedName)); helpIdCandidates = stripName(qualifiedName);
} else { } else {
m_qualifiedName = m_name; qualifiedName = name;
setHelpIdCandidates(QStringList(m_name)); helpIdCandidates.append(name);
} }
setTooltip(overview.prettyType(declaration->type(), m_qualifiedName)); tooltip = overview.prettyType(declaration->type(), qualifiedName);
setLink(CPPEditorWidget::linkToSymbol(declaration)); link = CPPEditorWidget::linkToSymbol(declaration);
setHelpMark(m_name); helpMark = name;
} }
CppDeclarableElement::~CppDeclarableElement()
{}
void CppDeclarableElement::setName(const QString &name)
{ m_name = name; }
const QString &CppDeclarableElement::name() const
{ return m_name; }
void CppDeclarableElement::setQualifiedName(const QString &name)
{ m_qualifiedName = name; }
const QString &CppDeclarableElement::qualifiedName() const
{ return m_qualifiedName; }
void CppDeclarableElement::setType(const QString &type)
{ m_type = type; }
const QString &CppDeclarableElement::type() const
{ return m_type; }
void CppDeclarableElement::setIcon(const QIcon &icon)
{ m_icon = icon; }
const QIcon &CppDeclarableElement::icon() const
{ return m_icon; }
// CppNamespace // CppNamespace
CppNamespace::CppNamespace(Symbol *declaration) : CppDeclarableElement(declaration) CppNamespace::CppNamespace(Symbol *declaration) : CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::ClassOrNamespace); helpCategory = TextEditor::HelpItem::ClassOrNamespace;
setTooltip(qualifiedName()); tooltip = qualifiedName;
} }
CppNamespace::~CppNamespace()
{}
// CppClass // CppClass
CppClass::CppClass()
{}
CppClass::CppClass(Symbol *declaration) : CppDeclarableElement(declaration) CppClass::CppClass(Symbol *declaration) : CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::ClassOrNamespace); helpCategory = TextEditor::HelpItem::ClassOrNamespace;
setTooltip(qualifiedName()); tooltip = qualifiedName;
} }
CppClass::~CppClass()
{}
void CppClass::lookupBases(Symbol *declaration, const CPlusPlus::LookupContext &context) void CppClass::lookupBases(Symbol *declaration, const CPlusPlus::LookupContext &context)
{ {
typedef QPair<ClassOrNamespace *, CppClass *> Data; typedef QPair<ClassOrNamespace *, CppClass *> Data;
...@@ -424,8 +335,8 @@ void CppClass::lookupBases(Symbol *declaration, const CPlusPlus::LookupContext & ...@@ -424,8 +335,8 @@ void CppClass::lookupBases(Symbol *declaration, const CPlusPlus::LookupContext &
!visited.contains(clazz)) { !visited.contains(clazz)) {
CppClass baseCppClass(symbol); CppClass baseCppClass(symbol);
CppClass *cppClass = current.second; CppClass *cppClass = current.second;
cppClass->m_bases.append(baseCppClass); cppClass->bases.append(baseCppClass);
q.enqueue(qMakePair(clazz, &cppClass->m_bases.last())); q.enqueue(qMakePair(clazz, &cppClass->bases.last()));
} }
} }
} }
...@@ -447,22 +358,17 @@ void CppClass::lookupDerived(CPlusPlus::Symbol *declaration, const CPlusPlus::Sn ...@@ -447,22 +358,17 @@ void CppClass::lookupDerived(CPlusPlus::Symbol *declaration, const CPlusPlus::Sn
CppClass *clazz = current.first; CppClass *clazz = current.first;
const TypeHierarchy &classHierarchy = current.second; const TypeHierarchy &classHierarchy = current.second;
foreach (const TypeHierarchy &derivedHierarchy, classHierarchy.hierarchy()) { foreach (const TypeHierarchy &derivedHierarchy, classHierarchy.hierarchy()) {
clazz->m_derived.append(CppClass(derivedHierarchy.symbol())); clazz->derived.append(CppClass(derivedHierarchy.symbol()));
q.enqueue(qMakePair(&clazz->m_derived.last(), derivedHierarchy)); q.enqueue(qMakePair(&clazz->derived.last(), derivedHierarchy));
} }
} }
} }
const QList<CppClass> &CppClass::bases() const
{ return m_bases; }
const QList<CppClass> &CppClass::derived() const
{ return m_derived; }
// CppFunction // CppFunction
CppFunction::CppFunction(Symbol *declaration) : CppDeclarableElement(declaration) CppFunction::CppFunction(Symbol *declaration)
: CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::Function); helpCategory = TextEditor::HelpItem::Function;
const FullySpecifiedType &type = declaration->type(); const FullySpecifiedType &type = declaration->type();
...@@ -470,36 +376,27 @@ CppFunction::CppFunction(Symbol *declaration) : CppDeclarableElement(declaration ...@@ -470,36 +376,27 @@ CppFunction::CppFunction(Symbol *declaration) : CppDeclarableElement(declaration
// (with no argument names and no return). Help ids have no signature at all. // (with no argument names and no return). Help ids have no signature at all.
Overview overview; Overview overview;
overview.showDefaultArguments = false; overview.showDefaultArguments = false;
setHelpMark(overview.prettyType(type, name())); helpMark = overview.prettyType(type, name);
overview.showFunctionSignatures = false; overview.showFunctionSignatures = false;
addHelpIdCandidate(overview.prettyName(declaration->name())); helpIdCandidates.append(overview.prettyName(declaration->name()));
} }
CppFunction::~CppFunction()
{}
// CppEnum // CppEnum
CppEnum::CppEnum(Enum *declaration) CppEnum::CppEnum(Enum *declaration)
: CppDeclarableElement(declaration) : CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::Enum); helpCategory = TextEditor::HelpItem::Enum;
setTooltip(qualifiedName()); tooltip = qualifiedName;
} }
CppEnum::~CppEnum()
{}
// CppTypedef // CppTypedef
CppTypedef::CppTypedef(Symbol *declaration) : CppDeclarableElement(declaration) CppTypedef::CppTypedef(Symbol *declaration) : CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::Typedef); helpCategory = TextEditor::HelpItem::Typedef;
setTooltip(Overview().prettyType(declaration->type(), qualifiedName())); tooltip = Overview().prettyType(declaration->type(), qualifiedName);
} }
CppTypedef::~CppTypedef()
{}
// CppVariable // CppVariable
CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scope *scope) : CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scope *scope) :
CppDeclarableElement(declaration) CppDeclarableElement(declaration)
...@@ -527,12 +424,12 @@ CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scop ...@@ -527,12 +424,12 @@ CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scop
const QString &name = const QString &name =
overview.prettyName(LookupContext::fullyQualifiedName(symbol)); overview.prettyName(LookupContext::fullyQualifiedName(symbol));
if (!name.isEmpty()) { if (!name.isEmpty()) {
setTooltip(name); tooltip = name;
setHelpCategory(TextEditor::HelpItem::ClassOrNamespace); helpCategory = TextEditor::HelpItem::ClassOrNamespace;
const QStringList &allNames = stripName(name); const QStringList &allNames = stripName(name);
if (!allNames.isEmpty()) { if (!allNames.isEmpty()) {
setHelpMark(allNames.last()); helpMark = allNames.last();
setHelpIdCandidates(allNames); helpIdCandidates = allNames;
} }
} }
} }
...@@ -540,13 +437,10 @@ CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scop ...@@ -540,13 +437,10 @@ CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scop
} }
} }
CppVariable::~CppVariable()
{}
CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration) CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration)
: CppDeclarableElement(declaration) : CppDeclarableElement(declaration)
{ {
setHelpCategory(TextEditor::HelpItem::Enum); helpCategory = TextEditor::HelpItem::Enum;
Overview overview; Overview overview;
...@@ -554,19 +448,14 @@ CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration) ...@@ -554,19 +448,14 @@ CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration)
const QString enumName = overview.prettyName(LookupContext::fullyQualifiedName(enumSymbol)); const QString enumName = overview.prettyName(LookupContext::fullyQualifiedName(enumSymbol));
const QString enumeratorName = overview.prettyName(declaration->name()); const QString enumeratorName = overview.prettyName(declaration->name());
QString enumeratorValue; QString enumeratorValue;
if (const StringLiteral *value = declaration->constantValue()) { if (const StringLiteral *value = declaration->constantValue())
enumeratorValue = QString::fromUtf8(value->chars(), value->size()); enumeratorValue = QString::fromUtf8(value->chars(), value->size());
}
setHelpMark(overview.prettyName(enumSymbol->name())); helpMark = overview.prettyName(enumSymbol->name());
QString tooltip = enumeratorName; tooltip = enumeratorName;
if (!enumName.isEmpty()) if (!enumName.isEmpty())
tooltip.prepend(enumName + QLatin1Char(' ')); tooltip.prepend(enumName + QLatin1Char(' '));
if (!enumeratorValue.isEmpty()) if (!enumeratorValue.isEmpty())
tooltip.append(QLatin1String(" = ") + enumeratorValue); tooltip.append(QLatin1String(" = ") + enumeratorValue);
setTooltip(tooltip);
} }
CppEnumerator::~CppEnumerator()
{}
...@@ -94,96 +94,60 @@ private: ...@@ -94,96 +94,60 @@ private:
class CppElement class CppElement
{ {
public:
virtual ~CppElement();
const TextEditor::HelpItem::Category &helpCategory() const;
const QStringList &helpIdCandidates() const;
const QString &helpMark() const;
const CPPEditorWidget::Link &link() const;
const QString &tooltip() const;
protected: protected:
CppElement(); CppElement();
void setHelpCategory(const TextEditor::HelpItem::Category &category); public:
void setLink(const CPPEditorWidget::Link &link); virtual ~CppElement();
void setTooltip(const QString &tooltip);
void setHelpIdCandidates(const QStringList &candidates);
void addHelpIdCandidate(const QString &candidate);
void setHelpMark(const QString &mark);
private: TextEditor::HelpItem::Category helpCategory;
TextEditor::HelpItem::Category m_helpCategory; QStringList helpIdCandidates;
QStringList m_helpIdCandidates; QString helpMark;
QString m_helpMark; CPPEditorWidget::Link link;
CPPEditorWidget::Link m_link; QString tooltip;
QString m_tooltip;
}; };
class Unknown : public CppElement class Unknown : public CppElement
{ {
public: public:
explicit Unknown(const QString &type); explicit Unknown(const QString &type);
virtual ~Unknown();
const QString &type() const;
private: public:
QString m_type; QString type;
}; };
class CppInclude : public CppElement class CppInclude : public CppElement
{ {
public: public:
explicit CppInclude(const CPlusPlus::Document::Include &includeFile); explicit CppInclude(const CPlusPlus::Document::Include &includeFile);
virtual ~CppInclude();
const QString &path() const;
const QString &fileName() const;
private: public:
QString m_path; QString path;
QString m_fileName; QString fileName;
}; };
class CppMacro : public CppElement class CppMacro : public CppElement
{ {
public: public:
explicit CppMacro(const CPlusPlus::Macro &macro); explicit CppMacro(const CPlusPlus::Macro &macro);
virtual ~CppMacro();
}; };
class CppDeclarableElement : public CppElement class CppDeclarableElement : public CppElement
{ {
public: public:
CppDeclarableElement();
explicit CppDeclarableElement(CPlusPlus::Symbol *declaration); explicit CppDeclarableElement(CPlusPlus::Symbol *declaration);
virtual ~CppDeclarableElement();
const QString &name() const;
const QString &qualifiedName() const;
const QString &type() const;
const QIcon &icon() const;
protected:
void setName(const QString &name);
void setQualifiedName(const QString &name);
void setType(const QString &type);
void setIcon(const QIcon &icon);
private: public:
QString m_name; QString name;
QString m_qualifiedName; QString qualifiedName;
QString m_type; QString type;
QIcon m_icon; QIcon icon;
}; };
class CppNamespace : public CppDeclarableElement class CppNamespace : public CppDeclarableElement
{ {
public: public:
explicit CppNamespace(CPlusPlus::Symbol *declaration); explicit CppNamespace(CPlusPlus::Symbol *declaration);
virtual ~CppNamespace();
}; };
class CppClass : public CppDeclarableElement class CppClass : public CppDeclarableElement
...@@ -191,38 +155,31 @@ class CppClass : public CppDeclarableElement ...@@ -191,38 +155,31 @@ class CppClass : public CppDeclarableElement
public: public:
CppClass(); CppClass();
explicit CppClass(CPlusPlus::Symbol *declaration); explicit CppClass(CPlusPlus::Symbol *declaration);
virtual ~CppClass();
void lookupBases(CPlusPlus::Symbol *declaration, const CPlusPlus::LookupContext &context); void lookupBases(CPlusPlus::Symbol *declaration, const CPlusPlus::LookupContext &context);
void lookupDerived(CPlusPlus::Symbol *declaration, const CPlusPlus::Snapshot &snapshot); void lookupDerived(CPlusPlus::Symbol *declaration, const CPlusPlus::Snapshot &snapshot);
const QList<CppClass> &bases() const; public:
const QList<CppClass> &derived() const; QList<CppClass> bases;
QList<CppClass> derived;
private:
QList<CppClass> m_bases;
QList<CppClass> m_derived;
}; };
class CppFunction : public CppDeclarableElement