From 70b4d34910ccf9d358e5dbfca8e731b582944fa2 Mon Sep 17 00:00:00 2001 From: axelcl Date: Sun, 9 Oct 2005 07:23:41 +0000 Subject: [PATCH] Avoid NPE in update OccurrenceAnnotation --- .../phpeclipse/phpeditor/PHPEditor.java | 77 +++++++++++++------- 1 files changed, 52 insertions(+), 25 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index 7ecba2c..d0393cf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -2900,15 +2900,21 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I doSelectionChanged(event); } } + /** * The internal shell activation listener for updating occurrences. + * * @since 3.0 */ - private ActivationListener fActivationListener= new ActivationListener(); + private ActivationListener fActivationListener = new ActivationListener(); + private ISelectionListenerWithAST fPostSelectionListenerWithAST; + private OccurrencesFinderJob fOccurrencesFinderJob; + /** The occurrences finder job canceler */ private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler; + /** * Holds the current occurrence annotations. * @@ -3134,16 +3140,24 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I // setSourceViewerConfiguration(new // JavaSourceViewerConfiguration(textTools.getColorManager(), store, // this, IJavaPartitions.JAVA_PARTITIONING)); - fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); - fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); -// fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); -// fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); -// fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); -// fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); -// fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); -// fMarkExceptions= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES); -// fMarkImplementors= store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS); -// fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); + fMarkOccurrenceAnnotations = store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); + fStickyOccurrenceAnnotations = store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); + // fMarkTypeOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); + // fMarkMethodOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); + // fMarkConstantOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); + // fMarkFieldOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); + // fMarkLocalVariableypeOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); + // fMarkExceptions= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES); + // fMarkImplementors= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS); + // fMarkMethodExitPoints= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); } @@ -3576,15 +3590,15 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I if (isBrowserLikeLinks()) disableBrowserLikeLinks(); -// cancel possible running computation - fMarkOccurrenceAnnotations= false; + // cancel possible running computation + fMarkOccurrenceAnnotations = false; uninstallOccurrencesFinder(); uninstallOverrideIndicator(); if (fActivationListener != null) { PlatformUI.getWorkbench().removeWindowListener(fActivationListener); - fActivationListener= null; + fActivationListener = null; } if (fEncodingSupport != null) { @@ -4209,10 +4223,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I return; } - boolean newBooleanValue= false; - Object newValue= event.getNewValue(); + boolean newBooleanValue = false; + Object newValue = event.getNewValue(); if (newValue != null) - newBooleanValue= Boolean.valueOf(newValue.toString()).booleanValue(); + newBooleanValue = Boolean.valueOf(newValue.toString()).booleanValue(); if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) { if (newBooleanValue) @@ -4222,7 +4236,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) { if (newBooleanValue != fMarkOccurrenceAnnotations) { - fMarkOccurrenceAnnotations= newBooleanValue; + fMarkOccurrenceAnnotations = newBooleanValue; if (!fMarkOccurrenceAnnotations) uninstallOccurrencesFinder(); else @@ -4232,7 +4246,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I } if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) { - fStickyOccurrenceAnnotations= newBooleanValue; + fStickyOccurrenceAnnotations = newBooleanValue; return; } // } @@ -4246,7 +4260,6 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) // { - ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event); // if (affectsOverrideIndicatorAnnotations(event)) { @@ -5567,7 +5580,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I * the compilation unit AST * @since 3.0 */ - protected void updateOccurrenceAnnotations(ITextSelection selection) {//, CompilationUnit astRoot) { + protected void updateOccurrenceAnnotations(ITextSelection selection) {// , + // CompilationUnit + // astRoot) + // { if (fOccurrencesFinderJob != null) fOccurrencesFinderJob.cancel(); @@ -5575,7 +5591,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I if (!fMarkOccurrenceAnnotations) return; -// if (astRoot == null || selection == null) + // if (astRoot == null || selection == null) if (selection == null) return; @@ -5583,6 +5599,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I if (document == null) return; + fMarkOccurrenceTargetRegion = null; if (document instanceof IDocumentExtension4) { int offset = selection.getOffset(); long currentModificationStamp = ((IDocumentExtension4) document).getModificationStamp(); @@ -5595,6 +5612,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I fMarkOccurrenceModificationStamp = currentModificationStamp; } + if (fMarkOccurrenceTargetRegion == null) { + return; + } + List matches = null; if (matches == null) { @@ -5617,7 +5638,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I // global variable if (fScanner.equalsCurrentTokenSource(word)) { matches.add(new Region(fScanner.getCurrentTokenStartPosition(), fScanner.getCurrentTokenEndPosition() - - fScanner.getCurrentTokenStartPosition()+1)); + - fScanner.getCurrentTokenStartPosition() + 1)); } } fToken = fScanner.getNextToken(); @@ -5630,6 +5651,9 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I } catch (BadLocationException e1) { // ignore errors + } catch (Exception e) { + e.printStackTrace(); + // ignore errors } } @@ -5658,8 +5682,11 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I fMarkOccurrenceAnnotations = true; fPostSelectionListenerWithAST = new ISelectionListenerWithAST() { - public void selectionChanged(IEditorPart part, ITextSelection selection) { //, CompilationUnit astRoot) { - updateOccurrenceAnnotations(selection);//, astRoot); + public void selectionChanged(IEditorPart part, ITextSelection selection) { // , + // CompilationUnit + // astRoot) + // { + updateOccurrenceAnnotations(selection);// , astRoot); } }; SelectionListenerWithASTManager.getDefault().addListener(this, fPostSelectionListenerWithAST); -- 1.7.1