NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
CodeFormatter Class Reference

This class handles all formatting features of the editor. More...

#include <codeformatter.hpp>

Collaboration diagram for CodeFormatter:

Public Member Functions

 CodeFormatter (NumeReEditor *edit)
 
void IndentCode (int nFirstLine, int nLastLine)
 Automatically indents the code based upon its hierarchy. More...
 
void FormatCode (int nFirstLine, int nLastLine)
 Applies automatic formatting to the selected code lines. More...
 

Private Member Functions

int determineIndentationLevel (int nLine, int &singleLineIndent)
 Determines the indentation level of the selected line. More...
 
int determineIndentationLevelNSCR (int nLine, int &singleLineIndent)
 Determines the indentation level of the selected line of NumeRe code. More...
 
int determineIndentationLevelMATLAB (int nLine, int &singleLineIndent)
 Determines the indentation level of the selected line of MATLAB code. More...
 
int determineIndentationLevelCPP (int nLine, int &singleLineIndent)
 Determines the indentation level of the selected line of C++ code. More...
 
void ApplyAutoFormatNSCR (int nFirstLine, int nLastLine)
 Applies autoformatting to NumeRe code. More...
 
void ApplyAutoFormatMATLAB (int nFirstLine, int nLastLine)
 Applies autoformatting to MATLAB code. More...
 
void ApplyAutoFormatCPP (int nFirstLine, int nLastLine)
 Applies autoformatting to C++ code. More...
 
int formatFunctionParentheses (int &pos, int operatorStyleNum)
 Formats the contents of function parentheses. More...
 
int formatOperators (int pos, char prevChar, char currentChar, char nextChar, bool isNSCR)
 Helper to format binary operators. More...
 
int formatStrings (int pos, bool isNSCR)
 Helper to format characters around string literals. More...
 
int insertTextAndMove (int nPosition, const wxString &sText)
 Inserts text and returns the length of the insertion. More...
 

Private Attributes

NumeReEditorm_editor
 

Detailed Description

This class handles all formatting features of the editor.

Definition at line 30 of file codeformatter.hpp.

Constructor & Destructor Documentation

◆ CodeFormatter()

CodeFormatter::CodeFormatter ( NumeReEditor edit)
inline

Definition at line 49 of file codeformatter.hpp.

Member Function Documentation

◆ ApplyAutoFormatCPP()

void CodeFormatter::ApplyAutoFormatCPP ( int  nFirstLine,
int  nLastLine 
)
private

Applies autoformatting to C++ code.

Parameters
nFirstLineint
nLastLineint
Returns
void

Definition at line 776 of file codeformatter.cpp.

References FILE_CPP, formatFunctionParentheses(), formatOperators(), formatStrings(), NumeReEditor::getFileType(), insertTextAndMove(), NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMAND, NumeReEditor::STYLE_COMMENT_BLOCK, and NumeReEditor::STYLE_COMMENT_LINE.

Referenced by FormatCode().

Here is the call graph for this function:

◆ ApplyAutoFormatMATLAB()

void CodeFormatter::ApplyAutoFormatMATLAB ( int  nFirstLine,
int  nLastLine 
)
private

Applies autoformatting to MATLAB code.

Parameters
nFirstLineint
nLastLineint
Returns
void

Definition at line 578 of file codeformatter.cpp.

References FILE_MATLAB, formatFunctionParentheses(), formatOperators(), formatStrings(), NumeReEditor::getFileType(), insertTextAndMove(), and m_editor.

Referenced by FormatCode().

Here is the call graph for this function:

◆ ApplyAutoFormatNSCR()

void CodeFormatter::ApplyAutoFormatNSCR ( int  nFirstLine,
int  nLastLine 
)
private

Applies autoformatting to NumeRe code.

Parameters
nFirstLineint
nLastLineint
Returns
void

Definition at line 340 of file codeformatter.cpp.

References FILE_NPRC, FILE_NSCR, formatFunctionParentheses(), formatOperators(), formatStrings(), NumeReEditor::getBlockID(), NumeReEditor::getFileType(), insertTextAndMove(), NumeReEditor::isBlockEnd(), NumeReEditor::isBlockStart(), NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMENT_BLOCK, and NumeReEditor::STYLE_COMMENT_LINE.

Referenced by FormatCode().

Here is the call graph for this function:

◆ determineIndentationLevel()

int CodeFormatter::determineIndentationLevel ( int  nLine,
int &  singleLineIndent 
)
private

Determines the indentation level of the selected line.

Parameters
nLineint
singleLineIndentint&
Returns
int

This function determines the indentation level of the code at the selected line by delegating this task to the language specific calculator.

Definition at line 136 of file codeformatter.cpp.

References determineIndentationLevelCPP(), determineIndentationLevelMATLAB(), determineIndentationLevelNSCR(), FILE_CPP, FILE_MATLAB, FILE_NPRC, FILE_NSCR, NumeReEditor::getFileType(), and m_editor.

Referenced by IndentCode().

Here is the call graph for this function:

◆ determineIndentationLevelCPP()

