Commit 42f4595e authored by Eike Ziller's avatar Eike Ziller
Browse files

Merge remote-tracking branch 'origin/2.5'

Conflicts:
	src/libs/cplusplus/cplusplus-lib.pri

Change-Id: I430ec8c6dda4afad3aedb1bc47d3af64537cfe66
parents 3f6eed50 cebf6b93
Qt Creator version 2.5.1 contains bug fixes.
The most important changes are listed in this document. For a complete
list of changes, see the Git log for the Qt Creator sources that
you can check out from the public Git repository. For example:
git clone git://gitorious.org/qt-creator/qt-creator.git
git log --cherry-pick --pretty=oneline v2.5.0...origin/2.5
Managing Projects
* Fixed crash in CMake makestep if used in the deploystep list
(QTCREATORBUG-7427)
* Fixed crash on unloading Qt4 projects
C++ Support
* Fixed crash on invalid class name (QTCREATORBUG-7462)
* Fixed class scope completion for templates
QML/JS Support
* Fixed crash with e.g. color picker on Mac (QTCREATORBUG-7605)
Help
* Handle mailto links (QTCREATORBUG-4058)
Version Control
* Fixed SVN project status command when no document is open
* Fixed committing to Mercurial repositories (QTCREATORBUG-7511)
Platform Specific
Linux
* Fixed default UI language on systems where that contains region information
Mac
* Fixed font rendering problems (QTCREATORBUG-7127, fixed in Qt)
......@@ -40,6 +40,11 @@
#include <QFileInfo>
#include <QAtomicInt>
// in debug mode: make dumpers widely available without an extra include
#ifdef QT_DEBUG
#include "Dumpers.h"
#endif
namespace CPlusPlus {
class Macro;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "Dumpers.h"
#include <Overview.h>
#include <Literals.h>
#include <Scope.h>
#include <LookupContext.h>
#include <QDebug>
#include <typeinfo>
static QString indent(QString s, int level = 2)
{
QString indentString(level, QLatin1Char(' '));
QString result;
int last = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.at(i) == QLatin1Char('\n') || i == s.length() - 1) {
result.append(indentString);
result.append(s.midRef(last, i + 1));
last = i + 1;
}
}
return result;
}
QString CPlusPlus::toString(const Name *name, QString id)
{
Overview oo;
return QString("%0: %1").arg(id, name ? oo(name) : QLatin1String("(null)"));
}
QString CPlusPlus::toString(FullySpecifiedType ty, QString id)
{
Overview oo;
return QString("%0: %1 (a %2)").arg(id, oo(ty), ty.type() ? typeid(*ty.type()).name() : "(null)");
}
QString CPlusPlus::toString(const Symbol *s, QString id)
{
if (!s)
return QString("%0: (null)").arg(id);
return QString("%0: %1 (%2) at %3:%4:%5\n%6").arg(
id,
QString::fromLatin1(typeid(*s).name()),
QString::fromUtf8(s->identifier()->chars()),
QString::fromLatin1(s->fileName()),
QString::number(s->line()),
QString::number(s->column()),
indent(toString(s->type())));
}
QString CPlusPlus::toString(LookupItem it, QString id)
{
QString result = QString("%1:").arg(id);
if (it.declaration()) {
result.append(QString("\n%1").arg(indent(toString(it.declaration(), QLatin1String("Decl")))));
}
if (it.type().isValid()) {
result.append(QString("\n%1").arg(indent(toString(it.type()))));
}
if (it.scope()) {
result.append(QString("\n%1").arg(indent(toString(it.scope(), QLatin1String("Scope")))));
}
if (it.binding()) {
result.append(QString("\n%1").arg(indent(toString(it.binding(), QLatin1String("Binding")))));
}
return result;
}
QString CPlusPlus::toString(const ClassOrNamespace *binding, QString id)
{
if (!binding)
return QString("%0: (null)").arg(id);
QString result = QString("%0: %1 symbols").arg(
id,
QString::number(binding->symbols().length()));
if (binding->templateId()) {
result.append(QString("\n%1").arg(indent(toString(binding->templateId(), QLatin1String("Template")))));
}
return result;
}
void CPlusPlus::dump(const Name *name)
{
qDebug() << qPrintable(toString(name));
}
void CPlusPlus::dump(FullySpecifiedType ty)
{
qDebug() << qPrintable(toString(ty));
}
void CPlusPlus::dump(const Symbol *s)
{
qDebug() << qPrintable(toString(s));
}
void CPlusPlus::dump(LookupItem it)
{
qDebug() << qPrintable(toString(it));
}
void CPlusPlus::dump(const ClassOrNamespace *binding)
{
qDebug() << qPrintable(toString(binding));
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef CPLUSPLUS_DUMPERS_H
#define CPLUSPLUS_DUMPERS_H
#include <CPlusPlusForwardDeclarations.h>
#include <FullySpecifiedType.h>
#include <Symbol.h>
#include <LookupItem.h>
#include <QString>
namespace CPlusPlus {
QString CPLUSPLUS_EXPORT toString(const Name *name, QString id = QLatin1String("Name"));
QString CPLUSPLUS_EXPORT toString(FullySpecifiedType ty, QString id = QLatin1String("Type"));
QString CPLUSPLUS_EXPORT toString(const Symbol *s, QString id = QLatin1String("Symbol"));
QString CPLUSPLUS_EXPORT toString(LookupItem it, QString id = QLatin1String("LookupItem"));
QString CPLUSPLUS_EXPORT toString(const ClassOrNamespace *binding, QString id = QLatin1String("ClassOrNamespace"));
void CPLUSPLUS_EXPORT dump(const Name *name);
void CPLUSPLUS_EXPORT dump(FullySpecifiedType ty);
void CPLUSPLUS_EXPORT dump(const Symbol *s);
void CPLUSPLUS_EXPORT dump(LookupItem it);
void CPLUSPLUS_EXPORT dump(const ClassOrNamespace *binding);
} // namespace CPlusPlus
#endif
......@@ -53,7 +53,8 @@ HEADERS += \
$$PWD/pp-engine.h \
$$PWD/pp-scanner.h \
$$PWD/findcdbbreakpoint.h \
$$PWD/PPToken.h
$$PWD/PPToken.h \
$$PWD/Dumpers.h
SOURCES += \
$$PWD/SimpleLexer.cpp \
......@@ -80,6 +81,7 @@ SOURCES += \
$$PWD/pp-engine.cpp \
$$PWD/pp-scanner.cpp \
$$PWD/findcdbbreakpoint.cpp \
$$PWD/PPToken.cpp
$$PWD/PPToken.cpp \
$$PWD/Dumpers.cpp
RESOURCES += $$PWD/cplusplus.qrc
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "cpptoolsplugin.h"
#include <AST.h>
#include <Control.h>
#include <CppDocument.h>
#include <DiagnosticClient.h>
#include <Scope.h>
#include <TranslationUnit.h>
#include <Literals.h>
#include <Bind.h>
#include <Symbols.h>
#include <utils/changeset.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/codeassist/iassistproposalmodel.h>
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
#include <cpptools/cpptoolsplugin.h>
#include <cpptools/cppcompletionassist.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/fileutils.h>
#include <QtTest>
#include <QtDebug>
#include <QTextDocument>
#include <QDir>
/*!
Tests for code completion.
*/
using namespace CPlusPlus;
using namespace CppTools;
using namespace CppTools::Internal;
using namespace TextEditor;
using namespace Core;
struct TestData
{
QByteArray srcText;
int pos;
Snapshot snapshot;
BaseTextEditorWidget *editor;
QTextDocument *doc;
};
static QStringList getCompletions(TestData &data)
{
QStringList completions;
CppCompletionAssistInterface *ai = new CppCompletionAssistInterface(data.editor->document(), data.pos,
data.editor->editorDocument(), ExplicitlyInvoked,
data.snapshot, QStringList(), QStringList());
CppCompletionAssistProcessor processor;
IAssistProposal *proposal = processor.perform(ai);
if (!proposal)
return completions;
IAssistProposalModel *model = proposal->model();
if (!model)
return completions;
BasicProposalItemListModel *listmodel = dynamic_cast<BasicProposalItemListModel *>(model);
if (!listmodel)
return completions;
for (int i = 0; i < listmodel->size(); ++i)
completions << listmodel->text(i);
return completions;
}
static void setup(TestData *data)
{
data->pos = data->srcText.indexOf('@');
QVERIFY(data->pos != -1);
data->srcText[data->pos] = ' ';
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(data->srcText);
srcSaver.finalize();
src->setUtf8Source(data->srcText);
src->parse();
src->check();
data->snapshot.insert(src);
data->editor = new PlainTextEditorWidget(0);
QString error;
data->editor->open(&error, src->fileName(), src->fileName());
data->doc = data->editor->document();
}
void CppToolsPlugin::test_completion_basic_1()
{
TestData data;
data.srcText = "\n"
"class Foo\n"
"{\n"
" void foo();\n"
" int m;\n"
"};\n"
"\n"
"void func() {\n"
" Foo f;\n"
" @\n"
" // padding so we get the scope right\n"
"}";
setup(&data);
QStringList basicCompletions = getCompletions(data);
QVERIFY(!basicCompletions.contains("foo"));
QVERIFY(!basicCompletions.contains("m"));
QVERIFY(basicCompletions.contains("Foo"));
QVERIFY(basicCompletions.contains("func"));
QVERIFY(basicCompletions.contains("f"));
Utils::ChangeSet change;
change.insert(data.pos, "f.");
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += 2;
QStringList memberCompletions = getCompletions(data);
QVERIFY(memberCompletions.contains("foo"));
QVERIFY(memberCompletions.contains("m"));
QVERIFY(!memberCompletions.contains("func"));
QVERIFY(!memberCompletions.contains("f"));
}
void CppToolsPlugin::test_completion_template_1()
{
TestData data;
data.srcText = "\n"
"template <class T>\n"
"class Foo\n"
"{\n"
" typedef T Type;\n"
" T foo();\n"
" T m;\n"
"};\n"
"\n"
"void func() {\n"
" Foo f;\n"
" @\n"
" // padding so we get the scope right\n"
"}";
setup(&data);
Utils::ChangeSet change;
change.insert(data.pos, "Foo::");
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += 5;
QStringList completions = getCompletions(data);
QVERIFY(completions.contains("Type"));
QVERIFY(completions.contains("foo"));
QVERIFY(completions.contains("m"));
QVERIFY(!completions.contains("T"));
QVERIFY(!completions.contains("f"));
QVERIFY(!completions.contains("func"));
}
......@@ -1448,6 +1448,13 @@ bool CppCompletionAssistProcessor::completeScope(const QList<CPlusPlus::LookupIt
break;
}
} else if (Template *templ = ty->asTemplateType()) {
if (!result.binding())
continue;
if (ClassOrNamespace *b = result.binding()->lookupType(templ->name())) {
completeClass(b);
break;
}
}
}
......
......@@ -94,5 +94,6 @@ FORMS += completionsettingspage.ui \
equals(TEST, 1) {
SOURCES += \
cppcodegen_test.cpp
cppcodegen_test.cpp \
cppcompletion_test.cpp
}
......@@ -89,6 +89,9 @@ private slots:
void test_codegen_definition_first_member();
void test_codegen_definition_last_member();
void test_codegen_definition_middle_member();
void test_completion_basic_1();
void test_completion_template_1();
#endif
private:
......
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