X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index d1a64ad..52f8def 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -6,28 +6,36 @@ * Created on 05.03.2003 * * @author Stefan Langer (musk) - * @version $Revision: 1.16 $ + * @version $Revision: 1.19 $ */ package net.sourceforge.phpeclipse.phpeditor.php; -import java.util.*; -import org.eclipse.jface.text.*; -import org.eclipse.jface.text.rules.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.text.Assert; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IPartitionTokenScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; /** * */ public class PHPPartitionScanner implements IPartitionTokenScanner { - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; private boolean fInString = false; private boolean fInDoubString = false; private IDocument fDocument = null; private int fOffset = -1; private String fContentType = IPHPPartitionScannerConstants.HTML; private String fPrevContentType = IPHPPartitionScannerConstants.HTML; - private boolean partitionBorder = false; private int fTokenOffset; private int fEnd = -1; @@ -74,8 +82,8 @@ public class PHPPartitionScanner implements IPartitionTokenScanner } } catch (BadLocationException e) - { - // TODO Auto-generated catch block + { // should never happen + // TODO Write stacktrace to log e.printStackTrace(); } } @@ -131,9 +139,6 @@ public class PHPPartitionScanner implements IPartitionTokenScanner // sometimes we get a wrong partition so we retrieve the partition // directly from the document fContentType = fDocument.getContentType(partitionOffset); - //TODO determine the previouse contenttypes as a stack - //if(partitionOffset > 1) - // fPrevContentType = fDocument.getContentType(partitionOffset-1); } else this.setRange(document, offset, length); @@ -387,7 +392,8 @@ public class PHPPartitionScanner implements IPartitionTokenScanner fEnd = fOffset + length; fInString = false; fInDoubString = false; - //partitionBorder = false; + fContentType = IPHPPartitionScannerConstants.HTML; +// String[] prev = getPartitionStack(offset); } private int read() @@ -489,5 +495,41 @@ public class PHPPartitionScanner implements IPartitionTokenScanner else return false; } - + + /** + * Returns the previouse partition stack for the given offset. + * + * @param offset The offset to return the previouse partitionstack for. + * + * @return The stack as a string array. + */ + private String[] getPartitionStack(int offset) + { + ArrayList types = new ArrayList(); + int tmpOffset = 0; + try + { + ITypedRegion region = fDocument.getPartition(offset); + tmpOffset = region.getOffset(); + while(tmpOffset-1 > 0) + { + region = fDocument.getPartition(tmpOffset-1); + tmpOffset = region.getOffset(); + types.add(0, region.getType()); + } + } + catch (BadLocationException e) + { + if(DEBUG) + { + e.printStackTrace(); + } + } + + String[] retVal = new String[types.size()]; + + retVal = (String[])types.toArray(retVal); + return retVal; + } + }