From 22f633a96368e491ae077661321d965d78e74300 Mon Sep 17 00:00:00 2001 From: musk Date: Tue, 6 May 2003 13:03:45 +0000 Subject: [PATCH] Partitionscanner Framework --- .../phpeclipse/phpeditor/php/PHPPartition.java | 80 +++++++ .../phpeclipse/phpeditor/php/Partition.java | 233 ++++++++++++++++++++ .../phpeclipse/phpeditor/php/PartitionStack.java | 67 ++++++ 3 files changed, 380 insertions(+), 0 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PartitionStack.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java new file mode 100644 index 0000000..522df96 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java @@ -0,0 +1,80 @@ +/* + * Created on 28.04.2003 + * + */ +package net.sourceforge.phpeclipse.phpeditor.php; + +import org.eclipse.jface.text.*; + +/** + * @author slanger + * @version $Revision: 1.1 $ + */ +public class PHPPartition extends Partition +{ + private boolean fShortTagsEnabled = true; + + /** + * @param document + * @param delim + * @param contentType + * @param parentPartition + */ + public PHPPartition(IDocument document, String parentPartition) + { + super( + document, + new char[] { '<', '>' }, + IPHPPartitionScannerConstants.PHP, + parentPartition); + } + + + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#allowedPartition(java.lang.String) + */ + protected boolean allowedPartition(String type) + { + if(type.equals(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT)) + return true; + + return false; + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#scan() + */ + protected boolean scan() + { + int ch; + if(fShortTagsEnabled && checkPattern("", true)) + { + int offset = getOffset(); + if(checkPattern("/*", true)) + { + unread(2); + return; + } + } + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java new file mode 100644 index 0000000..bf83815 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java @@ -0,0 +1,233 @@ +/* + * Created on 28.04.2003 + * + */ +package net.sourceforge.phpeclipse.phpeditor.php; + +import org.eclipse.jface.text.*; +import org.eclipse.jface.text.rules.*; + + +/** + * Defines a partition in a phpdocument. This class keeps tracks of + * partitions contained within other partitions. + * + * @author Stefan Langer + * @version $Revision: 1.1 $ + */ +public abstract class Partition +{ + private IDocument fDocument; + private IToken fContentToken; + private String fParentPartition; + private char[] fTextBuffer; + private int fOffset = 0; + private char entry; + private char exit; + private boolean inDoubleString = false; + private boolean inSingleString = false; + + public Partition(IDocument document, char[] delim, String contentType, String parentPartition) + { + fDocument = document; + fContentToken = new Token(contentType); + fParentPartition = parentPartition; + entry = delim[0]; + exit = delim[1]; + } + + public Partition(IDocument document, char[] delim, String contentType) + { + this(document, delim, contentType, IPHPPartitionScannerConstants.HTML); + } + + /** + * Checks wether the specified type is allowed within this + * partition type. + * + * @param type The type of the partition to check. + * + * @return true if the partition is allowed within this + * partition otherwise false. + */ + abstract protected boolean allowedPartition(String type); + + abstract protected boolean scan(); + + protected boolean isEnd() + { + return fOffset >= fTextBuffer.length; + } + + protected int read() + { + if(fOffset > fTextBuffer.length) + return ICharacterScanner.EOF; + + char ret = fTextBuffer[fOffset++]; + switch(ret) + { + case '\'': + if(!inDoubleString) + inSingleString = !inSingleString; + break; + case '"': + if(!inSingleString) + inDoubleString = !inDoubleString; + break; + } + return ret; + } + + protected void unread(int i) + { + for (int j = 0; j < i && fOffset > 0; j++) + { + char read = fTextBuffer[--fOffset]; + + switch (read) + { + case '\'' : + if (!inDoubleString) + inSingleString = !inSingleString; + break; + case '"' : + if (!inSingleString) + inDoubleString = !inDoubleString; + break; + } + } // END FOR + } + + public boolean scanRange(int offset, int length) + throws BadLocationException + { // short circuit scanning if entry is not correct + if (fDocument.getChar(offset) != entry) + return false; + // read the full range into the internal buffer + fOffset = 0; + inSingleString = false; + inDoubleString = false; + fTextBuffer = fDocument.get(offset, length).toCharArray(); + return scan(); + } + + protected boolean checkPattern(String pattern, boolean ignoreCase) + { + char[] checkPattern = pattern.toCharArray(); + int offset = fOffset; + for(int i=0; i= 0) + { + return (String)fPartitionStack.get(fStackTop--); + } + + return IPHPPartitionScannerConstants.HTML; + } + + public boolean isEmpty() + { + return (fStackTop < 0); + } + + /** + * Initializes this stack from the specified document for the + * specified offset. + * @param offset The offset to initialize from + * @param fDocument The document to initialize from + */ + public void initializeStack(int offset, IDocument fDocument) + { + + } + +} -- 1.7.1