KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > propertiesfileeditor > LeadingWhitespacePredicateRule


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.propertiesfileeditor;
12
13 import org.eclipse.jface.text.rules.ICharacterScanner;
14 import org.eclipse.jface.text.rules.IToken;
15 import org.eclipse.jface.text.rules.IWordDetector;
16 import org.eclipse.jface.text.rules.WordPatternRule;
17
18
19 /**
20  * A leading white space predicate rule.
21  *
22  * @since 3.1
23  */

24 public final class LeadingWhitespacePredicateRule extends WordPatternRule {
25
26
27     private static class DummyDetector implements IWordDetector {
28
29         /*
30          * @see IWordDetector#isWordStart
31          */

32         public boolean isWordStart(char c) {
33             return false;
34         }
35
36         /*
37          * @see IWordDetector#isWordPart
38          */

39         public boolean isWordPart(char c) {
40             return false;
41         }
42     }
43
44
45     /**
46      * Creates a white space rule for the given <code>token</code>.
47      *
48      * @param token the token to be returned on success
49      */

50     public LeadingWhitespacePredicateRule(IToken token, String JavaDoc whitespace) {
51         super(new DummyDetector(), whitespace, "dummy", token); //$NON-NLS-1$
52
setColumnConstraint(0);
53     }
54
55     /*
56      * @see org.eclipse.jface.text.rules.WordPatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
57      */

58     protected boolean endSequenceDetected(ICharacterScanner scanner) {
59         int c;
60         do {
61             c= scanner.read();
62         } while (Character.isWhitespace((char) c));
63
64         scanner.unread();
65
66         return true;
67     }
68 }
69
Popular Tags