1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
15 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
16 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.jface.text.DefaultLineTracker;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.IDocumentPartitioner;
22 import org.eclipse.jface.text.ILineTracker;
23 import org.eclipse.jface.text.rules.DefaultPartitioner;
24 import org.eclipse.ui.editors.text.FileDocumentProvider;
27 * The PHPDocumentProvider provides the IDocuments used by java editors.
30 public class PHPDocumentProvider extends FileDocumentProvider {
32 // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
33 private final static String[] TYPES = new String[] {
34 IPHPPartitionScannerConstants.PHP,
35 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
36 IPHPPartitionScannerConstants.HTML,
37 IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
38 IPHPPartitionScannerConstants.JAVASCRIPT,
39 IPHPPartitionScannerConstants.CSS};
41 private static PHPPartitionScanner fgScanner = null;
43 public PHPDocumentProvider() {
48 * Method declared on AbstractDocumentProvider
50 protected IDocument createDocument(Object element) throws CoreException {
51 IDocument document = super.createDocument(element);
52 if (document != null) {
53 IDocumentPartitioner partitioner = createPHPPartitioner();
54 document.setDocumentPartitioner(partitioner);
55 partitioner.connect(document);
61 * Return a partitioner for .php files.
63 private IDocumentPartitioner createPHPPartitioner() {
64 return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
68 * Return a scanner for creating java partitions.
70 private PHPPartitionScanner getPHPPartitionScanner() {
71 if (fgScanner == null)
72 fgScanner = new PHPPartitionScanner();
77 * Creates a line tracker working with the same line delimiters as the document
78 * of the given element. Assumes the element to be managed by this document provider.
80 * @param element the element serving as blue print
81 * @return a line tracker based on the same line delimiters as the element's document
83 public ILineTracker createLineTracker(Object element) {
84 return new DefaultLineTracker();