01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import org.eclipse.jface.text.rules.ICharacterScanner;
13: import org.eclipse.jface.text.rules.IToken;
14: import org.eclipse.jface.text.rules.IWordDetector;
15: import org.eclipse.jface.text.rules.WordPatternRule;
16:
17: /**
18: * ExternalizedStringRule
19: *
20: */
21: public class ExternalizedStringRule extends WordPatternRule {
22:
23: /**
24: * ExternalizedStringDetector
25: *
26: */
27: private static class ExternalizedStringDetector implements
28: IWordDetector {
29:
30: /**
31: *
32: */
33: public ExternalizedStringDetector() {
34: super ();
35: }
36:
37: /* (non-Javadoc)
38: * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char)
39: */
40: public boolean isWordStart(char character) {
41: if (character == '%') {
42: return true;
43: }
44: return false;
45: }
46:
47: /* (non-Javadoc)
48: * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char)
49: */
50: public boolean isWordPart(char character) {
51: if (Character.isLetterOrDigit(character)) {
52: return true;
53: } else if (character == '.') {
54: return true;
55: } else if (character == '-') {
56: return true;
57: } else if (character == '_') {
58: return true;
59: }
60: return false;
61: }
62: }
63:
64: /**
65: * @param token
66: */
67: public ExternalizedStringRule(IToken token) {
68: super (new ExternalizedStringDetector(), "%", null, token); //$NON-NLS-1$
69: }
70:
71: /* (non-Javadoc)
72: * @see org.eclipse.jface.text.rules.WordPatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
73: */
74: protected boolean endSequenceDetected(ICharacterScanner scanner) {
75: // Read the next character
76: char character = (char) scanner.read();
77: // Detect end character
78: if (Character.isWhitespace(character)) {
79: return true;
80: } else if (character == '<') {
81: return true;
82: }
83: // Unread the character just read
84: scanner.unread();
85: // Process as normal
86: return super.endSequenceDetected(scanner);
87: }
88:
89: }
|