类com.intellij.psi.impl.source.tree.CompositeElement源码实例Demo

下面列出了怎么用com.intellij.psi.impl.source.tree.CompositeElement的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: BashSupport   文件: BashSpacingProcessor.java
private void init(final ASTNode child) {
    if (child == null) {
        return;
    }
    ASTNode treePrev = child.getTreePrev();
    while (treePrev != null && SpacingUtil.isWhiteSpace(treePrev)) {
        treePrev = treePrev.getTreePrev();
    }

    if (treePrev == null) {
        init(child.getTreeParent());
    } else {
        myChild2 = child;
        myChild1 = treePrev;
        final CompositeElement parent = (CompositeElement) treePrev.getTreeParent();
        myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
    }
}
 
源代码2 项目: consulo   文件: ChangeInfoImpl.java
void fireEvent(int parentStart, PsiFile file, CompositeElement parent) {
  PsiTreeChangeEventImpl e = createEvent(file, myOffset + parentStart);

  if (myOldChild == myNewChild && myNewChild != null) {
    childrenChanged(e, myNewChild, myOldLength);
  }
  else if (myOldChild != null && myNewChild != null) {
    childReplaced(e, myOldChild, myNewChild, parent);
  }
  else if (myOldChild != null) {
    childRemoved(e, myOldChild, parent);
  }
  else if (myNewChild != null) {
    childAdded(e, myNewChild, parent);
  }
}
 
源代码3 项目: consulo   文件: StubBasedPsiElementBase.java
@Nonnull
private String dumpCreationTraces(@Nonnull FileElement fileElement) {
  final StringBuilder traces = new StringBuilder("\nNow " + Thread.currentThread() + "\n");
  traces.append("My creation trace:\n").append(getUserData(CREATION_TRACE));
  traces.append("AST creation traces:\n");
  fileElement.acceptTree(new RecursiveTreeElementWalkingVisitor(false) {
    @Override
    public void visitComposite(CompositeElement composite) {
      PsiElement psi = composite.getPsi();
      if (psi != null) {
        traces.append(psi).append("@").append(System.identityHashCode(psi)).append("\n");
        String trace = psi.getUserData(CREATION_TRACE);
        if (trace != null) {
          traces.append(trace).append("\n");
        }
      }
      super.visitComposite(composite);
    }
  });
  return traces.toString();
}
 
源代码4 项目: consulo   文件: FileTrees.java
private static void bindStubsWithAst(@Nonnull List<PsiElement> srcSpine, List<StubElement<?>> stubList, List<CompositeElement> nodeList, boolean takePsiFromStubs) {
  for (int i = firstNonFilePsiIndex; i < stubList.size(); i++) {
    StubElement<?> stub = stubList.get(i);
    CompositeElement node = nodeList.get(i);
    assert stub.getStubType() == node.getElementType() : "Stub type mismatch: " + stub.getStubType() + "!=" + node.getElementType() + " in #" + node.getElementType().getLanguage();

    PsiElement psi = Objects.requireNonNull(srcSpine.get(i));
    if (takePsiFromStubs) {
      node.setPsi(psi);
    }
    else {
      //noinspection unchecked
      ((StubBase)stub).setPsi(psi);
    }
  }
}
 
源代码5 项目: BashSupport   文件: BashPsiUtils.java
public static void visitRecursively(PsiElement element, BashVisitor visitor) {
    element.accept(visitor);

    // calling element.getChildren() is expensive,
    // better iterate over the chilren
    PsiElement child = element.getFirstChild();
    while (child != null) {
        if (child.getNode() instanceof CompositeElement) {
            visitRecursively(child, visitor);
        }

        child = child.getNextSibling();
    }
}
 
源代码6 项目: intellij-plugin-v4   文件: ANTLRv4ASTFactory.java
/** Create a FileElement for root or a parse tree CompositeElement (not
*  PSI) for the token. This impl is more or less the default.
*/
  @Override
  public CompositeElement createComposite(IElementType type) {
      if (type instanceof IFileElementType) {
          return new FileElement(type, null);
}
      return new CompositeElement(type);
  }
 
源代码7 项目: consulo   文件: DefaultASTCompositeFactory.java
@Nonnull
@Override
public CompositeElement createComposite(@Nonnull IElementType type) {
  if (type instanceof IFileElementType) {
    return new FileElement(type, null);
  }
  if (type instanceof ICompositeElementType) {
    return (CompositeElement)((ICompositeElementType)type).createCompositeNode();
  }
  return new CompositeElement(type);
}
 
源代码8 项目: consulo   文件: TreeChangeImpl.java
public TreeChangeImpl(@Nonnull CompositeElement parent) {
  myParent = parent;
  assert myParent.getPsi() != null : myParent.getElementType() + " of " + myParent.getClass();
  mySuperParents = JBIterable.generate(parent.getTreeParent(), TreeElement::getTreeParent).toList();
  for (TreeElement child : getCurrentChildren()) {
    myInitialLengths.put(child, child.getTextLength());
  }
}
 
源代码9 项目: consulo   文件: TreeChangeImpl.java
@Override
public int compareTo(@Nonnull TreeChangeImpl o) {
  List<CompositeElement> thisParents = ContainerUtil.reverse(getSuperParents());
  List<CompositeElement> thatParents = ContainerUtil.reverse(o.getSuperParents());
  for (int i = 1; i <= thisParents.size() && i <= thatParents.size(); i++) {
    CompositeElement thisParent = i < thisParents.size() ? thisParents.get(i) : myParent;
    CompositeElement thatParent = i < thatParents.size() ? thatParents.get(i) : o.myParent;
    int result = compareNodePositions(thisParent, thatParent);
    if (result != 0) return result;
  }
  return 0;
}
 
源代码10 项目: consulo   文件: TreeChangeImpl.java
private static int compareNodePositions(CompositeElement node1, CompositeElement node2) {
  if (node1 == node2) return 0;

  int o1 = node1.getStartOffsetInParent();
  int o2 = node2.getStartOffsetInParent();
  return o1 != o2 ? Integer.compare(o1, o2) : Integer.compare(getChildIndex(node1), getChildIndex(node2));
}
 
源代码11 项目: consulo   文件: TreeChangeEventImpl.java
public void addElementaryChange(@Nonnull CompositeElement parent) {
  TreeChangeImpl existing = myChangedElements.get(parent);
  if (existing != null) {
    existing.clearCache();
  }
  else if (!integrateIntoExistingChanges(parent)) {
    mergeChange(new TreeChangeImpl(parent));
  }
}
 
源代码12 项目: consulo   文件: TreeChangeEventImpl.java
private boolean integrateIntoExistingChanges(CompositeElement nextParent) {
  for (CompositeElement eachParent : JBIterable.generate(nextParent, TreeElement::getTreeParent)) {
    CompositeElement superParent = eachParent.getTreeParent();
    TreeChangeImpl superChange = myChangedElements.get(superParent);
    if (superChange != null) {
      superChange.markChildChanged(eachParent, 0);
      return true;
    }
  }
  return false;
}
 
源代码13 项目: consulo   文件: TreeChangeEventImpl.java
private void mergeChange(TreeChangeImpl nextChange) {
  CompositeElement newParent = nextChange.getChangedParent();

  for (TreeChangeImpl descendant : new ArrayList<>(myChangesByAllParents.get(newParent))) {
    TreeElement ancestorChild = findAncestorChild(newParent, descendant);
    if (ancestorChild != null) {
      nextChange.markChildChanged(ancestorChild, descendant.getLengthDelta());
    }

    unregisterChange(descendant);
  }

  registerChange(nextChange);
}
 
源代码14 项目: consulo   文件: TreeChangeEventImpl.java
/**
 * @return a direct child of {@code ancestor} which contains {@code change}
 */
@Nullable
private static TreeElement findAncestorChild(@Nonnull CompositeElement ancestor, @Nonnull TreeChangeImpl change) {
  List<CompositeElement> superParents = change.getSuperParents();
  int index = superParents.indexOf(ancestor);
  return index < 0 ? null : index == 0 ? change.getChangedParent() : superParents.get(index - 1);
}
 
源代码15 项目: consulo   文件: ChangeInfoImpl.java
private void childReplaced(PsiTreeChangeEventImpl e, TreeElement oldChild, TreeElement newChild, CompositeElement parent) {
  e.setParent(parent.getPsi());
  e.setOldChild(oldChild.getPsi());
  e.setChild(newChild.getPsi());
  e.setNewChild(newChild.getPsi());
  e.setOldLength(myOldLength);
  getPsiManagerImpl(e).childReplaced(e);
}
 
源代码16 项目: consulo   文件: DiffLog.java
private ReplaceElementWithEvents(@Nonnull CompositeElement oldRoot, @Nonnull CompositeElement newRoot) {
  myOldRoot = oldRoot;
  myNewRoot = newRoot;
  // parse in background to reduce time spent in EDT and to ensure the newRoot light containing file is still valid
  TreeUtil.ensureParsed(myOldRoot.getFirstChildNode());
  TreeUtil.ensureParsed(myNewRoot.getFirstChildNode());
}
 
源代码17 项目: consulo   文件: DebugUtil.java
private static void treeToBufferWithUserData(Appendable buffer, PsiElement root, int indent, boolean skipWhiteSpaces) {
  if (skipWhiteSpaces && root instanceof PsiWhiteSpace) return;

  StringUtil.repeatSymbol(buffer, ' ', indent);
  try {
    if (root instanceof CompositeElement) {
      buffer.append(root.toString());
    }
    else {
      final String text = fixWhiteSpaces(root.getText());
      buffer.append(root.toString()).append("('").append(text).append("')");
    }
    buffer.append(((UserDataHolderBase)root).getUserDataString());
    buffer.append("\n");

    PsiElement[] children = root.getChildren();

    for (PsiElement child : children) {
      treeToBufferWithUserData(buffer, child, indent + 2, skipWhiteSpaces);
    }

    if (children.length == 0) {
      StringUtil.repeatSymbol(buffer, ' ', indent + 2);
      buffer.append("<empty list>\n");
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
源代码18 项目: consulo   文件: DebugUtil.java
public static void doCheckTreeStructure(@Nullable ASTNode anyElement) {
  if (anyElement == null) return;
  ASTNode root = anyElement;
  while (root.getTreeParent() != null) {
    root = root.getTreeParent();
  }
  if (root instanceof CompositeElement) {
    checkSubtree((CompositeElement)root);
  }
}
 
源代码19 项目: consulo   文件: DebugUtil.java
private static void checkSubtree(CompositeElement root) {
  if (root.rawFirstChild() == null) {
    if (root.rawLastChild() != null) {
      throw new IncorrectTreeStructureException(root, "firstChild == null, but lastChild != null");
    }
  }
  else {
    for (ASTNode child = root.getFirstChildNode(); child != null; child = child.getTreeNext()) {
      if (child instanceof CompositeElement) {
        checkSubtree((CompositeElement)child);
      }
      if (child.getTreeParent() != root) {
        throw new IncorrectTreeStructureException(child, "child has wrong parent value");
      }
      if (child == root.getFirstChildNode()) {
        if (child.getTreePrev() != null) {
          throw new IncorrectTreeStructureException(root, "firstChild.prev != null");
        }
      }
      else {
        if (child.getTreePrev() == null) {
          throw new IncorrectTreeStructureException(child, "not first child has prev == null");
        }
        if (child.getTreePrev().getTreeNext() != child) {
          throw new IncorrectTreeStructureException(child, "element.prev.next != element");
        }
      }
      if (child.getTreeNext() == null) {
        if (root.getLastChildNode() != child) {
          throw new IncorrectTreeStructureException(child, "not last child has next == null");
        }
      }
    }
  }
}
 
源代码20 项目: consulo   文件: FileTrees.java
private void bindSubstratesToCachedPsi(List<StubElement<?>> stubList, List<CompositeElement> nodeList) {
  assert myRefToPsi != null;
  for (int i = firstNonFilePsiIndex; i < myRefToPsi.length; i++) {
    StubBasedPsiElementBase cachedPsi = SoftReference.dereference(myRefToPsi[i]);
    if (cachedPsi != null) {
      if (stubList != null) {
        //noinspection unchecked
        ((StubBase)stubList.get(i)).setPsi(cachedPsi);
      }
      if (nodeList != null) {
        nodeList.get(i).setPsi(cachedPsi);
      }
    }
  }
}
 
源代码21 项目: consulo   文件: SimpleTreePatcher.java
@Override
public void insert(CompositeElement parent, TreeElement anchorBefore, OuterLanguageElement toInsert) {
  if(anchorBefore != null) {
    anchorBefore.rawInsertBeforeMe((TreeElement)toInsert);
  }
  else parent.rawAddChildren((TreeElement)toInsert);
}
 
源代码22 项目: jetbrains-plugin-sample   文件: SampleASTFactory.java
/** Create an internal parse tree node. FileElement for root or a parse tree CompositeElement (not
 *  PSI) for the token.
 *  The FileElement is a parse tree node, which is converted to a PsiFile
 *  by {@link ParserDefinition#createFile}.
 */
@NotNull
   @Override
   public CompositeElement createComposite(IElementType type) {
    return super.createComposite(type);
   }
 
源代码23 项目: intellij-haxe   文件: HaxeAstFactory.java
@Nullable
@Override
public CompositeElement createComposite(IElementType type) {
  return super.createComposite(type);
}
 
源代码24 项目: consulo   文件: ASTCompositeFactory.java
@Nonnull
CompositeElement createComposite(@Nonnull IElementType type);
 
源代码25 项目: consulo   文件: TreeChangeImpl.java
List<CompositeElement> getSuperParents() {
  return mySuperParents;
}
 
源代码26 项目: consulo   文件: TreeChangeImpl.java
private static int getChildIndex(CompositeElement e) {
  return ArrayUtil.indexOf(e.getTreeParent().getChildren(null), e);
}
 
源代码27 项目: consulo   文件: TreeChangeImpl.java
@Nonnull
public CompositeElement getChangedParent() {
  return myParent;
}
 
源代码28 项目: consulo   文件: TreeChangeEventImpl.java
@Override
public TreeChange getChangesByElement(@Nonnull ASTNode element) {
  return myChangedElements.get((CompositeElement)element);
}
 
源代码29 项目: consulo   文件: TreeChangeEventImpl.java
private void registerChange(TreeChangeImpl nextChange) {
  myChangedElements.put(nextChange.getChangedParent(), nextChange);
  for (CompositeElement eachParent : nextChange.getSuperParents()) {
    myChangesByAllParents.putValue(eachParent, nextChange);
  }
}
 
源代码30 项目: consulo   文件: TreeChangeEventImpl.java
private void unregisterChange(TreeChangeImpl change) {
  myChangedElements.remove(change.getChangedParent());
  for (CompositeElement superParent : change.getSuperParents()) {
    myChangesByAllParents.remove(superParent, change);
  }
}
 
 类所在包
 类方法
 同包方法