/**
  * Determines if the specified completion applies to the current offset context in the document
  *
  * @param document
  * @param completiontext
  * @param offset
  * @return true if the completion applies, false otherwise
  */
 private boolean appliesToContext(
     IDocument document, String completiontext, int tokenstart, int length) {
   if (length > completiontext.length()) {
     return false;
   }
   try {
     String prefix = document.get(tokenstart, length);
     return prefix.equals(completiontext.substring(0, length));
   } catch (BadLocationException e) {
     ApiUIPlugin.log(e);
   }
   return false;
 }