Changeset View
Changeset View
Standalone View
Standalone View
javalanguagesupport.cpp
Show All 16 Lines | |||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "javalanguagesupport.h" | 21 | #include "javalanguagesupport.h" | ||
22 | 22 | | |||
23 | #include <limits.h> | 23 | #include <limits.h> | ||
24 | 24 | | |||
25 | #include <kdebug.h> | 25 | #include <QDebug> | ||
26 | #include <kcomponentdata.h> | | |||
27 | #include <kstandarddirs.h> | | |||
28 | #include <kgenericfactory.h> | | |||
29 | #include <KConfigGroup> | | |||
30 | 26 | | |||
31 | #include <QExtensionFactory> | 27 | #include <KConfigGroup> | ||
32 | #include <QDir> | 28 | #include <KPluginFactory> | ||
33 | 29 | | |||
34 | #include <interfaces/icore.h> | 30 | #include <interfaces/icore.h> | ||
35 | #include <interfaces/ilanguagecontroller.h> | 31 | #include <interfaces/ilanguagecontroller.h> | ||
36 | #include <interfaces/idocumentcontroller.h> | 32 | #include <interfaces/idocumentcontroller.h> | ||
37 | #include <interfaces/iprojectcontroller.h> | 33 | #include <interfaces/iprojectcontroller.h> | ||
38 | #include <language/backgroundparser/backgroundparser.h> | 34 | #include <language/backgroundparser/backgroundparser.h> | ||
39 | #include <language/duchain/duchain.h> | 35 | #include <language/duchain/duchain.h> | ||
40 | #include <language/duchain/duchainlock.h> | 36 | #include <language/duchain/duchainlock.h> | ||
41 | #include <interfaces/iproject.h> | 37 | #include <interfaces/iproject.h> | ||
42 | 38 | | |||
43 | #include "parsejob.h" | 39 | #include "parsejob.h" | ||
40 | #include "settings/javapreferences.h" | ||||
44 | 41 | | |||
45 | #include <language/codecompletion/codecompletion.h> | 42 | #include <language/codecompletion/codecompletion.h> | ||
46 | #include <language/codecompletion/codecompletionmodel.h> | 43 | #include <language/codecompletion/codecompletionmodel.h> | ||
47 | #include "completion/model.h" | 44 | #include "completion/model.h" | ||
48 | #include <language/duchain/duchainutils.h> | 45 | #include <language/duchain/duchainutils.h> | ||
49 | #include <project/projectmodel.h> | 46 | #include <project/projectmodel.h> | ||
50 | #include <KIO/NetAccess> | | |||
51 | #include <qapplication.h> | 47 | #include <qapplication.h> | ||
52 | #include <kio/job.h> | 48 | #include <kio/job.h> | ||
53 | #include <language/highlighting/codehighlighting.h> | 49 | #include <language/highlighting/codehighlighting.h> | ||
54 | #include <interfaces/ilanguage.h> | | |||
55 | #include <QReadWriteLock> | 50 | #include <QReadWriteLock> | ||
56 | #include <kzip.h> | 51 | #include <kzip.h> | ||
57 | 52 | | |||
58 | using namespace java; | 53 | using namespace java; | ||
59 | 54 | | |||
60 | K_PLUGIN_FACTORY(KDevJavaSupportFactory, registerPlugin<JavaLanguageSupport>(); ) | 55 | K_PLUGIN_FACTORY_WITH_JSON(KDevJavaSupportFactory, "kdevjavasupport.json", registerPlugin<JavaLanguageSupport>(); ) | ||
61 | K_EXPORT_PLUGIN(KDevJavaSupportFactory("kdevjavasupport")) | | |||
62 | 56 | | |||
63 | JavaLanguageSupport* JavaLanguageSupport::s_self = 0; | 57 | JavaLanguageSupport* JavaLanguageSupport::s_self = 0; | ||
64 | 58 | | |||
65 | JavaLanguageSupport::JavaLanguageSupport( QObject* parent, | 59 | JavaLanguageSupport::JavaLanguageSupport( QObject* parent, | ||
66 | const QVariantList& /*args*/ ) | 60 | const QVariantList& /*args*/ ) | ||
67 | : KDevelop::IPlugin( KDevJavaSupportFactory::componentData(), parent ) | 61 | : KDevelop::IPlugin(QStringLiteral("kdevjavasupport"), parent ) | ||
68 | , KDevelop::ILanguageSupport() | 62 | , KDevelop::ILanguageSupport() | ||
69 | , m_allJavaContext(0) | 63 | , m_allJavaContext(0) | ||
70 | , m_javaSourceZipMutex(new QMutex()) | 64 | , m_javaSourceZipMutex(new QMutex()) | ||
71 | , m_javaSourceZip(0) | 65 | , m_javaSourceZip(0) | ||
72 | { | 66 | { | ||
73 | s_self = this; | 67 | s_self = this; | ||
74 | 68 | | |||
75 | KDEV_USE_EXTENSION_INTERFACE( KDevelop::ILanguageSupport ) | | |||
76 | | ||||
77 | m_highlighting = new KDevelop::CodeHighlighting( this ); | 69 | m_highlighting = new KDevelop::CodeHighlighting( this ); | ||
78 | 70 | | |||
79 | CodeCompletionModel* ccModel = new CodeCompletionModel(this); | 71 | CodeCompletionModel* ccModel = new CodeCompletionModel(this); | ||
80 | new KDevelop::CodeCompletion( this, ccModel, name() ); | 72 | new KDevelop::CodeCompletion( this, ccModel, name() ); | ||
81 | 73 | | |||
82 | scheduleInternalSources(); | 74 | scheduleInternalSources(); | ||
83 | 75 | | |||
84 | kDebug() << "Java support loaded"; | 76 | qDebug() << "Java support loaded"; | ||
85 | } | 77 | } | ||
86 | 78 | | |||
87 | JavaLanguageSupport::~JavaLanguageSupport() | 79 | JavaLanguageSupport::~JavaLanguageSupport() | ||
88 | { | 80 | { | ||
89 | KDevelop::ILanguage* lang = language(); | 81 | KDevelop::ILanguageSupport* lang = language(); | ||
90 | if (lang) { | 82 | if (lang) { | ||
91 | lang->parseLock()->lockForWrite(); | 83 | lang->parseLock()->lockForWrite(); | ||
92 | s_self = 0; //By locking the parse-mutexes, we make sure that parse- and preprocess-jobs get a chance to finish in a good state | 84 | s_self = 0; //By locking the parse-mutexes, we make sure that parse- and preprocess-jobs get a chance to finish in a good state | ||
93 | lang->parseLock()->unlock(); | 85 | lang->parseLock()->unlock(); | ||
94 | } | 86 | } | ||
95 | 87 | | |||
96 | delete m_javaSourceZip; | 88 | delete m_javaSourceZip; | ||
97 | } | 89 | } | ||
Show All 9 Lines | 98 | { | |||
107 | return new ParseJob( url, this ); | 99 | return new ParseJob( url, this ); | ||
108 | } | 100 | } | ||
109 | 101 | | |||
110 | QString JavaLanguageSupport::name() const | 102 | QString JavaLanguageSupport::name() const | ||
111 | { | 103 | { | ||
112 | return "Java"; | 104 | return "Java"; | ||
113 | } | 105 | } | ||
114 | 106 | | |||
115 | KDevelop::ILanguage * JavaLanguageSupport::language() | 107 | KDevelop::ILanguageSupport * JavaLanguageSupport::language() | ||
116 | { | 108 | { | ||
117 | return core()->languageController()->language(name()); | 109 | return core()->languageController()->language(name()); | ||
118 | } | 110 | } | ||
119 | 111 | | |||
120 | void JavaLanguageSupport::scheduleInternalSources() | 112 | void JavaLanguageSupport::scheduleInternalSources() | ||
121 | { | 113 | { | ||
122 | KConfigGroup config(KGlobal::config(), "Java Support"); | 114 | KConfigGroup config(KSharedConfig::openConfig(), "Java Support"); | ||
123 | m_javaSourceUrl = config.readEntry("Java Source Zip", KUrl()); | 115 | m_javaSourceUrl = config.readEntry("Java Source Zip", QUrl()); | ||
124 | 116 | | |||
125 | if (m_javaSourceUrl.protocol() == "file") { | 117 | if (m_javaSourceUrl.scheme() == "file") { | ||
126 | // KIO method - replace with KZip method if you can understand the KArchive API | 118 | // KIO method - replace with KZip method if you can understand the KArchive API | ||
127 | QFileInfo info(m_javaSourceUrl.path()); | 119 | QFileInfo info(m_javaSourceUrl.path()); | ||
128 | if (info.exists() && info.isReadable() && info.isFile()) { | 120 | if (info.exists() && info.isReadable() && info.isFile()) { | ||
129 | m_javaSourceZip = new KZip(m_javaSourceUrl.path()); | 121 | m_javaSourceZip = new KZip(m_javaSourceUrl.path()); | ||
130 | if (!m_javaSourceZip->open(QIODevice::ReadOnly)) { | 122 | if (!m_javaSourceZip->open(QIODevice::ReadOnly)) { | ||
131 | kDebug() << "error, could not open zip file"<< m_javaSourceUrl <<"for reading."; | 123 | qDebug() << "error, could not open zip file"<< m_javaSourceUrl <<"for reading."; | ||
132 | return; | 124 | return; | ||
133 | } | 125 | } | ||
134 | 126 | | |||
135 | m_javaSourceUrl.setProtocol("zip"); | 127 | m_javaSourceUrl.setScheme("zip"); | ||
136 | m_javaSourceUrl.adjustPath(KUrl::AddTrailingSlash); | 128 | | ||
129 | QString path = m_javaSourceUrl.path(); | ||||
130 | if (path.length() > 0 && path.back() != QLatin1Char('/')) { | ||||
131 | m_javaSourceUrl.setPath(path + QLatin1Char('/')); | ||||
132 | } | ||||
133 | | ||||
137 | KIO::ListJob* list = KIO::listRecursive(m_javaSourceUrl, KIO::DefaultFlags, false); | 134 | KIO::ListJob* list = KIO::listRecursive(m_javaSourceUrl, KIO::DefaultFlags, false); | ||
138 | connect(list, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)), SLOT(slotJavaSourceEntries(KIO::Job*,KIO::UDSEntryList))); | 135 | connect(list, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)), SLOT(slotJavaSourceEntries(KIO::Job*,KIO::UDSEntryList))); | ||
139 | list->start(); | 136 | list->start(); | ||
140 | } else { | 137 | } else { | ||
141 | kDebug() << m_javaSourceUrl << "error, file doesn't exist or is not readable"; | 138 | qDebug() << m_javaSourceUrl << "error, file doesn't exist or is not readable"; | ||
142 | } | 139 | } | ||
143 | } else { | 140 | } else { | ||
144 | kDebug() << m_javaSourceUrl << "error, non file protocol url"; | 141 | qDebug() << m_javaSourceUrl << "error, non file protocol url"; | ||
145 | } | 142 | } | ||
146 | } | 143 | } | ||
147 | 144 | | |||
148 | void JavaLanguageSupport::slotJavaSourceEntries(KIO::Job* job, KIO::UDSEntryList entries) | 145 | void JavaLanguageSupport::slotJavaSourceEntries(KIO::Job* job, KIO::UDSEntryList entries) | ||
149 | { | 146 | { | ||
150 | Q_UNUSED(job); | 147 | Q_UNUSED(job); | ||
151 | 148 | | |||
152 | foreach (KIO::UDSEntry entry, entries) { | 149 | foreach (KIO::UDSEntry entry, entries) { | ||
153 | KUrl url = m_javaSourceUrl; | 150 | QUrl url = m_javaSourceUrl; | ||
154 | url.addPath(entry.stringValue(KIO::UDSEntry::UDS_NAME)); | 151 | url = url.adjusted(QUrl::StripTrailingSlash); | ||
152 | url.setPath(url.path() + '/' + (entry.stringValue(KIO::UDSEntry::UDS_NAME))); | ||||
155 | if (!entry.isDir() && !entry.isLink()) { | 153 | if (!entry.isDir() && !entry.isLink()) { | ||
156 | kDebug() << "Found" << url << "in the java source zip, scheduled for parsing"; | 154 | qDebug() << "Found" << url << "in the java source zip, scheduled for parsing"; | ||
157 | KDevelop::ICore::self()->languageController()->backgroundParser()->addDocument(KDevelop::IndexedString(url), KDevelop::TopDUContext::SimplifiedVisibleDeclarationsAndContexts); | 155 | KDevelop::ICore::self()->languageController()->backgroundParser()->addDocument(KDevelop::IndexedString(url), KDevelop::TopDUContext::SimplifiedVisibleDeclarationsAndContexts); | ||
158 | } | 156 | } | ||
159 | } | 157 | } | ||
160 | } | 158 | } | ||
161 | 159 | | |||
162 | KZip* JavaLanguageSupport::javaSourceZip() const | 160 | KZip* JavaLanguageSupport::javaSourceZip() const | ||
163 | { | 161 | { | ||
164 | return m_javaSourceZip; | 162 | return m_javaSourceZip; | ||
165 | } | 163 | } | ||
166 | 164 | | |||
167 | 165 | | |||
168 | QMutex* JavaLanguageSupport::javaSourceZipMutex() const | 166 | QMutex* JavaLanguageSupport::javaSourceZipMutex() const | ||
169 | { | 167 | { | ||
170 | return m_javaSourceZipMutex; | 168 | return m_javaSourceZipMutex; | ||
171 | } | 169 | } | ||
172 | 170 | | |||
173 | KDevelop::ICodeHighlighting* JavaLanguageSupport::codeHighlighting() const | 171 | KDevelop::ICodeHighlighting* JavaLanguageSupport::codeHighlighting() const | ||
174 | { | 172 | { | ||
175 | return m_highlighting; | 173 | return m_highlighting; | ||
176 | } | 174 | } | ||
177 | 175 | | |||
176 | KDevelop::ConfigPage* JavaLanguageSupport::configPage(int number, QWidget* parent) | ||||
177 | { | ||||
178 | return number == 0 ? new JavaPreferences(parent) : nullptr; | ||||
179 | } | ||||
180 | | ||||
181 | int JavaLanguageSupport::configPages() const | ||||
182 | { | ||||
183 | return 1; | ||||
184 | } | ||||
185 | | ||||
186 | | ||||
178 | #include "javalanguagesupport.moc" | 187 | #include "javalanguagesupport.moc" | ||
179 | 188 | | |||
180 | // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on | 189 | // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on |