codeinformationrepository.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "codeinformationrepository.h"
00013 #include "cpp_tags.h"
00014
00015 #include <kdevcoderepository.h>
00016 #include <kdebug.h>
00017
00019 static QValueList<KTextEditor::CompletionEntry>
00020 my_unique( const QValueList<KTextEditor::CompletionEntry>& entryList )
00021 {
00022
00023 QValueList< KTextEditor::CompletionEntry > l;
00024 QMap<QString, bool> map;
00025 QValueList< KTextEditor::CompletionEntry >::ConstIterator it=entryList.begin();
00026 while( it != entryList.end() ){
00027 KTextEditor::CompletionEntry e = *it++;
00028 QString key = e.type + " " +
00029 e.text + " " +
00030 e.prefix + " " +
00031 e.postfix + " ";
00032 if( map.find(key) == map.end() ){
00033 map[ key ] = TRUE;
00034 l << e;
00035 }
00036 }
00037 return l;
00038 }
00039
00040 CodeInformationRepository::CodeInformationRepository( KDevCodeRepository* rep )
00041 : m_rep( rep )
00042 {
00043 }
00044
00045 CodeInformationRepository::~CodeInformationRepository()
00046 {
00047 }
00048
00049 QValueList<Tag> CodeInformationRepository::query( const QValueList<Catalog :: QueryArgument> & args )
00050 {
00051 kdDebug(9007) << "CodeInformationRepository::query()" << endl;
00052
00053 QValueList<Tag> tags;
00054
00055 QValueList<Catalog*> catalogs = m_rep->registeredCatalogs();
00056 QValueList<Catalog*>::Iterator it = catalogs.begin();
00057 while( it != catalogs.end() ){
00058 Catalog* catalog = *it;
00059 ++it;
00060
00061 if( !catalog->enabled() )
00062 continue;
00063
00064 tags += catalog->query( args );
00065 }
00066
00067 return tags;
00068 }
00069
00070 QValueList<Tag> CodeInformationRepository::getTagsInFile( const QString & fileName )
00071 {
00072 kdDebug(9007) << "CodeInformationRepository::getTagsInFile()" << endl;
00073
00074 QValueList<Catalog::QueryArgument> args;
00075 args << Catalog::QueryArgument( "fileName", fileName );
00076
00077 QValueList<Catalog*> catalogs = m_rep->registeredCatalogs();
00078 QValueList<Catalog*>::Iterator it = catalogs.begin();
00079 while( it != catalogs.end() ){
00080 Catalog* catalog = *it;
00081 ++it;
00082
00083 QValueList<Tag> tags = catalog->query( args );
00084
00085 if( tags.size() )
00086 return tags;
00087 }
00088
00089 return QValueList<Tag>();
00090 }
00091
00092 QValueList<Tag> CodeInformationRepository::getTagsInScope( const QStringList & scope, bool isInstance )
00093 {
00094 kdDebug(9007) << "CodeInformationRepository::getTagsInScope()" << endl;
00095
00096 QValueList<Tag> tags;
00097 QValueList<Catalog::QueryArgument> args;
00098
00099 #if 0
00100 args.clear();
00101 args << Catalog::QueryArgument( "kind", Tag::Kind_Namespace )
00102 << Catalog::QueryArgument( "scope", scope );
00103 tags += query( args );
00104
00105 args.clear();
00106 args << Catalog::QueryArgument( "kind", Tag::Kind_Class )
00107 << Catalog::QueryArgument( "scope", scope );
00108 tags += query( args );
00109 #endif
00110
00111 args.clear();
00112 args << Catalog::QueryArgument( "kind", Tag::Kind_FunctionDeclaration )
00113 << Catalog::QueryArgument( "scope", scope );
00114 tags += query( args );
00115
00116 args.clear();
00117 args << Catalog::QueryArgument( "kind", Tag::Kind_Variable )
00118 << Catalog::QueryArgument( "scope", scope );
00119 tags += query( args );
00120
00121 if( true ){
00122 args.clear();
00123 args << Catalog::QueryArgument( "kind", Tag::Kind_Enumerator )
00124 << Catalog::QueryArgument( "scope", scope );
00125 tags += query( args );
00126 }
00127
00128 return tags;
00129 }
00130
00131 QValueList<KTextEditor::CompletionEntry> CodeInformationRepository::getEntriesInScope( const QStringList & scope, bool isInstance, bool recompute )
00132 {
00133 kdDebug(9007) << "CodeInformationRepository::getEntriesInScope()" << endl;
00134
00135 if( !recompute && !scope.size() && m_globalEntries.size() )
00136 return m_globalEntries;
00137 else if( scope.size() == 0 ){
00138 m_globalEntries = my_unique( toEntryList( getTagsInScope(scope, isInstance) ) );
00139 return m_globalEntries;
00140 }
00141
00142 return toEntryList( getTagsInScope(scope, isInstance) );
00143 }
00144
00145
00146 QValueList<Tag> CodeInformationRepository::getBaseClassList( const QString& className )
00147 {
00148 kdDebug(9007) << "CodeInformationRepository::getBaseClasseList()" << endl;
00149
00150 if( className.isEmpty() )
00151 return QValueList<Tag>();
00152
00153 QValueList<Catalog::QueryArgument> args;
00154 args << Catalog::QueryArgument( "kind", Tag::Kind_Base_class );
00155
00156
00157 args << Catalog::QueryArgument( "name", className );
00158 return query( args );
00159 }
00160
00161 QValueList<Tag> CodeInformationRepository::getClassOrNamespaceList( const QStringList & scope )
00162 {
00163 kdDebug(9007) << "CodeInformationRepository::getClassOrNamespaceList()" << endl;
00164
00165 QValueList<Tag> tags;
00166 QValueList<Catalog::QueryArgument> args;
00167
00168 args << Catalog::QueryArgument( "kind", Tag::Kind_Namespace )
00169 << Catalog::QueryArgument( "scope", scope );
00170 tags += query( args );
00171
00172 args.clear();
00173 args << Catalog::QueryArgument( "kind", Tag::Kind_Class )
00174 << Catalog::QueryArgument( "scope", scope );
00175 tags += query( args );
00176
00177 return tags;
00178 }
00179
00180 QValueList<Tag> CodeInformationRepository::getTagsInScope( const QString & name, const QStringList & scope )
00181 {
00182 QValueList<Tag> tags;
00183 QValueList<Catalog::QueryArgument> args;
00184
00185 args.clear();
00186 args << Catalog::QueryArgument( "scope", scope );
00187
00188
00189 args << Catalog::QueryArgument( "name", name );
00190
00191 tags += query( args );
00192
00193 return tags;
00194 }
00195
00196 KTextEditor::CompletionEntry CodeInformationRepository::toEntry( Tag & tag, CppCodeCompletion::CompletionMode completionMode )
00197 {
00198 KTextEditor::CompletionEntry entry;
00199
00200 if( tag.name().isEmpty() )
00201 return entry;
00202
00203 switch( tag.kind() ){
00204 case Tag::Kind_Typedef:
00205 entry.prefix = "typedef";
00206 entry.text = tag.name();
00207 break;
00208
00209 case Tag::Kind_Class:
00210 entry.prefix = "class";
00211 entry.text = tag.name();
00212 break;
00213
00214 case Tag::Kind_Namespace:
00215 entry.prefix = "namespace";
00216 entry.text = tag.name();
00217 break;
00218
00219 case Tag::Kind_FunctionDeclaration:
00220
00221 {
00222 entry.text = tag.name();
00223 entry.text += "(";
00224
00225 CppFunction<Tag> tagInfo( tag );
00226 QStringList arguments = tagInfo.arguments();
00227 QStringList argumentNames = tagInfo.argumentNames();
00228
00229 QString signature;
00230 for( uint i=0; i<arguments.size(); ++i ){
00231 signature += arguments[ i ];
00232 if( completionMode == CppCodeCompletion::NormalCompletion ){
00233 QString argName = argumentNames[ i ];
00234 if( !argName.isEmpty() )
00235 signature += QString::fromLatin1( " " ) + argName;
00236 }
00237
00238 if( i != (arguments.size()-1) ){
00239 signature += ", ";
00240 }
00241 }
00242
00243 if( signature.isEmpty() )
00244 entry.text += ")";
00245 else
00246 entry.postfix = signature + " )";
00247
00248 if( tagInfo.isConst() )
00249 entry.postfix += " const";
00250
00251 if( completionMode != CppCodeCompletion::NormalCompletion ){
00252 entry.text += entry.postfix;
00253 entry.postfix = QString::null;
00254 }
00255
00256 QString comment = tag.attribute("description").toString();
00257 if (!comment.isNull())
00258 entry.comment = comment;
00259
00260
00261 }
00262
00263 break;
00264
00265 case Tag::Kind_Enumerator:
00266 case Tag::Kind_Variable:
00267 entry.text = tag.name();
00268 break;
00269
00270 default:
00271 ;
00272 }
00273
00274 return entry;
00275 }
00276
00277 QValueList<KTextEditor :: CompletionEntry> CodeInformationRepository::toEntryList( const QValueList<Tag> & tags, CppCodeCompletion::CompletionMode completionMode )
00278 {
00279 QValueList<KTextEditor :: CompletionEntry> entryList;
00280 QMap<QString, bool> ns;
00281
00282 QValueList<Tag>::ConstIterator it = tags.begin();
00283 while( it != tags.end() ){
00284 Tag tag = *it;
00285 ++it;
00286
00287 KTextEditor::CompletionEntry entry = toEntry( tag, completionMode );
00288 if( !entry.text.isEmpty() )
00289 entryList << entry;
00290 }
00291
00292 return entryList;
00293 }
00294
00295
This file is part of the documentation for KDevelop Version 3.1.2.