Clang: Remove unused code

Change-Id: I1fa597d1cd582f8eb4a37c3bbb963441696e9f4a
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-07-02 12:11:18 +02:00
parent aa90184581
commit 07b3f65a20
25 changed files with 7 additions and 2649 deletions

View File

@@ -13,7 +13,6 @@ unix:QMAKE_LFLAGS += -Wl,-rpath,\'$$LLVM_LIBDIR\'
SOURCES += \
$$PWD/clangcodemodelplugin.cpp \
$$PWD/clangcompleter.cpp \
$$PWD/clangcompletioncontextanalyzer.cpp \
$$PWD/clangcompletion.cpp \
$$PWD/clangeditordocumentparser.cpp \
@@ -24,7 +23,6 @@ SOURCES += \
$$PWD/clangutils.cpp \
$$PWD/clangbackendipcintegration.cpp \
$$PWD/completionchunkstotextconverter.cpp \
$$PWD/completionproposalsbuilder.cpp \
$$PWD/cppcreatemarkers.cpp \
$$PWD/cxprettyprinter.cpp \
$$PWD/diagnostic.cpp \
@@ -43,7 +41,6 @@ SOURCES += \
HEADERS += \
$$PWD/clangcodemodelplugin.h \
$$PWD/clangcompleter.h \
$$PWD/clangcompletioncontextanalyzer.h \
$$PWD/clangcompletion.h \
$$PWD/clangeditordocumentparser.h \
@@ -55,7 +52,6 @@ HEADERS += \
$$PWD/clangutils.h \
$$PWD/clangbackendipcintegration.h \
$$PWD/completionchunkstotextconverter.h \
$$PWD/completionproposalsbuilder.h \
$$PWD/constants.h \
$$PWD/cppcreatemarkers.h \
$$PWD/cxprettyprinter.h \
@@ -96,14 +92,12 @@ equals(TEST, 1) {
HEADERS += \
$$PWD/test/clangcodecompletion_test.h \
$$PWD/test/clangcompletioncontextanalyzertest.h \
$$PWD/test/completiontesthelper.h
$$PWD/test/clangcompletioncontextanalyzertest.h
SOURCES += \
$$PWD/test/clangcodecompletion_test.cpp \
$$PWD/test/clangcompletioncontextanalyzertest.cpp \
$$PWD/test/clangcompletion_test.cpp \
$$PWD/test/completiontesthelper.cpp
$$PWD/test/clangcompletioncontextanalyzertest.cpp
DISTFILES += \
$$PWD/test/mysource.cpp \
@@ -112,23 +106,7 @@ equals(TEST, 1) {
$$PWD/test/memberCompletion.cpp \
$$PWD/test/doxygenKeywordsCompletion.cpp \
$$PWD/test/preprocessorKeywordsCompletion.cpp \
$$PWD/test/includeDirectiveCompletion.cpp \
$$PWD/test/cxx_regression_1.cpp \
$$PWD/test/cxx_regression_2.cpp \
$$PWD/test/cxx_regression_3.cpp \
$$PWD/test/cxx_regression_4.cpp \
$$PWD/test/cxx_regression_5.cpp \
$$PWD/test/cxx_regression_6.cpp \
$$PWD/test/cxx_regression_7.cpp \
$$PWD/test/cxx_regression_8.cpp \
$$PWD/test/cxx_regression_9.cpp \
$$PWD/test/cxx_snippets_1.cpp \
$$PWD/test/cxx_snippets_2.cpp \
$$PWD/test/cxx_snippets_3.cpp \
$$PWD/test/cxx_snippets_4.cpp \
$$PWD/test/objc_messages_1.mm \
$$PWD/test/objc_messages_2.mm \
$$PWD/test/objc_messages_3.mm
$$PWD/test/includeDirectiveCompletion.cpp
}
macx {

View File

@@ -53,12 +53,8 @@ QtcPlugin {
name: "Completion support"
condition: product.clangCompletion
files: [
"clangcompleter.cpp",
"clangcompleter.h",
"clangcompletion.cpp",
"clangcompletion.h",
"completionproposalsbuilder.cpp",
"completionproposalsbuilder.h",
]
}
@@ -92,9 +88,6 @@ QtcPlugin {
prefix: "test/"
files: [
"clang_tests_database.qrc",
"clangcompletion_test.cpp",
"completiontesthelper.cpp",
"completiontesthelper.h",
"clangcodecompletion_test.cpp",
"clangcodecompletion_test.h",
"clangcompletioncontextanalyzertest.cpp",
@@ -114,19 +107,6 @@ QtcPlugin {
"doxygenKeywordsCompletion.cpp",
"preprocessorKeywordsCompletion.cpp",
"includeDirectiveCompletion.cpp",
"cxx_regression_1.cpp",
"cxx_regression_2.cpp",
"cxx_regression_3.cpp",
"cxx_regression_4.cpp",
"cxx_regression_5.cpp",
"cxx_regression_6.cpp",
"cxx_regression_7.cpp",
"cxx_regression_8.cpp",
"cxx_regression_9.cpp",
"cxx_snippets_1.cpp",
"cxx_snippets_2.cpp",
"cxx_snippets_3.cpp",
"cxx_snippets_4.cpp",
"objc_messages_1.mm",
"objc_messages_2.mm",
"objc_messages_3.mm",

View File

@@ -61,14 +61,6 @@ private:
#ifdef WITH_TESTS
QList<QObject *> createTestObjects() const;
private slots:
void test_CXX_regressions();
void test_CXX_regressions_data();
void test_CXX_snippets();
void test_CXX_snippets_data();
void test_ObjC_hints();
void test_ObjC_hints_data();
#endif
};

View File

@@ -1,213 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clangcompleter.h"
#include "sourcemarker.h"
#include "unsavedfiledata.h"
#include "utils_p.h"
#include "completionproposalsbuilder.h"
#include "raii/scopedclangoptions.h"
#include "unit.h"
#include <QDebug>
#include <QFile>
#include <QMutex>
#include <QMutexLocker>
#include <QTime>
#include <clang-c/Index.h>
//#define TIME_COMPLETION
using namespace ClangCodeModel::Internal;
namespace ClangCodeModel {
class ClangCompleter::PrivateData
{
public:
PrivateData()
: m_mutex(QMutex::Recursive)
, m_unit(Unit::create())
, m_isSignalSlotCompletion(false)
{
}
~PrivateData()
{
}
bool parseFromFile(const UnsavedFiles &unsavedFiles)
{
Q_ASSERT(!m_unit->isLoaded());
if (m_unit->fileName().isEmpty())
return false;
unsigned opts = clang_defaultEditingTranslationUnitOptions();
#if defined(CINDEX_VERSION) && (CINDEX_VERSION > 5)
opts |= CXTranslationUnit_CacheCompletionResults;
opts |= CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
#endif
m_unit->setManagementOptions(opts);
m_unit->setUnsavedFiles(unsavedFiles);
m_unit->parse();
return m_unit->isLoaded();
}
public:
QMutex m_mutex;
Unit::Ptr m_unit;
bool m_isSignalSlotCompletion;
};
/**
* @brief Constructs with highest possible priority
*/
CodeCompletionResult::CodeCompletionResult()
: m_priority(SHRT_MAX)
, m_completionKind(Other)
, m_availability(Available)
, m_hasParameters(false)
{}
/**
* @brief Constructs with given priority
* @param priority Will be reversed, because clang's highest priority is 0,
* but inside QtCreator it is the lowest priority
*/
CodeCompletionResult::CodeCompletionResult(unsigned priority)
: m_priority(SHRT_MAX - priority)
, m_completionKind(Other)
, m_availability(Available)
, m_hasParameters(false)
{
}
ClangCompleter::ClangCompleter()
: d(new PrivateData)
{
}
ClangCompleter::~ClangCompleter()
{
}
QString ClangCompleter::fileName() const
{
return d->m_unit->fileName();
}
void ClangCompleter::setFileName(const QString &fileName)
{
if (d->m_unit->fileName() != fileName) {
d->m_unit = Unit::create(fileName);
}
}
QStringList ClangCompleter::options() const
{
return d->m_unit->compilationOptions();
}
void ClangCompleter::setOptions(const QStringList &options) const
{
if (d->m_unit->compilationOptions() != options) {
d->m_unit->setCompilationOptions(options);
d->m_unit->unload();
}
}
bool ClangCompleter::isSignalSlotCompletion() const
{
return d->m_isSignalSlotCompletion;
}
void ClangCompleter::setSignalSlotCompletion(bool isSignalSlot)
{
d->m_isSignalSlotCompletion = isSignalSlot;
}
bool ClangCompleter::reparse(const UnsavedFiles &unsavedFiles)
{
if (!d->m_unit->isLoaded())
return d->parseFromFile(unsavedFiles);
d->m_unit->setUnsavedFiles(unsavedFiles);
d->m_unit->reparse();
return d->m_unit->isLoaded();
}
QList<CodeCompletionResult> ClangCompleter::codeCompleteAt(unsigned line,
unsigned column,
const UnsavedFiles &unsavedFiles)
{
#ifdef TIME_COMPLETION
QTime t;t.start();
#endif // TIME_COMPLETION
if (!d->m_unit->isLoaded())
if (!d->parseFromFile(unsavedFiles))
return QList<CodeCompletionResult>();
ScopedCXCodeCompleteResults results;
d->m_unit->setUnsavedFiles(unsavedFiles);
d->m_unit->codeCompleteAt(line, column, results);
QList<CodeCompletionResult> completions;
if (results) {
const quint64 contexts = clang_codeCompleteGetContexts(results);
CompletionProposalsBuilder builder(completions, contexts, d->m_isSignalSlotCompletion);
for (unsigned i = 0; i < results.size(); ++i)
builder(results.completionAt(i));
}
#ifdef TIME_COMPLETION
qDebug() << "Completion timing:" << completions.size() << "results in" << t.elapsed() << "ms.";
#endif // TIME_COMPLETION
return completions;
}
bool ClangCompleter::objcEnabled() const
{
static const QString objcppOption = QLatin1String("-ObjC++");
static const QString objcOption = QLatin1String("-ObjC");
QStringList options = d->m_unit->compilationOptions();
return options.contains(objcOption) || options.contains(objcppOption);
}
QMutex *ClangCompleter::mutex() const
{
return &d->m_mutex;
}
} // namespace ClangCodeModel

View File

@@ -1,224 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGCOMPLETER_H
#define CLANGCOMPLETER_H
#include "clang_global.h"
#include "diagnostic.h"
#include "sourcelocation.h"
#include "utils.h"
#include <QList>
#include <QMap>
#include <QMutex>
#include <QPair>
#include <QSharedPointer>
#include <QString>
#include <QStringList>
#include <QVariant>
namespace ClangCodeModel {
class SourceMarker;
class CLANG_EXPORT CodeCompletionResult
{
public:
enum Kind {
Other = 0,
FunctionCompletionKind,
ConstructorCompletionKind,
DestructorCompletionKind,
VariableCompletionKind,
ClassCompletionKind,
EnumCompletionKind,
EnumeratorCompletionKind,
NamespaceCompletionKind,
PreProcessorCompletionKind,
SignalCompletionKind,
SlotCompletionKind,
ObjCMessageCompletionKind,
KeywordCompletionKind,
ClangSnippetKind
};
enum Availability {
Available,
Deprecated,
NotAvailable,
NotAccessible
};
public:
CodeCompletionResult();
CodeCompletionResult(unsigned priority);
unsigned priority() const
{ return m_priority; }
bool isValid() const
{ return !m_text.isEmpty(); }
QString text() const
{ return m_text; }
void setText(const QString &text)
{ m_text = text; }
QString hint() const
{ return m_hint; }
void setHint(const QString &hint)
{ m_hint = hint; }
QString snippet() const
{ return m_snippet; }
void setSnippet(const QString &snippet)
{ m_snippet = snippet; }
Kind completionKind() const
{ return m_completionKind; }
void setCompletionKind(Kind type)
{ m_completionKind = type; }
int compare(const CodeCompletionResult &other) const
{
if (m_priority < other.m_priority)
return -1;
else if (m_priority > other.m_priority)
return 1;
if (m_completionKind < other.m_completionKind)
return -1;
else if (m_completionKind > other.m_completionKind)
return 1;
if (m_text < other.m_text)
return -1;
else if (m_text > other.m_text)
return 1;
if (m_hint < other.m_hint)
return -1;
else if (m_hint > other.m_hint)
return 1;
if (!m_hasParameters && other.m_hasParameters)
return -1;
else if (m_hasParameters && !other.m_hasParameters)
return 1;
if (m_availability < other.m_availability)
return -1;
else if (m_availability > other.m_availability)
return 1;
return 0;
}
bool hasParameters() const
{ return m_hasParameters; }
void setHasParameters(bool hasParameters)
{ m_hasParameters = hasParameters; }
Availability availability() const
{ return m_availability; }
void setAvailability(Availability availability)
{ m_availability = availability; }
private:
unsigned m_priority;
Kind m_completionKind;
QString m_text;
QString m_hint;
QString m_snippet;
Availability m_availability;
bool m_hasParameters;
};
inline CLANG_EXPORT uint qHash(const CodeCompletionResult &ccr)
{ return ccr.completionKind() ^ qHash(ccr.text()); }
inline CLANG_EXPORT bool operator==(const CodeCompletionResult &ccr1, const CodeCompletionResult &ccr2)
{ return ccr1.compare(ccr2) == 0; }
inline CLANG_EXPORT bool operator<(const CodeCompletionResult &ccr1, const CodeCompletionResult &ccr2)
{
return ccr1.compare(ccr2) < 0;
}
class CLANG_EXPORT ClangCompleter
{
Q_DISABLE_COPY(ClangCompleter)
class PrivateData;
public: // data structures
typedef QSharedPointer<ClangCompleter> Ptr;
public: // methods
ClangCompleter();
~ClangCompleter();
QString fileName() const;
void setFileName(const QString &fileName);
QStringList options() const;
void setOptions(const QStringList &options) const;
bool isSignalSlotCompletion() const;
void setSignalSlotCompletion(bool isSignalSlot);
bool reparse(const Internal::UnsavedFiles &unsavedFiles);
/**
* Do code-completion at the specified position.
*
* \param line The line number on which to do code-completion. The first
* line of a file has line number 1.
* \param column The column number where to do code-completion. Column
* numbers start with 1.
*/
QList<CodeCompletionResult> codeCompleteAt(unsigned line,
unsigned column,
const Internal::UnsavedFiles &unsavedFiles);
bool objcEnabled() const;
QMutex *mutex() const;
private: // instance fields
QScopedPointer<PrivateData> d;
};
} // namespace Clang
Q_DECLARE_METATYPE(ClangCodeModel::CodeCompletionResult)
#endif // CLANGCOMPLETER_H

View File

@@ -31,9 +31,11 @@
#ifndef CPPEDITOR_INTERNAL_CLANGCOMPLETION_H
#define CPPEDITOR_INTERNAL_CLANGCOMPLETION_H
#include "clangcompleter.h"
#include "clangbackendipcintegration.h"
#include "pchinfo.h"
#include "utils.h"
#include <cpptools/cppcompletionassistprocessor.h>
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cppmodelmanager.h>

View File

@@ -1,750 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "completionproposalsbuilder.h"
#include "utils_p.h"
#include <QTextDocument>
#include <QCoreApplication>
enum PriorityFixes {
PriorityFix_ExplicitDestructorCall = 10
};
namespace ClangCodeModel {
namespace {
struct ObjCMessagePart {
QString text;
int signatureLen; // length of "setScale:" in "setScale: 13"
ObjCMessagePart() : signatureLen(0) {}
ObjCMessagePart(const QString &signature, int &indentBonus)
: text(signature)
, signatureLen(signature.length() + indentBonus)
{
indentBonus = 0;
}
void addToSignature(const QString &signature)
{
text += signature;
signatureLen += signature.length();
}
};
} // anonymous namespace
/**
* @class ClangCodeModel::CompletionProposalsBuilder
* @brief Captures completion lists and than processes sequence of completion chunks
*
* Can produce several completion proposals for one CXCompletionResult, if and
* only if result contains chunks with kind 'Optional'
* Different proposals can have the same text, it's normal behavior.
*
* @note Unit tests are in \a clangcompletion_test.cpp
*
* @note Unresolved problems:
* Function hint not appear after space: "foo(1, ";
* Slot can have optional arguments, that produces 2 slots.
*
*/
CompletionProposalsBuilder::CompletionProposalsBuilder(QList<CodeCompletionResult> &results, quint64 contexts, bool isSignalSlotCompletion)
: m_results(results)
, m_contexts(contexts)
, m_isSignalSlotCompletion(isSignalSlotCompletion)
{
}
void CompletionProposalsBuilder::operator ()(const CXCompletionResult &cxResult)
{
resetWithResult(cxResult);
#if defined(CINDEX_VERSION) && (CINDEX_VERSION > 5)
const QString brief = Internal::getQString(clang_getCompletionBriefComment(cxResult.CompletionString));
if (!brief.isEmpty())
m_comment += QString(QLatin1String("<b>Brief:</b> ") + brief).toHtmlEscaped();
#endif
if (m_resultAvailability == CodeCompletionResult::Deprecated) {
m_comment += QLatin1String("<b>@note</b> ");
//: deprecated C++ symbol
m_comment += tr("Is deprecated");
}
m_hint = QLatin1String("<p>");
switch (m_resultKind) {
case CodeCompletionResult::ObjCMessageCompletionKind:
concatChunksForObjectiveCMessage(cxResult);
break;
case CodeCompletionResult::ClassCompletionKind:
case CodeCompletionResult::NamespaceCompletionKind:
case CodeCompletionResult::EnumeratorCompletionKind:
concatChunksForNestedName(cxResult.CompletionString);
break;
case CodeCompletionResult::ClangSnippetKind:
concatChunksAsSnippet(cxResult.CompletionString);
break;
case CodeCompletionResult::SlotCompletionKind:
case CodeCompletionResult::SignalCompletionKind:
if (m_isSignalSlotCompletion)
concatSlotSignalSignature(cxResult.CompletionString);
else
concatChunksOnlyTypedText(cxResult.CompletionString);
break;
default:
concatChunksOnlyTypedText(cxResult.CompletionString);
break;
}
m_hint += QLatin1String("</p>");
m_hint += m_comment;
finalize();
foreach (const OptionalChunk &chunk, m_optionalChunks) {
m_hint.insert(chunk.positionInHint, chunk.hint);
finalize();
}
}
/**
* @return Internal ClangCodeModel's completion kind, that affects further postprocessing
*/
CodeCompletionResult::Kind CompletionProposalsBuilder::getKind(const CXCompletionResult &cxResult)
{
CXCompletionString complStr = cxResult.CompletionString;
CXCursorKind cursorKind = cxResult.CursorKind;
switch (cursorKind) {
case CXCursor_Constructor:
return CodeCompletionResult::ConstructorCompletionKind;
case CXCursor_Destructor:
return CodeCompletionResult::DestructorCompletionKind;
case CXCursor_CXXMethod: {
const unsigned numAnnotations = clang_getCompletionNumAnnotations(complStr);
bool isSignal = false, isSlot = false;
for (unsigned i = 0; i < numAnnotations && !isSignal && !isSlot; ++i) {
CXString cxAnn = clang_getCompletionAnnotation(complStr, i);
QString ann = Internal::getQString(cxAnn);
isSignal = ann == QLatin1String("qt_signal");
isSlot = ann == QLatin1String("qt_slot");
}
if (isSignal)
return CodeCompletionResult::SignalCompletionKind;
if (isSlot)
return CodeCompletionResult::SlotCompletionKind;
} // intentional fall-through!
case CXCursor_ConversionFunction:
case CXCursor_FunctionDecl:
case CXCursor_FunctionTemplate:
case CXCursor_MemberRef:
case CXCursor_MemberRefExpr:
return CodeCompletionResult::FunctionCompletionKind;
break;
case CXCursor_FieldDecl:
case CXCursor_VarDecl:
case CXCursor_ParmDecl:
case CXCursor_ObjCIvarDecl:
case CXCursor_ObjCPropertyDecl:
case CXCursor_ObjCSynthesizeDecl:
case CXCursor_NonTypeTemplateParameter:
return CodeCompletionResult::VariableCompletionKind;
case CXCursor_Namespace:
case CXCursor_NamespaceAlias:
case CXCursor_NamespaceRef:
return CodeCompletionResult::NamespaceCompletionKind;
case CXCursor_StructDecl:
case CXCursor_UnionDecl:
case CXCursor_ClassDecl:
case CXCursor_TypeRef:
case CXCursor_TemplateRef:
case CXCursor_TypedefDecl:
case CXCursor_ClassTemplate:
case CXCursor_ClassTemplatePartialSpecialization:
case CXCursor_ObjCClassRef:
case CXCursor_ObjCInterfaceDecl:
case CXCursor_ObjCImplementationDecl:
case CXCursor_ObjCCategoryDecl:
case CXCursor_ObjCCategoryImplDecl:
case CXCursor_ObjCProtocolDecl:
case CXCursor_ObjCProtocolRef:
case CXCursor_TemplateTypeParameter:
case CXCursor_TemplateTemplateParameter:
return CodeCompletionResult::ClassCompletionKind;
case CXCursor_EnumConstantDecl:
return CodeCompletionResult::EnumeratorCompletionKind;
case CXCursor_EnumDecl:
return CodeCompletionResult::EnumCompletionKind;
case CXCursor_MacroDefinition: {
const unsigned numChunks = clang_getNumCompletionChunks(complStr);
for (unsigned i = 0; i < numChunks; ++i) {
CXCompletionChunkKind kind = clang_getCompletionChunkKind(complStr, i);
if (kind == CXCompletionChunk_Placeholder) {
return CodeCompletionResult::FunctionCompletionKind;
}
}
return CodeCompletionResult::PreProcessorCompletionKind;
}
case CXCursor_PreprocessingDirective:
case CXCursor_MacroExpansion:
case CXCursor_InclusionDirective:
return CodeCompletionResult::PreProcessorCompletionKind;
case CXCursor_ObjCClassMethodDecl:
case CXCursor_ObjCInstanceMethodDecl:
return CodeCompletionResult::ObjCMessageCompletionKind;
case CXCursor_NotImplemented: {
const unsigned numChunks = clang_getNumCompletionChunks(complStr);
for (unsigned i = 0; i < numChunks; ++i) {
CXCompletionChunkKind kind = clang_getCompletionChunkKind(complStr, i);
if (kind == CXCompletionChunk_Placeholder) {
return CodeCompletionResult::ClangSnippetKind;
}
}
return CodeCompletionResult::KeywordCompletionKind;
}
default:
break;
}
return CodeCompletionResult::Other;
}
/**
* @return Symbol availability, which is almost unused
*/
CodeCompletionResult::Availability CompletionProposalsBuilder::getAvailability(const CXCompletionResult &cxResult)
{
CXCompletionString complStr = cxResult.CompletionString;
switch (clang_getCompletionAvailability(complStr)) {
case CXAvailability_Deprecated:
return CodeCompletionResult::Deprecated;
case CXAvailability_NotAvailable:
return CodeCompletionResult::NotAvailable;
case CXAvailability_NotAccessible:
return CodeCompletionResult::NotAccessible;
default:
return CodeCompletionResult::Available;
}
}
/**
* @return Start index of name, which is unused in Qt signal/slot signature
* @param text Text of Placeholder completion string chunk
*/
int CompletionProposalsBuilder::findNameInPlaceholder(const QString &text)
{
bool firstIdPassed = false;
bool isInIdentifier = false;
int bracesCounter = 0;
int idStart = 0;
for (int i = 0, n = text.size(); i < n; ++i) {
const QChar ch = text[i];
if (ch == QLatin1Char(':')) {
firstIdPassed = false;
isInIdentifier = false;
}
if (ch == QLatin1Char('<') || ch == QLatin1Char('(')) {
if (isInIdentifier && text.mid(idStart, i - idStart) == QLatin1String("const"))
firstIdPassed = false;
++bracesCounter;
isInIdentifier = false;
} else if (ch == QLatin1Char('>') || ch == QLatin1Char(')')) {
if (isInIdentifier && text.mid(idStart, i - idStart) == QLatin1String("const"))
firstIdPassed = false;
--bracesCounter;
isInIdentifier = false;
} else if (bracesCounter == 0) {
if (isInIdentifier) {
isInIdentifier = ch.isLetterOrNumber() || (ch == QLatin1Char('_'));
if (!isInIdentifier && text.mid(idStart, i - idStart) == QLatin1String("const"))
firstIdPassed = false;
} else if (ch.isLetter() || (ch == QLatin1Char('_'))) {
if (firstIdPassed)
return i;
isInIdentifier = true;
idStart = i;
firstIdPassed = true;
}
}
}
return text.size();
}
void CompletionProposalsBuilder::resetWithResult(const CXCompletionResult &cxResult)
{
m_priority = clang_getCompletionPriority(cxResult.CompletionString);
m_resultKind = getKind(cxResult);
m_resultAvailability = getAvailability(cxResult);
m_hasParameters = false;
m_hint.clear();
m_text.clear();
m_snippet.clear();
m_comment.clear();
m_optionalChunks.clear();
}
/**
* @brief Appends completion proposal initialized with collected data
*/
void CompletionProposalsBuilder::finalize()
{
// Fixes code completion: operator and destructor cases
if (m_contexts & (CXCompletionContext_DotMemberAccess
| CXCompletionContext_ArrowMemberAccess
| CXCompletionContext_AnyValue)) {
if (m_resultKind == CodeCompletionResult::DestructorCompletionKind)
m_priority *= PriorityFix_ExplicitDestructorCall;
else if (m_resultKind == CodeCompletionResult::FunctionCompletionKind
&& m_text.startsWith(QLatin1String("operator")))
return;
}
CodeCompletionResult ccr(m_priority);
ccr.setCompletionKind(m_resultKind);
ccr.setAvailability(m_resultAvailability);
ccr.setHasParameters(m_hasParameters);
ccr.setHint(m_hint);
ccr.setText(m_text);
ccr.setSnippet(m_snippet);
m_results.append(ccr);
}
/**
* @brief Creates text, hint and snippet
*
* Text is just signature, e.g. 'length' for [NSString length] or 'respondsToSelector:'
* for [id respondsToSelector:(SEL)sel].
* Snippet is actual text, where any message parameter becames snippet part:
* 'respondsToSelector:$(SEL)sel$'.
* Hint consists of snippet preview and doxygen 'return' entry with returned type.
*/
void CompletionProposalsBuilder::concatChunksForObjectiveCMessage(const CXCompletionResult &cxResult)
{
CXCompletionString cxString = cxResult.CompletionString;
const unsigned count = clang_getNumCompletionChunks(cxString);
unsigned index = 0;
QString hintPrefix;
if (cxResult.CursorKind == CXCursor_ObjCClassMethodDecl)
hintPrefix += QLatin1Char('+');
else
hintPrefix += QLatin1Char('-');
int indentBonus = 1;
bool addSpaceAtPrefixEnd = true;
for (; index < count; ++index) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, index);
if (chunkKind == CXCompletionChunk_TypedText || chunkKind == CXCompletionChunk_Informative) {
break;
}
const QString text = Internal::getQString(clang_getCompletionChunkText(cxString, index), false);
if (chunkKind == CXCompletionChunk_ResultType) {
hintPrefix += QLatin1Char('(');
hintPrefix += text.toHtmlEscaped();
hintPrefix += QLatin1String(") ");
indentBonus += 3 + text.length();
addSpaceAtPrefixEnd = false;
} else {
hintPrefix += text.toHtmlEscaped();
indentBonus += text.length();
m_snippet += text;
}
}
if (addSpaceAtPrefixEnd) {
m_snippet += QLatin1Char(' ');
hintPrefix += QLatin1Char(' ');
indentBonus += 1;
}
m_hint += hintPrefix;
QList<ObjCMessagePart> parts;
bool previousWasTypedText = false;
for (; index < count; ++index) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, index);
const QString text = Internal::getQString(clang_getCompletionChunkText(cxString, index), false);
switch (chunkKind) {
case CXCompletionChunk_TypedText:
if (previousWasTypedText)
parts.back().addToSignature(text);
else
parts.append(ObjCMessagePart(text, indentBonus));
m_snippet += text;
m_text += text;
break;
case CXCompletionChunk_Informative:
parts.append(ObjCMessagePart(text, indentBonus));
break;
case CXCompletionChunk_Text:
case CXCompletionChunk_LeftParen:
case CXCompletionChunk_RightParen:
case CXCompletionChunk_Comma:
case CXCompletionChunk_HorizontalSpace:
m_snippet += text;
parts.back().text += text.toHtmlEscaped();
break;
case CXCompletionChunk_Placeholder:
appendSnippet(text);
parts.back().text += QLatin1String("<b>");
parts.back().text += text.toHtmlEscaped();
parts.back().text += QLatin1String("</b>");
break;
case CXCompletionChunk_LeftAngle:
m_snippet += text;
parts.back().text += QLatin1String("&lt;");
break;
case CXCompletionChunk_RightAngle:
m_snippet += text;
parts.back().text += QLatin1String("&gt;");
break;
default:
break;
}
previousWasTypedText = (chunkKind == CXCompletionChunk_TypedText);
}
int indent = 0;
foreach (const ObjCMessagePart &part, parts)
indent = qMax(indent, part.signatureLen);
bool isFirstPart = true;
foreach (const ObjCMessagePart &part, parts) {
if (!isFirstPart)
m_hint += QLatin1String("<br/>");
isFirstPart = false;
for (int i = 0; i < indent - part.signatureLen; ++i)
m_hint += QLatin1String("&nbsp;");
m_hint += part.text;
}
}
/**
* @brief Creates entries like 'MyClass', 'MyNamespace::', 'MyEnumClass::Value1'
*/
void CompletionProposalsBuilder::concatChunksForNestedName(const CXCompletionString &cxString)
{
bool hasPlaceholder = false;
unsigned count = clang_getNumCompletionChunks(cxString);
for (unsigned i = 0; i < count; ++i) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, i);
QString text = Internal::getQString(clang_getCompletionChunkText(cxString, i), false);
switch (chunkKind) {
case CXCompletionChunk_TypedText:
case CXCompletionChunk_Text:
m_text += text;
m_snippet += text;
m_hint += text;
break;
case CXCompletionChunk_LeftAngle:
case CXCompletionChunk_RightAngle:
case CXCompletionChunk_Comma:
case CXCompletionChunk_HorizontalSpace:
m_snippet += text;
m_hint += text.toHtmlEscaped();
break;
case CXCompletionChunk_Placeholder:
hasPlaceholder = true;
appendSnippet(text);
appendHintBold(text);
break;
default:
break;
}
}
if (!hasPlaceholder)
m_snippet.clear();
}
/**
* @brief Creates text, snippet and hint for snippet preview
*
* Text is copy of snippet without '$' marks.
* Hint also have 'return' doxygen entry if applicable (e.g. 'typeid...')
*/
void CompletionProposalsBuilder::concatChunksAsSnippet(const CXCompletionString &cxString)
{
unsigned count = clang_getNumCompletionChunks(cxString);
for (unsigned i = 0; i < count; ++i) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, i);
const QString text = Internal::getQString(clang_getCompletionChunkText(cxString, i), false);
switch (chunkKind) {
case CXCompletionChunk_ResultType:
attachResultTypeToComment(text);
break;
case CXCompletionChunk_Placeholder:
m_text += text;
appendSnippet(text);
appendHintBold(text);
break;
case CXCompletionChunk_LeftAngle:
m_snippet += text;
m_text += text;
m_hint += QLatin1String("&lt;");
break;
case CXCompletionChunk_RightAngle:
m_snippet += text;
m_text += text;
m_hint += QLatin1String("&gt;");
break;
case CXCompletionChunk_VerticalSpace:
m_snippet += QLatin1Char('\n');
m_text += QLatin1Char(' ');
m_hint += QLatin1String("<br/>");
break;
default:
m_snippet += text;
m_text += text;
m_hint += text;
break;
}
}
}
/**
* @brief Creates short text and hint with details
*
* Text is just function or variable name. Hint also contains function signature
* or variable type.
*/
void CompletionProposalsBuilder::concatChunksOnlyTypedText(const CXCompletionString &cxString)
{
bool previousChunkWasLParen = false;
bool isInsideTemplateSpec = false;
unsigned count = clang_getNumCompletionChunks(cxString);
for (unsigned i = 0; i < count; ++i) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, i);
QString text = Internal::getQString(clang_getCompletionChunkText(cxString, i), false);
switch (chunkKind) {
case CXCompletionChunk_LeftParen:
case CXCompletionChunk_RightParen:
case CXCompletionChunk_Text:
case CXCompletionChunk_LeftAngle:
case CXCompletionChunk_RightAngle:
m_hint += text.toHtmlEscaped();
break;
case CXCompletionChunk_HorizontalSpace:
case CXCompletionChunk_Comma:
if (isInsideTemplateSpec) {
m_snippet += text;
}
m_hint += text.toHtmlEscaped();
break;
case CXCompletionChunk_Placeholder:
if (isInsideTemplateSpec) {
appendSnippet(text);
}
m_hint += text.toHtmlEscaped();
break;
case CXCompletionChunk_TypedText:
m_text = text;
appendHintBold(text);
break;
case CXCompletionChunk_ResultType: {
m_hint += text.toHtmlEscaped();
QChar last = text[text.size() - 1];
if (last != QLatin1Char('*') && last != QLatin1Char('&'))
m_hint += QLatin1Char(' ');
}
break;
case CXCompletionChunk_Informative:
if (text == QLatin1String(" const"))
m_hint += text;
break;
case CXCompletionChunk_Optional:
appendOptionalChunks(clang_getCompletionChunkCompletionString(cxString, i),
m_hint.size());
break;
default:
break;
}
if (chunkKind == CXCompletionChunk_RightParen && previousChunkWasLParen)
m_hasParameters = false;
if (chunkKind == CXCompletionChunk_LeftParen) {
previousChunkWasLParen = true;
m_hasParameters = true;
} else {
previousChunkWasLParen = false;
}
if (chunkKind == CXCompletionChunk_LeftAngle) {
m_snippet = m_text;
m_snippet += text;
isInsideTemplateSpec = true;
} else if (chunkKind == CXCompletionChunk_RightAngle) {
isInsideTemplateSpec = false;
m_snippet += text;
}
}
}
/**
* @brief Produces signal/slot signatures for 'connect' methods family
*/
void CompletionProposalsBuilder::concatSlotSignalSignature(const CXCompletionString &cxString)
{
QString resultType;
unsigned count = clang_getNumCompletionChunks(cxString);
for (unsigned i = 0; i < count; ++i) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, i);
QString text = Internal::getQString(clang_getCompletionChunkText(cxString, i), false);
switch (chunkKind) {
case CXCompletionChunk_Placeholder:
text.truncate(findNameInPlaceholder(text));
// fall-through
case CXCompletionChunk_TypedText:
case CXCompletionChunk_LeftParen:
case CXCompletionChunk_RightParen:
case CXCompletionChunk_Comma:
case CXCompletionChunk_Text:
m_text += text;
break;
case CXCompletionChunk_ResultType:
resultType += text;
resultType += QLatin1Char(' ');
break;
default:
break;
}
}
const QString parent = Internal::getQString(clang_getCompletionParent(cxString, NULL));
if (m_resultKind == CodeCompletionResult::SlotCompletionKind)
m_hint += tr("Slot of %1, returns %2").arg(parent, resultType);
else
m_hint += tr("Signal of %1, returns %2").arg(parent, resultType);
}
/**
* @brief Stores optional part for further postprocessing in \a finalize()
* @param insertionIndex Index where to insert optional chunk into hint
*/
void CompletionProposalsBuilder::appendOptionalChunks(const CXCompletionString &cxString,
int insertionIndex)
{
OptionalChunk chunk;
chunk.positionInHint = insertionIndex;
unsigned count = clang_getNumCompletionChunks(cxString);
for (unsigned i = 0; i < count; ++i) {
CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxString, i);
QString text = Internal::getQString(clang_getCompletionChunkText(cxString, i), false);
switch (chunkKind) {
case CXCompletionChunk_Placeholder:
chunk.hint += text.toHtmlEscaped();
break;
case CXCompletionChunk_Comma:
chunk.hint += text;
chunk.hint += QLatin1Char(' ');
break;
case CXCompletionChunk_Optional:
m_optionalChunks.append(chunk);
appendOptionalChunks(clang_getCompletionChunkCompletionString(cxString, i),
insertionIndex + chunk.hint.size());
return;
default:
break;
}
}
m_optionalChunks.append(chunk);
}
void CompletionProposalsBuilder::attachResultTypeToComment(const QString &resultType)
{
if (resultType.isEmpty())
return;
if (!m_comment.isEmpty())
m_comment += QLatin1String("<br/>");
m_comment += QLatin1String("<b>@return</b> ");
m_comment += resultType;
}
void CompletionProposalsBuilder::appendSnippet(const QString &text)
{
m_snippet += QLatin1Char('$');
m_snippet += text;
m_snippet += QLatin1Char('$');
}
void CompletionProposalsBuilder::appendHintBold(const QString &text)
{
m_hint += QLatin1String("<b>");
m_hint += text.toHtmlEscaped();
m_hint += QLatin1String("</b>");
}
} // namespace ClangCodeModel

