org.eclipse.jface.text.rules.IWordDetector Java Examples

The following examples show how to use org.eclipse.jface.text.rules.IWordDetector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * At a given position in text retrieves the region marking the word, starting before and ending on current position 
 * @param document document
 * @param documentOffset offset (position of the cursor)
 * @param detector for identification of words 
 * @return a region expanded backwards
 */
public static IRegion getRegionExpandedBackwards(IDocument document, int documentOffset, IWordDetector detector)
{

    // Use string buffer to collect characters
    int charCounter = 0;
    while (true)
    {
        try
        {

            // Read character backwards
            char c = document.getChar(--documentOffset);

            // This was the start of a word
            if (!detector.isWordPart(c))
                break;

            // Count character
            charCounter++;

        } catch (BadLocationException e)
        {

            // Document start reached, no word
            break;
        }
    }
    return new Region(documentOffset + 1, charCounter);
}
 
Example #2
Source File: DocumentHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * At a given position in text retrieves the region marking the word, starting at and ending after the current position 
 * @param document document
 * @param documentOffset offset (position of the cursor)
 * @param detector for identification of words 
 * @return a region expanded forward
 */
public static IRegion getRegionExpandedForwards(IDocument document, int documentOffset, IWordDetector detector)
{

    // Use string buffer to collect characters
    int charCounter = 0;
    while (true)
    {
        try
        {
            // Read character forward
            char c = document.getChar(++documentOffset);

            // This was the start of a word
            if (!detector.isWordPart(c))
                break;

            // Count character
            charCounter++;

        } catch (BadLocationException e)
        {

            // Document end reached, no word
            break;
        }
    }

    return new Region(documentOffset - charCounter, charCounter + 1);
}
 
Example #3
Source File: FullPatternRule.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public FullPatternRule(IToken token, String[] possibleSequences, IWordDetector ruleCancelWordDetector) {
	this.token = token;
	this.ruleCancelWordDetector = ruleCancelWordDetector;
	this.possibleSequences = ArrayUtil.map(possibleSequences, STRING_to_CHAR_ARRAY, char[].class);
}
 
Example #4
Source File: PredicateWrodRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public PredicateWordRule(IWordDetector detector, IToken defaultToken) {
	super(detector, defaultToken);
}
 
Example #5
Source File: DocumentHelper.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Factory method for the word detector
 */
public static IWordDetector getDefaultWordDetector()
{
    return new TLAWordDetector();
}
 
Example #6
Source File: InnerTagRule.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public InnerTagRule(int ruleType, IWordDetector detector) {
	super(detector);
	this.ruleType = ruleType;
}
 
Example #7
Source File: InnerTagRule.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public InnerTagRule(IWordDetector detector) {
	super(detector);
}
 
Example #8
Source File: CSSCodeScannerRuleBased.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private VendorPropertyWordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase)
{
	super(detector, defaultToken, ignoreCase);
}
 
Example #9
Source File: AddRemoveList.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Display a prompt to allow adding new elements.
 */
protected void promptForNewElements()
{
	IInputValidator inputValidator = new IInputValidator()
	{
		public String isValid(String newText)
		{
			IWordDetector dtdDetector = new DTDNameDetector();
			String[] inputWords = newText.split(" |,"); //$NON-NLS-1$
			for (String word : inputWords)
			{
				// Only letters, digits, spaces and commas are valid here.
				int length = word.length();
				for (int i = 0; i < length; i++)
				{
					char c = word.charAt(i);
					if (i == 0)
					{
						if (!dtdDetector.isWordStart(c))
						{
							return NLS.bind(Messages.AddRemoveList_invalidBeginTagChar, word);
						}
					}
					else if (!dtdDetector.isWordPart(c))
					{
						return NLS.bind(Messages.AddRemoveList_invalidCharInTag, word);
					}
				}
			}
			return null;
		}
	};
	InputDialog dialog = new InputDialog(listViewer.getList().getShell(), Messages.AddRemoveList_inputMessageTitle,
			Messages.AddRemoveList_inputMessageText, "", inputValidator); //$NON-NLS-1$
	if (dialog.open() == Window.OK)
	{
		String value = dialog.getValue().trim();
		if (value.length() == 0)
		{
			return;
		}
		// At this point we know that the elements have been validated by the input-validator.
		value = value.replaceAll(",", " "); //$NON-NLS-1$ //$NON-NLS-2$
		String[] values = value.split(" "); //$NON-NLS-1$
		// Filter out any duplicates that we might have before setting the input.
		Set<Object> elementsSet = new TreeSet<Object>();
		Object[] existingElements = contentProvider.getElements(null);
		for (Object o : existingElements)
		{
			elementsSet.add(o);
		}
		for (String v : values)
		{
			if (v.trim().length() != 0)
			{
				elementsSet.add(v.toLowerCase());
			}
		}
		listViewer.setInput(elementsSet.toArray(new Object[elementsSet.size()]));
	}
}
 
Example #10
Source File: HTMLDoctypeScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private TagStartRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase)
{
	super(detector, defaultToken, ignoreCase);
}
 
Example #11
Source File: InnerTagRule.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public InnerTagRule(IWordDetector detector) {
	super(detector);
}
 
Example #12
Source File: InnerTagRule.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public InnerTagRule(int ruleType, IWordDetector detector) {
	super(detector);
	this.ruleType = ruleType;
}
 
Example #13
Source File: InnerTagRule.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public InnerTagRule(IWordDetector detector) {
	super(detector);
}
 
