1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text;
14 import com.ibm.icu.text.UTF16;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.Region;
21 public class JavaWordFinder {
23 public static IRegion findWord(IDocument document, int offset) {
33 c= document.getChar(pos);
34 if (!Character.isJavaIdentifierPart(c)) {
35 // Check for surrogates
36 if (UTF16.isSurrogate(c)) {
38 * XXX: Here we should create the code point and test whether
39 * it is a Java identifier part. Currently this is not possible
40 * because java.lang.Character in 1.4 does not support surrogates
41 * and because com.ibm.icu.lang.UCharacter.isJavaIdentifierPart(int)
42 * is not correctly implemented.
53 int length= document.getLength();
55 while (pos < length) {
56 c= document.getChar(pos);
57 if (!Character.isJavaIdentifierPart(c)) {
58 if (UTF16.isSurrogate(c)) {
60 * XXX: Here we should create the code point and test whether
61 * it is a Java identifier part. Currently this is not possible
62 * because java.lang.Character in 1.4 does not support surrogates
63 * and because com.ibm.icu.lang.UCharacter.isJavaIdentifierPart(int)
64 * is not correctly implemented.
75 } catch (BadLocationException x) {
78 if (start >= -1 && end > -1) {
79 if (start == offset && end == offset)
80 return new Region(offset, 0);
81 else if (start == offset)
82 return new Region(start, end - start);
84 return new Region(start + 1, end - start - 1);