From 32fe77564e287d3be8dcb86e88618e4ec4de295a Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 31 Oct 2019 16:15:03 +0100 Subject: CppTools: Simplify Change-Id: Id10cbcf541d8105265c531e63a64e2fd34e27379 Reviewed-by: Christian Stenger --- src/plugins/cpptools/cppchecksymbols.cpp | 23 +++++++++------------- src/plugins/cpptools/cppcodeformatter.cpp | 8 ++++---- .../cpptools/cppcompletionassistprovider.cpp | 4 +--- .../cpptools/cppfollowsymbolundercursor.cpp | 2 +- src/plugins/cpptools/cpprefactoringchanges.cpp | 10 ++-------- src/plugins/cpptools/semantichighlighter.cpp | 2 +- 6 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index f4458bd059..b42875492a 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -461,11 +461,7 @@ Scope *CheckSymbols::enclosingScope() const bool CheckSymbols::preVisit(AST *ast) { _astStack.append(ast); - - if (isCanceled()) - return false; - - return true; + return !isCanceled(); } void CheckSymbols::postVisit(AST *) @@ -1256,13 +1252,12 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList &candidates, Nam Symbol *c = r.declaration(); if (c->isUsingDeclaration()) // skip using declarations... continue; - else if (c->isUsingNamespaceDirective()) // ... and using namespace directives. + if (c->isUsingNamespaceDirective()) // ... and using namespace directives. continue; - else if (c->isTypedef() || c->isNamespace() || - c->isStatic() || //consider also static variable - c->isClass() || c->isEnum() || isTemplateClass(c) || - c->isForwardClassDeclaration() || c->isTypenameArgument() || c->enclosingEnum() != nullptr) { - + if (c->isTypedef() || c->isNamespace() || + c->isStatic() || //consider also static variable + c->isClass() || c->isEnum() || isTemplateClass(c) || + c->isForwardClassDeclaration() || c->isTypenameArgument() || c->enclosingEnum()) { int line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); @@ -1298,11 +1293,11 @@ bool CheckSymbols::maybeAddField(const QList &candidates, NameAST *a Symbol *c = r.declaration(); if (!c) continue; - else if (!c->isDeclaration()) + if (!c->isDeclaration()) return false; - else if (!(c->enclosingScope() && c->enclosingScope()->isClass())) + if (!(c->enclosingScope() && c->enclosingScope()->isClass())) return false; // shadowed - else if (c->isTypedef() || (c->type() && c->type()->isFunctionType())) + if (c->isTypedef() || (c->type() && c->type()->isFunctionType())) return false; // shadowed int line, column; diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index fca7998ece..413a5fde7b 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -179,8 +179,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) switch (kind) { case T_LBRACE: enter(brace_list_open); break; case T_RBRACE: leave(true); continue; - case T_SEMICOLON: leave(); continue; - case T_RPAREN: leave(); continue; + case T_SEMICOLON: + case T_RPAREN: case T_COMMA: leave(); continue; default: enter(assign_open); continue; } break; @@ -205,8 +205,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case assign_open: switch (kind) { case T_RBRACE: leave(true); continue; - case T_SEMICOLON: leave(); continue; - case T_RPAREN: leave(); continue; + case T_SEMICOLON: + case T_RPAREN: case T_COMMA: leave(); continue; default: tryExpression(); break; } break; diff --git a/src/plugins/cpptools/cppcompletionassistprovider.cpp b/src/plugins/cpptools/cppcompletionassistprovider.cpp index a06c4c7b42..08100dba44 100644 --- a/src/plugins/cpptools/cppcompletionassistprovider.cpp +++ b/src/plugins/cpptools/cppcompletionassistprovider.cpp @@ -51,9 +51,7 @@ bool CppCompletionAssistProvider::isActivationCharSequence(const QString &sequen const QChar &ch = sequence.at(2); const QChar &ch2 = sequence.at(1); const QChar &ch3 = sequence.at(0); - if (activationSequenceChar(ch, ch2, ch3, nullptr, true, false) != 0) - return true; - return false; + return activationSequenceChar(ch, ch2, ch3, nullptr, true, false); } bool CppCompletionAssistProvider::isContinuationChar(const QChar &c) const diff --git a/src/plugins/cpptools/cppfollowsymbolundercursor.cpp b/src/plugins/cpptools/cppfollowsymbolundercursor.cpp index 9a66467951..ded069a96e 100644 --- a/src/plugins/cpptools/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cpptools/cppfollowsymbolundercursor.cpp @@ -374,7 +374,7 @@ Symbol *findDefinition(Symbol *symbol, const Snapshot &snapshot, SymbolFinder *s if (symbol->isFunction()) return nullptr; // symbol is a function definition. - else if (!symbol->type()->isFunctionType()) + if (!symbol->type()->isFunctionType()) return nullptr; // not a function declaration return symbolFinder->findMatchingDefinition(symbol, snapshot); diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index 4d16dd4813..c063e1efdd 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -172,10 +172,7 @@ bool CppRefactoringFile::isCursorOn(unsigned tokenIndex) const int start = startOf(tokenIndex); int end = endOf(tokenIndex); - if (cursorBegin >= start && cursorBegin <= end) - return true; - - return false; + return cursorBegin >= start && cursorBegin <= end; } bool CppRefactoringFile::isCursorOn(const AST *ast) const @@ -186,10 +183,7 @@ bool CppRefactoringFile::isCursorOn(const AST *ast) const int start = startOf(ast); int end = endOf(ast); - if (cursorBegin >= start && cursorBegin <= end) - return true; - - return false; + return cursorBegin >= start && cursorBegin <= end; } Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const diff --git a/src/plugins/cpptools/semantichighlighter.cpp b/src/plugins/cpptools/semantichighlighter.cpp index 5c7c8110ca..2fdce4c743 100644 --- a/src/plugins/cpptools/semantichighlighter.cpp +++ b/src/plugins/cpptools/semantichighlighter.cpp @@ -87,7 +87,7 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to) { if (documentRevision() != m_revision) return; // outdated - else if (!m_watcher || m_watcher->isCanceled()) + if (!m_watcher || m_watcher->isCanceled()) return; // aborted qCDebug(log) << "onHighlighterResultAvailable()" << from << to; -- cgit v1.2.1