com.intellij.util.diff.FlyweightCapableTreeStructure Java Examples

The following examples show how to use com.intellij.util.diff.FlyweightCapableTreeStructure. 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: BlockSupportImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T> void diffTrees(@Nonnull final ASTNode oldRoot,
                                 @Nonnull final DiffTreeChangeBuilder<ASTNode, T> builder,
                                 @Nonnull final ShallowNodeComparator<ASTNode, T> comparator,
                                 @Nonnull final FlyweightCapableTreeStructure<T> newTreeStructure,
                                 @Nonnull ProgressIndicator indicator,
                                 @Nonnull CharSequence lastCommittedText) {
  DiffTree.diff(createInterruptibleASTStructure(oldRoot, indicator), newTreeStructure, comparator, builder, lastCommittedText);
}
 
Example #2
Source File: DebugUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String lightTreeToString(@Nonnull final FlyweightCapableTreeStructure<LighterASTNode> tree,
                                       final boolean skipWhitespaces) {
  final LengthBuilder ruler = new LengthBuilder();
  lightTreeToBuffer(tree, tree.getRoot(), ruler, 0, skipWhitespaces);
  final StringBuilder buffer = new StringBuilder(ruler.getLength());
  lightTreeToBuffer(tree, tree.getRoot(), buffer, 0, skipWhitespaces);
  return buffer.toString();
}
 
Example #3
Source File: ILightStubFileElementType.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(final ASTNode chameleon) {
  final PsiElement psi = chameleon.getPsi();
  assert psi != null : "Bad chameleon: " + chameleon;

  final Project project = psi.getProject();
  final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
  final Language language = getLanguage();
  final LanguageVersion languageVersion = psi.getLanguageVersion();
  final PsiBuilder builder = factory.createBuilder(project, chameleon, languageVersion);
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
  assert parserDefinition != null : this;
  final PsiParser parser = parserDefinition.createParser(languageVersion);
  parser.parse(this, builder, languageVersion);
  return builder.getLightTree();
}
 
Example #4
Source File: SyntaxTraverser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public JBIterable<? extends T> children(@Nonnull final T node) {
  return new JBIterable<T>() {
    @Override
    public Iterator<T> iterator() {
      FlyweightCapableTreeStructure<T> structure = getStructure();
      Ref<T[]> ref = Ref.create();
      int count = structure.getChildren(node, ref);
      if (count == 0) return ContainerUtil.emptyIterator();
      T[] array = ref.get();
      LinkedList<T> list = ContainerUtil.newLinkedList();
      for (int i = 0; i < count; i++) {
        T child = array[i];
        IElementType childType = typeOf(child);
        // tokens and errors getParent() == null
        if (childType == TokenType.WHITE_SPACE || childType == TokenType.BAD_CHARACTER) {
          continue;
        }
        array[i] = null; // do not dispose meaningful TokenNodes
        list.addLast(child);
      }
      structure.disposeChildren(array, count);
      return list.iterator();
    }
  };
}
 
Example #5
Source File: SyntaxTraverser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
FlyweightCapableTreeStructure<LighterASTNode> getStructure() {
  return structure.getValue();
}
 
Example #6
Source File: DebugUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void lightTreeToBuffer(@Nonnull final FlyweightCapableTreeStructure<LighterASTNode> tree,
                                     @Nonnull final LighterASTNode node,
                                     @Nonnull final Appendable buffer,
                                     final int indent,
                                     final boolean skipWhiteSpaces) {
  final IElementType tokenType = node.getTokenType();
  if (skipWhiteSpaces && tokenType == TokenType.WHITE_SPACE) return;

  final boolean isLeaf = (node instanceof LighterASTTokenNode);

  StringUtil.repeatSymbol(buffer, ' ', indent);
  try {
    if (tokenType == TokenType.ERROR_ELEMENT) {
      buffer.append("PsiErrorElement:").append(PsiBuilderImpl.getErrorMessage(node));
    }
    else if (tokenType == TokenType.WHITE_SPACE) {
      buffer.append("PsiWhiteSpace");
    }
    else {
      buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType.toString()).append(')');
    }

    if (isLeaf) {
      final String text = ((LighterASTTokenNode)node).getText().toString();
      buffer.append("('").append(fixWhiteSpaces(text)).append("')");
    }
    buffer.append('\n');

    if (!isLeaf) {
      final Ref<LighterASTNode[]> kids = new Ref<LighterASTNode[]>();
      final int numKids = tree.getChildren(tree.prepareForGetChildren(node), kids);
      if (numKids == 0) {
        StringUtil.repeatSymbol(buffer, ' ', indent + 2);
        buffer.append("<empty list>\n");
      }
      else {
        for (int i = 0; i < numKids; i++) {
          lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, skipWhiteSpaces);
        }
      }
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
Example #7
Source File: PsiBuilderAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> getLightTree() {
  return myDelegate.getLightTree();
}
 
Example #8
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int getChildren(@Nonnull final LighterASTNode item, @Nonnull final Ref<LighterASTNode[]> into) {
  if (item instanceof LazyParseableToken) {
    final FlyweightCapableTreeStructure<LighterASTNode> tree = ((LazyParseableToken)item).parseContents();
    final LighterASTNode root = tree.getRoot();
    if (root instanceof ProductionMarker) {
      ((ProductionMarker)root).myParent = ((Token)item).myParentNode;
    }
    return tree.getChildren(tree.prepareForGetChildren(root), into);  // todo: set offset shift for kids?
  }

  if (item instanceof Token || item instanceof ErrorItem) return 0;
  StartMarker marker = (StartMarker)item;

  count = 0;
  ProductionMarker child = marker.myFirstChild;
  int lexIndex = marker.myLexemeIndex;
  while (child != null) {
    lexIndex = insertLeaves(lexIndex, child.myLexemeIndex, marker.myBuilder, marker);

    if (child instanceof StartMarker && ((StartMarker)child).myDoneMarker.myCollapse) {
      int lastIndex = ((StartMarker)child).myDoneMarker.myLexemeIndex;
      insertLeaf(child.getTokenType(), marker.myBuilder, child.myLexemeIndex, lastIndex, true, marker);
    }
    else {
      ensureCapacity();
      nodes[count++] = child;
    }

    if (child instanceof StartMarker) {
      lexIndex = ((StartMarker)child).myDoneMarker.myLexemeIndex;
    }
    child = child.myNext;
  }

  insertLeaves(lexIndex, marker.myDoneMarker.myLexemeIndex, marker.myBuilder, marker);
  into.set(nodes == null ? LighterASTNode.EMPTY_ARRAY : nodes);
  nodes = null;

  return count;
}
 
Example #9
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private MyComparator(TripleFunction<ASTNode, LighterASTNode, FlyweightCapableTreeStructure<LighterASTNode>, ThreeState> custom,
                     @Nonnull MyTreeStructure treeStructure) {
  this.custom = custom;
  myTreeStructure = treeStructure;
}
 
Example #10
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public FlyweightCapableTreeStructure<LighterASTNode> getLightTree() {
  final StartMarker rootMarker = prepareLightTree();
  return new MyTreeStructure(rootMarker, myParentLightTree);
}
 
Example #11
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FlyweightCapableTreeStructure<LighterASTNode> parseContents() {
  if (myParsed == null) {
    myParsed = ((ILightLazyParseableElementType)getTokenType()).parseContents(this);
  }
  return myParsed;
}
 
Example #12
Source File: MockPsiBuilder.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@NotNull
public FlyweightCapableTreeStructure<LighterASTNode> getLightTree() {
    //fixme
    //noinspection ConstantConditions
    return null;
}
 
Example #13
Source File: SyntaxTraverser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected FlyweightCapableTreeStructure<LighterASTNode> create() {
  return builder.getLightTree();
}
 
Example #14
Source File: SyntaxTraverser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
abstract FlyweightCapableTreeStructure<T> getStructure();
 
Example #15
Source File: FCTSBackedLighterAST.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FCTSBackedLighterAST(@Nonnull CharTable charTable, @Nonnull FlyweightCapableTreeStructure<LighterASTNode> treeStructure) {
  super(charTable);
  myTreeStructure = treeStructure;
}
 
Example #16
Source File: PsiBuilderQuickTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContents(LighterLazyParseableNode chameleon) {
  final PsiBuilder builder = createBuilder(chameleon.getText());
  parse(builder);
  return builder.getLightTree();
}
 
Example #17
Source File: PsiBuilderQuickTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public FlyweightCapableTreeStructure<LighterASTNode> parseContents(LighterLazyParseableNode chameleon) {
  final PsiBuilder builder = createBuilder(chameleon.getText());
  parse(builder);
  return builder.getLightTree();
}
 
Example #18
Source File: ILightLazyParseableElementType.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Parses the contents of the specified chameleon node and returns the lightweight tree
 * representing parsed contents.
 *
 * @param chameleon the node to parse.
 * @return the parsed contents of the node.
 */
FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon);
 
Example #19
Source File: PsiBuilder.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Same as {@link #getTreeBuilt()} but returns a light tree, which is build faster,
 * produces less garbage but is incapable of creating a PSI over.
 * <br><b>Note</b>: this method shouldn't be called if {@link #getTreeBuilt()} was called before.
 *
 * @return the light tree built.
 */
FlyweightCapableTreeStructure<LighterASTNode> getLightTree();