View File

@@ -1,93 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGCODEMODEL_COMPLETIONPROPOSALSBUILDER_H
#define CLANGCODEMODEL_COMPLETIONPROPOSALSBUILDER_H
#include "clangcompleter.h"
#include "clang_global.h"
#include <clang-c/Index.h>
#include <QCoreApplication>
namespace ClangCodeModel {
class CLANG_EXPORT CompletionProposalsBuilder
{
Q_DECLARE_TR_FUNCTIONS(ClangCodeModel::CompletionProposalsBuilder)
public:
CompletionProposalsBuilder(QList<CodeCompletionResult> &results, quint64 contexts, bool isSignalSlotCompletion);
void operator ()(const CXCompletionResult &cxResult);
private:
struct OptionalChunk {
int positionInHint;
QString hint;
OptionalChunk() : positionInHint(0) {}
};
static CodeCompletionResult::Kind getKind(const CXCompletionResult &cxResult);
static CodeCompletionResult::Availability getAvailability(const CXCompletionResult &cxResult);
static int findNameInPlaceholder(const QString &text);
void resetWithResult(const CXCompletionResult &cxResult);
void finalize();
void concatChunksForObjectiveCMessage(const CXCompletionResult &cxResult);
void concatChunksForNestedName(const CXCompletionString &cxString);
void concatChunksAsSnippet(const CXCompletionString &cxString);
void concatChunksOnlyTypedText(const CXCompletionString &cxString);
void concatSlotSignalSignature(const CXCompletionString &cxString);
void appendOptionalChunks(const CXCompletionString &cxString,
int insertionIndex);
void attachResultTypeToComment(const QString &text);
void appendSnippet(const QString &text);
void appendHintBold(const QString &text);
QList<CodeCompletionResult> &m_results;
const quint64 m_contexts;
const bool m_isSignalSlotCompletion;
unsigned m_priority;
CodeCompletionResult::Kind m_resultKind;
CodeCompletionResult::Availability m_resultAvailability;
bool m_hasParameters;
QString m_hint;
QString m_text;
QString m_snippet;
QString m_comment;
QList<OptionalChunk> m_optionalChunks;
};
} // namespace ClangCodeModel
#endif // CLANGCODEMODEL_COMPLETIONPROPOSALSBUILDER_H