int CodeFormatter::determineIndentationLevelCPP ( int  nLine,
int &  singleLineIndent 
)
private

Determines the indentation level of the selected line of C++ code.

Parameters
nLineint
singleLineIndentint&
Returns
int

Definition at line 262 of file codeformatter.cpp.

References m_editor.

Referenced by determineIndentationLevel().

◆ determineIndentationLevelMATLAB()

int CodeFormatter::determineIndentationLevelMATLAB ( int  nLine,
int &  singleLineIndent 
)
private

Determines the indentation level of the selected line of MATLAB code.

Parameters
nLineint
singleLineIndentint&
Returns
int

Definition at line 222 of file codeformatter.cpp.

References NumeReEditor::isBlockEnd(), NumeReEditor::isBlockMiddle(), NumeReEditor::isBlockStart(), and m_editor.

Referenced by determineIndentationLevel().

Here is the call graph for this function:

◆ determineIndentationLevelNSCR()

int CodeFormatter::determineIndentationLevelNSCR ( int  nLine,
int &  singleLineIndent 
)
private

Determines the indentation level of the selected line of NumeRe code.

Parameters
nLineint
singleLineIndentint&
Returns
int

Definition at line 160 of file codeformatter.cpp.

References FILE_NSCR, NumeReEditor::getFileType(), NumeReEditor::isBlockEnd(), NumeReEditor::isBlockMiddle(), NumeReEditor::isBlockStart(), and m_editor.

Referenced by determineIndentationLevel().

Here is the call graph for this function:

◆ FormatCode()

void CodeFormatter::FormatCode ( int  nFirstLine,
int  nLastLine 
)

Applies automatic formatting to the selected code lines.

Parameters
nFirstLineint
nLastLineint
Returns
void

Formatting is done by delegating this taks to the specialized formatting function. It also indents the code automatically based upon its hierarchy.

Definition at line 311 of file codeformatter.cpp.

References ApplyAutoFormatCPP(), ApplyAutoFormatMATLAB(), ApplyAutoFormatNSCR(), FILE_CPP, FILE_MATLAB, FILE_NPRC, FILE_NSCR, NumeReEditor::getFileType(), IndentCode(), and m_editor.

Referenced by NumeReEditor::ApplyAutoFormat().

Here is the call graph for this function:

◆ formatFunctionParentheses()

int CodeFormatter::formatFunctionParentheses ( int &  pos,
int  operatorStyleNum 
)
private

Formats the contents of function parentheses.

Parameters
posint&
operatorStyleNumint
Returns
int

Definition at line 973 of file codeformatter.cpp.

References insertTextAndMove(), and m_editor.

Referenced by ApplyAutoFormatCPP(), ApplyAutoFormatMATLAB(), and ApplyAutoFormatNSCR().

Here is the call graph for this function:

◆ formatOperators()

int CodeFormatter::formatOperators ( int  pos,
char  prevChar,
char  currentChar,
char  nextChar,
bool  isNSCR 
)
private

Helper to format binary operators.

Parameters
posint
prevCharchar
currentCharchar
nextCharchar
isNSCRbool
Returns
int

Definition at line 1024 of file codeformatter.cpp.

References insertTextAndMove(), and m_editor.

Referenced by ApplyAutoFormatCPP(), ApplyAutoFormatMATLAB(), and ApplyAutoFormatNSCR().

Here is the call graph for this function:

◆ formatStrings()

int CodeFormatter::formatStrings ( int  pos,
bool  isNSCR 
)
private

Helper to format characters around string literals.

Parameters
posint
isNSCRbool
Returns
int

Definition at line 1082 of file codeformatter.cpp.

References insertTextAndMove(), and m_editor.

Referenced by ApplyAutoFormatCPP(), ApplyAutoFormatMATLAB(), and ApplyAutoFormatNSCR().

Here is the call graph for this function:

◆ IndentCode()

void CodeFormatter::IndentCode ( int  nFirstLine,
int  nLastLine 
)

Automatically indents the code based upon its hierarchy.

Parameters
nFirstLineint
nLastLineint
Returns
void

Definition at line 51 of file codeformatter.cpp.

References determineIndentationLevel(), FILE_CPP, NumeReEditor::getFileType(), NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMENT_BLOCK, and NumeReEditor::STYLE_COMMENT_LINE.

Referenced by NumeReEditor::ApplyAutoIndentation(), and FormatCode().

Here is the call graph for this function:

◆ insertTextAndMove()

int CodeFormatter::insertTextAndMove ( int  nPosition,
const wxString &  sText 
)
private

Inserts text and returns the length of the insertion.

Parameters
nPositionint
sTextconst wxString&
Returns
int

This is a simple helper function to simplify keeping track of the actual insertion position.

Definition at line 35 of file codeformatter.cpp.

References m_editor.

Referenced by ApplyAutoFormatCPP(), ApplyAutoFormatMATLAB(), ApplyAutoFormatNSCR(), formatFunctionParentheses(), formatOperators(), and formatStrings().

Member Data Documentation

◆ m_editor


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