• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ASTFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.lang.ASTFactory的典型用法代码示例。如果您正苦于以下问题:Java ASTFactory类的具体用法?Java ASTFactory怎么用?Java ASTFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ASTFactory类属于com.intellij.lang包,在下文中一共展示了ASTFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createCharEntity

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@SuppressWarnings({"HardCodedStringLiteral"})
private static TreeElement createCharEntity(char ch, CharTable charTable) {
  switch (ch) {
    case '<':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&lt;");
    case '\'':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&apos;");
    case '"':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&quot;");
    case '>':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&gt;");
    case '&':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&amp;");
    case '\u00a0':
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, "&nbsp;");

    default:
      final String charEncoding = "&#" + (int)ch + ";";
      return ASTFactory.leaf(XmlTokenType.XML_CHAR_ENTITY_REF, charTable.intern(charEncoding));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:EncodeEachSymbolPolicy.java


示例2: addParenthToReplacedChild

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType,
                                                    @NotNull TreeElement newChild,
                                                    @NotNull PsiManager manager) {
  CompositeElement parenthExpr = ASTFactory.composite(parenthType);

  TreeElement dummyExpr = (TreeElement)newChild.clone();
  final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild);
  new DummyHolder(manager, parenthExpr, null, charTableByTree);
  parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree);
  parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "("));
  parenthExpr.rawAddChildren(dummyExpr);
  parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")"));

  try {
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
    PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr));
    parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(formatted);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e); // should not happen
  }

  newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild));
  dummyExpr.getTreeParent().replaceChild(dummyExpr, newChild);

  // TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification
  TreeUtil.clearCaches(TreeUtil.getFileElement(parenthExpr));
  return parenthExpr;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:JavaSourceUtil.java