View File

@@ -1,18 +1,5 @@
<RCC>
<qresource prefix="/unittests/ClangCodeModel">
<file>cxx_regression_1.cpp</file>
<file>cxx_regression_2.cpp</file>
<file>cxx_regression_3.cpp</file>
<file>cxx_regression_4.cpp</file>
<file>cxx_regression_5.cpp</file>
<file>cxx_regression_6.cpp</file>
<file>cxx_regression_7.cpp</file>
<file>cxx_regression_8.cpp</file>
<file>cxx_regression_9.cpp</file>
<file>cxx_snippets_1.cpp</file>
<file>cxx_snippets_2.cpp</file>
<file>cxx_snippets_3.cpp</file>
<file>cxx_snippets_4.cpp</file>
<file>objc_messages_1.mm</file>
<file>objc_messages_2.mm</file>
<file>objc_messages_3.mm</file>

View File

@@ -1,393 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/**
* @file clangcompletion_test.cpp
* @brief Performs test for C/C++ code completion
*
* All test cases given as strings with @ character that points to completion
* location.
*/
#ifdef WITH_TESTS
// Disabled because there still no tool to detect system Objective-C headers
#define ENABLE_OBJC_TESTS 0
#include <QtTest>
#include <QDebug>
#undef interface // Canceling "#DEFINE interface struct" on Windows
#include "completiontesthelper.h"
#include "../clangcodemodelplugin.h"
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
////////////////////////////////////////////////////////////////////////////////
// Test cases
/**
* \defgroup Regression tests
*
* This group tests possible regressions in non-standard completion chunks
* handling: for example, macro arguments and clang's code snippets.
*
* @{
*/
void ClangCodeModelPlugin::test_CXX_regressions()
{
QFETCH(QString, file);
QFETCH(QStringList, unexpected);
QFETCH(QStringList, mustHave);
CompletionTestHelper helper;
helper << file;
QStringList proposals = helper.codeCompleteTexts();
foreach (const QString &p, unexpected)
QTEST_ASSERT(false == proposals.contains(p));
foreach (const QString &p, mustHave)
QTEST_ASSERT(true == proposals.contains(p));
}
void ClangCodeModelPlugin::test_CXX_regressions_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<QStringList>("unexpected");
QTest::addColumn<QStringList>("mustHave");
QString file;
QStringList unexpected;
QStringList mustHave;
file = QLatin1String("cxx_regression_1.cpp");
mustHave << QLatin1String("sqr");
mustHave << QLatin1String("~Math");
unexpected << QLatin1String("operator=");
QTest::newRow("case 1: method call completion") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_2.cpp");
unexpected << QLatin1String("i_second");
unexpected << QLatin1String("c_second");
unexpected << QLatin1String("f_second");
mustHave << QLatin1String("i_first");
mustHave << QLatin1String("c_first");
QTest::newRow("case 2: multiple anonymous structs") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_3.cpp");
mustHave << QLatin1String("i8");
mustHave << QLatin1String("i64");
mustHave << QLatin1String("~Priv");
unexpected << QLatin1String("operator=");
QTest::newRow("case 3: nested class resolution") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_4.cpp");
mustHave << QLatin1String("action");
QTest::newRow("case 4: local (in function) class resolution") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_5.cpp");
mustHave << QLatin1String("doB");
unexpected << QLatin1String("doA");
QTest::newRow("case 5: nested template class resolution") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_6.cpp");
mustHave << QLatin1String("OwningPtr");
QTest::newRow("case 6: using particular symbol from namespace") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_7.cpp");
mustHave << QLatin1String("dataMember");
mustHave << QLatin1String("anotherMember");
QTest::newRow("case 7: template class inherited from template parameter") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_8.cpp");
mustHave << QLatin1String("utils::");
unexpected << QLatin1String("utils");
QTest::newRow("case 8: namespace completion in function body") << file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
file = QLatin1String("cxx_regression_9.cpp");
mustHave << QLatin1String("EnumScoped::Value1");
mustHave << QLatin1String("EnumScoped::Value2");
mustHave << QLatin1String("EnumScoped::Value3");
unexpected << QLatin1String("Value1");
unexpected << QLatin1String("EnumScoped");
QTest::newRow("case 9: c++11 enum class, value used in switch and 'case' completed")
<< file << unexpected << mustHave;
mustHave.clear();
unexpected.clear();
}
void ClangCodeModelPlugin::test_CXX_snippets()
{
QFETCH(QString, file);
QFETCH(QStringList, texts);
QFETCH(QStringList, snippets);
Q_ASSERT(texts.size() == snippets.size());
CompletionTestHelper helper;
helper << file;
QList<CodeCompletionResult> proposals = helper.codeComplete();
for (int i = 0, n = texts.size(); i < n; ++i) {
const QString &text = texts[i];
const QString &snippet = snippets[i];
const QString snippetError =
QLatin1String("Text and snippet mismatch: text '") + text
+ QLatin1String("', snippet '") + snippet
+ QLatin1String("', got snippet \"%1\"");
bool hasText = false;
foreach (const CodeCompletionResult &ccr, proposals) {
if (ccr.text() != text)
continue;
hasText = true;
QVERIFY2(snippet == ccr.snippet(), snippetError.arg(ccr.snippet()).toLatin1());
}
const QString textError(QLatin1String("Text not found:") + text);
QVERIFY2(hasText, textError.toLatin1());
}
}
void ClangCodeModelPlugin::test_CXX_snippets_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<QStringList>("texts");
QTest::addColumn<QStringList>("snippets");
QString file;
QStringList texts;
QStringList snippets;
file = QLatin1String("cxx_snippets_1.cpp");
texts << QLatin1String("reinterpret_cast<type>(expression)");
snippets << QLatin1String("reinterpret_cast<$type$>($expression$)");
texts << QLatin1String("static_cast<type>(expression)");
snippets << QLatin1String("static_cast<$type$>($expression$)");
texts << QLatin1String("new type(expressions)");
snippets << QLatin1String("new $type$($expressions$)");
QTest::newRow("case: snippets for var declaration") << file << texts << snippets;
texts.clear();
snippets.clear();
file = QLatin1String("cxx_snippets_2.cpp");
texts << QLatin1String("private");
snippets << QLatin1String("");
texts << QLatin1String("protected");
snippets << QLatin1String("");
texts << QLatin1String("public");
snippets << QLatin1String("");
texts << QLatin1String("friend");
snippets << QLatin1String("");
texts << QLatin1String("virtual");
snippets << QLatin1String("");
texts << QLatin1String("typedef type name");
snippets << QLatin1String("typedef $type$ $name$");
QTest::newRow("case: snippets inside class declaration") << file << texts << snippets;
texts.clear();
snippets.clear();
file = QLatin1String("cxx_snippets_3.cpp");
texts << QLatin1String("List");
snippets << QLatin1String("List<$class Item$>");
texts << QLatin1String("Tuple");
snippets << QLatin1String("Tuple<$class First$, $class Second$, $typename Third$>");
QTest::newRow("case: template class insertion as snippet") << file << texts << snippets;
texts.clear();
snippets.clear();
file = QLatin1String("cxx_snippets_4.cpp");
texts << QLatin1String("clamp");
snippets << QLatin1String("");
texts << QLatin1String("perform");
snippets << QLatin1String("perform<$class T$>");
QTest::newRow("case: template function insertion as snippet") << file << texts << snippets;
texts.clear();
snippets.clear();
}
void ClangCodeModelPlugin::test_ObjC_hints()
{
QFETCH(QString, file);
QFETCH(QStringList, texts);
QFETCH(QStringList, snippets);
QFETCH(QStringList, hints);
Q_ASSERT(texts.size() == snippets.size());
Q_ASSERT(texts.size() == hints.size());
CompletionTestHelper helper;
helper << file;
QList<CodeCompletionResult> proposals = helper.codeComplete();
for (int i = 0, n = texts.size(); i < n; ++i) {
const QString &text = texts[i];
const QString &snippet = snippets[i];
const QString &hint = hints[i];
const QString snippetError =
QLatin1String("Text and snippet mismatch: text '") + text
+ QLatin1String("', snippet '") + snippet
+ QLatin1String("', got snippet \"%1\"");
const QString hintError =
QLatin1String("Text and hint mismatch: text '") + text
+ QLatin1String("', hint\n'") + hint
+ QLatin1String(", got hint\n\"%1\"");
bool hasText = false;
QStringList texts;
foreach (const CodeCompletionResult &ccr, proposals) {
texts << ccr.text();
if (ccr.text() != text)
continue;
hasText = true;
QVERIFY2(snippet == ccr.snippet(), snippetError.arg(ccr.snippet()).toLatin1());
QVERIFY2(hint == ccr.hint(), hintError.arg(ccr.hint()).toLatin1());
}
const QString textError(QString::fromLatin1("Text \"%1\" not found in set %2")
.arg(text).arg(texts.join(QLatin1Char(','))));
QVERIFY2(hasText, textError.toLatin1());
}
}
static QString makeObjCHint(const char *cHintPattern)
{
QString hintPattern(QString::fromUtf8(cHintPattern));
QStringList lines = hintPattern.split(QLatin1Char('\n'));
QString hint = QLatin1String("<p>");
bool prependNewline = false;
foreach (const QString &line, lines) {
if (prependNewline)
hint += QLatin1String("<br/>");
prependNewline = true;
int i = 0;
while (i < line.size() && line[i] == QLatin1Char(' ')) {
++i;
hint += QLatin1String("&nbsp;");
}
hint += line.mid(i);
}
hint += QLatin1String("</p>");
return hint;
}
void ClangCodeModelPlugin::test_ObjC_hints_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<QStringList>("texts");
QTest::addColumn<QStringList>("snippets");
QTest::addColumn<QStringList>("hints");
QString file;
QStringList texts;
QStringList snippets;
QStringList hints;
file = QLatin1String("objc_messages_1.mm");
texts << QLatin1String("spectacleQuality:");
snippets << QLatin1String("spectacleQuality:$(bool)$");
hints << makeObjCHint("-(int) spectacleQuality:<b>(bool)</b>");
texts << QLatin1String("desiredAmountForDramaDose:andPersonsCount:");
snippets << QLatin1String("desiredAmountForDramaDose:$(int)$ andPersonsCount:$(int)$");
hints << makeObjCHint("-(int) desiredAmountForDramaDose:<b>(int)</b> \n"
" andPersonsCount:<b>(int)</b>");
QTest::newRow("case: objective-c instance messages call") << file << texts << snippets << hints;
texts.clear();
snippets.clear();
hints.clear();
file = QLatin1String("objc_messages_2.mm");
texts << QLatin1String("eatenAmount");
snippets << QLatin1String("(int) eatenAmount");
hints << makeObjCHint("+(int) eatenAmount");
texts << QLatin1String("desiredAmountForDramaDose:andPersonsCount:");
snippets << QLatin1String("(int) desiredAmountForDramaDose:(int)dose andPersonsCount:(int)count");
hints << makeObjCHint("+(int) desiredAmountForDramaDose:(int)dose \n"
" andPersonsCount:(int)count");
QTest::newRow("case: objective-c class messages in @implementation") << file << texts << snippets << hints;
texts.clear();
snippets.clear();
hints.clear();
file = QLatin1String("objc_messages_3.mm");
texts << QLatin1String("eatenAmount");
snippets << QLatin1String("(int) eatenAmount");
hints << makeObjCHint("-(int) eatenAmount");
texts << QLatin1String("spectacleQuality");
snippets << QLatin1String("(int) spectacleQuality");
hints << makeObjCHint("-(int) spectacleQuality");
texts << QLatin1String("desiredAmountForDramaDose:andPersonsCount:");
snippets << QLatin1String("(int) desiredAmountForDramaDose:(int)dose andPersonsCount:(int)count");
hints << makeObjCHint("-(int) desiredAmountForDramaDose:(int)dose \n"
" andPersonsCount:(int)count");
texts << QLatin1String("initWithOldTracker:");
snippets << QLatin1String("(id) initWithOldTracker:(Bbbb<Aaaa> *)aabb");
hints << makeObjCHint("-(id) initWithOldTracker:(Bbbb&lt;Aaaa&gt; *)aabb");
QTest::newRow("case: objective-c class messages from base class") << file << texts << snippets << hints;
texts.clear();
snippets.clear();
hints.clear();
}
#endif

