1 /******************************************************************************* 2 * Copyright (c) 2000, 2006 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.compare.contentmergeviewer; 12 13 import org.eclipse.compare.rangedifferencer.IRangeComparator; 14 15 16 /** 17 * For performing a so-called "token compare" on a line of text. 18 * This interface extends the <code>IRangeComparator</code> interface 19 * so that it can be used by the <code>TextMergeViewer</code>. 20 * <p> 21 * <code>TextMergeViewer</code> activates the token compare when navigating into 22 * a range of differing lines. At first the lines are selected as a block. 23 * When navigating into this block the token compare shows for every line 24 * the differing token by selecting them. 25 * <p> 26 * <code>TextMergeViewer</code>'s default token comparator works on characters separated 27 * by whitespace. If a different strategy is needed (for example, to use Java tokens in 28 * a Java-aware merge viewer), clients may create their own token 29 * comparators by implementing this interface (and overriding the 30 * <code>TextMergeViewer.createTokenComparator</code> factory method). 31 * </p> 32 * 33 * @see TextMergeViewer 34 */ 35 public interface ITokenComparator extends IRangeComparator { 36 37 /** 38 * Returns the start character position of the token with the given index. 39 * If the index is out of range (but not negative) the character position 40 * behind the last character (the length of the input string) is returned. 41 * 42 * @param index index of the token for which to return the start position 43 * @return the start position of the token with the given index 44 * @throws java.lang.IndexOutOfBoundsException if index is negative 45 */ 46 int getTokenStart(int index); 47 48 /** 49 * Returns the character length of the token with the given index. 50 * If the index is out of range (but not negative) the value 0 is returned. 51 * 52 * @param index index of the token for which to return the start position 53 * @return the character length of the token with the given index 54 * @throws java.lang.IndexOutOfBoundsException if index is negative 55 */ 56 int getTokenLength(int index); 57 } 58