KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A specific single line rule for arguments in a property value.
20  * <p>
21  * An argument is defined as '{', digit, {digit}, '}'
22  * </p>
23  *
24  * @since 3.1
25  */

26 public final class ArgumentRule extends WordPatternRule {
27
28     private static class ArgumentDetector implements IWordDetector {
29
30         /*
31          * @see IWordDetector#isWordStart
32          */

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

40         public boolean isWordPart(char c) {
41             return c == '}' || Character.isDigit(c);
42         }
43     }
44
45
46     private int fCount= 0;
47
48     /**
49      * Creates an argument rule for the given <code>token</code>.
50      *
51      * @param token the token to be returned on success
52      */

53     public ArgumentRule(IToken token) {
54         super(new ArgumentDetector(), "{", "}", token); //$NON-NLS-1$//$NON-NLS-2$
55
}
56
57     /*
58      * @see org.eclipse.jface.text.rules.WordPatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
59      */

60     protected boolean endSequenceDetected(ICharacterScanner scanner) {
61         fCount++;
62
63         if (scanner.read() == '}')
64             return fCount > 2;
65
66         scanner.unread();
67         return super.endSequenceDetected(scanner);
68     }
69
70     /*
71      * @see org.eclipse.jface.text.rules.PatternRule#sequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner, char[], boolean)
72      */

73     protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
74         fCount= 0;
75         return super.sequenceDetected(scanner, sequence, eofAllowed);
76     }
77 }
78
Popular Tags