View File

@@ -1,148 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifdef WITH_TESTS
#include "completiontesthelper.h"
#include "../clangcompletion.h"
#include "../clangcompleter.h"
#include "../clangcodemodelplugin.h"
#include <cpptools/cppcompletionassist.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/codeassist/genericproposalmodel.h>
#include <utils/fileutils.h>
#include <utils/changeset.h>
#include <QDir>
#include <QtTest>
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
using namespace TextEditor;
using namespace CPlusPlus;
using namespace CppTools::Internal;
namespace ClangCodeModel {
namespace Internal {
CompletionTestHelper::CompletionTestHelper(QObject *parent) :
QObject(parent),
m_completer(new ClangCompleter()),
m_position(0),
m_line(0),
m_column(0)
{
m_clangOptions << QLatin1String("-std=c++0x")
<< QLatin1String("-ObjC++");
}
CompletionTestHelper::~CompletionTestHelper()
{
}
void CompletionTestHelper::operator <<(const QString &fileName)
{
QResource res(QLatin1String(":/unittests/ClangCodeModel/") + fileName);
m_sourceCode = QByteArray(reinterpret_cast<const char*>(res.data()), res.size());
findCompletionPos();
QString path = QDir::tempPath() + QLatin1String("/file.h");
::Utils::FileSaver srcSaver(path);
srcSaver.write(m_sourceCode);
srcSaver.finalize();
m_completer->setFileName(path);
m_completer->setOptions(m_clangOptions);
}
QStringList CompletionTestHelper::codeCompleteTexts()
{
QList<CodeCompletionResult> results =
m_completer->codeCompleteAt(m_line, m_column, m_unsavedFiles);
QStringList completions;
foreach (const CodeCompletionResult& ccr, results)
completions << ccr.text();
return completions;
}
QList<CodeCompletionResult> CompletionTestHelper::codeComplete()
{
return m_completer->codeCompleteAt(m_line, m_column, m_unsavedFiles);
}
int CompletionTestHelper::position() const
{
return m_position;
}
const QByteArray &CompletionTestHelper::source() const
{
return m_sourceCode;
}
void CompletionTestHelper::addOption(const QString &option)
{
m_clangOptions << option;
}
void CompletionTestHelper::findCompletionPos()
{
m_position = m_sourceCode.indexOf("<<<<");
QVERIFY(m_position != -1);
m_sourceCode[m_position] = ' ';
m_sourceCode[m_position + 1] = ' ';
m_sourceCode[m_position + 2] = ' ';
m_sourceCode[m_position + 3] = ' ';
// substring from 0 to '@' position
QByteArray substr(m_sourceCode.data(), m_position);
m_line = 1;
m_column = 1;
for (int i = 0; i < substr.size(); ++i) {
if (substr[i] == '\n') {
++m_line;
m_column = 1;
} else {
++m_column;
}
}
}
} // namespace Internal
} // namespace ClangCodeModel
#endif

View File

@@ -1,82 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGCODEMODEL_TESTS_COMPLETIONTESTHELPER_H
#define CLANGCODEMODEL_TESTS_COMPLETIONTESTHELPER_H
#ifdef WITH_TESTS
#include "../clangcompleter.h"
#include <QObject>
#include <QTextDocument>
#include <texteditor/texteditor.h>
#include <cplusplus/CppDocument.h>
namespace TextEditor { class IAssistProposal; }
namespace ClangCodeModel {
namespace Internal {
class CompletionTestHelper : public QObject
{
Q_OBJECT
public:
explicit CompletionTestHelper(QObject *parent = 0);
~CompletionTestHelper();
void operator <<(const QString &fileName);
QStringList codeCompleteTexts();
QList<CodeCompletionResult> codeComplete();
int position() const;
const QByteArray &source() const;
void addOption(const QString &option);
private:
void findCompletionPos();
UnsavedFiles m_unsavedFiles;
ClangCompleter::Ptr m_completer;
QStringList m_clangOptions;
QByteArray m_sourceCode;
int m_position;
int m_line;
int m_column;
};
} // namespace Internal
} // namespace ClangCodeModel
#endif
#endif // CLANGCODEMODEL_TESTS_COMPLETIONTESTHELPER_H

View File

