forked from qt-creator/qt-creator
ClangFormat: Refactor indenter to allow ClangFormat unit-tests
We do not build texteditor files in unit-tests so some tricks were required to make ClangFormatIndenter available. First simple unit-test proofs it builds and runs. Change-Id: I81d5ea099bd27fd1c1ed8b5b7877299dcc62a67f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -49,7 +49,7 @@ static TextEditor::TextDocument *createJavaDocument()
|
||||
auto doc = new TextEditor::TextDocument;
|
||||
doc->setId(Constants::JAVA_EDITOR_ID);
|
||||
doc->setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
|
||||
doc->setIndenter(new JavaIndenter);
|
||||
doc->setIndenter(new JavaIndenter(doc->document()));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
using namespace Android;
|
||||
using namespace Android::Internal;
|
||||
|
||||
JavaIndenter::JavaIndenter() = default;
|
||||
JavaIndenter::JavaIndenter(QTextDocument *doc)
|
||||
: TextEditor::TextIndenter(doc)
|
||||
{}
|
||||
|
||||
JavaIndenter::~JavaIndenter() = default;
|
||||
|
||||
@@ -44,20 +46,17 @@ bool JavaIndenter::isElectricCharacter(const QChar &ch) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void JavaIndenter::indentBlock(QTextDocument *doc,
|
||||
const QTextBlock &block,
|
||||
void JavaIndenter::indentBlock(const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
Q_UNUSED(doc);
|
||||
int indent = indentFor(block, tabSettings);
|
||||
if (typedChar == QLatin1Char('}'))
|
||||
indent -= tabSettings.m_indentSize;
|
||||
tabSettings.indentLine(block, qMax(0, indent));
|
||||
}
|
||||
|
||||
int JavaIndenter::indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
int JavaIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
QTextBlock previous = block.previous();
|
||||
if (!previous.isValid())
|
||||
|
||||
@@ -25,20 +25,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <texteditor/indenter.h>
|
||||
#include <texteditor/textindenter.h>
|
||||
|
||||
namespace Android {
|
||||
namespace Internal {
|
||||
class JavaIndenter : public TextEditor::Indenter
|
||||
class JavaIndenter : public TextEditor::TextIndenter
|
||||
{
|
||||
public:
|
||||
JavaIndenter();
|
||||
explicit JavaIndenter(QTextDocument *doc);
|
||||
~JavaIndenter() override;
|
||||
|
||||
bool isElectricCharacter(const QChar &ch) const override;
|
||||
|
||||
void indentBlock(QTextDocument *doc,
|
||||
const QTextBlock &block,
|
||||
void indentBlock(const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user