private ASTNode createAST(String text) { ParserDefinition definition = new BuildParserDefinition(); PsiParser parser = definition.createParser(getProject()); Lexer lexer = definition.createLexer(getProject()); PsiBuilderImpl psiBuilder = new PsiBuilderImpl( getProject(), null, definition, lexer, new CharTableImpl(), text, null, null); PsiBuilderAdapter adapter = new PsiBuilderAdapter(psiBuilder) { @Override public void error(String messageText) { super.error(messageText); errors.add(messageText); } }; return parser.parse(definition.getFileNodeType(), adapter); }
@NotNull private ASTNode createRootAST(@NotNull StartMarker rootMarker) { final IElementType type = rootMarker.getTokenType(); @SuppressWarnings("NullableProblems") final ASTNode rootNode = type instanceof ILazyParseableElementType ? ASTFactory.lazy((ILazyParseableElementType)type, null) : createComposite(rootMarker); if (myCharTable == null) { myCharTable = rootNode instanceof FileElement ? ((FileElement)rootNode).getCharTable() : new CharTableImpl(); } if (!(rootNode instanceof FileElement)) { rootNode.putUserData(CharTable.CHAR_TABLE_KEY, myCharTable); } return rootNode; }
public static @NotNull <T extends PsiElement> T parseText( @NotNull String text, @NotNull IElementType rootElementType, @NotNull Class<T> rootElementClass, @NotNull ParserDefinition parserDefinition, @Nullable ErrorProcessor errorProcessor) { LanguageParserDefinitions.INSTANCE.addExplicitExtension( parserDefinition.getFileNodeType().getLanguage(), parserDefinition ); PsiParser parser = parserDefinition.createParser(model.first); Lexer lexer = parserDefinition.createLexer(model.first); PsiBuilderImpl psiBuilder = new PsiBuilderImpl( model.first, null, parserDefinition, lexer, new CharTableImpl(), text, null, null ); ASTNode astNode = parser.parse(rootElementType, psiBuilder); T res = astNode.getPsi(rootElementClass); collectErrors(res, errorProcessor); return res; }
private ASTNode createRootAST(final StartMarker rootMarker) { final IElementType type = rootMarker.getTokenType(); @SuppressWarnings("NullableProblems") final ASTNode rootNode = type instanceof ILazyParseableElementType ? ASTFactory.lazy((ILazyParseableElementType)type, null) : createComposite(rootMarker); if (myCharTable == null) { myCharTable = rootNode instanceof FileElement ? ((FileElement)rootNode).getCharTable() : new CharTableImpl(); } if (!(rootNode instanceof FileElement)) { rootNode.putUserData(CharTable.CHAR_TABLE_KEY, myCharTable); } return rootNode; }
@Nonnull private TreeElement createRootAST(@Nonnull StartMarker rootMarker) { final IElementType type = rootMarker.getTokenType(); @SuppressWarnings("NullableProblems") final TreeElement rootNode = type instanceof ILazyParseableElementType ? ASTFactory.lazy((ILazyParseableElementType)type, null) : createComposite(rootMarker); if (myCharTable == null) { myCharTable = rootNode instanceof FileElement ? ((FileElement)rootNode).getCharTable() : new CharTableImpl(); } if (!(rootNode instanceof FileElement)) { rootNode.putUserData(CharTable.CHAR_TABLE_KEY, myCharTable); } return rootNode; }
public PsiAnnotationStubImpl(final StubElement parent, final String text) { super(parent, JavaStubElementTypes.ANNOTATION); CharSequence interned = CharTableImpl.getStaticInterned(text); myText = interned == null ? text : interned.toString(); }