private FileSourceRangeCollection extractHqlNamedQuery(LanguageElement hqlQueryElement) { string hqlQuery = (hqlQueryElement as IPrimitiveExpression).Value.ToString(); SourceFile namedQueriesXmlFile = getNamedQueriesXmlFile(hqlQueryElement.Project as ProjectElement); if (namedQueriesXmlFile != null) { string tempQueryName = getTempQueryName(); if (!namedQueriesXmlFile.IsOpened) { CodeRush.File.Activate(namedQueriesXmlFile.FilePath); } TextDocument namedQueriesXmlDocument = namedQueriesXmlFile.Document as TextDocument; TextDocument currentDocument = hqlQueryElement.Document as TextDocument; string currentFilePath = hqlQueryElement.FileNode.FilePath; SourceFile currentSourceFile = hqlQueryElement.FileNode; string xmlContent = getXmlContent(hqlQuery, tempQueryName); insertXmlContentInNamedQueriesFile(namedQueriesXmlFile, xmlContent); string quotedTempQueryName = String.Format("\"{0}\"", tempQueryName); currentDocument.Replace(hqlQueryElement.Range, quotedTempQueryName, string.Empty, true); currentDocument.ParseIfTextChanged(); FileSourceRangeCollection rangesToLink = new FileSourceRangeCollection(); SourceRange queryNameElementRange = findElementByName(currentDocument.FileNode, quotedTempQueryName).Range; SourceRange queryNameElementRangeWithoutQuotes = new SourceRange( queryNameElementRange.Start.Line, queryNameElementRange.Start.Offset + 1, queryNameElementRange.End.Line, queryNameElementRange.End.Offset - 1); rangesToLink.Add(new FileSourceRange(currentSourceFile, queryNameElementRangeWithoutQuotes)); SourcePoint queryNameLocationInNamedQueriesXmlDocument = namedQueriesXmlDocument.FindText(tempQueryName); SourceRange queryNameElementRangeInNamedQueriesXmlDocument = new SourceRange( queryNameLocationInNamedQueriesXmlDocument, new SourcePoint(queryNameLocationInNamedQueriesXmlDocument.Line, queryNameLocationInNamedQueriesXmlDocument.Offset + tempQueryName.Length)); rangesToLink.Add(new FileSourceRange(namedQueriesXmlFile, queryNameElementRangeInNamedQueriesXmlDocument)); CodeRush.File.Activate(currentFilePath); TextDocument.Active.SelectText(queryNameElementRangeWithoutQuotes); return(rangesToLink); } else { MessageBox.Show("No file for hql named queries found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(null); }