[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/devtools/kdevelop4-extra-plugins/java/completion
From: Niko Sams <niko.sams () gmail ! com>
Date: 2009-02-01 14:36:22
Message-ID: 1233498982.627912.30742.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 919675 by nsams:
CodeCompletionWorker: adapt to platform changes.
untested, as the plugin isn't working currently.
M +1 -1 context.cpp
M +1 -1 context.h
M +2 -128 worker.cpp
M +1 -6 worker.h
--- trunk/playground/devtools/kdevelop4-extra-plugins/java/completion/context.cpp \
#919674:919675 @@ -71,7 +71,7 @@
int completionRecursionDepth = 0;
-CodeCompletionContext::CodeCompletionContext(DUContextPointer context, const \
QString& text, int depth) \
+CodeCompletionContext::CodeCompletionContext(DUContextPointer context, const \
QString& text, const QString& followingText, int depth) : \
KDevelop::CodeCompletionContext(context, text, depth) , \
m_memberAccessOperation(NoMemberAccess) {
--- trunk/playground/devtools/kdevelop4-extra-plugins/java/completion/context.h \
#919674:919675 @@ -53,7 +53,7 @@
* @param text the text to analyze. It usually is the text in the range \
starting at the beginning of the context, and ending at the position where completion \
should start
* @warning The du-chain must be unlocked when this is called
* */
- CodeCompletionContext(KDevelop::DUContextPointer context, const QString& text, \
int depth = 0); + CodeCompletionContext(KDevelop::DUContextPointer context, \
const QString& text, const QString& followingText, int depth = 0); \
~CodeCompletionContext();
///Computes the full set of completion items, using the information retrieved \
earlier.
--- trunk/playground/devtools/kdevelop4-extra-plugins/java/completion/worker.cpp \
#919674:919675 @@ -46,133 +46,7 @@
{
}
-CodeCompletionModel* CodeCompletionWorker::model() const
+KDevelop::CodeCompletionContext* \
CodeCompletionWorker::createCompletionContext(KDevelop::DUContextPointer context, \
const QString &contextText, const QString &followingText) const {
- return static_cast<CodeCompletionModel*>(const_cast<QObject*>(parent()));
+ return new CodeCompletionContext(context, contextText, followingText);
}
-
-void CodeCompletionWorker::computeCompletions(KDevelop::DUContextPointer context, \
const KTextEditor::Cursor& position, KTextEditor::View* view, const \
KTextEditor::Range& contextRange, const QString& contextText)
-{
- CodeCompletionContext::Ptr completionContext( new CodeCompletionContext( context, \
contextText ) );
- if (CodeCompletionModel* m = model())
- m->setCompletionContext(KDevelop::CodeCompletionContext::Ptr::staticCast(completionContext));
-
- if( completionContext->isValid() ) {
- DUChainReadLocker lock(DUChain::lock());
-
- if (!context) {
- kDebug(9007) << "Completion context disappeared before completions could be \
calculated";
- return;
- }
-
- QList<CompletionTreeItemPointer> items = \
completionContext->completionItems(SimpleCursor(position), \
aborting());
-
- if (aborting())
- return;
-
- computeGroups( items, completionContext );
-
- } else {
- kDebug(9007) << "setContext: Invalid code-completion context";
- }
-}
-
-///Always the last item of a grouping chain: Only inserts the items
-struct LastGrouper {
- LastGrouper(QList<KSharedPtr<CompletionTreeElement> >& tree, CompletionTreeNode* \
parent, QList<CompletionTreeItemPointer> items)
- {
- foreach( CompletionTreeItemPointer item, items ) {
- item->setParent(parent);
- tree << KSharedPtr<CompletionTreeElement>( item.data() );
- }
- }
-};
-
-///Helper class that helps us grouping the completion-list. A chain of groupers can \
be built, by using NextGrouper.
-template<class KeyExtractor, class NextGrouper = LastGrouper>
-struct ItemGrouper {
- typedef typename KeyExtractor::KeyType KeyType;
-
- ItemGrouper(QList<KSharedPtr<CompletionTreeElement> >& tree, CompletionTreeNode* \
parent, QList<CompletionTreeItemPointer> items)
- {
- typedef QMap<KeyType, QList<CompletionTreeItemPointer> > GroupMap;
- GroupMap groups;
-
- foreach(const CompletionTreeItemPointer& item, items) {
- KeyType key = KeyExtractor::extract(item);
- typename GroupMap::iterator it = groups.find(key);
- if(it == groups.end())
- it = groups.insert(key, QList<CompletionTreeItemPointer>());
-
- (*it).append(item);
- }
-
- for( typename GroupMap::const_iterator it = groups.begin(); it != groups.end(); \
++it ) {
- KSharedPtr<CompletionTreeNode> node(new CompletionTreeNode());
- node->setParent(parent);
- node->role = (KTextEditor::CodeCompletionModel::ExtraItemDataRoles)KeyExtractor::Role;
- node->roleValue = QVariant(it.key());
-
- tree << KSharedPtr<CompletionTreeElement>( node.data() );
-
- NextGrouper nextGrouper(node->children, node.data(), *it);
- }
- }
-};
-
-///Extracts the argument-hint depth from completion-items, to be used in ItemGrouper \
for grouping by argument-hint depth.
-struct ArgumentHintDepthExtractor {
- typedef int KeyType;
- enum { Role = KTextEditor::CodeCompletionModel::ArgumentHintDepth };
-
- static KeyType extract( const CompletionTreeItemPointer& item ) {
- return item->argumentHintDepth();
- }
-};
-
-struct InheritanceDepthExtractor {
- typedef int KeyType;
-
- enum { Role = KTextEditor::CodeCompletionModel::InheritanceDepth };
-
- static KeyType extract( const CompletionTreeItemPointer& item ) {
- return item->inheritanceDepth();
- }
-};
-
-struct SimplifiedAttributesExtractor {
- typedef int KeyType;
-
- enum { Role = KTextEditor::CodeCompletionModel::CompletionRole };
-
- static int groupingProperties;
-
- static KeyType extract( const CompletionTreeItemPointer& item ) {
- const NormalDeclarationCompletionItem* decItem = \
item->asItem<NormalDeclarationCompletionItem>();
- if( decItem && decItem->declaration.data() )
- return DUChainUtils::completionProperties(decItem->declaration.data()) & \
groupingProperties;
- else
- return 0;
- }
-};
-
-///@todo make configurable. These are the attributes that can be respected for \
grouping.
-int SimplifiedAttributesExtractor::groupingProperties = CodeCompletionModel::Public \
| CodeCompletionModel::Protected | CodeCompletionModel::Private | \
CodeCompletionModel::Static | CodeCompletionModel::TypeAlias | \
CodeCompletionModel::Variable | CodeCompletionModel::Class | \
CodeCompletionModel::GlobalScope | CodeCompletionModel::LocalScope | \
CodeCompletionModel::GlobalScope | \
CodeCompletionModel::NamespaceScope;
-
-void CodeCompletionWorker::computeGroups(QList<CompletionTreeItemPointer> items, \
KSharedPtr<CodeCompletionContext> completionContext)
-{
- kDebug(9007) << "grouping" << items.count() << "completion-items";
- QList<KSharedPtr<CompletionTreeElement> > tree;
- /**
- * 1. Group by argument-hint depth
- * 2. Group by inheritance depth
- * 3. Group by simplified attributes
- * */
- ItemGrouper<ArgumentHintDepthExtractor, ItemGrouper<InheritanceDepthExtractor, \
ItemGrouper<SimplifiedAttributesExtractor> > > argumentHintDepthGrouper(tree, 0, \
items);
-
- emit foundDeclarations( tree, completionContext.data() );
-}
-
-}
-
-#include "worker.moc"
--- trunk/playground/devtools/kdevelop4-extra-plugins/java/completion/worker.h \
#919674:919675 @@ -39,13 +39,8 @@
public:
CodeCompletionWorker(CodeCompletionModel* parent);
- CodeCompletionModel* model() const;
-
protected:
- virtual void computeCompletions(KDevelop::DUContextPointer context, const \
KTextEditor::Cursor& position, KTextEditor::View* view, const KTextEditor::Range& \
contextRange, const QString& contextText);
-
- private:
- void computeGroups(QList<KDevelop::CompletionTreeItemPointer> items, \
KSharedPtr<CodeCompletionContext> completionContext); + virtual \
KDevelop::CodeCompletionContext* createCompletionContext(KDevelop::DUContextPointer \
context, const QString &contextText, const QString &followingText) const; };
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic