@Override public PsiElement setName(@NotNull String newElementName) throws IncorrectOperationException { final MonkeyId identifier = getId(); final MonkeyId identifierNew = MonkeyElementGenerator.createIdentifierFromText(getProject(), newElementName); if (identifierNew != null) { getNode().replaceChild(identifier.getNode(), identifierNew.getNode()); } return this; }
/** * Set name. */ public PsiElement setName(@NotNull String name) throws IncorrectOperationException { Project project = getProject(); ProtoElementFactory elementFactory = project.getComponent(ProtoElementFactory.class); GenericNameNode newNameNode = elementFactory.createGenericNameNode(name); identNode().replaceChild(identNode().getFirstChildNode(), newNameNode.identNode().getFirstChildNode()); return this; }
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { PsiElement element = this; if (getText().indexOf('.') != -1) { // libPrefix.name final PsiElement lastChild = getLastChild(); element = lastChild == null ? this : lastChild; } final MonkeyId identifier = PsiTreeUtil.getChildOfType(element, MonkeyId.class); final MonkeyId identifierNew = MonkeyElementGenerator.createIdentifierFromText(getProject(), newElementName); if (identifier != null && identifierNew != null) { element.getNode().replaceChild(identifier.getNode(), identifierNew.getNode()); } return this; }
@Override public PsiElement setName(@NonNls @NotNull String name) { ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject()); final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name); ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); if (identifierNode != null && newElm != null) { getNode().replaceChild(identifierNode, newElm); } return this; }
public PsiElement setName(@NotNull @NonNls String name) throws IncorrectOperationException { if (StringUtil.isEmpty(name)) { return null; } //fixme validate name final PsiElement nameNode = getNameSymbol(); if (nameNode == null) { throw new IncorrectOperationException("invalid name"); } final PsiElement newNameSymbol = BashPsiElementFactory.createSymbol(getProject(), name); getNode().replaceChild(nameNode.getNode(), newNameSymbol.getNode()); return this; }
@Override public PsiElement setName(@NonNls @NotNull String name) { ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject()); final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name); ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); if (identifierNode != null && newElm != null) { getNode().replaceChild(identifierNode, newElm); } return this; }
/** * Safely replaces symbolic name node with new node. * It's possible that nothing happens if newElement is invalid. No error thrown in such case. * <p> * TODO: handle cases with invalid newElement (e.g. cyrilic name is set) */ private static void safelyReplaceSymbolicName(CypherNamedElement element, CypherNamedElement newElement) { ASTNode oldNameNode = element.getNode().findChildByType(CypherTypes.SYMBOLIC_NAME_STRING); if (oldNameNode != null) { if (newElement != null) { ASTNode newNameNode = newElement .getNode() .findChildByType(CypherTypes.SYMBOLIC_NAME_STRING); if (newNameNode != null) { element.getNode().replaceChild(oldNameNode, newNameNode); } } } } }
@Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { ASTNode literalNode = getNode().findChildByType(MathematicaElementTypes.STRING_LITERAL); final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject()); final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name); ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.STRING_LITERAL); if (literalNode != null && newElm != null) { getNode().replaceChild(literalNode, newElm); } return this; }
public void updateCommand(String command, @Nullable TextRange replacementRange) { log.debug("Updating command to " + command); PsiFile file = getContainingFile(); if (file == null) { return; } Document document = file.getViewProvider().getDocument(); if (document != null) { TextRange textRange = replacementRange != null ? replacementRange : commandRange(); document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), command); } else { //fallback PsiElement newElement = BashPsiElementFactory.createShebang(getProject(), command, hasNewline()); getNode().replaceChild(getNode().getFirstChildNode(), newElement.getNode()); } }