@@ -1,45 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'sqr'
* Not expected: '~Math', 'operator='s
*/
class Math
{
int sqr(int a);
};
void foo()
{
Math math;
int sqr = math.<<<<;
}

View File

@@ -1,51 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'i_first' 'c_first'
* Not expected: 'i_second' 'c_second' 'f_second'
*/
typedef struct {
int i_first;
char c_first;
} S1;
typedef struct {
int i_second;
char c_second;
float f_second;
} S2;
void foo()
{
S1 s;
s.<<<<;
}

View File

@@ -1,69 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'i8' 'i64'
* Unexpected: 'Priv' 'operator='
*/
class Example
{
public:
Example();
~Example();
private:
class Priv;
Priv *d;
};
class Example::Priv
{
public:
int i8;
int i64;
Priv() : i8(8), i64(64) {}
};
Example::Example()
: d(new Example::Priv())
{
d-><<<<;
}
Example::~Example()
{
}
void f()
{
Example w;
}

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'action'
*/
void func()
{
struct impl
{
static void action() {}
};
impl::<<<<;
}

View File

@@ -1,62 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'doB'
* Not expected: 'doA'
*/
struct A {
struct Inside {
void doA() {}
};
};
struct B {
struct Inside {
void doB() {}
};
};
template<class T> class C {
public:
typename T::Inside inner;
};
int main()
{
C<A> ca;
C<B> cb;
ca.inner.doA();
cb.inner.<<<<;
return 0;
}

