Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQmlJS::Dom::LineWriter Class Reference

#include <qqmldomlinewriter_p.h>

+ Inheritance diagram for QQmlJS::Dom::LineWriter:
+ Collaboration diagram for QQmlJS::Dom::LineWriter:

Public Types

enum class  TextAddType {
  Normal , Extra , Newline , NewlineSplit ,
  NewlineExtra , PartialCommit , Eof
}
 

Public Member Functions

 LineWriter (SinkF innerSink, QString fileName, const LineWriterOptions &options=LineWriterOptions(), int lineNr=0, int columnNr=0, int utf16Offset=0, QString currentLine=QString())
 
std::function< void(QStringView)> sink ()
 
virtual ~LineWriter ()
 
QList< SinkFinnerSinks ()
 
void addInnerSink (SinkF s)
 
LineWriterensureNewline (int nNewlines=1, TextAddType t=TextAddType::Extra)
 
LineWriterensureSpace (TextAddType t=TextAddType::Extra)
 
LineWriterensureSpace (QStringView space, TextAddType t=TextAddType::Extra)
 
LineWriternewline ()
 
LineWriterspace ()
 
LineWriterwrite (QStringView v, TextAddType tType=TextAddType::Normal)
 
LineWriterwrite (QStringView v, SourceLocation *toUpdate)
 
void commitLine (QString eol, TextAddType t=TextAddType::Normal, int untilChar=-1)
 
void flush ()
 
void eof (bool ensureNewline=true)
 
SourceLocation committedLocation () const
 
PendingSourceLocationId startSourceLocation (SourceLocation *)
 
PendingSourceLocationId startSourceLocation (std::function< void(SourceLocation)>)
 
void endSourceLocation (PendingSourceLocationId)
 
quint32 counter () const
 
int addTextAddCallback (std::function< bool(LineWriter &, TextAddType)> callback)
 
bool removeTextAddCallback (int i)
 
int addNewlinesAutospacerCallback (int nLines)
 
void handleTrailingSpace (LineWriterOptions::TrailingSpace s)
 
void setLineIndent (int indentAmount)
 
QString fileName () const
 
const QStringcurrentLine () const
 
const LineWriterOptionsoptions () const
 
virtual void lineChanged ()
 
virtual void reindentAndSplit (QString eol, bool eof=false)
 
virtual void willCommit ()
 

Protected Member Functions

void changeAtOffset (quint32 offset, qint32 change, qint32 colChange, qint32 lineChange)
 
QString eolToWrite () const
 
SourceLocation currentSourceLocation () const
 
int column (int localIndex)
 
void textAddCallback (TextAddType t)
 

Protected Attributes

QList< SinkFm_innerSinks
 
QString m_fileName
 
int m_lineNr = 0
 
int m_columnNr = 0
 
int m_lineUtf16Offset = 0
 
int m_currentColumnNr = 0
 
int m_utf16Offset = 0
 
QString m_currentLine
 
LineWriterOptions m_options
 
PendingSourceLocationId m_lastSourceLocationId
 
QMap< PendingSourceLocationId, PendingSourceLocationm_pendingSourceLocations
 
QAtomicInt m_lastCallbackId
 
QMap< int, std::function< bool(LineWriter &, TextAddType)> > m_textAddCallbacks
 
quint32 m_counter = 0
 
quint32 m_committedEmptyLines = 0x7FFFFFFF
 
bool m_reindent = true
 

Detailed Description

Definition at line 121 of file qqmldomlinewriter_p.h.

Member Enumeration Documentation

◆ TextAddType

Enumerator
Normal 
Extra 
Newline 
NewlineSplit 
NewlineExtra 
PartialCommit 
Eof 

Definition at line 125 of file qqmldomlinewriter_p.h.

Constructor & Destructor Documentation

◆ LineWriter()

QQmlJS::Dom::LineWriter::LineWriter ( SinkF  innerSink,
QString  fileName,
const LineWriterOptions options = LineWriterOptions(),
int  lineNr = 0,
int  columnNr = 0,
int  utf16Offset = 0,
QString  currentLine = QString() 
)

Definition at line 53 of file qqmldomlinewriter.cpp.

◆ ~LineWriter()

