SubstrateRef (@NotNull ASTNode node) { return new SubstrateRef() { @Override public @NotNull ASTNode getNode() { return node; } @Override public boolean isValid() { FileASTNode fileElement = SharedImplUtil.findFileElement(node); PsiElement file = fileElement == null ? null : fileElement.getPsi(); return file != null && file.isValid(); } @Override public @NotNull PsiFile getContainingFile() { PsiFile file = SharedImplUtil.getContainingFile(node); if (file == null) throw PsiInvalidElementAccessException.createByNode(node, null); return file; } }; }