Example #14
Source File: TodoTaskTagRule.java    From xds-ide with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a rule which, with the help of a task tag detector, will return the token
 * associated with the detected task tag. If no token has been associated, the
 * specified default token will be returned.
 *
 * @param detector the task tag detector to be used by this rule, 
 *        may not be <code>null</code>
 * @param defaultToken the default token to be returned on success
 *        if nothing else is specified, may not be <code>null</code>
 * @param taskToken the token to be returned if the tag task has been found, 
 *        may not be <code>null</code>
 */
public TodoTaskTagRule(IWordDetector detector, IToken defaultToken, IToken taskToken) 
{
    super(detector, defaultToken, !TodoTaskManager.getInstance().isCaseSensitive());
    for (TodoTask task : TodoTaskManager.getInstance().getAllTasks()) {
        addWord(task.tag, taskToken);
    }
}
 
Example #15
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a rule which, with the help of an word detector, will return the token
 * associated with the detected word. If no token has been associated, the
 * specified default token will be returned.
 *
 * @param detector the word detector to be used by this rule, may not be <code>null</code>
 * @param matcher the initial word matcher
 * @param defaultToken the default token to be returned on success
 *		if nothing else is specified, may not be <code>null</code>
 *
 * @see WordMatcher#addWord(String, IToken)
 */
public CombinedWordRule(IWordDetector detector, WordMatcher matcher, IToken defaultToken) {

	Assert.isNotNull(detector);
	Assert.isNotNull(defaultToken);

	fDetector= detector;
	fDefaultToken= defaultToken;
	if (matcher != null)
		addWordMatcher(matcher);
}
 
Example #16
Source File: DocumentHelper.java    From tlaplus with MIT License 3 votes vote down vote up
/**
 * Combines the effect of backwards and forwards region expansion
 * @param document
 * @param offset
 * @param defaultWordDetector
 * @return A {@link WordRegion} or null if no region could be found.
 * @throws BadLocationException 
 */
public static WordRegion getRegionExpandedBoth(IDocument document, int documentOffset, IWordDetector detector) throws BadLocationException
{
    final IRegion backwards = getRegionExpandedBackwards(document, documentOffset, detector);
    final IRegion forwards = getRegionExpandedForwards(document, documentOffset, detector);
    final String word = document.get(backwards.getOffset(), backwards.getLength() + forwards.getLength());
    return new WordRegion(backwards.getOffset(), backwards.getLength() + forwards.getLength(), word);
}
 
Example #17
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a rule which, with the help of an word detector, will return the token
 * associated with the detected word. If no token has been associated, the scanner
 * will be rolled back and an undefined token will be returned in order to allow
 * any subsequent rules to analyze the characters.
 *
 * @param detector the word detector to be used by this rule, may not be <code>null</code>
 * @param matcher the initial word matcher
 *
 * @see WordMatcher#addWord(String, IToken)
 */
public CombinedWordRule(IWordDetector detector, WordMatcher matcher) {
	this(detector, matcher, Token.UNDEFINED);
}
 
Example #18
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a rule which, with the help of an word detector, will return the token
 * associated with the detected word. If no token has been associated, the
 * specified default token will be returned.
 *
 * @param detector the word detector to be used by this rule, may not be <code>null</code>
 * @param defaultToken the default token to be returned on success
 *		if nothing else is specified, may not be <code>null</code>
 *
 * @see WordMatcher#addWord(String, IToken)
 */
public CombinedWordRule(IWordDetector detector, IToken defaultToken) {
	this(detector, null, defaultToken);
}
 
Example #19
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a rule which, with the help of an word detector, will return the token
 * associated with the detected word. If no token has been associated, the scanner
 * will be rolled back and an undefined token will be returned in order to allow
 * any subsequent rules to analyze the characters.
 *
 * @param detector the word detector to be used by this rule, may not be <code>null</code>
 *
 * @see WordMatcher#addWord(String, IToken)
 */
public CombinedWordRule(IWordDetector detector) {
	this(detector, null, Token.UNDEFINED);
}
 
Example #20
Source File: ExtendedWordRule.java    From APICloud-Studio with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a rule which, with the help of a word detector, will return the
 * token associated with the detected word. If no token has been associated,
 * the specified default token will be returned.
 * 
 * @param detector
 *            the word detector to be used by this rule, may not be
 *            <code>null</code>
 * @param defaultToken
 *            the default token to be returned on success if nothing else is
 *            specified, may not be <code>null</code>
 * @param ignoreCase
 *            the case sensitivity associated with this rule
 * @see #addWord(String, IToken)
 */
protected ExtendedWordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase) {
	super(detector, defaultToken, ignoreCase);
	this.ignoreCase = ignoreCase;
}
 
Example #21
Source File: TagWordRule.java    From APICloud-Studio with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param detector
 * @param defaultToken
 * @param ignoreCase
 */
public TagWordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase)
{
	super(detector, defaultToken, ignoreCase);
}
 
Example #22
Source File: SuffixedWordRule.java    From xds-ide with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a rule for the given ending character which, if detected, will 
 * return the specified token. A word detector is used to identify words.
 *
 * @param detector the word detector to be used
 * @param endCharacter the end character of the word pattern
 * @param token the token to be returned on success
 */
public SuffixedWordRule(IWordDetector detector, char endCharacter, IToken successToken) {
    wordDetector      = detector;
    this.successToken = successToken;
    this.endCharacter = endCharacter;
}
 
Example #23
Source File: MultiSuffixedWordRule.java    From xds-ide with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a rule for the given ending character which, if detected, will 
 * return the specified token. A word detector is used to identify words.
 *
 * @param detector the word detector to be used
 * @param endCharacter the end character of the word pattern
 * @param token the token to be returned on success
 */
public MultiSuffixedWordRule(IWordDetector detector, IToken successToken, char... endCharacters) {
    wordDetector       = detector;
    this.successToken  = successToken;
    this.endCharacters = endCharacters;
}