changes for new Action
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPPartition.java
1 /*
2  * Created on 28.04.2003
3  *
4  */
5 package net.sourceforge.phpeclipse.phpeditor.php;
6
7 import org.eclipse.jface.text.IDocument;
8
9 /**
10  * @author slanger
11  * @version $Revision: 1.2 $
12  */
13 public class PHPPartition extends Partition
14 {
15         private boolean fShortTagsEnabled = true;
16         
17     /**
18      * @param document
19      * @param delim
20      * @param contentType
21      * @param parentPartition
22      */
23     public PHPPartition(IDocument document, String parentPartition)
24     {
25         super(
26             document,
27             new char[] { '<', '>' },
28             IPHPPartitionScannerConstants.PHP,
29             parentPartition);
30     }
31
32     
33
34     /* (non-Javadoc)
35      * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#allowedPartition(java.lang.String)
36      */
37     protected boolean allowedPartition(String type)
38     {
39         if(type.equals(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT))
40                 return true;
41                 
42         return false;
43     }
44
45     /* (non-Javadoc)
46      * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#scan()
47      */
48     protected boolean scan()
49     {
50         int ch;
51         if(fShortTagsEnabled && checkPattern("<?", true))
52         {
53                 scanToEnd();
54         }
55         else if(checkPattern("<?php", false))
56         {
57                 scanToEnd();
58         }    
59         else
60                 return false;
61         
62         return true;    
63     }
64         
65         private void scanToEnd()
66         {
67                 if(isEnd())
68                         return;
69                                 
70                 while(!checkPattern("?>", true))
71                 {
72                         int offset = getOffset();
73                         if(checkPattern("/*", true))
74                         {       
75                                 unread(2);
76                                 return;
77                         }
78                 }               
79         }
80 }