1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
14 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
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) {
35 c= document.getChar(pos);
36 if (!Scanner.isPHPIdentifierPart(c))
44 int length= document.getLength();
46 while (pos < length) {
47 c= document.getChar(pos);
48 if (!Scanner.isPHPIdentifierPart(c))
55 } catch (BadLocationException x) {
58 if (start > -1 && end > -1) {
59 if (start == offset && end == offset)
60 return new Region(offset, 0);
61 else if (start == offset)
62 return new Region(start, end - start);
64 return new Region(start + 1, end - start - 1);