aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/glsleditor
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@theqtcompany.com>2016-04-15 09:35:20 +0200
committerDavid Schulz <david.schulz@theqtcompany.com>2016-05-20 12:35:10 +0000
commitb482a6158c91b4f7dd89d2e4adcae60e922df08c (patch)
treefbb08495e7c2cdfaea743119931544049008d7be /src/plugins/glsleditor
parent61be2397955fe29e328b9fc4ac1783390604d6e4 (diff)
Remove duplicated code from c++ and glsl completer.
Change-Id: Ibda04771fceffef6344f6a6128d77dd8192379ca Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/glsleditor')
-rw-r--r--src/plugins/glsleditor/glslautocompleter.cpp79
-rw-r--r--src/plugins/glsleditor/glslautocompleter.h3
2 files changed, 5 insertions, 77 deletions
diff --git a/src/plugins/glsleditor/glslautocompleter.cpp b/src/plugins/glsleditor/glslautocompleter.cpp
index 9c98858d41..b2e7d6313b 100644
--- a/src/plugins/glsleditor/glslautocompleter.cpp
+++ b/src/plugins/glsleditor/glslautocompleter.cpp
@@ -25,96 +25,27 @@
#include "glslautocompleter.h"
-#include <cplusplus/Token.h>
-#include <cplusplus/SimpleLexer.h>
#include <cplusplus/MatchingText.h>
-#include <cplusplus/BackwardsScanner.h>
-#include <QLatin1Char>
#include <QTextCursor>
-using namespace CPlusPlus;
-
namespace GlslEditor {
namespace Internal {
-GlslCompleter::GlslCompleter()
-{}
-
-GlslCompleter::~GlslCompleter()
-{}
-
bool GlslCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const
{
- QChar ch;
-
- if (! textToInsert.isEmpty())
- ch = textToInsert.at(0);
-
- if (! (MatchingText::shouldInsertMatchingText(cursor)
- || ch == QLatin1Char('\'')
- || ch == QLatin1Char('"')))
- return false;
- else if (isInComment(cursor))
- return false;
-
- return true;
+ return CPlusPlus::MatchingText::contextAllowsAutoParentheses(cursor, textToInsert);
}
bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
- const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
- BackwardsScanner::previousBlockState(cursor.block()),
- LanguageFeatures::defaultFeatures());
-
- // XXX Duplicated from CppEditor::isInComment to avoid tokenizing twice
- if (tk.isComment()) {
- const unsigned pos = cursor.selectionEnd() - cursor.block().position();
-
- if (pos == tk.utf16charsEnd()) {
- if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
- return false;
-
- const int state = cursor.block().userState() & 0xFF;
- if (state > 0)
- return false;
- }
-
- if (pos < tk.utf16charsEnd())
- return false;
- } else if (tk.isStringLiteral() || tk.isCharLiteral()) {
- const unsigned pos = cursor.selectionEnd() - cursor.block().position();
- if (pos <= tk.utf16charsEnd())
- return false;
- }
-
- return true;
+ return CPlusPlus::MatchingText::contextAllowsElectricCharacters(cursor);
}
bool GlslCompleter::isInComment(const QTextCursor &cursor) const
{
- const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
- BackwardsScanner::previousBlockState(cursor.block()),
- LanguageFeatures::defaultFeatures());
-
- if (tk.isComment()) {
- const unsigned pos = cursor.selectionEnd() - cursor.block().position();
-
- if (pos == tk.utf16charsEnd()) {
- if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
- return true;
-
- const int state = cursor.block().userState() & 0xFF;
- if (state > 0)
- return true;
- }
-
- if (pos < tk.utf16charsEnd())
- return true;
- }
-
- return false;
+ return CPlusPlus::MatchingText::isInCommentHelper(cursor);
}
QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
@@ -122,12 +53,12 @@ QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
QChar la,
int *skippedChars) const
{
- return MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
+ return CPlusPlus::MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
}
QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{
- return MatchingText::insertParagraphSeparator(cursor);
+ return CPlusPlus::MatchingText::insertParagraphSeparator(cursor);
}
} // namespace Internal
diff --git a/src/plugins/glsleditor/glslautocompleter.h b/src/plugins/glsleditor/glslautocompleter.h
index 8f09d242cd..1e1d1a0f84 100644
--- a/src/plugins/glsleditor/glslautocompleter.h
+++ b/src/plugins/glsleditor/glslautocompleter.h
@@ -33,9 +33,6 @@ namespace Internal {
class GlslCompleter : public TextEditor::AutoCompleter
{
public:
- GlslCompleter();
- virtual ~GlslCompleter();
-
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;