[prev in list] [next in list] [prev in thread] [next in thread]
List: kdevelop-bugs
Subject: [Bug 213665] cannot jump to classes with same identifier in class
From: Milian Wolff <mail () milianw ! de>
Date: 2010-09-28 14:28:25
Message-ID: 20100928142825.ACB416A7D7 () immanuel ! kde ! org
[Download RAW message or body]
https://bugs.kde.org/show_bug.cgi?id=213665
Milian Wolff <mail@milianw.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #3 from Milian Wolff <mail milianw de> 2010-09-28 16:28:24 ---
commit ac5d506c4e531be29623fed119293e689e619d6f
Author: Milian Wolff <mail@milianw.de>
Date: Tue Sep 28 16:27:39 2010 +0200
don't rely on the QualifiedIdentifier for distinction between declarations
two classes with the same name in different files / projects would not be
distinguishable otherwise
BUG: 213665
diff --git a/plugins/classbrowser/classbrowserplugin.cpp
b/plugins/classbrowser/classbrowserplugin.cpp
index 61021e9..1212b63 100644
--- a/plugins/classbrowser/classbrowserplugin.cpp
+++ b/plugins/classbrowser/classbrowserplugin.cpp
@@ -154,32 +154,6 @@ void ClassBrowserPlugin::findInClassBrowser()
m_activeClassTree->highlightIdentifier(decl->qualifiedIdentifier());
}
-template<class DestClass>
-static DestClass* getBestDeclaration(Declaration* a_decl)
-{
- if ( a_decl == 0 )
- return 0;
-
- uint declarationCount = 0;
- const IndexedDeclaration* declarations = 0;
- PersistentSymbolTable::self().declarations(
- a_decl->qualifiedIdentifier(),
- declarationCount,
- declarations );
-
- for ( uint i = 0; i < declarationCount; ++i )
- {
- // See if this declaration matches and return it.
- DestClass* decl = dynamic_cast<DestClass*>(declarations[i].declaration());
- if ( decl && !decl->isForwardDeclaration() )
- {
- return decl;
- }
- }
-
- return 0;
-}
-
void ClassBrowserPlugin::showDefinition(DeclarationPointer declaration)
{
DUChainReadLocker readLock(DUChain::lock());
@@ -187,22 +161,21 @@ void
ClassBrowserPlugin::showDefinition(DeclarationPointer declaration)
if ( !declaration )
return;
- Declaration* bestDeclaration =
getBestDeclaration<Declaration>(declaration.data());
-
+ Declaration* decl = declaration.data();
// If it's a function, find the function definition to go to the actual
declaration.
- if ( bestDeclaration && bestDeclaration->isFunctionDeclaration() )
+ if ( decl && decl->isFunctionDeclaration() )
{
- FunctionDefinition* funcDefinition =
dynamic_cast<FunctionDefinition*>(bestDeclaration);
+ FunctionDefinition* funcDefinition =
dynamic_cast<FunctionDefinition*>(decl);
if ( funcDefinition == 0 )
- funcDefinition = FunctionDefinition::definition(bestDeclaration);
+ funcDefinition = FunctionDefinition::definition(decl);
if ( funcDefinition )
- bestDeclaration = funcDefinition;
+ decl = funcDefinition;
}
- if (bestDeclaration)
+ if (decl)
{
- KUrl url(bestDeclaration->url().str());
- KTextEditor::Range range =
bestDeclaration->rangeInCurrentRevision().textRange();
+ KUrl url(decl->url().str());
+ KTextEditor::Range range = decl->rangeInCurrentRevision().textRange();
readLock.unlock();
diff --git a/plugins/classbrowser/classmodelnode.cpp
b/plugins/classbrowser/classmodelnode.cpp
index fb82e6b..3818bc5 100644
--- a/plugins/classbrowser/classmodelnode.cpp
+++ b/plugins/classbrowser/classmodelnode.cpp
@@ -35,52 +35,21 @@
using namespace KDevelop;
using namespace ClassModelNodes;
-IdentifierNode::IdentifierNode(const KDevelop::QualifiedIdentifier&
a_identifier, NodesModelInterface* a_model)
- : DynamicNode(a_identifier.toString(), a_model)
- , m_identifier(a_identifier)
-{
-}
-
-IdentifierNode::IdentifierNode(const QString& a_displayName,
- const KDevelop::QualifiedIdentifier&
a_identifier,
- NodesModelInterface* a_model)
- : DynamicNode(a_displayName, a_model)
- , m_identifier(a_identifier)
-{
-}
-
-IdentifierNode::IdentifierNode(const QString& a_displayName,
- KDevelop::Declaration* a_decl,
- NodesModelInterface* a_model)
- : DynamicNode(a_displayName, a_model)
+IdentifierNode::IdentifierNode(KDevelop::Declaration* a_decl,
+ NodesModelInterface* a_model,
+ const QString& a_displayName)
+ : DynamicNode(a_displayName.isEmpty() ? a_decl->identifier().toString() :
a_displayName, a_model)
, m_identifier(a_decl->qualifiedIdentifier())
+ , m_indexedDeclaration(a_decl)
, m_cachedDeclaration(a_decl)
{
}
Declaration* IdentifierNode::getDeclaration()
{
- if ( m_cachedDeclaration )
- return m_cachedDeclaration.data();
-
- uint declarationCount = 0;
- const IndexedDeclaration* declarations = 0;
- PersistentSymbolTable::self().declarations(
- m_identifier,
- declarationCount,
- declarations );
-
- for ( uint i = 0; i < declarationCount; ++i )
- {
- // See if this declaration matches and return it.
- Declaration* decl =
dynamic_cast<Declaration*>(declarations[i].declaration());
- if ( decl && !decl->isForwardDeclaration() )
- {
- m_cachedDeclaration = decl;
- break;
- }
- }
-
+ if ( !m_cachedDeclaration )
+ m_cachedDeclaration = m_indexedDeclaration.declaration();
+
return m_cachedDeclaration.data();
}
@@ -99,7 +68,7 @@ bool IdentifierNode::getIcon(QIcon& a_resultIcon)
//////////////////////////////////////////////////////////////////////////////
EnumNode::EnumNode(KDevelop::Declaration* a_decl, NodesModelInterface*
a_model)
- : IdentifierNode(a_decl->identifier().toString(), a_decl, a_model)
+ : IdentifierNode(a_decl, a_model)
{
// Set display name for anonymous enums
if ( m_displayName.isEmpty() )
@@ -152,8 +121,8 @@ void EnumNode::populateNode()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-ClassNode::ClassNode(const KDevelop::QualifiedIdentifier& a_identifier,
NodesModelInterface* a_model)
- : IdentifierNode(a_identifier.last().toString(), a_identifier, a_model)
+ClassNode::ClassNode(Declaration* a_decl, NodesModelInterface* a_model)
+ : IdentifierNode(a_decl, a_model)
{
}
@@ -215,7 +184,7 @@ bool ClassNode::updateClassDeclarations()
else if ( ClassFunctionDeclaration* funcDecl =
dynamic_cast<ClassFunctionDeclaration*>(decl) )
newNode = new FunctionNode( funcDecl, m_model );
else if ( ClassDeclaration* classDecl =
dynamic_cast<ClassDeclaration*>(decl) )
- newNode = new ClassNode(classDecl->qualifiedIdentifier(), m_model);
+ newNode = new ClassNode(classDecl, m_model);
else if ( ClassMemberDeclaration* memDecl =
dynamic_cast<ClassMemberDeclaration*>(decl) )
newNode = new ClassMemberNode( memDecl, m_model );
else
@@ -292,7 +261,7 @@ ClassNode* ClassNode::findSubClass(const
KDevelop::IndexedQualifiedIdentifier& a
//////////////////////////////////////////////////////////////////////////////
FunctionNode::FunctionNode(KDevelop::ClassFunctionDeclaration* a_decl,
NodesModelInterface* a_model)
- : IdentifierNode(a_decl->identifier().toString(), a_decl, a_model)
+ : IdentifierNode(a_decl, a_model)
{
// Append the argument signature to the identifier's name (which is what the
displayName is.
if (FunctionType::Ptr type = a_decl->type<FunctionType>())
@@ -309,7 +278,7 @@
FunctionNode::FunctionNode(KDevelop::ClassFunctionDeclaration* a_decl,
NodesMode
//////////////////////////////////////////////////////////////////////////////
ClassMemberNode::ClassMemberNode(KDevelop::ClassMemberDeclaration* a_decl,
NodesModelInterface* a_model)
- : IdentifierNode(a_decl->identifier().toString(), a_decl, a_model)
+ : IdentifierNode(a_decl, a_model)
{
}
@@ -403,7 +372,7 @@ void BaseClassesFolderNode::populateNode()
if ( baseClassDeclaration )
{
// Add the base class.
- addNode( new ClassNode(baseClassDeclaration->qualifiedIdentifier(),
m_model) );
+ addNode( new ClassNode(baseClassDeclaration, m_model) );
}
}
}
@@ -431,7 +400,7 @@ void DerivedClassesFolderNode::populateNode()
foreach( Declaration* decl, inheriters )
{
- addNode( new ClassNode(decl->qualifiedIdentifier(), m_model) );
+ addNode( new ClassNode(decl, m_model) );
}
}
}
diff --git a/plugins/classbrowser/classmodelnode.h
b/plugins/classbrowser/classmodelnode.h
index 873ca41..e1ff084 100644
--- a/plugins/classbrowser/classmodelnode.h
+++ b/plugins/classbrowser/classmodelnode.h
@@ -162,9 +162,7 @@ private:
class IdentifierNode : public DynamicNode
{
public:
- IdentifierNode(const KDevelop::QualifiedIdentifier& a_identifier,
NodesModelInterface* a_model);
- IdentifierNode(const QString& a_displayName, const
KDevelop::QualifiedIdentifier& a_identifier, NodesModelInterface* a_model);
- IdentifierNode(const QString& a_displayName, KDevelop::Declaration* a_decl,
NodesModelInterface* a_model);
+ IdentifierNode(KDevelop::Declaration* a_decl, NodesModelInterface* a_model,
const QString& a_displayName = QString());
public:
/// Returns the qualified identifier for this node by going through the tree
@@ -180,6 +178,7 @@ public: // Overridables
private:
KDevelop::IndexedQualifiedIdentifier m_identifier;
+ KDevelop::IndexedDeclaration m_indexedDeclaration;
KDevelop::DeclarationPointer m_cachedDeclaration;
};
@@ -205,7 +204,7 @@ public: // Node overrides
class ClassNode : public IdentifierNode, public
ClassModelNodeDocumentChangedInterface
{
public:
- ClassNode(const KDevelop::QualifiedIdentifier& a_identifier,
NodesModelInterface* a_model);
+ ClassNode(KDevelop::Declaration* a_decl, NodesModelInterface* a_model);
virtual ~ClassNode();
/// Lookup a contained class and return the related node.
diff --git a/plugins/classbrowser/documentclassesfolder.cpp
b/plugins/classbrowser/documentclassesfolder.cpp
index 7128418..24c80f3 100644
--- a/plugins/classbrowser/documentclassesfolder.cpp
+++ b/plugins/classbrowser/documentclassesfolder.cpp
@@ -355,8 +355,24 @@ bool DocumentClassesFolder::updateDocument(const
KDevelop::IndexedString& a_file
if ( parentNode != 0 )
{
// Create the new node and add it.
- newNode = new ClassNode(id, m_model);
- parentNode->addNode( newNode );
+ IndexedDeclaration decl;
+ uint count = 0;
+ const IndexedDeclaration* declarations;
+ DUChainReadLocker lock;
+ PersistentSymbolTable::self().declarations(item.id, count,
declarations);
+ for ( int i = 0; i < count; ++i )
+ {
+ if (declarations[i].indexedTopContext().url() == a_file)
+ {
+ decl = declarations[i];
+ break;
+ }
+ }
+ if (decl.isValid())
+ {
+ newNode = new ClassNode(decl.declaration(), m_model);
+ parentNode->addNode( newNode );
+ }
}
// Insert it to the map - newNode can be 0 - meaning the class is
hidden.
--
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
_______________________________________________
KDevelop-bugs mailing list
KDevelop-bugs@kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-bugs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic