Skip to content

Commit 22727cf

Browse files
committed
fix NPEs in error checker service
1 parent 710c0fe commit 22727cf

File tree

7 files changed

+93
-91
lines changed

7 files changed

+93
-91
lines changed

java/src/processing/mode/java/JavaEditor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void actionPerformed(ActionEvent e) {
169169
// add our hacked version back to the editor
170170
box.add(textAndError);
171171

172-
getJavaTextArea().setECSandThemeforTextArea(errorCheckerService, jmode);
172+
getJavaTextArea().setMode(jmode);
173173

174174
// ensure completion is hidden when editor loses focus
175175
addWindowFocusListener(new WindowFocusListener() {
@@ -221,7 +221,7 @@ public EditorFooter createFooter() {
221221

222222
// Adding Error Table in a scroll pane
223223
errorTableScrollPane = new JScrollPane();
224-
errorTable = new XQErrorTable(errorCheckerService);
224+
errorTable = new XQErrorTable(this);
225225
// errorTableScrollPane.setBorder(new EmptyBorder(2, 2, 2, 2));
226226
// errorTableScrollPane.setBorder(new EtchedBorder());
227227
errorTableScrollPane.setBorder(BorderFactory.createEmptyBorder());
@@ -1913,6 +1913,11 @@ public JavaTextArea getJavaTextArea() {
19131913
}
19141914

19151915

1916+
public ErrorCheckerService getErrorChecker() {
1917+
return errorCheckerService;
1918+
}
1919+
1920+
19161921
/**
19171922
* Grab current contents of the sketch window, advance the console, stop any
19181923
* other running sketches, auto-save the user's code... not in that order.

java/src/processing/mode/java/pdex/CompletionPanel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public class CompletionPanel {
104104
* @param dedit
105105
*/
106106
public CompletionPanel(final JEditTextArea textarea, int position, String subWord,
107-
DefaultListModel<CompletionCandidate> items, final Point location, JavaEditor dedit) {
107+
DefaultListModel<CompletionCandidate> items, final Point location, JavaEditor editor) {
108108
this.textarea = (JavaTextArea) textarea;
109-
editor = dedit;
109+
this.editor = editor;
110110
this.insertionPosition = position;
111111
if (subWord.indexOf('.') != -1)
112112
this.subWord = subWord.substring(subWord.lastIndexOf('.') + 1);
@@ -121,7 +121,7 @@ public CompletionPanel(final JEditTextArea textarea, int position, String subWor
121121
scrollPane.setViewportView(completionList = createSuggestionList(position, items));
122122
popupMenu.add(scrollPane, BorderLayout.CENTER);
123123
popupMenu.setPopupSize(calcWidth(), calcHeight(items.getSize())); //TODO: Eradicate this evil
124-
this.textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
124+
editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
125125
textarea.requestFocusInWindow();
126126
popupMenu.show(textarea, location.x, textarea.getBaseline(0, 0) + location.y);
127127
//log("Suggestion shown: " + System.currentTimeMillis());
@@ -487,7 +487,7 @@ protected void moveUp() {
487487
.getVerticalScrollBar()
488488
.getValue()
489489
- step);
490-
textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
490+
editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
491491
}
492492
}
493493

@@ -504,7 +504,7 @@ protected void moveDown() {
504504
int index = Math.min(completionList.getSelectedIndex() + 1,
505505
completionList.getModel().getSize() - 1);
506506
selectIndex(index);
507-
textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
507+
editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue());
508508
int step = scrollPane.getVerticalScrollBar().getMaximum() / completionList.getModel().getSize();
509509
scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getValue() + step);
510510
}

java/src/processing/mode/java/pdex/ErrorCheckerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ErrorCheckerService implements Runnable {
111111
/**
112112
* Stores all Problems in the sketch
113113
*/
114-
public ArrayList<Problem> problemsList;
114+
public List<Problem> problemsList;
115115

116116
/**
117117
* How many lines are present till the initial class declaration? In static

java/src/processing/mode/java/pdex/ErrorWindow.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import java.awt.BorderLayout;
2424
import java.awt.Frame;
25-
import java.awt.Point;
2625
import java.awt.event.ComponentEvent;
2726
import java.awt.event.ComponentListener;
2827
import java.awt.event.WindowAdapter;
@@ -35,16 +34,16 @@
3534
import javax.swing.border.EmptyBorder;
3635
import javax.swing.table.TableModel;
3736

38-
import processing.app.Editor;
3937
import processing.app.Toolkit;
4038
import processing.mode.java.JavaEditor;
4139

40+
4241
/**
4342
* Error Window that displays a tablular list of errors. Clicking on an error
4443
* scrolls to its location in the code.
45-
*
44+
*
4645
* @author Manindra Moharana &lt;me@mkmoharana.com&gt;
47-
*
46+
*
4847
*/
4948
public class ErrorWindow extends JFrame {
5049

@@ -58,9 +57,10 @@ public class ErrorWindow extends JFrame {
5857
*/
5958
protected JScrollPane scrollPane;
6059

61-
protected JavaEditor thisEditor;
60+
//protected JavaEditor thisEditor;
61+
protected JavaEditor editor;
6262
private JFrame thisErrorWindow;
63-
63+
6464
/**
6565
* Handles the sticky Problem window
6666
*/
@@ -70,19 +70,20 @@ public class ErrorWindow extends JFrame {
7070

7171
/**
7272
* Preps up ErrorWindow
73-
*
73+
*
7474
* @param editor
7575
* - Editor
7676
* @param ecs - ErrorCheckerService
7777
*/
7878
public ErrorWindow(JavaEditor editor, ErrorCheckerService ecs) {
7979
thisErrorWindow = this;
8080
errorCheckerService = ecs;
81-
thisEditor = editor;
81+
this.editor = editor;
8282
setTitle("Problems");
8383
prepareFrame();
8484
}
8585

86+
8687
/**
8788
* Sets up ErrorWindow
8889
*/
@@ -100,7 +101,7 @@ protected void prepareFrame() {
100101
scrollPane = new JScrollPane();
101102
contentPane.add(scrollPane);
102103

103-
errorTable = new XQErrorTable(errorCheckerService);
104+
errorTable = new XQErrorTable(editor);
104105
scrollPane.setViewportView(errorTable);
105106

106107
try {
@@ -111,17 +112,17 @@ protected void prepareFrame() {
111112
e.printStackTrace();
112113
}
113114

114-
if (thisEditor != null) {
115-
setLocation(new Point(thisEditor.getLocation().x
116-
+ thisEditor.getWidth(), thisEditor.getLocation().y));
115+
if (editor != null) {
116+
setLocation(editor.getLocation().x + editor.getWidth(),
117+
editor.getLocation().y);
117118
}
118-
119119
}
120120

121+
121122
/**
122123
* Updates the error table with new data(Table Model). Called from Error
123124
* Checker Service.
124-
*
125+
*
125126
* @param tableModel
126127
* - Table Model
127128
* @return True - If error table was updated successfully.
@@ -173,12 +174,12 @@ public void windowClosing(WindowEvent e) {
173174

174175
@Override
175176
public void windowDeiconified(WindowEvent e) {
176-
thisEditor.setExtendedState(Frame.NORMAL);
177+
editor.setExtendedState(Frame.NORMAL);
177178
}
178179

179180
});
180181

181-
if (thisEditor == null) {
182+
if (editor == null) {
182183
System.out.println("Editor null");
183184
return;
184185
}
@@ -209,7 +210,7 @@ public void windowDeiconified(WindowEvent e) {
209210
210211
});*/
211212

212-
thisEditor.addComponentListener(new ComponentListener() {
213+
editor.addComponentListener(new ComponentListener() {
213214

214215
@Override
215216
public void componentShown(ComponentEvent e) {
@@ -249,10 +250,10 @@ public void componentHidden(ComponentEvent e) {
249250
* Implements the docking feature of the tool - The frame sticks to the
250251
* editor and once docked, moves along with it as the editor is resized,
251252
* moved, or closed.
252-
*
253+
*
253254
* This class has been borrowed from Tab Manager tool by Thomas Diewald. It
254255
* has been slightly modified and used here.
255-
*
256+
*
256257
* @author Thomas Diewald , http://thomasdiewald.com
257258
*/
258259
private class DockTool2Base {
@@ -285,9 +286,7 @@ public boolean isDocked() {
285286

286287
//
287288
public void tryDocking() {
288-
if (thisEditor == null)
289-
return;
290-
Editor editor = thisEditor;
289+
if (editor == null) return;
291290
Frame frame = thisErrorWindow;
292291

293292
int ex = editor.getX();
@@ -330,9 +329,7 @@ public void tryDocking() {
330329
}
331330

332331
public void dock() {
333-
if (thisEditor == null)
334-
return;
335-
Editor editor = thisEditor;
332+
if (editor == null) return;
336333
Frame frame = thisErrorWindow;
337334

338335
int ex = editor.getX();
@@ -369,6 +366,5 @@ public void dock() {
369366
}
370367
frame.setLocation(x, y);
371368
}
372-
373369
}
374370
}

java/src/processing/mode/java/pdex/JavaTextArea.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class JavaTextArea extends JEditTextArea {
8282
/// maps line index to gutter text color
8383
protected Map<Integer, Color> gutterTextColors = new HashMap<Integer, Color>();
8484

85-
protected ErrorCheckerService errorCheckerService;
85+
// protected ErrorCheckerService errorCheckerService;
8686
private CompletionPanel suggestion;
8787

8888

@@ -159,10 +159,9 @@ protected JavaTextAreaPainter createPainter(final TextAreaDefaults defaults) {
159159
* @param ecs
160160
* @param mode
161161
*/
162-
public void setECSandThemeforTextArea(ErrorCheckerService ecs,
163-
JavaMode mode) {
164-
errorCheckerService = ecs;
165-
getCustomPainter().setECSandTheme(ecs, mode);
162+
public void setMode(JavaMode mode) {
163+
// errorCheckerService = ecs;
164+
getCustomPainter().setMode(mode);
166165
}
167166

168167

@@ -383,7 +382,7 @@ else if (s.length() == 0)
383382
return null;
384383
}
385384
Base.log("Mouse click, word: " + word.trim());
386-
errorCheckerService.getASTGenerator().setLastClickedWord(line, word, xLS);
385+
editor.getErrorChecker().getASTGenerator().setLastClickedWord(line, word, xLS);
387386
return word.trim();
388387
}
389388
}
@@ -443,8 +442,7 @@ public String fetchPhrase(KeyEvent evt) {
443442
if (word.endsWith("."))
444443
word = word.substring(0, word.length() - 1);
445444

446-
errorCheckerService.getASTGenerator().preparePredictions(word, line
447-
+ errorCheckerService.mainClassOffset,0);
445+
editor.getErrorChecker().getASTGenerator().preparePredictions(word, line + editor.getErrorChecker().mainClassOffset,0);
448446
return word;
449447
}
450448

@@ -506,8 +504,8 @@ else if (s.charAt(x1) == ']') {
506504
// word = word.substring(0, word.length() - 1);
507505
int lineStartNonWSOffset = 0;
508506
if (word.length() >= JavaMode.codeCompletionTriggerLength) {
509-
errorCheckerService.getASTGenerator()
510-
.preparePredictions(word, line + errorCheckerService.mainClassOffset,
507+
editor.getErrorChecker().getASTGenerator()
508+
.preparePredictions(word, line + editor.getErrorChecker().mainClassOffset,
511509
lineStartNonWSOffset);
512510
}
513511
return word;

java/src/processing/mode/java/pdex/JavaTextAreaPainter.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
6666
implements MouseListener, MouseMotionListener {
6767

6868
// protected JavaTextArea ta; // we need the subclassed textarea
69-
protected ErrorCheckerService errorCheckerService;
69+
// protected ErrorCheckerService errorCheckerService;
7070

7171
public Color errorColor; // = new Color(0xED2630);
7272
public Color warningColor; // = new Color(0xFFC30E);
@@ -188,8 +188,8 @@ else if (s.length() == 0)
188188
if (Character.isDigit(word.charAt(0)))
189189
return;
190190

191-
Base.log(errorCheckerService.mainClassOffset + line + "|" + line + "| offset " + xLS + word + " <= \n");
192-
errorCheckerService.getASTGenerator().scrollToDeclaration(line, word, xLS);
191+
Base.log(getEditor().getErrorChecker().mainClassOffset + line + "|" + line + "| offset " + xLS + word + " <= \n");
192+
getEditor().getErrorChecker().getASTGenerator().scrollToDeclaration(line, word, xLS);
193193
}
194194
}
195195

@@ -398,11 +398,8 @@ protected void paintLineBgColor(Graphics gfx, int line, int x) {
398398
* @param x
399399
*/
400400
protected void paintErrorLine(Graphics gfx, int line, int x) {
401-
if (errorCheckerService == null) {
402-
return;
403-
}
404-
405-
if (errorCheckerService.problemsList == null) {
401+
ErrorCheckerService ecs = getEditor().getErrorChecker();
402+
if (ecs == null || ecs.problemsList == null) {
406403
return;
407404
}
408405

@@ -413,7 +410,7 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
413410
errorLineCoords.clear();
414411
// Check if current line contains an error. If it does, find if it's an
415412
// error or warning
416-
for (ErrorMarker emarker : errorCheckerService.getEditor().getErrorPoints()) {
413+
for (ErrorMarker emarker : getEditor().getErrorPoints()) {
417414
if (emarker.getProblem().getLineNumber() == line) {
418415
notFound = false;
419416
if (emarker.getType() == ErrorMarker.Warning) {
@@ -529,8 +526,8 @@ static private String trimRight(String string) {
529526
* @param ecs
530527
* @param mode
531528
*/
532-
public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) {
533-
this.errorCheckerService = ecs;
529+
public void setMode(JavaMode mode) {
530+
//this.errorCheckerService = ecs;
534531
//loadTheme(mode);
535532

536533
errorColor = mode.getColor("editor.errorcolor"); //, errorColor);
@@ -543,6 +540,7 @@ public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) {
543540
gutterLineHighlightColor = mode.getColor("editor.gutter.linehighlight.color");
544541
}
545542

543+
546544
@Override
547545
public String getToolTipText(MouseEvent event) {
548546
if (!getEditor().hasJavaTabs()) {
@@ -614,7 +612,7 @@ public String getToolTipText(MouseEvent event) {
614612
setToolTipText(null);
615613
return super.getToolTipText(event);
616614
}
617-
String tooltipText = errorCheckerService.getASTGenerator()
615+
String tooltipText = getEditor().getErrorChecker().getASTGenerator()
618616
.getLabelForASTNode(line, word, xLS);
619617

620618
// log(errorCheckerService.mainClassOffset + " MCO "

0 commit comments

Comments
 (0)