PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null) { int fileLength = psiFile.getTextLength(); System.out.println("File length: " + fileLength); }
PsiElement element = ...; // get PsiElement from somewhere int elementLength = element.getTextLength(); System.out.println("Element length: " + elementLength);This code retrieves a PsiElement object from somewhere and prints the length of the text represented by the PsiElement object. Package/Library: com.intellij.psi