mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 567124: Disable QML Analyzer relatively quietly on Java 15
Instead of pop-up NPEs and hung UI, log once that QML Analyzer is
unsupported.
Change-Id: I4ad599e870bd73f5cbda8992dedb14405af545f4
(cherry picked from commit 6d76cc5839
)
This commit is contained in:
parent
41b741f358
commit
16750b6528
8 changed files with 67 additions and 10 deletions
11
qt/org.eclipse.cdt.qt.core/.settings/.api_filters
Normal file
11
qt/org.eclipse.cdt.qt.core/.settings/.api_filters
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<component id="org.eclipse.cdt.qt.core" version="2">
|
||||||
|
<resource path="src/org/eclipse/cdt/qt/core/IQMLAnalyzer.java" type="org.eclipse.cdt.qt.core.IQMLAnalyzer">
|
||||||
|
<filter id="404000815">
|
||||||
|
<message_arguments>
|
||||||
|
<message_argument value="org.eclipse.cdt.qt.core.IQMLAnalyzer"/>
|
||||||
|
<message_argument value="isSupported()"/>
|
||||||
|
</message_arguments>
|
||||||
|
</filter>
|
||||||
|
</resource>
|
||||||
|
</component>
|
|
@ -39,6 +39,7 @@ public class QMLAnalyzer implements IQMLAnalyzer {
|
||||||
|
|
||||||
private QMLModuleResolver moduleResolver;
|
private QMLModuleResolver moduleResolver;
|
||||||
private ScriptEngine engine;
|
private ScriptEngine engine;
|
||||||
|
private Boolean supported;
|
||||||
private Invocable invoke;
|
private Invocable invoke;
|
||||||
private Object tern;
|
private Object tern;
|
||||||
|
|
||||||
|
@ -46,6 +47,14 @@ public class QMLAnalyzer implements IQMLAnalyzer {
|
||||||
public void load() throws ScriptException, IOException, NoSuchMethodException {
|
public void load() throws ScriptException, IOException, NoSuchMethodException {
|
||||||
moduleResolver = new QMLModuleResolver(this);
|
moduleResolver = new QMLModuleResolver(this);
|
||||||
engine = new ScriptEngineManager().getEngineByName("nashorn");
|
engine = new ScriptEngineManager().getEngineByName("nashorn");
|
||||||
|
if (engine == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
supported = false;
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
throw new ScriptException(
|
||||||
|
"Nashorn script engine is not available in Java 15 and above. The QML Analyzer is not supported.");
|
||||||
|
}
|
||||||
invoke = (Invocable) engine;
|
invoke = (Invocable) engine;
|
||||||
|
|
||||||
loadDep("/tern-qml/node_modules/acorn/dist/acorn.js");
|
loadDep("/tern-qml/node_modules/acorn/dist/acorn.js");
|
||||||
|
@ -100,6 +109,7 @@ public class QMLAnalyzer implements IQMLAnalyzer {
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
tern = invoke.invokeFunction("newTernServer", options);
|
tern = invoke.invokeFunction("newTernServer", options);
|
||||||
|
supported = tern != null;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,16 +136,25 @@ public class QMLAnalyzer implements IQMLAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitUntilLoaded() {
|
@Override
|
||||||
|
public boolean isSupported() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
while (tern == null) {
|
while (supported == null) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitUntilLoaded() throws ScriptException {
|
||||||
|
if (!isSupported()) {
|
||||||
|
throw new ScriptException(
|
||||||
|
"Nashorn script engine is not available in Java 15 and above. The QML Analyzer is not supported.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,14 @@ import org.eclipse.cdt.qt.core.qmljs.IQmlASTNode;
|
||||||
|
|
||||||
public interface IQMLAnalyzer {
|
public interface IQMLAnalyzer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Added in CDT 10.0.1 with no version bump. See Bug 567124.
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
default boolean isSupported() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void addFile(String fileName, String code) throws NoSuchMethodException, ScriptException;
|
void addFile(String fileName, String code) throws NoSuchMethodException, ScriptException;
|
||||||
|
|
||||||
void deleteFile(String fileName) throws NoSuchMethodException, ScriptException;
|
void deleteFile(String fileName) throws NoSuchMethodException, ScriptException;
|
||||||
|
|
|
@ -41,6 +41,9 @@ public class QMLContentAssistProcessor implements IContentAssistProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
|
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
|
||||||
|
if (analyzer == null || !analyzer.isSupported()) {
|
||||||
|
return NO_COMPLETIONS;
|
||||||
|
}
|
||||||
IDocument document = viewer.getDocument();
|
IDocument document = viewer.getDocument();
|
||||||
String prefix = lastWord(document, offset);
|
String prefix = lastWord(document, offset);
|
||||||
// Save the file
|
// Save the file
|
||||||
|
|
|
@ -81,13 +81,15 @@ public class QMLEditor extends TextEditor {
|
||||||
String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath();
|
String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath();
|
||||||
IDocument document = getSourceViewer().getDocument();
|
IDocument document = getSourceViewer().getDocument();
|
||||||
|
|
||||||
try {
|
if (analyzer != null && analyzer.isSupported()) {
|
||||||
analyzer.deleteFile(fileName);
|
try {
|
||||||
analyzer.addFile(fileName, document.get());
|
analyzer.deleteFile(fileName);
|
||||||
} catch (NoSuchMethodException e) {
|
analyzer.addFile(fileName, document.get());
|
||||||
Activator.log(e);
|
} catch (NoSuchMethodException e) {
|
||||||
} catch (ScriptException e) {
|
Activator.log(e);
|
||||||
Activator.log(e);
|
} catch (ScriptException e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.doSave(progressMonitor);
|
super.doSave(progressMonitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,10 @@ public class QMLHyperlink implements IHyperlink {
|
||||||
@Override
|
@Override
|
||||||
public void open() {
|
public void open() {
|
||||||
IQMLAnalyzer analyzer = Activator.getService(IQMLAnalyzer.class);
|
IQMLAnalyzer analyzer = Activator.getService(IQMLAnalyzer.class);
|
||||||
|
if (analyzer == null || !analyzer.isSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IDocument document = viewer.getDocument();
|
IDocument document = viewer.getDocument();
|
||||||
String selected = document.get(region.getOffset(), region.getLength());
|
String selected = document.get(region.getOffset(), region.getLength());
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.qt.ui.editor;
|
package org.eclipse.cdt.internal.qt.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.qt.core.Activator;
|
||||||
|
import org.eclipse.cdt.qt.core.IQMLAnalyzer;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextViewer;
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
|
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
|
||||||
|
@ -20,6 +22,11 @@ public class QMLHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
|
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
|
||||||
|
IQMLAnalyzer analyzer = Activator.getService(IQMLAnalyzer.class);
|
||||||
|
if (analyzer == null || !analyzer.isSupported()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO is length of region ever > 0?
|
// TODO is length of region ever > 0?
|
||||||
IRegion wordRegion = QMLEditor.findWord(textViewer.getDocument(), region.getOffset());
|
IRegion wordRegion = QMLEditor.findWord(textViewer.getDocument(), region.getOffset());
|
||||||
if (wordRegion != null) {
|
if (wordRegion != null) {
|
||||||
|
|
|
@ -42,6 +42,9 @@ public class QMLTernFileUpdateJob extends Job {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
if (analyzer == null || !analyzer.isSupported()) {
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
for (IResourceDelta delta : deltaList) {
|
for (IResourceDelta delta : deltaList) {
|
||||||
IResource resource = delta.getResource();
|
IResource resource = delta.getResource();
|
||||||
String fileName = resource.getFullPath().toString().substring(1);
|
String fileName = resource.getFullPath().toString().substring(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue