com.intellij.psi.impl.source.tree.ChangeUtil Java Examples

The following examples show how to use com.intellij.psi.impl.source.tree.ChangeUtil. 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: GroovyDslUtil.java    From ok-gradle with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used in order to add elements to the back of a map,
 * it is derived from {@link ASTDelegatePsiElement#addInternal(ASTNode, ASTNode, ASTNode, Boolean)}.
 */
private static PsiElement realAddBefore(@NotNull GrListOrMap element, @NotNull PsiElement newElement, @NotNull PsiElement anchor) {
  CheckUtil.checkWritable(element);
  TreeElement elementCopy = ChangeUtil.copyToElement(newElement);
  ASTNode anchorNode = getAnchorNode(element, anchor.getNode(), true);
  ASTNode newNode = CodeEditUtil.addChildren(element.getNode(), elementCopy, elementCopy, anchorNode);
  if (newNode == null) {
    throw new IncorrectOperationException("Element cannot be added");
  }
  if (newNode instanceof TreeElement) {
    return ChangeUtil.decodeInformation((TreeElement)newNode).getPsi();
  }
  return newNode.getPsi();
}
 
Example #2
Source File: SqliteMagicLightMethodGenerator.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public TreeElement generateTreeFor(PsiElement original, CharTable table, PsiManager manager) {
  TreeElement result = null;
  if (original instanceof SqliteMagicLightMethodBuilder) {
    result = ChangeUtil.copyElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(original), table);
  }
  return result;
}
 
Example #3
Source File: LombokLightMethodTreeGenerator.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public TreeElement generateTreeFor(PsiElement original, CharTable table, PsiManager manager) {
  TreeElement result = null;
  if (original instanceof LombokLightMethodBuilder) {
    result = ChangeUtil.copyElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(original), table);
  }
  return result;
}
 
Example #4
Source File: PsiDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void updateAddedFile(PsiFile copyPsi) throws IncorrectOperationException {
  final UpdateAddedFileProcessor processor = UpdateAddedFileProcessor.forElement(copyPsi);
  if (processor != null) {
    final TreeElement tree = (TreeElement)SourceTreeToPsiMap.psiElementToTree(copyPsi);
    if (tree != null) {
      ChangeUtil.encodeInformation(tree);
    }
    processor.update(copyPsi, null);
    if (tree != null) {
      ChangeUtil.decodeInformation(tree);
    }
  }
}