virtual QQmlJS::Dom::LineWriter::~LineWriter ( )
inlinevirtual

Definition at line 143 of file qqmldomlinewriter_p.h.

Member Function Documentation

◆ addInnerSink()

void QQmlJS::Dom::LineWriter::addInnerSink ( SinkF  s)
inline

Definition at line 146 of file qqmldomlinewriter_p.h.

Referenced by QQmlJS::Dom::OutWriter::OutWriter().

+ Here is the caller graph for this function:

◆ addNewlinesAutospacerCallback()

int QQmlJS::Dom::LineWriter::addNewlinesAutospacerCallback ( int  nLines)

Definition at line 257 of file qqmldomlinewriter.cpp.

References addTextAddCallback(), Extra, QString::isEmpty(), QStringView::isEmpty(), Normal, and QStringView::trimmed().

Referenced by QQmlJS::Dom::OutWriter::addNewlinesAutospacerCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTextAddCallback()

int QQmlJS::Dom::LineWriter::addTextAddCallback ( std::function< bool(LineWriter &, TextAddType)>  callback)

Definition at line 248 of file qqmldomlinewriter.cpp.

References m_lastCallbackId, m_textAddCallbacks, nextId, and Q_ASSERT.

Referenced by QQmlJS::Dom::OutWriter::OutWriter(), addNewlinesAutospacerCallback(), and QQmlJS::Dom::OutWriter::addTextAddCallback().

+ Here is the caller graph for this function:

◆ changeAtOffset()

void QQmlJS::Dom::LineWriter::changeAtOffset ( quint32  offset,
qint32  change,
qint32  colChange,
qint32  lineChange 
)
protected

Definition at line 338 of file qqmldomlinewriter.cpp.

References i, and m_pendingSourceLocations.

Referenced by commitLine(), ensureSpace(), handleTrailingSpace(), QQmlJS::Dom::IndentingLineWriter::reindentAndSplit(), and setLineIndent().

+ Here is the caller graph for this function:

◆ column()

int QQmlJS::Dom::LineWriter::column ( int  localIndex)
protected

Definition at line 348 of file qqmldomlinewriter.cpp.

References QQmlJS::Dom::IndentInfo::column, QQmlJS::Dom::LineWriterOptions::formatOptions, m_columnNr, m_currentLine, m_options, QString::size(), and QQmlJS::Dom::FormatOptions::tabSize.

+ Here is the call graph for this function:

◆ commitLine()

void QQmlJS::Dom::LineWriter::commitLine ( QString  eol,
TextAddType  t = TextAddType::Normal,
int  untilChar = -1 
)

Definition at line 373 of file qqmldomlinewriter.cpp.

References changeAtOffset(), QString::clear(), Eof, Extra, i, QString::isEmpty(), QStringView::isEmpty(), lineChanged(), m_columnNr, m_committedEmptyLines, m_currentColumnNr, m_currentLine, m_innerSinks, m_lineNr, m_lineUtf16Offset, m_pendingSourceLocations, m_utf16Offset, QStringView::mid(), QString::mid(), Newline, NewlineExtra, NewlineSplit, Normal, PartialCommit, sink(), QString::size(), textAddCallback(), QStringView::trimmed(), and willCommit().

Referenced by flush(), reindentAndSplit(), and QQmlJS::Dom::IndentingLineWriter::reindentAndSplit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ committedLocation()

SourceLocation QQmlJS::Dom::LineWriter::committedLocation ( ) const

Definition at line 209 of file qqmldomlinewriter.cpp.

References m_lineNr, m_lineUtf16Offset, and m_utf16Offset.

◆ counter()

quint32 QQmlJS::Dom::LineWriter::counter ( ) const
inline

Definition at line 176 of file qqmldomlinewriter_p.h.

Referenced by QQmlJS::Dom::OutWriter::counter(), and ensureSpace().

+ Here is the caller graph for this function:

◆ currentLine()

const QString & QQmlJS::Dom::LineWriter::currentLine ( ) const
inline

Definition at line 183 of file qqmldomlinewriter_p.h.

Referenced by QQmlJS::Dom::OutWriter::OutWriter().

+ Here is the caller graph for this function:

◆ currentSourceLocation()

