/**
  * Creates a 'match'. It also checks whether the 'found' expression's text actually contains the
  * searched text and ensures to make the match cover exactly the searchedText.
  */
 public Match createMatch(Expression valueExpression, String searchedText) throws CoreException {
   int start = valueExpression.getStart();
   int len = valueExpression.getLength();
   String foundText = cuText.substring(start, start + len);
   int displace = foundText.indexOf(searchedText);
   if (displace >= 0) {
     IJavaElement el = cu.getElementAt(start);
     return new Match(el, start + displace, searchedText.length());
   } else {
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             GrailsCoreActivator.PLUGIN_ID,
             "Found AST node, but it doesn't contain searched text"));
   }
 }
  protected void addError(String msg, ASTNode expr) {
    int line = expr.getLineNumber();
    int col = expr.getColumnNumber();
    // GRECLIPSE
    int start = expr.getStart();
    int end = expr.getEnd() - 1;
    if (expr instanceof ClassNode) {
      // assume we have a class declaration
      ClassNode cn = (ClassNode) expr;
      if (cn.getNameEnd() > 0) {
        start = cn.getNameStart();
        end = cn.getNameEnd();
      } else if (cn.getComponentType() != null) {
        // avoid extra whitespace after closing ]
        end--;
      }

    } else if (expr instanceof DeclarationExpression) {
      // assume that we just want to underline the variable declaration
      DeclarationExpression decl = (DeclarationExpression) expr;
      Expression lhs = decl.getLeftExpression();
      start = lhs.getStart();
      // avoid extra space before = if a variable
      end =
          lhs instanceof VariableExpression ? start + lhs.getText().length() - 1 : lhs.getEnd() - 1;
    }
    // end

    SourceUnit source = getSourceUnit();
    source
        .getErrorCollector()
        .addErrorAndContinue(
            // GRECLIPSE: start
            new SyntaxErrorMessage(
                new PreciseSyntaxException(msg + '\n', line, col, start, end), source)
            // end
            );
  }