@Override public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myText = buffer; myEnd = endOffset; myScanner = new ErrorSkippingScanner(new CharSequenceReader(buffer.subSequence(0, endOffset))); myToken = myScanner.peekToken(); myState = initialState; if (startOffset > 0) { // Here comes ugly. Emulate incremental lexer by re-lexing from start while (myScanner.peekToken().getStartMark().getIndex() < startOffset) { advance(); } } }
@Nullable private static String getCharsetFromEncodingDeclaration(@Nullable CharSequence content) { if (content == null || content.length() == 0) { return null; } try { final BufferedReader reader = new BufferedReader(new CharSequenceReader(content)); try { for (int i = 0; i < MAX_CHARSET_ENCODING_LINE; i++) { final String line = reader.readLine(); if (line == null) { return null; } final Matcher matcher = ENCODING_PATTERN.matcher(line); if (matcher.find()) { final String charset = matcher.group(1); return normalizeCharset(charset); } } } finally { reader.close(); } } catch (IOException ignored) { } return null; }
@NotNull private static XmlFileHeader calcXmlFileHeader(final XmlFile file) { if (file instanceof PsiFileEx && ((PsiFileEx)file).isContentsLoaded() && file.getNode().isParsed()) { return computeHeaderByPsi(file); } if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile instanceof VirtualFileWithId) { ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile); if (tree != null) { Stub root = tree.getRoot(); if (root instanceof FileStub) { return ((FileStub)root).getHeader(); } } } } if (!file.isValid()) return XmlFileHeader.EMPTY; if (XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { FileContent fileContent = file.getUserData(DomStubBuilder.CONTENT_FOR_DOM_STUBS); if (fileContent != null) { //noinspection IOResourceOpenedButNotSafelyClosed return NanoXmlUtil.parseHeader(new CharSequenceReader(fileContent.getContentAsText())); } } return NanoXmlUtil.parseHeader(file); }
public ScannerAndBuilderSynchronizer(PsiBuilder builder) { super(new CharSequenceReader(builder.getOriginalText())); this.builder = builder; }
@NotNull public static Document loadDocument(@NotNull CharSequence seq) throws IOException, JDOMException { return loadDocument(new CharSequenceReader(seq)); }
private static MyXMLReader createReader(PsiFile psiFile) { return new MyXMLReader(new CharSequenceReader(psiFile.getViewProvider().getContents())); }
@NotNull public static Document loadDocument(@NotNull CharSequence seq) throws IOException, JDOMException { return getSaxBuilder().build(new CharSequenceReader(seq)); }
@Nonnull public static Document loadDocument(@Nonnull CharSequence seq) throws IOException, JDOMException { return loadDocument(new CharSequenceReader(seq)); }