SourceLocation QQmlJS::Dom::LineWriter::currentSourceLocation ( ) const
protected

Definition at line 332 of file qqmldomlinewriter.cpp.

References m_currentLine, m_lineNr, m_lineUtf16Offset, m_utf16Offset, and QString::size().

Referenced by startSourceLocation(), and startSourceLocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endSourceLocation()

void QQmlJS::Dom::LineWriter::endSourceLocation ( PendingSourceLocationId  slId)

Definition at line 234 of file qqmldomlinewriter.cpp.

References m_currentLine, m_pendingSourceLocations, m_utf16Offset, qWarning, and QString::size().

Referenced by QQmlJS::Dom::OutWriter::regionEnd(), and QQmlJS::Dom::Comment::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureNewline()

LineWriter & QQmlJS::Dom::LineWriter::ensureNewline ( int  nNewlines = 1,
TextAddType  t = TextAddType::Extra 
)

Definition at line 66 of file qqmldomlinewriter.cpp.

References i, QString::isEmpty(), m_committedEmptyLines, m_currentLine, QString::trimmed(), and write().

Referenced by QQmlJS::Dom::OutWriter::ensureNewline(), ensureSpace(), and eof().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureSpace() [1/2]

◆ ensureSpace() [2/2]

LineWriter & QQmlJS::Dom::LineWriter::ensureSpace ( TextAddType  t = TextAddType::Extra)

Definition at line 82 of file qqmldomlinewriter.cpp.

References QString::at(), QString::isEmpty(), QChar::isSpace(), m_currentLine, QString::size(), and write().

Referenced by QQmlJS::Dom::OutWriter::ensureSpace(), and QQmlJS::Dom::OutWriter::ensureSpace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eof()

void QQmlJS::Dom::LineWriter::eof ( bool  ensureNewline = true)

Definition at line 202 of file qqmldomlinewriter.cpp.

References ensureNewline(), and reindentAndSplit().

Referenced by QQmlJS::Dom::OutWriter::eof(), reindentAndSplit(), and QQmlJS::Dom::IndentingLineWriter::reindentAndSplit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eolToWrite()

QString QQmlJS::Dom::LineWriter::eolToWrite ( ) const
protected

Definition at line 126 of file qqmldomlinewriter.cpp.

References QQmlJS::Dom::LineWriterOptions::lineEndings, m_options, QQmlJS::Dom::LineWriterOptions::OldMacOs, Q_ASSERT, QStringLiteral, QQmlJS::Dom::LineWriterOptions::Unix, and QQmlJS::Dom::LineWriterOptions::Windows.

Referenced by QQmlJS::Dom::IndentingLineWriter::reindentAndSplit(), and write().

+ Here is the caller graph for this function:

◆ fileName()

QString QQmlJS::Dom::LineWriter::fileName ( ) const
inline

Definition at line 182 of file qqmldomlinewriter_p.h.

◆ flush()

void QQmlJS::Dom::LineWriter::flush ( )

Definition at line 196 of file qqmldomlinewriter.cpp.

References commitLine(), m_currentLine, and QString::size().

Referenced by QQmlJS::Dom::OutWriter::flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleTrailingSpace()

void QQmlJS::Dom::LineWriter::handleTrailingSpace ( LineWriterOptions::TrailingSpace  s)

Definition at line 302 of file qqmldomlinewriter.cpp.

References QString::at(), changeAtOffset(), QChar::isSpace(), lineChanged(), m_currentColumnNr, m_currentLine, m_utf16Offset, QString::mid(), QQmlJS::Dom::LineWriterOptions::Preserve, QQmlJS::Dom::LineWriterOptions::Remove, and QString::size().

Referenced by reindentAndSplit(), and QQmlJS::Dom::IndentingLineWriter::reindentAndSplit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ innerSinks()

QList< SinkF > QQmlJS::Dom::LineWriter::innerSinks ( )
inline

Definition at line 145 of file qqmldomlinewriter_p.h.

◆ lineChanged()

virtual void QQmlJS::Dom::LineWriter::lineChanged ( )
inlinevirtual

Reimplemented in QQmlJS::Dom::IndentingLineWriter.

Definition at line 185 of file qqmldomlinewriter_p.h.

