Commit 53335c2f authored by Jochen Becher's avatar Jochen Becher

ModelEditor: Apply some source code formatting rules

1. Reduce 2 or more empty lines to a single empty line
2. Remove duplicate access specifiers
3. Remove lots of single empty lines between member declarations
4. Remove braces around single lines
5. List base classes on same line as class declaration
6. Ensure opening brace of class declaration is on next line
7. Add comment to end of namespace block

Change-Id: I95e2efa3abea806683e0943d54d6f203ad4af0e4
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent f3902fff
......@@ -42,7 +42,6 @@
#include <QDebug>
namespace qmt {
class ConfigController::ConfigControllerPrivate
......
......@@ -40,35 +40,24 @@ class StereotypeController;
class StereotypeIcon;
class Toolbar;
class QMT_EXPORT ConfigController : public QObject
{
Q_OBJECT
class ConfigControllerPrivate;
public:
explicit ConfigController(QObject *parent = 0);
~ConfigController();
public:
void setStereotypeController(StereotypeController *stereotypeController);
public:
void readStereotypeDefinitions(const QString &path);
private slots:
void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon);
void onToolbarParsed(const Toolbar &toolbar);
private:
ConfigControllerPrivate *d;
};
......
......@@ -38,21 +38,13 @@ namespace qmt {
class QMT_EXPORT SourcePos
{
public:
SourcePos();
SourcePos(int sourceId, int lineNumber, int columnNumber = -1);
public:
bool isValid() const { return m_sourceId >= 0 && m_lineNumber >= 0; }
int sourceId() const { return m_sourceId; }
int lineNumber() const { return m_lineNumber; }
bool hasColumnNumber() const { return m_columnNumber >= 0; }
int columnNumber() const { return m_columnNumber; }
private:
......
......@@ -87,26 +87,22 @@ static const int OPERATOR_COMMA = 3;
static const int OPERATOR_PERIOD = 4;
static const int OPERATOR_MINUS = 5;
template <typename T, typename U>
QHash<T, U> operator<<(QHash<T, U> hash, QPair<T, U> pair) {
hash.insert(pair.first, pair.second);
return hash;
}
StereotypeDefinitionParserError::StereotypeDefinitionParserError(const QString &errorMsg, const SourcePos &sourcePos)
: Exception(errorMsg),
m_sourcePos(sourcePos)
{
}
StereotypeDefinitionParserError::~StereotypeDefinitionParserError()
{
}
class StereotypeDefinitionParser::StereotypeDefinitionParserPrivate
{
public:
......@@ -119,7 +115,6 @@ public:
};
class StereotypeDefinitionParser::IconCommandParameter
{
public:
......@@ -133,7 +128,6 @@ public:
ShapeValueF::Origin m_origin;
};
StereotypeDefinitionParser::StereotypeDefinitionParser(QObject *parent) :
QObject(parent),
d(new StereotypeDefinitionParserPrivate)
......@@ -204,43 +198,38 @@ void StereotypeDefinitionParser::parseFile()
{
for (;;) {
Token token = readNextToken();
if (token.type() == Token::TokenEndOfInput) {
if (token.type() == Token::TokenEndOfInput)
break;
} else if (token.type() != Token::TokenKeyword || token.subtype() == KEYWORD_ICON) {
else if (token.type() != Token::TokenKeyword || token.subtype() == KEYWORD_ICON)
parseIcon();
} else if (token.type() != Token::TokenKeyword || token.subtype() == KEYWORD_TOOLBAR) {
else if (token.type() != Token::TokenKeyword || token.subtype() == KEYWORD_TOOLBAR)
parseToolbar();
} else {
else
throw StereotypeDefinitionParserError(QStringLiteral("Expected 'icon' or 'toolbar'."), token.sourcePos());
}
token = d->m_scanner->read();
if (token.type() == Token::TokenOperator && token.subtype() == OPERATOR_PERIOD) {
if (token.type() == Token::TokenOperator && token.subtype() == OPERATOR_PERIOD)
break;
} else if (token.type() != Token::TokenOperator || token.subtype() != OPERATOR_SEMICOLON) {
else if (token.type() != Token::TokenOperator || token.subtype() != OPERATOR_SEMICOLON)
d->m_scanner->unread(token);
}
}
}
void StereotypeDefinitionParser::parseIcon()
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword) {
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword)
throw StereotypeDefinitionParserError(QStringLiteral("Expected identifier."), token.sourcePos());
}
QString id = token.text();
StereotypeIcon stereotypeIcon;
stereotypeIcon.setId(id);
parseIconProperties(&stereotypeIcon);
token = readNextToken();
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_BEGIN) {
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_BEGIN)
throw StereotypeDefinitionParserError(QStringLiteral("Expected token 'begin'."), token.sourcePos());
}
parseIconCommands(&stereotypeIcon);
token = readNextToken();
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_END) {
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_END)
throw StereotypeDefinitionParserError(QStringLiteral("Expected token 'end'."), token.sourcePos());
}
emit iconParsed(stereotypeIcon);
}
......@@ -271,9 +260,8 @@ void StereotypeDefinitionParser::parseIconProperties(StereotypeIcon *stereotypeI
<< qMakePair(QString(QStringLiteral("diagram")), StereotypeIcon::ElementDiagram)
<< qMakePair(QString(QStringLiteral("item")), StereotypeIcon::ElementItem);
QString elementName = identifier.toLower();
if (!elementNames.contains(elementName)) {
if (!elementNames.contains(elementName))
throw StereotypeDefinitionParserError(QString(QStringLiteral("Unexpected value \"%1\" for element.")).arg(identifier), token.sourcePos());
}
elements.insert(elementNames.value(elementName));
}
expectSemicolonOrEndOfLine();
......@@ -369,22 +357,19 @@ void StereotypeDefinitionParser::parseIconProperties(StereotypeIcon *stereotypeI
void StereotypeDefinitionParser::parseToolbar()
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword) {
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword)
throw StereotypeDefinitionParserError(QStringLiteral("Expected identifier."), token.sourcePos());
}
QString id = token.text();
Toolbar toolbar;
toolbar.setId(id);
parseToolbarProperties(&toolbar);
token = readNextToken();
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_BEGIN) {
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_BEGIN)
throw StereotypeDefinitionParserError(QStringLiteral("Expected token 'begin'."), token.sourcePos());
}
parseToolbarCommands(&toolbar);
token = readNextToken();
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_END) {
if (token.type() != Token::TokenKeyword || token.subtype() != KEYWORD_END)
throw StereotypeDefinitionParserError(QStringLiteral("Expected token 'end'."), token.sourcePos());
}
emit toolbarParsed(toolbar);
}
......@@ -564,22 +549,20 @@ QList<ShapeValueF> StereotypeDefinitionParser::parseIconCommandParameters(const
QList<ShapeValueF> values;
Token token;
for (;;) {
if (values.count() <= parameters.count()) {
if (values.count() <= parameters.count())
values << ShapeValueF(parseFloatExpression(), parameters.at(values.count()).m_unit, parameters.at(values.count()).m_origin);
} else {
else
values << ShapeValueF(parseFloatExpression());
}
token = d->m_scanner->read();
if (token.type() != Token::TokenOperator || token.subtype() != OPERATOR_COMMA) {
d->m_scanner->unread(token);
break;
}
}
if (values.count() < parameters.count()) {
if (values.count() < parameters.count())
throw StereotypeDefinitionParserError(QStringLiteral("More parameters expected."), token.sourcePos());
} else if (values.count() > parameters.count()) {
else if (values.count() > parameters.count())
throw StereotypeDefinitionParserError(QStringLiteral("Too many parameters given."), token.sourcePos());
}
return values;
}
......@@ -607,13 +590,11 @@ void StereotypeDefinitionParser::parseToolbarCommands(Toolbar *toolbar)
<< QStringLiteral("annotation")
<< QStringLiteral("boundary");
QString elementName = element.toLower();
if (!elementNames.contains(elementName)) {
if (!elementNames.contains(elementName))
throw StereotypeDefinitionParserError(QString(QStringLiteral("Unexpected value \"%1\" for element.")).arg(element), token.sourcePos());
}
QString stereotype;
if (nextIsComma()) {
if (nextIsComma())
stereotype = parseStringExpression();
}
tools.append(Toolbar::Tool(toolName, element, stereotype));
expectSemicolonOrEndOfLine();
break;
......@@ -635,9 +616,8 @@ void StereotypeDefinitionParser::parseToolbarCommands(Toolbar *toolbar)
QString StereotypeDefinitionParser::parseStringExpression()
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenString) {
if (token.type() != Token::TokenString)
throw StereotypeDefinitionParserError(QStringLiteral("Expected string constant."), token.sourcePos());
}
return token.text();
}
......@@ -684,9 +664,8 @@ int StereotypeDefinitionParser::parseIntExpression()
QString StereotypeDefinitionParser::parseIdentifierExpression()
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword) {
if (token.type() != Token::TokenIdentifier && token.type() != Token::TokenKeyword)
throw StereotypeDefinitionParserError(QStringLiteral("Expected identifier."), token.sourcePos());
}
return token.text();
}
......@@ -695,11 +674,10 @@ bool StereotypeDefinitionParser::parseBoolExpression()
Token token = d->m_scanner->read();
if (token.type() == Token::TokenIdentifier) {
QString value = token.text().toLower();
if (value == QStringLiteral("yes") || value == QStringLiteral("true")) {
if (value == QStringLiteral("yes") || value == QStringLiteral("true"))
return true;
} else if (value == QStringLiteral("no") || value == QStringLiteral("false")) {
else if (value == QStringLiteral("no") || value == QStringLiteral("false"))
return false;
}
}
throw StereotypeDefinitionParserError(QStringLiteral("Expected 'yes', 'no', 'true' or 'false'."), token.sourcePos());
}
......@@ -723,26 +701,23 @@ Token StereotypeDefinitionParser::readNextToken()
Token token;
for (;;) {
token = d->m_scanner->read();
if (token.type() != Token::TokenEndOfLine) {
if (token.type() != Token::TokenEndOfLine)
return token;
}
}
}
qreal StereotypeDefinitionParser::expectAbsoluteValue(const ShapeValueF &value, const SourcePos &sourcePos)
{
if (value.unit() != ShapeValueF::UnitAbsolute || value.origin() != ShapeValueF::OriginSmart) {
if (value.unit() != ShapeValueF::UnitAbsolute || value.origin() != ShapeValueF::OriginSmart)
throw StereotypeDefinitionParserError(QStringLiteral("Expected absolute value"), sourcePos);
}
return value.value();
}
void StereotypeDefinitionParser::expectSemicolonOrEndOfLine()
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenEndOfLine && (token.type() != Token::TokenOperator || token.subtype() != OPERATOR_SEMICOLON)) {
if (token.type() != Token::TokenEndOfLine && (token.type() != Token::TokenOperator || token.subtype() != OPERATOR_SEMICOLON))
throw StereotypeDefinitionParserError(QStringLiteral("Expected ';' or end-of-line."), token.sourcePos());
}
}
bool StereotypeDefinitionParser::nextIsComma()
......@@ -758,9 +733,8 @@ bool StereotypeDefinitionParser::nextIsComma()
void StereotypeDefinitionParser::expectOperator(int op, const QString &opName)
{
Token token = d->m_scanner->read();
if (token.type() != Token::TokenOperator || token.subtype() != op) {
if (token.type() != Token::TokenOperator || token.subtype() != op)
throw StereotypeDefinitionParserError(QString(QStringLiteral("Expected '%1'.")).arg(opName), token.sourcePos());
}
}
void StereotypeDefinitionParser::expectComma()
......@@ -773,4 +747,4 @@ void StereotypeDefinitionParser::expectColon()
expectOperator(OPERATOR_COLON, QStringLiteral(":"));
}
}
} // namespace qmt
......@@ -36,7 +36,6 @@
#include "sourcepos.h"
namespace qmt {
class ITextSource;
......@@ -45,111 +44,74 @@ class StereotypeIcon;
class Toolbar;
class ShapeValueF;
class QMT_EXPORT StereotypeDefinitionParserError :
public Exception
class QMT_EXPORT StereotypeDefinitionParserError : public Exception
{
public:
StereotypeDefinitionParserError(const QString &errorMsg, const SourcePos &sourcePos);
~StereotypeDefinitionParserError();
public:
SourcePos sourcePos() const { return m_sourcePos; }
private:
SourcePos m_sourcePos;
};
class QMT_EXPORT StereotypeDefinitionParser : public QObject
{
Q_OBJECT
class StereotypeDefinitionParserPrivate;
class IconCommandParameter;
public:
explicit StereotypeDefinitionParser(QObject *parent = 0);
~StereotypeDefinitionParser();
signals:
void iconParsed(const StereotypeIcon &stereotypeIcon);
void toolbarParsed(const Toolbar &toolbar);
public:
void parse(ITextSource *source);
private:
void parseFile();
void parseIcon();
void parseIconProperties(StereotypeIcon *stereotypeIcon);
void parseToolbar();
void parseToolbarProperties(Toolbar *toolbar);
QString parseStringProperty();
int parseIntProperty();
qreal parseFloatProperty();
QString parseIdentifierProperty();
QList<QString> parseIdentifierListProperty();
bool parseBoolProperty();
QColor parseColorProperty();
void parseIconCommands(StereotypeIcon *stereotypeIcon);
QList<ShapeValueF> parseIconCommandParameters(const QList<IconCommandParameter> &parameters);
void parseToolbarCommands(Toolbar *toolbar);
QString parseStringExpression();
qreal parseFloatExpression();
int parseIntExpression();
QString parseIdentifierExpression();
bool parseBoolExpression();
QColor parseColorExpression();
Token readNextToken();
qreal expectAbsoluteValue(const ShapeValueF &value, const SourcePos &sourcePos);
void expectSemicolonOrEndOfLine();
bool nextIsComma();
void expectOperator(int op, const QString &opName);
void expectComma();
void expectColon();
private:
StereotypeDefinitionParserPrivate *d;
};
}
} // namespace qmt
#endif // QMT_STEREOTYPEDEFINITIONPARSER_H
......@@ -67,9 +67,8 @@ SourceChar StringTextSource::readNextChar()
QMT_CHECK(m_lineNumber >= 0);
QMT_CHECK(m_columnNumber >= 0);
if (m_index >= m_text.length()) {
if (m_index >= m_text.length())
return SourceChar(QChar(), SourcePos(m_sourceId, m_lineNumber, m_columnNumber));
}
SourcePos pos(m_sourceId, m_lineNumber, m_columnNumber);
QChar ch(m_text.at(m_index));
......
......@@ -37,37 +37,25 @@
namespace qmt {
class QMT_EXPORT StringTextSource :
public ITextSource
class QMT_EXPORT StringTextSource : public ITextSource
{
public:
StringTextSource();
~StringTextSource();
public:
void setText(const QString &text);
int sourceId() const { return m_sourceId; }
void setSourceId(int sourceId);
// ITextSource interface
public:
SourceChar readNextChar();
private:
QString m_text;
int m_sourceId;
int m_index;
int m_lineNumber;
int m_columnNumber;
};
......
......@@ -88,9 +88,8 @@ TextScanner::~TextScanner()
void TextScanner::setKeywords(const QList<QPair<QString, int> > &keywords)
{
d->m_keywordToSubtypeMap.clear();
foreach (const DefTuple &tuple, keywords) {
foreach (const DefTuple &tuple, keywords)
d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second);
}
}
void TextScanner::setOperators(const QList<QPair<QString, int> > &operators)
......@@ -102,13 +101,11 @@ void TextScanner::setOperators(const QList<QPair<QString, int> > &operators)
foreach (const DefTuple &tuple, operators) {
QString op = tuple.first;
d->m_operatorToSubtypeMap.insert(op, tuple.second);
if (op.length() > d->m_maxOperatorLength) {
if (op.length() > d->m_maxOperatorLength)
d->m_maxOperatorLength = op.length();
}
d->m_operatorFirstCharsSet.insert(op.at(0));
foreach (const QChar ch, op) {
foreach (const QChar ch, op)
d->m_operatorCharsSet.insert(ch);
}
}
}
......@@ -124,28 +121,26 @@ SourcePos TextScanner::sourcePos() const
Token TextScanner::read()
{
if (!d->m_unreadTokens.isEmpty()) {
if (!d->m_unreadTokens.isEmpty())
return d->m_unreadTokens.pop();
}
skipWhitespaces();
SourceChar sourceChar = readChar();
if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"')) {
if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"'))
return scanString(sourceChar);
} else if (sourceChar.ch.isDigit()) {
else if (sourceChar.ch.isDigit())