1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +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:
Jonah Graham 2020-09-18 10:48:16 -04:00
parent 41b741f358
commit 16750b6528
8 changed files with 67 additions and 10 deletions

View 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>

View file

@ -39,6 +39,7 @@ public class QMLAnalyzer implements IQMLAnalyzer {
private QMLModuleResolver moduleResolver;
private ScriptEngine engine;
private Boolean supported;
private Invocable invoke;
private Object tern;
@ -46,6 +47,14 @@ public class QMLAnalyzer implements IQMLAnalyzer {
public void load() throws ScriptException, IOException, NoSuchMethodException {
moduleResolver = new QMLModuleResolver(this);
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;
loadDep("/tern-qml/node_modules/acorn/dist/acorn.js");
@ -100,6 +109,7 @@ public class QMLAnalyzer implements IQMLAnalyzer {
synchronized (this) {
tern = invoke.invokeFunction("newTernServer", options);
supported = tern != null;
notifyAll();
}
}
@ -126,16 +136,25 @@ public class QMLAnalyzer implements IQMLAnalyzer {
}
}
private void waitUntilLoaded() {
@Override
public boolean isSupported() {
synchronized (this) {
while (tern == null) {
while (supported == null) {
try {
wait();
} catch (InterruptedException 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.");
}
}

View file

@ -24,6 +24,14 @@ import org.eclipse.cdt.qt.core.qmljs.IQmlASTNode;
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 deleteFile(String fileName) throws NoSuchMethodException, ScriptException;

View file

@ -41,6 +41,9 @@ public class QMLContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
if (analyzer == null || !analyzer.isSupported()) {
return NO_COMPLETIONS;
}
IDocument document = viewer.getDocument();
String prefix = lastWord(document, offset);
// Save the file

View file

@ -81,13 +81,15 @@ public class QMLEditor extends TextEditor {
String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath();
IDocument document = getSourceViewer().getDocument();
try {
analyzer.deleteFile(fileName);
analyzer.addFile(fileName, document.get());
} catch (NoSuchMethodException e) {
Activator.log(e);
} catch (ScriptException e) {
Activator.log(e);
if (analyzer != null && analyzer.isSupported()) {
try {
analyzer.deleteFile(fileName);
analyzer.addFile(fileName, document.get());
} catch (NoSuchMethodException e) {
Activator.log(e);
} catch (ScriptException e) {
Activator.log(e);
}
}
super.doSave(progressMonitor);
}

View file

@ -61,6 +61,10 @@ public class QMLHyperlink implements IHyperlink {
@Override
public void open() {
IQMLAnalyzer analyzer = Activator.getService(IQMLAnalyzer.class);
if (analyzer == null || !analyzer.isSupported()) {
return;
}
try {
IDocument document = viewer.getDocument();
String selected = document.get(region.getOffset(), region.getLength());

View file

@ -10,6 +10,8 @@
*******************************************************************************/
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.ITextViewer;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
@ -20,6 +22,11 @@ public class QMLHyperlinkDetector extends AbstractHyperlinkDetector {
@Override
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?
IRegion wordRegion = QMLEditor.findWord(textViewer.getDocument(), region.getOffset());
if (wordRegion != null) {

View file

@ -42,6 +42,9 @@ public class QMLTernFileUpdateJob extends Job {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (analyzer == null || !analyzer.isSupported()) {
return Status.OK_STATUS;
}
for (IResourceDelta delta : deltaList) {
IResource resource = delta.getResource();
String fileName = resource.getFullPath().toString().substring(1);