Allow preproc service to run on .java files.

This commit is contained in:
A Pottinger
2021-07-24 17:46:30 -07:00
parent a1122aa674
commit 9a4fdd15ce
3 changed files with 8 additions and 63 deletions

View File

@@ -78,9 +78,6 @@ public class JavaEditor extends Editor {
// static final int ERROR_TAB_INDEX = 0;
private boolean hasJavaTabs;
private boolean javaTabWarned;
protected PreprocService preprocService;
protected Debugger debugger;
@@ -90,8 +87,6 @@ public class JavaEditor extends Editor {
final private Rename rename;
final private ErrorChecker errorChecker;
private boolean pdexEnabled;
// set true to show AST debugging window
static private final boolean SHOW_AST_VIEWER = false;
private ASTViewer astViewer;
@@ -116,8 +111,6 @@ public class JavaEditor extends Editor {
// setting breakpoints will flag sketch as modified, so override this here
getSketch().setModified(false);
hasJavaTabs = checkForJavaTabs();
/*
// hack to add a JPanel to the right-hand side of the text area
JPanel textAndError = new JPanel();
@@ -136,8 +129,6 @@ public class JavaEditor extends Editor {
preprocService = new PreprocService(this);
pdexEnabled = !hasJavaTabs();
// long t5 = System.currentTimeMillis();
usage = new ShowUsage(this, preprocService);
@@ -201,23 +192,8 @@ public class JavaEditor extends Editor {
super.rebuild();
// after Rename and New Tab, we may have new .java tabs
boolean newHasJavaTabs = checkForJavaTabs();
boolean hasJavaTabsChanged = hasJavaTabs != newHasJavaTabs;
hasJavaTabs = newHasJavaTabs;
if (preprocService != null) {
if (hasJavaTabsChanged) {
preprocService.handleHasJavaTabsChange(hasJavaTabs);
pdexEnabled = !hasJavaTabs;
if (!pdexEnabled) {
usage.hide();
}
if (hasJavaTabs) {
setProblemList(Collections.emptyList());
}
}
int currentTabCount = sketch.getCodeCount();
if (currentTabCount != previousTabCount) {
previousTabCount = currentTabCount;
@@ -2156,12 +2132,6 @@ public class JavaEditor extends Editor {
frmImportSuggest.setVisible(true);
}
public boolean hasJavaTabs() {
return hasJavaTabs;
}
/**
* Checks if the sketch contains java tabs. If it does, the editor ain't
* built for it, yet. Also, user should really start looking at a full IDE
@@ -2170,13 +2140,6 @@ public class JavaEditor extends Editor {
private boolean checkForJavaTabs() {
for (SketchCode code : getSketch().getCode()) {
if (code.getExtension().equals("java")) {
if (!javaTabWarned) {
System.out.println(getSketch().getName() + " contains .java tabs. ");
System.out.println("Some editor features (like completion " +
"and error checking) will be disabled.");
//Base.showWarning("Cannot debug advanced sketches", msg);
javaTabWarned = true;
}
return true;
}
}

View File

@@ -141,14 +141,12 @@ public class JavaTextArea extends PdeTextArea {
super.processKeyEvent(evt);
// code completion disabled if Java tabs present
if (!getJavaEditor().hasJavaTabs()) {
if (evt.getID() == KeyEvent.KEY_TYPED) {
processCompletionKeys(evt);
} else if (!Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
processCompletionKeys(evt);
} else if (Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
processControlSpace(evt);
}
if (evt.getID() == KeyEvent.KEY_TYPED) {
processCompletionKeys(evt);
} else if (!Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
processCompletionKeys(evt);
} else if (Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
processControlSpace(evt);
}
}

View File

@@ -93,7 +93,7 @@ public class PreprocService {
complete(null); // initialization block
}};
private volatile boolean enabled;
private volatile boolean enabled = true;
/**
* Create a new preprocessing service to support an editor.
@@ -101,7 +101,6 @@ public class PreprocService {
*/
public PreprocService(JavaEditor editor) {
this.editor = editor;
enabled = !editor.hasJavaTabs();
// Register listeners for first run
whenDone(this::fireListeners);
@@ -349,7 +348,7 @@ public class PreprocService {
IntList tabStartsList = new IntList();
List<Integer> tabLineStarts = new ArrayList<>();
for (SketchCode sc : sketch.getCode()) {
if (sc.isExtension("pde")) {
if (sc.isExtension("pde") || sc.isExtension("java")) {
tabStartsList.append(workBuffer.length());
tabLineStarts.add(numLines);
@@ -588,21 +587,6 @@ public class PreprocService {
/// --------------------------------------------------------------------------
/**
* Emit events and update internal state (isEnabled) if java tabs added or modified.
*
* @param hasJavaTabs True if java tabs are in the sketch and false otherwise.
*/
public void handleHasJavaTabsChange(boolean hasJavaTabs) {
enabled = !hasJavaTabs;
if (enabled) {
notifySketchChanged();
} else {
preprocessingTask.cancel(false);
}
}
static private final Map<String, String> COMPILER_OPTIONS;
static {
Map<String, String> compilerOptions = new HashMap<>();