1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*******************************************************************************
* Copyright (c) 2006, 2015 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat Incorporated - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.autotools.ui.editors;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
public class AutoconfPartitioner extends FastPartitioner {
public AutoconfPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
// TODO Auto-generated constructor stub
super(scanner, legalContentTypes);
}
public void connect(IDocument document, int blah) {
super.connect(document);
}
// To optionally show partitions, we must do so by overriding the computePartitioning
// method. We cannot do it at connect time because the document may be zero length
// at the time and we will end up getting default partitioning from then on.
@Override
public ITypedRegion[] computePartitioning(int offset, int length,
boolean includeZeroLength) {
ITypedRegion[] regions = super.computePartitioning(offset, length, includeZeroLength);
// Uncomment the following line to see partitioning.
// printPartitions(regions);
return regions;
}
public void printPartitions(ITypedRegion[] partitions)
{
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < partitions.length; i++)
{
try
{
buffer.append("Partition type: " + partitions[i].getType() //$NON-NLS-1$
+ ", offset: " + partitions[i].getOffset() //$NON-NLS-1$
+ ", length: " + partitions[i].getLength()); //$NON-NLS-1$
buffer.append("\n"); //$NON-NLS-1$
buffer.append("Text:\n"); //$NON-NLS-1$
buffer.append(super.fDocument.get(partitions[i].getOffset(), partitions[i].getLength()));
buffer.append("\n---------------------------\n\n\n"); //$NON-NLS-1$
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
System.out.print(buffer);
}
}
|