Add AbstractDeclarationNavigationContext, and move the html-method from
[kdevelopdvcssupport.git] / language / duchain / forwarddeclaration.cpp
blob752aec4c4b6c789c22be2bfee6b5aa676ce5e10d
1 /* This file is part of KDevelop
2 Copyright 2006 Hamish Rodda <rodda@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "forwarddeclaration.h"
21 #include <ktexteditor/smartrange.h>
22 #include <ktexteditor/document.h>
23 #include <klocale.h>
25 #include "duchain.h"
26 #include "duchainlock.h"
27 #include "ducontext.h"
28 #include "use.h"
29 #include "duchainregister.h"
30 #include "types/identifiedtype.h"
32 using namespace KTextEditor;
34 namespace KDevelop
36 REGISTER_DUCHAIN_ITEM(ForwardDeclaration);
38 ForwardDeclaration::ForwardDeclaration(const ForwardDeclaration& rhs) : Declaration(*new ForwardDeclarationData(*rhs.d_func())) {
39 setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
42 ForwardDeclaration::ForwardDeclaration(ForwardDeclarationData& data) : Declaration(data) {
45 ForwardDeclaration::ForwardDeclaration(const SimpleRange& range, DUContext* context )
46 : Declaration(*new ForwardDeclarationData, range)
48 d_func_dynamic()->setClassId(this);
49 if( context )
50 setContext( context );
53 ForwardDeclaration::~ForwardDeclaration()
57 QString ForwardDeclaration::toString() const
59 if(context() )
60 return qualifiedIdentifier().toString();
61 else
62 return i18n("context-free forward-declaration") + " " + identifier().toString();
65 Declaration * ForwardDeclaration::resolve(const TopDUContext* topContext) const
67 ENSURE_CAN_READ
69 //If we've got a type assigned, that counts as a way of resolution.
70 AbstractType::Ptr t = abstractType();
71 IdentifiedType* idType = dynamic_cast<IdentifiedType*>(t.unsafeData());
72 if( idType ) {
73 Declaration* decl = idType->declaration(topContext);
74 if(decl && !decl->isForwardDeclaration())
75 return decl;
76 else
77 return 0;
80 if(!topContext)
81 topContext = this->topContext();
83 QualifiedIdentifier globalIdentifier = qualifiedIdentifier();
84 globalIdentifier.setExplicitlyGlobal(true);
86 //We've got to use DUContext::DirectQualifiedLookup so C++ works correctly.
87 QList<Declaration*> declarations = topContext->findDeclarations(globalIdentifier, SimpleCursor::invalid(), AbstractType::Ptr(), 0, DUContext::DirectQualifiedLookup);
89 foreach(Declaration* decl, declarations) {
90 if( !decl->isForwardDeclaration() )
91 return decl;
94 return 0;
97 DUContext * ForwardDeclaration::logicalInternalContext(const TopDUContext* topContext) const
99 ENSURE_CAN_READ
100 Declaration* resolved = resolve(topContext);
101 if(resolved && resolved != this)
102 return resolved->logicalInternalContext(topContext);
103 else
104 return Declaration::logicalInternalContext(topContext);
107 bool ForwardDeclaration::isForwardDeclaration() const
109 return true;
112 Declaration* ForwardDeclaration::clonePrivate() const {
113 return new ForwardDeclaration(*this);
118 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on