Referenced by commitLine(), ensureSpace(), handleTrailingSpace(), setLineIndent(), and write().

+ Here is the caller graph for this function:

◆ newline()

LineWriter & QQmlJS::Dom::LineWriter::newline ( )
inline

Definition at line 151 of file qqmldomlinewriter_p.h.

References write().

Referenced by QQmlJS::Dom::OutWriter::newline().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ options()

const LineWriterOptions & QQmlJS::Dom::LineWriter::options ( ) const
inline

Definition at line 184 of file qqmldomlinewriter_p.h.

References m_options.

Referenced by QQmlJS::Dom::OutWriter::decreaseIndent(), QQmlJS::Dom::OutWriter::increaseIndent(), QQmlJS::Dom::OutWriter::itemStart(), QQmlJS::Dom::OutWriter::regionEnd(), and QQmlJS::Dom::OutWriter::regionStart().

+ Here is the caller graph for this function:

◆ reindentAndSplit()

void QQmlJS::Dom::LineWriter::reindentAndSplit ( QString  eol,
bool  eof = false 
)
virtual

Reimplemented in QQmlJS::Dom::IndentingLineWriter.

Definition at line 323 of file qqmldomlinewriter.cpp.

References QQmlJS::Dom::LineWriterOptions::codeTrailingSpace, commitLine(), eof(), handleTrailingSpace(), QString::isEmpty(), and m_options.

Referenced by eof(), and write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeTextAddCallback()

bool QQmlJS::Dom::LineWriter::removeTextAddCallback ( int  i)
inline

Definition at line 178 of file qqmldomlinewriter_p.h.

References i.

Referenced by QQmlJS::Dom::OutWriter::removeTextAddCallback().

+ Here is the caller graph for this function:

◆ setLineIndent()

void QQmlJS::Dom::LineWriter::setLineIndent ( int  indentAmount)

Definition at line 276 of file qqmldomlinewriter.cpp.

References QString::at(), changeAtOffset(), QQmlJS::Dom::LineWriterOptions::formatOptions, QChar::isSpace(), lineChanged(), m_currentColumnNr, m_currentLine, m_options, m_utf16Offset, QString::mid(), QStringLiteral, QString::size(), QQmlJS::Dom::FormatOptions::tabSize, and QQmlJS::Dom::FormatOptions::useTabs.

Referenced by QQmlJS::Dom::OutWriter::OutWriter(), and QQmlJS::Dom::IndentingLineWriter::reindentAndSplit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sink()

std::function< void(QStringView)> QQmlJS::Dom::LineWriter::sink ( )
inline

Definition at line 138 of file qqmldomlinewriter_p.h.

References write().

Referenced by commitLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ space()

LineWriter & QQmlJS::Dom::LineWriter::space ( )
inline

Definition at line 156 of file qqmldomlinewriter_p.h.

References write().

Referenced by ensureSpace(), and QQmlJS::Dom::OutWriter::space().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startSourceLocation() [1/2]

PendingSourceLocationId QQmlJS::Dom::LineWriter::startSourceLocation ( SourceLocation toUpdate)

Definition at line 214 of file qqmldomlinewriter.cpp.

References currentSourceLocation(), m_lastSourceLocationId, and m_pendingSourceLocations.

Referenced by QQmlJS::Dom::OutWriter::itemStart(), QQmlJS::Dom::OutWriter::regionStart(), and QQmlJS::Dom::Comment::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startSourceLocation() [2/2]

PendingSourceLocationId QQmlJS::Dom::LineWriter::startSourceLocation ( std::function< void(SourceLocation)>  updater)

Definition at line 224 of file qqmldomlinewriter.cpp.

References currentSourceLocation(), m_lastSourceLocationId, and m_pendingSourceLocations.

+ Here is the call graph for this function:

◆ textAddCallback()

void QQmlJS::Dom::LineWriter::textAddCallback ( LineWriter::TextAddType  t)
protected

Definition at line 357 of file qqmldomlinewriter.cpp.

References it, and m_textAddCallbacks.

Referenced by commitLine(), and write().

+ Here is the caller graph for this function:

◆ willCommit()

virtual void QQmlJS::Dom::LineWriter::willCommit ( )
inlinevirtual

Reimplemented in QQmlJS::Dom::IndentingLineWriter.

