This change allows the user to use a simple query syntax in the search field to filter the results using names,
operators and predefined filters.
The class QueryTree is capable of parsing a simple query language consiting of QueryNodes, subclassed as
QueryOperators, QueryCommands and QueryTokens. QueryToken identifies a Token by name. QueryCommand represents predefined
filters. QueryOperator defines the syntactic relationship.
QueryNode examples:
"A" -> QueryToken that identifies the Token named A
class -> QueryCommand that filters all Nodes that are classes
. -> QueryOperator that concatenates filters
QueryExamples:
"A".class -> All Tokens named A that are classes
method.(private|protected) -> All methods that are private or protected
"A".member -> All members of A
"A":field.!const -> All fields of A that are not const (':' can be used instead of '.member')
QueryTree checks for correct operator precedence and validity of the query.
All QueryCommands can be found in data/query/QueryCommand.cpp
All QueryOperators can be found in data/query/QueryOperator.cpp
The parsed QueryTree is then passed to the class GraphFilterConductor, which is capable of applying the query on a
Graph. Each part of the query gets assigned a GraphFilter that filters the input Graph in order of node precedence. The
class SubGraph is used as intermediate container, only holding bare pointers to Nodes and Edges. The output Graph holds
all Nodes that match the query.
MessageActivateTokens is used to show all of the results in the CodeView. The GraphView currently only shows the first
Node of the results.
bug id = #6
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#ifndef CODE_CONTROLLER_H
|
|
#define CODE_CONTROLLER_H
|
|
|
|
#include <string>
|
|
|
|
#include "component/controller/Controller.h"
|
|
#include "utility/messaging/MessageListener.h"
|
|
#include "utility/messaging/type/MessageActivateToken.h"
|
|
#include "utility/messaging/type/MessageActivateTokens.h"
|
|
#include "utility/messaging/type/MessageRefresh.h"
|
|
#include "utility/messaging/type/MessageShowFile.h"
|
|
#include "utility/types.h"
|
|
|
|
class CodeView;
|
|
class GraphAccess;
|
|
class LocationAccess;
|
|
class TokenLocationFile;
|
|
|
|
struct AnnotatedText
|
|
{
|
|
std::string text;
|
|
Id tokenId;
|
|
};
|
|
|
|
class CodeController
|
|
: public Controller
|
|
, public MessageListener<MessageActivateToken>
|
|
, public MessageListener<MessageActivateTokens>
|
|
, public MessageListener<MessageRefresh>
|
|
, public MessageListener<MessageShowFile>
|
|
{
|
|
public:
|
|
CodeController(GraphAccess* graphAccess, LocationAccess* locationAccess);
|
|
~CodeController();
|
|
|
|
void setActiveTokenIds(const std::vector<Id>& ids);
|
|
|
|
private:
|
|
virtual void handleMessage(MessageActivateToken* message);
|
|
virtual void handleMessage(MessageActivateTokens* message);
|
|
virtual void handleMessage(MessageRefresh* message);
|
|
virtual void handleMessage(MessageShowFile* message);
|
|
|
|
CodeView* getView();
|
|
|
|
std::vector<std::pair<uint, uint>> getSnippetRangesForFile(TokenLocationFile* file, const uint lineRadius) const;
|
|
|
|
GraphAccess* m_graphAccess;
|
|
LocationAccess* m_locationAccess;
|
|
};
|
|
|
|
#endif // CODE_CONTROLLER_H
|