Commit 6aceadac authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Fix "! condition" coding style

Change-Id: I216b74933f5e94c49be7f05f0b09ac01b3319d8c
Reviewed-by: default avatarAurindam Jana <aurindam.jana@digia.com>
parent dbb1cb84
......@@ -50,12 +50,12 @@ bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
{
QChar ch;
if (! textToInsert.isEmpty())
if (!textToInsert.isEmpty())
ch = textToInsert.at(0);
if (! (MatchingText::shouldInsertMatchingText(cursor)
|| ch == QLatin1Char('\'')
|| ch == QLatin1Char('"')))
if (!(MatchingText::shouldInsertMatchingText(cursor)
|| ch == QLatin1Char('\'')
|| ch == QLatin1Char('"')))
return false;
else if (isInCommentHelper(cursor))
return false;
......
......@@ -243,7 +243,7 @@ struct CanonicalSymbol
const QTextCursor &cursor,
QString *code)
{
if (! info.doc)
if (!info.doc)
return 0;
QTextCursor tc = cursor;
......@@ -255,8 +255,8 @@ struct CanonicalSymbol
int pos = tc.position();
if (! isIdentifierChar(document->characterAt(pos)))
if (! (pos > 0 && isIdentifierChar(document->characterAt(pos - 1))))
if (!isIdentifierChar(document->characterAt(pos)))
if (!(pos > 0 && isIdentifierChar(document->characterAt(pos - 1))))
return 0;
while (isIdentifierChar(document->characterAt(pos)))
......@@ -293,7 +293,7 @@ struct CanonicalSymbol
const LookupItem &r = results.at(i);
Symbol *decl = r.declaration();
if (! (decl && decl->enclosingScope()))
if (!(decl && decl->enclosingScope()))
break;
if (Class *classScope = r.declaration()->enclosingScope()->asClass()) {
......@@ -771,7 +771,7 @@ void CPPEditorWidget::onDocumentUpdated()
const Macro *CPPEditorWidget::findCanonicalMacro(const QTextCursor &cursor, Document::Ptr doc) const
{
if (! doc)
if (!doc)
return 0;
int line, col;
......@@ -883,7 +883,7 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
{
abortRename();
if (! info.doc)
if (!info.doc)
return;
if (const Macro *macro = findCanonicalMacro(textCursor(), info.doc)) {
......@@ -934,7 +934,7 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
} else {
const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection);
if (! selections.isEmpty())
if (!selections.isEmpty())
setExtraSelections(CodeSemanticsSelection, QList<QTextEdit::ExtraSelection>());
}
}
......@@ -1011,7 +1011,7 @@ void CPPEditorWidget::jumpToOutlineElement(int index)
modelIndex = m_proxyModel->index(index, 0); // toplevel index
QModelIndex sourceIndex = m_proxyModel->mapToSource(modelIndex);
Symbol *symbol = m_outlineModel->symbolFromIndex(sourceIndex);
if (! symbol)
if (!symbol)
return;
openCppEditorAt(linkToSymbol(symbol));
......@@ -1248,10 +1248,10 @@ static inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolv
const FullySpecifiedType ty = result.type().simplified();
if (ty->isForwardClassDeclarationType()) {
while (! candidates.isEmpty()) {
while (!candidates.isEmpty()) {
LookupItem r = candidates.takeFirst();
if (! r.type()->isForwardClassDeclarationType()) {
if (!r.type()->isForwardClassDeclarationType()) {
result = r;
break;
}
......@@ -1259,10 +1259,10 @@ static inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolv
}
if (ty->isObjCForwardClassDeclarationType()) {
while (! candidates.isEmpty()) {
while (!candidates.isEmpty()) {
LookupItem r = candidates.takeFirst();
if (! r.type()->isObjCForwardClassDeclarationType()) {
if (!r.type()->isObjCForwardClassDeclarationType()) {
result = r;
break;
}
......@@ -1270,10 +1270,10 @@ static inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolv
}
if (ty->isObjCForwardProtocolDeclarationType()) {
while (! candidates.isEmpty()) {
while (!candidates.isEmpty()) {
LookupItem r = candidates.takeFirst();
if (! r.type()->isObjCForwardProtocolDeclarationType()) {
if (!r.type()->isObjCForwardProtocolDeclarationType()) {
result = r;
break;
}
......@@ -1359,7 +1359,7 @@ CPPEditorWidget::Link CPPEditorWidget::attemptFuncDeclDef(const QTextCursor &cur
CPPEditorWidget::Link CPPEditorWidget::findMacroLink(const QByteArray &name) const
{
if (! name.isEmpty()) {
if (!name.isEmpty()) {
if (Document::Ptr doc = m_lastSemanticInfo.doc) {
const Snapshot snapshot = m_modelManager->snapshot();
QSet<QString> processed;
......@@ -1375,7 +1375,7 @@ CPPEditorWidget::Link CPPEditorWidget::findMacroLink(const QByteArray &name,
const Snapshot &snapshot,
QSet<QString> *processed) const
{
if (doc && ! name.startsWith('<') && ! processed->contains(doc->fileName())) {
if (doc && !name.startsWith('<') && !processed->contains(doc->fileName())) {
processed->insert(doc->fileName());
foreach (const Macro &macro, doc->definedMacros()) {
......@@ -1476,7 +1476,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, boo
if (tokens.at(j).is(T_LPAREN)) {
++depth;
} else if (tokens.at(j).is(T_RPAREN)) {
if (! --depth)
if (!--depth)
break;
}
}
......@@ -1508,7 +1508,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, boo
const QTextBlock block = tc.block();
int pos = cursor.positionInBlock();
QChar ch = document()->characterAt(cursor.position());
if (pos > 0 && ! (ch.isLetterOrNumber() || ch == QLatin1Char('_')))
if (pos > 0 && !(ch.isLetterOrNumber() || ch == QLatin1Char('_')))
--pos; // positionInBlock points to a delimiter character.
const Token tk = SimpleLexer::tokenAt(block.text(), pos,
BackwardsScanner::previousBlockState(block), true);
......@@ -1567,7 +1567,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, boo
const QChar ch = document()->characterAt(pos);
if (ch.isSpace())
continue;
if (ch == QLatin1Char('(') && ! expression.isEmpty()) {
if (ch == QLatin1Char('(') && !expression.isEmpty()) {
tc.setPosition(pos);
if (TextEditor::TextBlockUserData::findNextClosingParenthesis(&tc, true))
expression.append(tc.selectedText());
......@@ -1648,7 +1648,7 @@ Symbol *CPPEditorWidget::findDefinition(Symbol *symbol, const Snapshot &snapshot
if (symbol->isFunction())
return 0; // symbol is a function definition.
else if (! symbol->type()->isFunctionType())
else if (!symbol->type()->isFunctionType())
return 0; // not a function declaration
return symbolFinder()->findMatchingDefinition(symbol, snapshot);
......@@ -1729,7 +1729,7 @@ void CPPEditorWidget::contextMenuEvent(QContextMenuEvent *e)
QSignalMapper mapper;
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
if (! isOutdated()) {
if (!isOutdated()) {
TextEditor::IAssistInterface *interface =
createAssistInterface(TextEditor::QuickFix, TextEditor::ExplicitlyInvoked);
if (interface) {
......@@ -2057,7 +2057,7 @@ void CPPEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
setExtraSelections(UnusedSymbolSelection, unusedSelections);
if (! m_renameSelections.isEmpty())
if (!m_renameSelections.isEmpty())
setExtraSelections(CodeSemanticsSelection, m_renameSelections); // ###
else
markSymbols(textCursor(), semanticInfo);
......
......@@ -373,7 +373,7 @@ void CppEditorPlugin::onAllTasksFinished(const QString &type)
void CppEditorPlugin::currentEditorChanged(Core::IEditor *editor)
{
if (! editor)
if (!editor)
return;
if (CPPEditorWidget *textEditor = qobject_cast<CPPEditorWidget *>(editor->widget()))
......
......@@ -175,8 +175,8 @@ void CppHighlighter::highlightBlock(const QString &text)
// we need to insert a close comment parenthesis, if
// - the line starts in a C Comment (initalState != 0)
// - the first token of the line is a T_COMMENT (i == 0 && tk.is(T_COMMENT))
// - is not a continuation line (tokens.size() > 1 || ! state)
if (initialState && i == 0 && (tokens.size() > 1 || ! state)) {
// - is not a continuation line (tokens.size() > 1 || !state)
if (initialState && i == 0 && (tokens.size() > 1 || !state)) {
--braceDepth;
// unless we are at the end of the block, we reduce the folding indent
if (i == tokens.size()-1)
......@@ -206,7 +206,7 @@ void CppHighlighter::highlightBlock(const QString &text)
if (text.length() > lastTokenEnd)
highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, m_formats[CppVisualWhitespace]);
if (! initialState && state && ! tokens.isEmpty()) {
if (!initialState && state && !tokens.isEmpty()) {
parentheses.append(Parenthesis(Parenthesis::Opened, QLatin1Char('+'),
tokens.last().begin()));
++braceDepth;
......@@ -356,7 +356,7 @@ void CppHighlighter::highlightWord(QStringRef word, int position, int length)
|| (word.at(1) == QLatin1Char('T') && word.at(2) == QLatin1Char('_'))) { // QT_
for (int i = 1; i < word.length(); ++i) {
const QChar &ch = word.at(i);
if (! (ch.isUpper() || ch == QLatin1Char('_')))
if (!(ch.isUpper() || ch == QLatin1Char('_')))
return;
}
......@@ -375,7 +375,7 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
const QTextCharFormat &format = m_formats[CppDoxygenCommentFormat];
const QTextCharFormat &kwFormat = m_formats[CppDoxygenTagFormat];
while (! it->isNull()) {
while (!it->isNull()) {
if (it->unicode() == QLatin1Char('\\') ||
it->unicode() == QLatin1Char('@')) {
++it;
......
......@@ -202,15 +202,15 @@ Class *isMemberFunction(const LookupContext &context, Function *function)
QTC_ASSERT(function, return 0);
Scope *enclosingScope = function->enclosingScope();
while (! (enclosingScope->isNamespace() || enclosingScope->isClass()))
while (!(enclosingScope->isNamespace() || enclosingScope->isClass()))
enclosingScope = enclosingScope->enclosingScope();
QTC_ASSERT(enclosingScope != 0, return 0);
const Name *functionName = function->name();
if (! functionName)
if (!functionName)
return 0; // anonymous function names are not valid c++
if (! functionName->isQualifiedNameId())
if (!functionName->isQualifiedNameId())
return 0; // trying to add a declaration for a global function
const QualifiedNameId *q = functionName->asQualifiedNameId();
......@@ -287,8 +287,10 @@ public:
// check for ! before parentheses
if (nested && priority - 2 >= 0) {
negation = interface->path()[priority - 2]->asUnaryExpression();
if (negation && ! interface->currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM))
if (negation
&& !interface->currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM)) {
negation = 0;
}
}
}
......@@ -335,9 +337,9 @@ void InverseLogicalComparison::match(const CppQuickFixInterface &interface,
const QList<AST *> &path = interface->path();
int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (! binary)
if (!binary)
return;
if (! interface->isCursorOn(binary->binary_op_token))
if (!interface->isCursorOn(binary->binary_op_token))
return;
Kind invertToken;
......@@ -398,7 +400,7 @@ public:
ChangeSet changes;
changes.flip(currentFile->range(binary->left_expression),
currentFile->range(binary->right_expression));
if (! replacement.isEmpty())
if (!replacement.isEmpty())
changes.replace(currentFile->range(binary->binary_op_token), replacement);
currentFile->setChangeSet(changes);
......@@ -419,9 +421,9 @@ void FlipLogicalOperands::match(const CppQuickFixInterface &interface, QuickFixO
int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (! binary)
if (!binary)
return;
if (! interface->isCursorOn(binary->binary_op_token))
if (!interface->isCursorOn(binary->binary_op_token))
return;
Kind flipToken;
......@@ -513,10 +515,10 @@ void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOpe
break;
}
if (! expression)
if (!expression)
return;
if (! interface->isCursorOn(expression->binary_op_token))
if (!interface->isCursorOn(expression->binary_op_token))
return;
QSharedPointer<RewriteLogicalAndOp> op(new RewriteLogicalAndOp(interface));
......@@ -534,10 +536,10 @@ void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOpe
bool SplitSimpleDeclaration::checkDeclaration(SimpleDeclarationAST *declaration)
{
if (! declaration->semicolon_token)
if (!declaration->semicolon_token)
return false;
if (! declaration->decl_specifier_list)
if (!declaration->decl_specifier_list)
return false;
for (SpecifierListAST *it = declaration->decl_specifier_list; it; it = it->next) {
......@@ -550,10 +552,10 @@ bool SplitSimpleDeclaration::checkDeclaration(SimpleDeclarationAST *declaration)
return false;
}
if (! declaration->declarator_list)
if (!declaration->declarator_list)
return false;
else if (! declaration->declarator_list->next)
else if (!declaration->declarator_list->next)
return false;
return true;
......@@ -697,7 +699,7 @@ void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperati
int index = path.size() - 1;
IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && interface->isCursorOn(ifStatement->if_token) && ifStatement->statement
&& ! ifStatement->statement->asCompoundStatement()) {
&& !ifStatement->statement->asCompoundStatement()) {
result.append(QuickFixOperation::Ptr(
new AddBracesToIfOp(interface, index, ifStatement->statement)));
return;
......@@ -709,7 +711,7 @@ void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperati
IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && ifStatement->statement
&& interface->isCursorOn(ifStatement->statement)
&& ! ifStatement->statement->asCompoundStatement()) {
&& !ifStatement->statement->asCompoundStatement()) {
result.append(QuickFixOperation::Ptr(
new AddBracesToIfOp(interface, index, ifStatement->statement)));
return;
......@@ -775,7 +777,7 @@ void MoveDeclarationOutOfIf::match(const CppQuickFixInterface &interface,
if (statement->match(op->pattern, &op->matcher) && op->condition->declarator) {
DeclaratorAST *declarator = op->condition->declarator;
op->core = declarator->core_declarator;
if (! op->core)
if (!op->core)
return;
if (interface->isCursorOn(op->core)) {
......@@ -846,13 +848,13 @@ void MoveDeclarationOutOfWhile::match(const CppQuickFixInterface &interface,
DeclaratorAST *declarator = op->condition->declarator;
op->core = declarator->core_declarator;
if (! op->core)
if (!op->core)
return;
if (! declarator->equal_token)
if (!declarator->equal_token)
return;
if (! declarator->initializer)
if (!declarator->initializer)
return;
if (interface->isCursorOn(op->core)) {
......@@ -961,20 +963,20 @@ void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOper
}
}
if (! pattern || ! pattern->statement)
if (!pattern || !pattern->statement)
return;
unsigned splitKind = 0;
for (++index; index < path.size(); ++index) {
AST *node = path.at(index);
BinaryExpressionAST *condition = node->asBinaryExpression();
if (! condition)
if (!condition)
return;
Token binaryToken = interface->currentFile()->tokenAt(condition->binary_op_token);
// only accept a chain of ||s or &&s - no mixing
if (! splitKind) {
if (!splitKind) {
splitKind = binaryToken.kind();
if (splitKind != T_AMPER_AMPER && splitKind != T_PIPE_PIPE)
return;
......@@ -1411,7 +1413,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
NumericLiteralAST *literal = path.last()->asNumericLiteral();
if (! literal)
if (!literal)
return;
Token token = file->tokenAt(literal->asNumericLiteral()->literal_token);
......@@ -1549,7 +1551,7 @@ public:
} else if (headerFileInfo.fileName().at(0).isUpper()) {
best = c;
// and continue
} else if (! best.isEmpty()) {
} else if (!best.isEmpty()) {
if (c.count(QLatin1Char('/')) < best.count(QLatin1Char('/')))
best = c;
}
......@@ -1574,7 +1576,7 @@ public:
foreach (const LookupItem &r,
interface->context().lookup(name, interface->semanticInfo().doc->scopeAt(line, column))) {
if (! r.declaration())
if (!r.declaration())
continue;
else if (ForwardClassDeclaration *fwd = r.declaration()->asForwardClassDeclaration())
fwdClass = fwd;
......@@ -1650,7 +1652,7 @@ public:
scope,
TypeOfExpression::Preprocess);
if (! result.isEmpty()) {
if (!result.isEmpty()) {
SubstitutionEnvironment env;
env.setContext(assistInterface()->context());
env.switchScope(result.first().scope());
......@@ -1665,7 +1667,7 @@ public:
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
QString ty = oo.prettyType(tn, simpleNameAST->name);
if (! ty.isEmpty()) {
if (!ty.isEmpty()) {
ChangeSet changes;
changes.replace(currentFile->startOf(binaryAST),
currentFile->endOf(simpleNameAST),
......@@ -1699,17 +1701,17 @@ void AddLocalDeclaration::match(const CppQuickFixInterface &interface, QuickFixO
const QList<LookupItem> results = interface->context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken()));
Declaration *decl = 0;
foreach (const LookupItem &r, results) {
if (! r.declaration())
if (!r.declaration())
continue;
if (Declaration *d = r.declaration()->asDeclaration()) {
if (! d->type()->isFunctionType()) {
if (!d->type()->isFunctionType()) {
decl = d;
break;
}
}
}
if (! decl) {
if (!decl) {
result.append(QuickFixOperation::Ptr(
new AddLocalDeclarationOp(interface, index, binary, nameAST)));
return;
......@@ -2082,25 +2084,25 @@ public:
for (int i = astPathList.size() - 1; i >= 0; --i) {
AST *ast = astPathList.at(i);
if (! m_hasSimpleDeclaration && ast->asSimpleDeclaration()) {
if (!m_hasSimpleDeclaration && ast->asSimpleDeclaration()) {
m_hasSimpleDeclaration = true;
filtered.append(ast);
} else if (! m_hasFunctionDefinition && ast->asFunctionDefinition()) {
} else if (!m_hasFunctionDefinition && ast->asFunctionDefinition()) {
m_hasFunctionDefinition = true;
filtered.append(ast);
} else if (! m_hasParameterDeclaration && ast->asParameterDeclaration()) {
} else if (!m_hasParameterDeclaration && ast->asParameterDeclaration()) {
m_hasParameterDeclaration = true;
filtered.append(ast);
} else if (! m_hasIfStatement && ast->asIfStatement()) {
} else if (!m_hasIfStatement && ast->asIfStatement()) {
m_hasIfStatement = true;
filtered.append(ast);
} else if (! m_hasWhileStatement && ast->asWhileStatement()) {
} else if (!m_hasWhileStatement && ast->asWhileStatement()) {
m_hasWhileStatement = true;
filtered.append(ast);
} else if (! m_hasForStatement && ast->asForStatement()) {
} else if (!m_hasForStatement && ast->asForStatement()) {
m_hasForStatement = true;
filtered.append(ast);
} else if (! m_hasForeachStatement && ast->asForeachStatement()) {
} else if (!m_hasForeachStatement && ast->asForeachStatement()) {
m_hasForeachStatement = true;
filtered.append(ast);
}
......@@ -2142,7 +2144,7 @@ void ReformatPointerDeclaration::match(const CppQuickFixInterface &interface,
// ctrl-a and there is an empty line in the end, then the cursor is not on
// any AST and therefore no quick fix will be triggered.
change = formatter.format(file->cppDocument()->translationUnit()->ast());
if (! change.isEmpty()) {
if (!change.isEmpty()) {
result.append(QuickFixOperation::Ptr(
new ReformatPointerDeclarationOp(interface, change)));
}
......@@ -2151,7 +2153,7 @@ void ReformatPointerDeclaration::match(const CppQuickFixInterface &interface,
= ReformatPointerDeclarationASTPathResultsFilter().filter(path);
foreach (AST *ast, suitableASTs) {
change = formatter.format(ast);
if (! change.isEmpty()) {
if (!change.isEmpty()) {
result.append(QuickFixOperation::Ptr(
new ReformatPointerDeclarationOp(interface, change)));
return;
......@@ -2620,7 +2622,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
if (SimpleDeclarationAST *simpleDecl = node->asSimpleDeclaration()) {
if (idx > 0 && path.at(idx - 1)->asStatement())
return;
if (simpleDecl->symbols && ! simpleDecl->symbols->next) {
if (simpleDecl->symbols && !simpleDecl->symbols->next) {
if (Symbol *symbol = simpleDecl->symbols->value) {
if (Declaration *decl = symbol->asDeclaration()) {
if (Function *func = decl->type()->asFunctionType()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment