protected void assertPhysical(final PsiElement element) { if (!element.isPhysical()) { LOG.error( "Non-physical PsiElement. Physical element is required to be able to anchor the problem in the source tree: " + element + "; file: " + element.getContainingFile()); } }
public int getLineNumber() { if (myLineNumber == -1) { PsiElement psiElement = getPsiElement(); if (psiElement == null) return -1; if (!psiElement.isValid()) return -1; LOG.assertTrue(psiElement.isPhysical()); PsiFile containingFile = InjectedLanguageUtil.getTopLevelFile(psiElement); Document document = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(containingFile); if (document == null) return -1; TextRange textRange = getTextRange(); if (textRange == null) return -1; textRange = InjectedLanguageManager.getInstance(containingFile.getProject()) .injectedToHost(psiElement, textRange); myLineNumber = document.getLineNumber(textRange.getStartOffset()) + 1; } return myLineNumber; }