Definition at line 187 of file qqmldomlinewriter_p.h.

Referenced by commitLine().

+ Here is the caller graph for this function:

◆ write() [1/2]

LineWriter & QQmlJS::Dom::LineWriter::write ( QStringView  v,
SourceLocation toUpdate 
)
inline

Definition at line 162 of file qqmldomlinewriter_p.h.

References write().

+ Here is the call graph for this function:

◆ write() [2/2]

LineWriter & QQmlJS::Dom::LineWriter::write ( QStringView  v,
TextAddType  tType = TextAddType::Normal 
)

Definition at line 146 of file qqmldomlinewriter.cpp.

References QString::append(), QQmlJS::Dom::IndentInfo::column, eolToWrite(), QQmlJS::Dom::LineWriterOptions::formatOptions, i, QString::isEmpty(), QStringView::isEmpty(), lineChanged(), m_counter, m_currentColumnNr, m_currentLine, m_options, QQmlJS::Dom::matchHelper(), QQmlJS::Dom::LineWriterOptions::maxLineLength, QStringView::mid(), reindentAndSplit(), QQmlJS::Dom::FormatOptions::tabSize, textAddCallback(), QStringView::trimmed(), and write().

Referenced by ensureNewline(), ensureSpace(), ensureSpace(), QQmlJS::Dom::OutWriter::write(), QQmlJS::Dom::OutWriter::write(), write(), and QQmlJS::Dom::OutWriter::writeRegion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_columnNr

int QQmlJS::Dom::LineWriter::m_columnNr = 0
protected

◆ m_committedEmptyLines

quint32 QQmlJS::Dom::LineWriter::m_committedEmptyLines = 0x7FFFFFFF
protected

Definition at line 213 of file qqmldomlinewriter_p.h.

Referenced by commitLine(), and ensureNewline().

◆ m_counter

quint32 QQmlJS::Dom::LineWriter::m_counter = 0
protected

Definition at line 212 of file qqmldomlinewriter_p.h.

Referenced by write().

◆ m_currentColumnNr

int QQmlJS::Dom::LineWriter::m_currentColumnNr = 0
protected

◆ m_currentLine

◆ m_fileName

QString QQmlJS::Dom::LineWriter::m_fileName
protected

Definition at line 199 of file qqmldomlinewriter_p.h.

◆ m_innerSinks

QList<SinkF> QQmlJS::Dom::LineWriter::m_innerSinks
protected

Definition at line 198 of file qqmldomlinewriter_p.h.

Referenced by commitLine().

◆ m_lastCallbackId

QAtomicInt QQmlJS::Dom::LineWriter::m_lastCallbackId
protected

Definition at line 210 of file qqmldomlinewriter_p.h.

Referenced by addTextAddCallback().

◆ m_lastSourceLocationId

PendingSourceLocationId QQmlJS::Dom::LineWriter::m_lastSourceLocationId
protected

Definition at line 208 of file qqmldomlinewriter_p.h.

Referenced by startSourceLocation(), and startSourceLocation().

◆ m_lineNr

int QQmlJS::Dom::LineWriter::m_lineNr = 0
protected

Definition at line 200 of file qqmldomlinewriter_p.h.

Referenced by commitLine(), committedLocation(), and currentSourceLocation().

◆ m_lineUtf16Offset

int QQmlJS::Dom::LineWriter::m_lineUtf16Offset = 0
protected

Definition at line 202 of file qqmldomlinewriter_p.h.

Referenced by commitLine(), committedLocation(), and currentSourceLocation().

◆ m_options

◆ m_pendingSourceLocations

QMap<PendingSourceLocationId, PendingSourceLocation> QQmlJS::Dom::LineWriter::m_pendingSourceLocations
protected

◆ m_reindent

bool QQmlJS::Dom::LineWriter::m_reindent = true
protected

◆ m_textAddCallbacks

QMap<int, std::function<bool(LineWriter &, TextAddType)> > QQmlJS::Dom::LineWriter::m_textAddCallbacks
protected

Definition at line 211 of file qqmldomlinewriter_p.h.

Referenced by addTextAddCallback(), and textAddCallback().

◆ m_utf16Offset


The documentation for this class was generated from the following files: