replaced a lot of deprecated code; if someone runs into a commit conflict afterwards...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
index 458a4ac..771eea3 100644 (file)
@@ -37,7 +37,6 @@ import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
-import net.sourceforge.phpdt.internal.core.CompilationUnit;
 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
@@ -98,7 +97,6 @@ import org.eclipse.jface.text.ITextPresentationListener;
 import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.ITextViewerExtension3;
 import org.eclipse.jface.text.ITextViewerExtension4;
 import org.eclipse.jface.text.ITextViewerExtension5;
 import org.eclipse.jface.text.ITypedRegion;
@@ -2186,8 +2184,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
 
                        try {
                                int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
-                               if (textViewer instanceof ITextViewerExtension3) {
-                                       ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
+                               if (textViewer instanceof ITextViewerExtension5) {
+                                       ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
                                        return extension.widgetOffset2ModelOffset(widgetLocation);
                                } else {
                                        IRegion visibleRegion = textViewer.getVisibleRegion();
@@ -4779,8 +4777,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
                int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
 
                boolean visible = false;
-               if (sourceViewer instanceof ITextViewerExtension3) {
-                       ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
+               if (sourceViewer instanceof ITextViewerExtension5) {
+                       ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
                        visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
                } else {
                        IRegion visibleRegion = sourceViewer.getVisibleRegion();
@@ -5584,9 +5582,9 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
         * @since 3.0
         */
        protected void updateOccurrenceAnnotations(ITextSelection selection) {// ,
-                                                                                                                                                                                                                                                                                               // CompilationUnit
-                                                                                                                                                                                                                                                                                               // astRoot)
-                                                                                                                                                                                                                                                                                               // {
+               // CompilationUnit
+               // astRoot)
+               // {
 
                if (fOccurrencesFinderJob != null)
                        fOccurrencesFinderJob.cancel();
@@ -5615,7 +5613,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
                        fMarkOccurrenceModificationStamp = currentModificationStamp;
                }
 
-               if (fMarkOccurrenceTargetRegion == null || fMarkOccurrenceTargetRegion.getLength()==0) {
+               if (fMarkOccurrenceTargetRegion == null || fMarkOccurrenceTargetRegion.getLength() == 0) {
                        return;
                }
 
@@ -5628,30 +5626,32 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
                                Scanner fScanner = new Scanner();
                                fScanner.setSource(document.get().toCharArray());
                                fScanner.setPHPMode(false);
+                               String wordStr;
                                char[] word;
 
-                               word = document.get(fMarkOccurrenceTargetRegion.getOffset(), fMarkOccurrenceTargetRegion.getLength()).toCharArray();
-
-                               int fToken = ITerminalSymbols.TokenNameEOF;
-                               try {
-                                       fToken = fScanner.getNextToken();
-                                       while (fToken != ITerminalSymbols.TokenNameEOF) { // && fToken !=
-                                               // TokenNameERROR) {
-                                               if (fToken == ITerminalSymbols.TokenNameVariable || fToken == ITerminalSymbols.TokenNameIdentifier) {
-                                                       // global variable
-                                                       if (fScanner.equalsCurrentTokenSource(word)) {
-                                                               matches.add(new Region(fScanner.getCurrentTokenStartPosition(), fScanner.getCurrentTokenEndPosition()
-                                                                               - fScanner.getCurrentTokenStartPosition() + 1));
+                               wordStr = document.get(fMarkOccurrenceTargetRegion.getOffset(), fMarkOccurrenceTargetRegion.getLength());
+                               if (wordStr != null) {
+                                       word = wordStr.toCharArray();
+                                       int fToken = ITerminalSymbols.TokenNameEOF;
+                                       try {
+                                               fToken = fScanner.getNextToken();
+                                               while (fToken != ITerminalSymbols.TokenNameEOF) { // && fToken !=
+                                                       // TokenNameERROR) {
+                                                       if (fToken == ITerminalSymbols.TokenNameVariable || fToken == ITerminalSymbols.TokenNameIdentifier) {
+                                                               // global variable
+                                                               if (fScanner.equalsCurrentTokenSource(word)) {
+                                                                       matches.add(new Region(fScanner.getCurrentTokenStartPosition(), fScanner.getCurrentTokenEndPosition()
+                                                                                       - fScanner.getCurrentTokenStartPosition() + 1));
+                                                               }
                                                        }
+                                                       fToken = fScanner.getNextToken();
                                                }
-                                               fToken = fScanner.getNextToken();
+                                       } catch (InvalidInputException e) {
+                                               // ignore errors
+                                       } catch (SyntaxError e) {
+                                               // ignore errors
                                        }
-                               } catch (InvalidInputException e) {
-                                       // ignore errors
-                               } catch (SyntaxError e) {
-                                       // ignore errors
                                }
-
                        } catch (BadLocationException e1) {
                                // ignore errors
                        } catch (Exception e) {
@@ -5686,9 +5686,9 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements I
 
                fPostSelectionListenerWithAST = new ISelectionListenerWithAST() {
                        public void selectionChanged(IEditorPart part, ITextSelection selection) { // ,
-                                                                                                                                                                                                                                                                                                                                       // CompilationUnit
-                                                                                                                                                                                                                                                                                                                                       // astRoot)
-                                                                                                                                                                                                                                                                                                                                       // {
+                               // CompilationUnit
+                               // astRoot)
+                               // {
                                updateOccurrenceAnnotations(selection);// , astRoot);
                        }
                };