View File

@@ -1,51 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'OwningPtr'
*/
namespace llvm {
class OwningPtr;
}
namespace clang {
using llvm::OwningPtr;
}
class llvm::OwningPtr
{
};
void foo()
{
clang::<<<< ptr;
(void)ptr;
}

View File

@@ -1,48 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'dataMember', 'anotherMember'
*/
class Data {
int dataMember;
};
template <class T> class Other : public T
{
int anotherMember;
};
void func()
{
Other<Data> c;
c.<<<<;
}

View File

@@ -1,47 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'utils::'
* Not expected: 'utils'
*/
namespace utils
{
int sqr(int a)
{
return a * a;
}
}
void foo()
{
<<<<
}

View File

@@ -1,55 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
* Expected: 'EnumScoped::Value1', 'EnumScoped::Value2', 'EnumScoped::Value3'
* Unexpected: 'Value1'
*/
enum class EnumScoped
{
Value1,
Value2,
Value3
};
class ClassOwnsEnum
{
};
int main()
{
EnumScoped scoped = ;
switch (scoped) {
default:
break;
case <<<<
}
}

View File

@@ -1,49 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
Expected:
text 'reinterpret_cast<type>(expression)'
snippet 'reinterpret_cast<$type$>($expression$)'
text 'static_cast<type>(expression)'
snippet 'static_cast<$type$>($expression$)'
text 'new type(expressions)'
snippet 'new $type$($expressions$)'
*/
void foo()
{
int data[] = {
1, 2, 3
};
char *cdata = <<<<;
}

View File

@@ -1,45 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*
Expected:
text 'private',
text 'protected',
text 'public',
text 'friend',
text 'virtual'
text 'typedef type name', snippet 'typedef $type$ $name$'
*/
class A
{
<<<<
};

View File

@@ -1,53 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
// Expected:
// (List, List<$class Item$>),
// (Tuple, Tuple<$class First$, $class Second$, $typename Third$>)
template <class Item>
class List
{
Item *data;
};
template <class First, class Second, typename Third>
class Tuple
{
First *data;
Second *data2;
Third *data3;
};
void check()
{
<<<<
}

View File

@@ -1,61 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
// Expected:
// (clamp, ),
// (perform, perform<$class T$>)
// (perform3, perform3<$class T$, $int E$, $class D$>)
// note: clang understands if parameter is redundant
template<class T>
T clamp(T value, T a = 0.0, T b = 1.0)
{
if (value < a)
return a;
if (value > b)
return b;
return value;
}
template<class T>
void perform()
{
}
template<class T, int E, class D>
void perform3()
{
}
void check()
{
<<<<
}