Commit d1fd61cb authored by Daniel Teske's avatar Daniel Teske

Android: Add minimal Java editing support

Indentation for blocks '{'. '}' and completion for keywords.

TODO: "New File" is missing,
TODO: probably needs some tweaks to the indentation.
Task-number: QTCREATORBUG-11220

Change-Id: I758b3815e47d1427d39c0248eb16e39ffb7a29fb
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent cdd19fe6
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-java">
<sub-class-of type="text/x-csrc"/>
<comment>Java Source file</comment>
<glob pattern="*.java"/>
</mime-type>
</mime-info>
......@@ -49,7 +49,12 @@ HEADERS += \
createandroidmanifestwizard.h \
androidpotentialkit.h \
androidextralibrarylistmodel.h \
androidsignaloperation.h
androidsignaloperation.h \
javaeditor.h \
javaeditorfactory.h \
javaindenter.h \
javaautocompleter.h \
javacompletionassistprovider.h
SOURCES += \
androidconfigurations.cpp \
......@@ -93,7 +98,12 @@ SOURCES += \
createandroidmanifestwizard.cpp \
androidpotentialkit.cpp \
androidextralibrarylistmodel.cpp \
androidsignaloperation.cpp
androidsignaloperation.cpp \
javaeditor.cpp \
javaeditorfactory.cpp \
javaindenter.cpp \
javaautocompleter.cpp \
javacompletionassistprovider.cpp
FORMS += \
androidsettingswidget.ui \
......
......@@ -112,6 +112,16 @@ QtcPlugin {
"certificatesmodel.h",
"createandroidmanifestwizard.cpp",
"createandroidmanifestwizard.h",
"javaautocompleter.cpp",
"javaautocompleter.h",
"javacompletionassistprovider.cpp",
"javacompletionassistprovider.h",
"javaeditor.cpp",
"javaeditor.h",
"javaeditorfactory.cpp",
"javaeditorfactory.h",
"javaindenter.cpp",
"javaindenter.h",
"javaparser.cpp",
"javaparser.h",
]
......
<RCC>
<qresource prefix="/android">
<file>images/QtAndroid.png</file>
<file>Java.mimetypes.xml</file>
</qresource>
</RCC>
......@@ -67,6 +67,9 @@ const char ANDROID_MANIFEST_EDITOR_ID[] = "Android.AndroidManifestEditor.Id";
const char ANDROID_MANIFEST_EDITOR_CONTEXT[] = "Android.AndroidManifestEditor.Id";
const char ANDROID_BUILDDIRECTORY[] = "android-build";
const char JAVA_EDITOR_ID[] = "java.editor";
const char C_JAVA_EDITOR[] = "Java Editor";
const char JAVA_MIMETYPE[] = "text/x-java";
} // namespace Constants;
} // namespace Android
......
......@@ -46,6 +46,8 @@
#include "androidgdbserverkitinformation.h"
#include "androidmanifesteditorfactory.h"
#include "androidpotentialkit.h"
#include "javaeditorfactory.h"
#include "javacompletionassistprovider.h"
#ifdef HAVE_QBS
# include "androidqbspropertyprovider.h"
#endif
......@@ -83,6 +85,8 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
addAutoReleasedObject(new Internal::AndroidDeployConfigurationFactory);
addAutoReleasedObject(new Internal::AndroidDeviceFactory);
addAutoReleasedObject(new Internal::AndroidPotentialKit);
addAutoReleasedObject(new Internal::JavaEditorFactory);
addAutoReleasedObject(new Internal::JavaCompletionAssistProvider);
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
// AndroidManifest.xml editor
......@@ -99,6 +103,9 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
}
addAutoReleasedObject(new Internal::AndroidManifestEditorFactory);
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":android/Java.mimetypes.xml"), errorMessage))
return false;
connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()),
this, SLOT(kitsRestored()));
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "javaautocompleter.h"
using namespace Android;
using namespace Android::Internal;
JavaAutoCompleter::JavaAutoCompleter()
{
}
bool JavaAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const
{
Q_UNUSED(cursor)
Q_UNUSED(textToInsert)
return true;
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef JAVAAUTOCOMPLETER_H
#define JAVAAUTOCOMPLETER_H
#include <texteditor/autocompleter.h>
namespace Android {
namespace Internal {
class JavaAutoCompleter : public TextEditor::AutoCompleter
{
public:
// TODO What does the base class do?
// I only need the contextAllowsAutoParenthses change
JavaAutoCompleter();
bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
};
}
}
#endif // JAVAAUTOCOMPLETER_H
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "javacompletionassistprovider.h"
#include "androidconstants.h"
#include <texteditor/codeassist/keywordscompletionassist.h>
using namespace Android;
using namespace Android::Internal;
static const char *const keywords[] = {
"abstract",
"continue",
"for",
"new",
"switch",
"assert",
"default",
"goto",
"package",
"synchronized",
"boolean",
"do",
"if",
"private",
"this",
"break",
"double",
"implements",
"protected",
"throw"
"byte",
"else",
"import",
"public",
"throws",
"case",
"enum",
"instanceof",
"return",
"transient",
"catch",
"extends",
"int",
"short",
"try",
"char",
"final",
"interface",
"static",
"void",
"class",
"finally",
"long",
"strictfp",
"volatile",
"const",
"float",
"native",
"super",
"while",
0
};
JavaCompletionAssistProvider::JavaCompletionAssistProvider()
{
}
JavaCompletionAssistProvider::~JavaCompletionAssistProvider()
{
}
void JavaCompletionAssistProvider::init() const
{
for (uint i = 0; i < sizeof keywords / sizeof keywords[0] - 1; i++)
m_keywords.append(QLatin1String(keywords[i]));
}
bool JavaCompletionAssistProvider::supportsEditor(const Core::Id &editorId) const
{
return editorId == Constants::JAVA_EDITOR_ID;
}
TextEditor::IAssistProcessor *JavaCompletionAssistProvider::createProcessor() const
{
if (m_keywords.isEmpty())
init();
TextEditor::Keywords keywords = TextEditor::Keywords(m_keywords,
QStringList(),
QMap<QString, QStringList>());
return new TextEditor::KeywordsCompletionAssistProcessor(keywords);
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef JAVACOMPLETIONASSISTPROVIDER_H
#define JAVACOMPLETIONASSISTPROVIDER_H
#include <texteditor/codeassist/completionassistprovider.h>
#include <QStringList>
namespace Android {
namespace Internal {
class JavaCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
JavaCompletionAssistProvider();
~JavaCompletionAssistProvider();
void init() const;
bool supportsEditor(const Core::Id &editorId) const;
TextEditor::IAssistProcessor *createProcessor() const;
private:
mutable QStringList m_keywords;
};
}
}
#endif // JAVACOMPLETIONASSISTPROVIDER_H
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "javaeditor.h"
#include "javaindenter.h"
#include "javaautocompleter.h"
#include "androidconstants.h"
#include "javacompletionassistprovider.h"
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/normalindenter.h>
#include <texteditor/highlighterutils.h>
#include <coreplugin/mimedatabase.h>
#include <extensionsystem/pluginmanager.h>
#include <QFileInfo>
using namespace Android;
using namespace Android::Internal;
//
// JavaEditor
//
JavaEditor::JavaEditor(JavaEditorWidget *editor)
: BaseTextEditor(editor)
{
setContext(Core::Context(Constants::C_JAVA_EDITOR,
TextEditor::Constants::C_TEXTEDITOR));
}
Core::IEditor *JavaEditor::duplicate()
{
JavaEditorWidget *ret = new JavaEditorWidget(
qobject_cast<JavaEditorWidget*>(editorWidget()));
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
}
Core::Id JavaEditor::id() const
{
return Core::Id(Constants::JAVA_EDITOR_ID);
}
TextEditor::CompletionAssistProvider *JavaEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>();
}
//
// JavaEditorWidget
//
JavaEditorWidget::JavaEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new JavaDocument(), parent)
{
ctor();
}
JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other)
: BaseTextEditorWidget(other)
{
ctor();
}
void JavaEditorWidget::ctor()
{
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1String("//");
m_commentDefinition.multiLineStart = QLatin1String("/*");
m_commentDefinition.multiLineEnd = QLatin1String("*/");
setAutoCompleter(new JavaAutoCompleter);
}
void JavaEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, m_commentDefinition);
}
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
{
return new JavaEditor(this);
}
//
// JavaDocument
//
JavaDocument::JavaDocument()
: TextEditor::BaseTextDocument()
{
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(Core::MimeDatabase::findByType(QLatin1String(Constants::JAVA_MIMETYPE))));
setIndenter(new JavaIndenter);
}
QString JavaDocument::defaultPath() const
{
QFileInfo fi(filePath());
return fi.absolutePath();
}
QString JavaDocument::suggestedFileName() const
{
QFileInfo fi(filePath());
return fi.fileName();
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef JAVAEDITOR_H
#define JAVAEDITOR_H
#include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h>
#include <utils/uncommentselection.h>
namespace Android {
namespace Internal {
class JavaEditorFactory;
class JavaEditorWidget;
class JavaEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
JavaEditor(JavaEditorWidget *);
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate();
Core::Id id() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
class JavaEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
JavaEditorWidget(QWidget *parent = 0);
JavaEditorWidget(JavaEditorWidget *other);
void unCommentSelection();
protected:
TextEditor::BaseTextEditor *createEditor();
private:
JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity
void ctor();
Utils::CommentDefinition m_commentDefinition;
};
class JavaDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
JavaDocument();
QString defaultPath() const;
QString suggestedFileName() const;
};
} // namespace Internal
} // namespace QmakeProjectManager
#endif // JAVAEDITOR_H
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "javaeditorfactory.h"
#include "javaeditor.h"
#include "androidconstants.h"
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
using namespace Android;
using namespace Android::Internal;
JavaEditorFactory::JavaEditorFactory()