C++: make InsertionPointLocator ready for re-use.

(cherry picked from commit 519f1d11947ff3109850e559fae868c4a55deb43)
This commit is contained in:
Erik Verbruggen
2010-09-27 18:01:04 +02:00
committed by Robert Loehning
parent 91208c827f
commit f39494e4c2
6 changed files with 345 additions and 93 deletions

View File

@@ -206,19 +206,23 @@ protected:
if (AccessDeclarationAST *xsDecl = decl->asAccessDeclaration()) {
const unsigned token = xsDecl->access_specifier_token;
int newXsSpec = initialXs;
bool isSlot = xsDecl->slots_token && tokenKind(xsDecl->slots_token) == T_Q_SLOTS;
bool isSlot = xsDecl->slots_token
&& tokenKind(xsDecl->slots_token) == T_Q_SLOTS;
switch (tokenKind(token)) {
case T_PUBLIC:
newXsSpec = isSlot ? InsertionPointLocator::PublicSlot : InsertionPointLocator::Public;
newXsSpec = isSlot ? InsertionPointLocator::PublicSlot
: InsertionPointLocator::Public;
break;
case T_PROTECTED:
newXsSpec = isSlot ? InsertionPointLocator::ProtectedSlot : InsertionPointLocator::Protected;
newXsSpec = isSlot ? InsertionPointLocator::ProtectedSlot
: InsertionPointLocator::Protected;
break;
case T_PRIVATE:
newXsSpec = isSlot ? InsertionPointLocator::PrivateSlot: InsertionPointLocator::Private;
newXsSpec = isSlot ? InsertionPointLocator::PrivateSlot
: InsertionPointLocator::Private;
break;
case T_Q_SIGNALS:
@@ -268,13 +272,37 @@ InsertionLocation::InsertionLocation(const QString &prefix, const QString &suffi
, m_column(column)
{}
InsertionPointLocator::InsertionPointLocator(const Document::Ptr &doc)
: m_doc(doc)
InsertionPointLocator::InsertionPointLocator(const Snapshot &snapshot)
: m_snapshot(snapshot)
{
}
InsertionLocation InsertionPointLocator::methodDeclarationInClass(const Class *clazz, AccessSpec xsSpec) const
InsertionLocation InsertionPointLocator::methodDeclarationInClass(
const QString &fileName,
const Class *clazz,
AccessSpec xsSpec) const
{
FindInClass find(m_doc, clazz, xsSpec);
return find();
const Document::Ptr doc = m_snapshot.document(fileName);
if (doc) {
FindInClass find(doc, clazz, xsSpec);
return find();
} else {
return InsertionLocation();
}
}
QList<InsertionLocation> InsertionPointLocator::methodDefinition(
const QString &fileName, DeclarationAST *prevDecl, DeclarationAST *nextDecl) const
{
QList<InsertionLocation> result;
// option 1: after the prevDecl
// option 2: before the nextDecl
// option 3: inline in fileName (if fileName is a .h file)
// option 4: at the end of fileName.cpp (if fileName is not a .cpp file)
return result;
}

View File

@@ -30,6 +30,7 @@
#ifndef INSERTIONPOINTLOCATOR_H
#define INSERTIONPOINTLOCATOR_H
#include <ASTfwd.h>
#include <CPlusPlusForwardDeclarations.h>
#include <Symbols.h>
@@ -82,19 +83,24 @@ public:
SlotBit = 1 << 2,
PublicSlot = Public | SlotBit,
PublicSlot = Public | SlotBit,
ProtectedSlot = Protected | SlotBit,
PrivateSlot = Private | SlotBit,
PrivateSlot = Private | SlotBit,
};
public:
InsertionPointLocator(const Document::Ptr &doc);
InsertionPointLocator(const Snapshot &snapshot);
InsertionLocation methodDeclarationInClass(const Class *clazz,
InsertionLocation methodDeclarationInClass(const QString &fileName,
const Class *clazz,
AccessSpec xsSpec) const;
QList<InsertionLocation> methodDefinition(const QString &fileName,
CPlusPlus::DeclarationAST *prevDecl,
CPlusPlus::DeclarationAST *nextDecl) const;
private:
Document::Ptr m_doc;
Snapshot m_snapshot;
};
} // namespace CPlusPlus