Java Code Examples for com.intellij.psi.impl.source.tree.Factory#createSingleLeafElement()
The following examples show how to use
com.intellij.psi.impl.source.tree.Factory#createSingleLeafElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphQLNamedElementImpl.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public PsiElement setName(@NotNull String newName) throws IncorrectOperationException { final GraphQLIdentifier nameIdentifier = getNameIdentifier(); if (nameIdentifier != null) { final LeafElement renamedLeaf = Factory.createSingleLeafElement(GraphQLElementTypes.NAME, newName, null, nameIdentifier.getManager()); final PsiElement renamedPsiElement = SourceTreeToPsiMap.treeElementToPsi(renamedLeaf); if (renamedPsiElement != null) { nameIdentifier.getFirstChild().replace(renamedPsiElement); } } return this; }
Example 2
Source File: GraphQLIdentifierManipulator.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public GraphQLIdentifierImpl handleContentChange(@NotNull GraphQLIdentifierImpl element, @NotNull TextRange range, String newContent) throws IncorrectOperationException { // replace the NAME leaf element inside the identifier final LeafElement renamedLeaf = Factory.createSingleLeafElement(GraphQLElementTypes.NAME, newContent, null, element.getManager()); final PsiElement renamedPsiElement = SourceTreeToPsiMap.treeElementToPsi(renamedLeaf); if (renamedPsiElement != null) { element.getFirstChild().replace(renamedPsiElement); } return element; }
Example 3
Source File: JSGraphQLEndpointImportFileReferencePsiElement.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { final PsiElement nameIdentifier = getNameIdentifier(); if(nameIdentifier != null) { final LeafElement renamedLeaf = Factory.createSingleLeafElement(JSGraphQLEndpointTokenTypes.STRING_BODY, name, null, getManager()); final PsiElement renamedPsiElement = SourceTreeToPsiMap.treeElementToPsi(renamedLeaf); if (renamedPsiElement != null) { nameIdentifier.replace(renamedPsiElement); } } return this; }
Example 4
Source File: JSGraphQLEndpointPsiUtil.java From js-graphql-intellij-plugin with MIT License | 5 votes |
/** * Renames an identifier, e.g. during a refactoring */ public static PsiElement renameIdentifier(PsiNameIdentifierOwner owner, String name) throws IncorrectOperationException { final PsiElement identifier = owner.getNameIdentifier(); if (identifier == null) { throw new IncorrectOperationException(); } final LeafElement renamedLeaf = Factory.createSingleLeafElement(JSGraphQLEndpointTokenTypes.IDENTIFIER, name, null, identifier.getManager()); final PsiElement renamedPsiElement = SourceTreeToPsiMap.treeElementToPsi(renamedLeaf); if (renamedPsiElement != null) { identifier.replace(renamedPsiElement); } return owner; }
Example 5
Source File: CSharpDeclarationMover.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void beforeMove(@Nonnull final Editor editor, @Nonnull final MoveInfo info, final boolean down) { super.beforeMove(editor, info, down); if(myEnumToInsertSemicolonAfter != null) { TreeElement semicolon = Factory.createSingleLeafElement(CSharpTokens.SEMICOLON, ";", 0, 1, null, myEnumToInsertSemicolonAfter.getManager()); try { PsiElement inserted = myEnumToInsertSemicolonAfter.getParent().addAfter(semicolon.getPsi(), myEnumToInsertSemicolonAfter); inserted = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(inserted); final LogicalPosition position = editor.offsetToLogicalPosition(inserted.getTextRange().getEndOffset()); info.toMove2 = new LineRange(position.line + 1, position.line + 1); } catch(IncorrectOperationException e) { LOG.error(e); } finally { myEnumToInsertSemicolonAfter = null; } } }
Example 6
Source File: LanguageTokenSeparatorGenerators.java From consulo with Apache License 2.0 | 5 votes |
private LanguageTokenSeparatorGenerators() { super("com.intellij.lang.tokenSeparatorGenerator", new TokenSeparatorGenerator() { @Override public ASTNode generateWhitespaceBetweenTokens(ASTNode left, ASTNode right) { Language l = PsiUtilCore.getNotAnyLanguage(left); Language rightLang = PsiUtilCore.getNotAnyLanguage(right); if (rightLang.isKindOf(l)) { l = rightLang; // get more precise lexer } final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l); if (parserDefinition != null) { PsiManager manager = right.getTreeParent().getPsi().getManager(); ASTNode generatedWhitespace; switch(parserDefinition.spaceExistenceTypeBetweenTokens(left, right)){ case MUST: generatedWhitespace = Factory.createSingleLeafElement(TokenType.WHITE_SPACE, " ", 0, 1, null, manager); break; case MUST_LINE_BREAK: generatedWhitespace = Factory.createSingleLeafElement(TokenType.WHITE_SPACE, "\n", 0, 1, null, manager); break; default: generatedWhitespace = null; } return generatedWhitespace; } return null; } }); }