示例3: createWhiteSpaceFromText

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Override
@NotNull
public PsiElement createWhiteSpaceFromText(@NotNull @NonNls String text) throws IncorrectOperationException {
  final FileElement holderElement = DummyHolderFactory.createHolder(myManager, null).getTreeElement();
  final LeafElement newElement = ASTFactory.leaf(TokenType.WHITE_SPACE, holderElement.getCharTable().intern(text));
  holderElement.rawAddChildren(newElement);
  GeneratedMarkerVisitor.markGenerated(newElement.getPsi());
  return newElement.getPsi();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PsiParserFacadeImpl.java


示例4: createSingleLeafElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@NotNull
public static LeafElement createSingleLeafElement(@NotNull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
  DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
  dummyHolder.setOriginalFile(originalFile);

  FileElement holderElement = dummyHolder.getTreeElement();
  
  LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
    buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:Factory.java


示例5: createCompositeElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@NotNull
public static CompositeElement createCompositeElement(@NotNull IElementType type,
                                                      final CharTable charTableByTree,
                                                      final PsiManager manager) {
  final FileElement treeElement = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
  final CompositeElement composite = ASTFactory.composite(type);
  treeElement.rawAddChildren(composite);
  return composite;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:Factory.java


示例6: rawReplaceWithText

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@NotNull
public LeafElement rawReplaceWithText(@NotNull String newText) {
  LeafElement newLeaf = ASTFactory.leaf(getElementType(), newText);
  copyUserDataTo(newLeaf);
  rawReplaceWithList(newLeaf);
  newLeaf.clearCaches();
  return newLeaf;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:LeafElement.java


示例7: copyLeafWithText

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@NotNull
public static LeafElement copyLeafWithText(@NotNull LeafElement original, @NotNull String text) {
  LeafElement element = ASTFactory.leaf(original.getElementType(), text);
  original.copyCopyableDataTo(element);
  encodeInformation(element, original);
  TreeUtil.clearCaches(element);
  saveIndentationToCopy(original, element);
  return element;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ChangeUtil.java


示例8: split

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Override
public LeafElement split(LeafElement leaf, int offset, final CharTable table) {
  final CharSequence chars = leaf.getChars();
  final LeafElement leftPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, 0, offset));
  final LeafElement rightPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, offset, chars.length()));
  leaf.rawInsertAfterMe(leftPart);
  leftPart.rawInsertAfterMe(rightPart);
  leaf.rawRemove();
  return leftPart;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:SimpleTreePatcher.java


示例9: replaceLastWhiteSpace

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public static void replaceLastWhiteSpace(final ASTNode astNode, final String whiteSpace, final TextRange textRange) {
  ASTNode lastWS = TreeUtil.findLastLeaf(astNode);
  if (lastWS == null) {
    return;
  }
  if (lastWS.getElementType() != TokenType.WHITE_SPACE) {
    lastWS = null;
  }
  if (lastWS != null && !lastWS.getTextRange().equals(textRange)) {
    return;
  }
  if (whiteSpace.isEmpty() && lastWS == null) {
    return;
  }
  if (lastWS != null && whiteSpace.isEmpty()) {
    lastWS.getTreeParent().removeRange(lastWS, null);
    return;
  }

  LeafElement whiteSpaceElement = ASTFactory.whitespace(whiteSpace);

  if (lastWS == null) {
    astNode.addChild(whiteSpaceElement, null);
  }
  else {
    ASTNode treeParent = lastWS.getTreeParent();
    treeParent.replaceChild(lastWS, whiteSpaceElement);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:FormatterUtil.java


示例10: createTokenElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Nullable
public static TreeElement createTokenElement(Lexer lexer, CharTable table) {
  IElementType tokenType = lexer.getTokenType();
  if (tokenType == null) {
    return null;
  }
  else if (tokenType instanceof ILazyParseableElementType) {
    return ASTFactory.lazy((ILazyParseableElementType)tokenType, LexerUtil.internToken(lexer, table));
  }
  else {
    return ASTFactory.leaf(tokenType, LexerUtil.internToken(lexer, table));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ParseUtilBase.java


示例11: addInternal

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
  if (first.getPsi() instanceof PyStatement && getStatements().length == 1) {
    ASTNode treePrev = getNode().getTreePrev();
    if (treePrev != null && treePrev.getElementType() == TokenType.WHITE_SPACE && !treePrev.textContains('\n')) {
      ASTNode lineBreak = ASTFactory.whitespace("\n");
      treePrev.getTreeParent().replaceChild(treePrev, lineBreak);
    }
  }
  return super.addInternal(first, last, anchor, before);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:PyStatementListImpl.java


示例12: addArgumentFirst

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public void addArgumentFirst(PyExpression arg) {
  ASTNode node = getNode();
  ASTNode[] pars = node.getChildren(TokenSet.create(PyTokenTypes.LPAR));
  if (pars.length == 0) {
    // there's no starting paren
    try {
      add(arg);
    }
    catch (IncorrectOperationException e1) {
      throw new IllegalStateException(e1);
    }
  }
  else {
    ASTNode before = PyPsiUtils.getNextNonWhitespaceSibling(pars[0]);
    ASTNode anchorBefore;
    if (before != null && elementPrecedesElementsOfType(before, PythonDialectsTokenSetProvider.INSTANCE.getExpressionTokens())) {
      ASTNode comma = createComma();
      node.addChild(comma, before);
      node.addChild(ASTFactory.whitespace(" "), before);
      anchorBefore = comma;
    }
    else {
      anchorBefore = before;
    }
    ASTNode argNode = arg.getNode();
    if (anchorBefore == null) {
      node.addChild(argNode);
    }
    else {
      node.addChild(argNode, anchorBefore);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:PyArgumentListImpl.java


示例13: addArgumentNode

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
private void addArgumentNode(PyExpression arg, ASTNode beforeThis, boolean commaFirst) {
  ASTNode comma = PyElementGenerator.getInstance(getProject()).createComma();
  ASTNode node = getNode();
  ASTNode argNode = arg.getNode();
  if (commaFirst) {
    node.addChild(comma, beforeThis);
    node.addChild(ASTFactory.whitespace(" "), beforeThis);
    node.addChild(argNode, beforeThis);
  }
  else {
    node.addChild(argNode, beforeThis);
    node.addChild(comma, beforeThis);
    node.addChild(ASTFactory.whitespace(" "), beforeThis);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PyArgumentListImpl.java


示例14: handleContentChange

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Override
public XmlToken handleContentChange(@NotNull XmlToken xmlToken, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
  String oldText = xmlToken.getText();
  String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
  IElementType tokenType = xmlToken.getTokenType();

  FileElement holder = DummyHolderFactory.createHolder(xmlToken.getManager(), null).getTreeElement();
  LeafElement leaf = ASTFactory.leaf(tokenType, holder.getCharTable().intern(newText));
  holder.rawAddChildren(leaf);
  return (XmlToken)xmlToken.replace(leaf.getPsi());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:XmlTokenManipulator.java


示例15: createCDATAElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@SuppressWarnings({"HardCodedStringLiteral"})
public static FileElement createCDATAElement(final PsiManager manager, final CharTable charTableByTree, final String displayText) {
  final FileElement dummyParent = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
  final CompositeElement cdata = ASTFactory.composite(XmlElementType.XML_CDATA);
  dummyParent.rawAddChildren(cdata);
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_START, "<![CDATA["));
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, dummyParent.getCharTable().intern(displayText)));
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_END, "]]>"));
  dummyParent.acceptTree(new GeneratedMarkerVisitor());
  return dummyParent;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:CDATAOnAnyEncodedPolicy.java


示例16: createDisplayText

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@Override
@NotNull
public XmlText createDisplayText(@NotNull String s) throws IncorrectOperationException {
  final XmlTag tagFromText = createTagFromText("<a>" + XmlTagUtil.getCDATAQuote(s) + "</a>");
  final XmlText[] textElements = tagFromText.getValue().getTextElements();
  if (textElements.length == 0) return (XmlText)ASTFactory.composite(XmlElementType.XML_TEXT);
  return textElements[0];
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:XmlElementFactoryImpl.java


示例17: addParenthToReplacedChild

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType,
                                                    @NotNull TreeElement newChild,
                                                    @NotNull PsiManager manager) {
  CompositeElement parenthExpr = ASTFactory.composite(parenthType);

  TreeElement dummyExpr = (TreeElement)newChild.clone();
  final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild);
  new DummyHolder(manager, parenthExpr, null, charTableByTree);
  parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree);
  parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "("));
  parenthExpr.rawAddChildren(dummyExpr);
  parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")"));

  try {
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
    PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr));
    parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(formatted);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e); // should not happen
  }

  newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild));
  dummyExpr.rawReplaceWithList(newChild);

  newChild = parenthExpr;
  // TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification
  TreeUtil.clearCaches(TreeUtil.getFileElement(newChild));
  return newChild;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:31,代码来源:SourceUtil.java


示例18: createSingleLeafElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public static LeafElement createSingleLeafElement(IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
  DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
  dummyHolder.setOriginalFile(originalFile);

  FileElement holderElement = dummyHolder.getTreeElement();
  
  LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
    buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:13,代码来源:Factory.java


示例19: createCompositeElement

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
@NotNull
public static CompositeElement createCompositeElement(final IElementType type,
                                                      final CharTable charTableByTree,
                                                      final PsiManager manager) {
  final FileElement treeElement = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
  final CompositeElement composite = ASTFactory.composite(type);
  treeElement.rawAddChildren(composite);
  return composite;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:Factory.java


示例20: rawReplaceWithText

import com.intellij.lang.ASTFactory; //导入依赖的package包/类
public LeafElement rawReplaceWithText(String newText) {
  LeafElement newLeaf = ASTFactory.leaf(getElementType(), newText);
  copyUserDataTo(newLeaf);
  rawReplaceWithList(newLeaf);
  newLeaf.clearCaches();
  return newLeaf;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:8,代码来源:LeafElement.java



注:本文中的com.intellij.lang.ASTFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OuterLanguageElement类代码示例发布时间:2022-05-22
下一篇:
Java CircularImageView类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap