Java 类com.intellij.psi.impl.source.tree.TreeElement 实例源码

项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final PsiJavaFile aFile = createDummyJavaFile(text);
  for (PsiElement aChildren : aFile.getChildren()) {
    if (aChildren instanceof PsiComment) {
      if (!aChildren.getText().equals(text)) {
        break;
      }
      final PsiComment comment = (PsiComment)aChildren;
      DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), context);
      return comment;
    }
  }

  throw new IncorrectOperationException("Incorrect comment '" + text + "'");
}
项目:intellij-ce-playground    文件:ClsMethodImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiMethod mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);

  setMirrorIfPresent(getDocComment(), mirror.getDocComment());
  setMirror(getModifierList(), mirror.getModifierList());
  setMirror(getTypeParameterList(), mirror.getTypeParameterList());
  if (!isConstructor()) {
    setMirror(getReturnTypeElement(), mirror.getReturnTypeElement());
  }
  setMirror(getNameIdentifier(), mirror.getNameIdentifier());
  setMirror(getParameterList(), mirror.getParameterList());
  setMirror(getThrowsList(), mirror.getThrowsList());

  PsiAnnotationMemberValue defaultValue = getDefaultValue();
  if (defaultValue != null) {
    assert mirror instanceof PsiAnnotationMethod : this;
    setMirror(defaultValue, ((PsiAnnotationMethod)mirror).getDefaultValue());
  }
}
项目:intellij-ce-playground    文件:ClsClassImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiClass mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);

  setMirrorIfPresent(getDocComment(), mirror.getDocComment());

  setMirror(getModifierList(), mirror.getModifierList());
  setMirror(getNameIdentifier(), mirror.getNameIdentifier());
  setMirror(getTypeParameterList(), mirror.getTypeParameterList());
  setMirror(getExtendsList(), mirror.getExtendsList());
  setMirror(getImplementsList(), mirror.getImplementsList());

  if (mirror instanceof PsiExtensibleClass) {
    PsiExtensibleClass extMirror = (PsiExtensibleClass)mirror;
    setMirrors(getOwnFields(), extMirror.getOwnFields());
    setMirrors(getOwnMethods(), extMirror.getOwnMethods());
    setMirrors(getOwnInnerClasses(), extMirror.getOwnInnerClasses());
  }
  else {
    setMirrors(getOwnFields(), mirror.getFields());
    setMirrors(getOwnMethods(), mirror.getMethods());
    setMirrors(getOwnInnerClasses(), mirror.getInnerClasses());
  }
}
项目:intellij-ce-playground    文件:GroovyChangeUtilSupport.java   
@Override
public TreeElement decodeInformation(TreeElement element, final Map<Object, Object> decodingState) {
  if (element instanceof CompositeElement) {
    if (element.getElementType() == GroovyElementTypes.REFERENCE_ELEMENT || element.getElementType() == GroovyElementTypes.REFERENCE_EXPRESSION) {
      GrReferenceElement ref = (GrReferenceElement)SourceTreeToPsiMap.treeElementToPsi(element);
      final PsiMember refMember = element.getCopyableUserData(REFERENCED_MEMBER_KEY);
      if (refMember != null) {
        element.putCopyableUserData(REFERENCED_MEMBER_KEY, null);
        PsiElement refElement1 = ref.resolve();
        if (!refMember.getManager().areElementsEquivalent(refMember, refElement1)) {
          try {
            if (!(refMember instanceof PsiClass) || ref.getQualifier() == null) {
              // can restore only if short (otherwise qualifier should be already restored)
              ref = (GrReferenceElement)ref.bindToElement(refMember);
            }
          }
          catch (IncorrectOperationException ignored) {
          }
          return (TreeElement)SourceTreeToPsiMap.psiElementToTree(ref);
        }
      }
      return element;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:PsiForStatementImpl.java   
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
  final boolean isForInitialization = getChildRole(child) == ChildRole.FOR_INITIALIZATION;

  if (isForInitialization) {
    try {
      final PsiStatement emptyStatement = JavaPsiFacade.getInstance(getProject()).getElementFactory().createStatementFromText(";", null);
      super.replaceChildInternal(child, (TreeElement)SourceTreeToPsiMap.psiElementToTree(emptyStatement));
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }
  else {
    super.deleteChildInternal(child);
  }
}
项目:intellij-ce-playground    文件:PropertiesFileImpl.java   
@Override
@NotNull
public PsiElement addPropertyAfter(@NotNull final IProperty property, @Nullable final IProperty anchor) throws IncorrectOperationException {
  final TreeElement copy = ChangeUtil.copyToElement(property.getPsiElement());
  List<IProperty> properties = getProperties();
  ASTNode anchorBefore = anchor == null ? properties.isEmpty() ? null : properties.get(0).getPsiElement().getNode()
                         : anchor.getPsiElement().getNode().getTreeNext();
  if (anchorBefore != null) {
    if (anchorBefore.getElementType() == TokenType.WHITE_SPACE) {
      anchorBefore = anchorBefore.getTreeNext();
    }
  }
  if (anchorBefore == null && haveToAddNewLine()) {
    insertLineBreakBefore(null);
  }
  getPropertiesList().addChild(copy, anchorBefore);
  if (anchorBefore != null) {
    insertLineBreakBefore(anchorBefore);
  }
  return copy.getPsi();
}
项目:intellij-ce-playground    文件:XmlDocumentImpl.java   
@Override
public TreeElement addInternal(final TreeElement first, final ASTNode last, final ASTNode anchor, final Boolean before) {
  final PomModel model = PomManager.getModel(getProject());
  final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
  final TreeElement[] holder = new TreeElement[1];
  try{
    model.runTransaction(new PomTransactionBase(this, aspect) {
      @Override
      public PomModelEvent runInner() {
        holder[0] = XmlDocumentImpl.super.addInternal(first, last, anchor, before);
        return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
      }
    });
  }
  catch(IncorrectOperationException ignored){}
  return holder[0];
}
项目:intellij-ce-playground    文件:DeclarationMover.java   
@Override
public void beforeMove(@NotNull final Editor editor, @NotNull final MoveInfo info, final boolean down) {
  super.beforeMove(editor, info, down);

  if (myEnumToInsertSemicolonAfter != null) {
    TreeElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", 0, 1, null, myEnumToInsertSemicolonAfter.getManager());

    try {
      PsiElement inserted = myEnumToInsertSemicolonAfter.getParent().addAfter(semicolon.getPsi(), myEnumToInsertSemicolonAfter);
      inserted = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(inserted);
      final LogicalPosition position = editor.offsetToLogicalPosition(inserted.getTextRange().getEndOffset());

      info.toMove2 = new LineRange(position.line + 1, position.line + 1);
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
    finally {
      myEnumToInsertSemicolonAfter = null;
    }
  }
}
项目:intellij-ce-playground    文件:PsiBuilderTest.java   
public void testMergeWhenEmptyElementAfterWhitespaceIsLastChild() throws Throwable {
  myBuilder = createBuilder(" foo bar");
  parseWhenEmptyElementAfterWhitespaceIsLastChild();
  final ASTNode tree = myBuilder.getTreeBuilt();
  new DummyHolder(getPsiManager(), (TreeElement)tree, null);

  myBuilder = createBuilder("  bar", tree);
  parseWhenEmptyElementAfterWhitespaceIsLastChild();
  DebugUtil.startPsiModification(null);
  try {
    myBuilder.getTreeBuilt();
    fail();
  }
  catch (BlockSupport.ReparsedSuccessfullyException e) {
    e.getDiffLog().performActualPsiChange(tree.getPsi().getContainingFile());
  }
  finally {
    DebugUtil.finishPsiModification();
  }

  assertEquals("  bar", tree.getText());
}
项目:intellij-ce-playground    文件:LowLevelSearchUtil.java   
private static TreeElement findNextLeafElementAt(ASTNode scopeNode, TreeElement last, int offset) {
  int offsetR = offset;
  if (last !=null) {
    offsetR -= last.getStartOffset() - scopeNode.getStartOffset() + last.getTextLength();
    while (offsetR >= 0) {
      TreeElement next = last.getTreeNext();
      if (next == null) {
        last = last.getTreeParent();
        continue;
      }
      int length = next.getTextLength();
      offsetR -= length;
      last = next;
    }
    scopeNode = last;
    offsetR += scopeNode.getTextLength();
  }
  return (LeafElement)scopeNode.findLeafElementAt(offsetR);
}
项目:intellij-ce-playground    文件:ChangeInfoImpl.java   
public void processElementaryChange(final ChangeInfo changeByChild, final ASTNode treeElement) {
  switch(changeByChild.getChangeType()){
    case ADD:
      myOldLength -= ((TreeElement)treeElement).getNotCachedLength();
      break;
    case REMOVED:
      myOldLength += changeByChild.getOldLength();
      break;
    case REPLACE:
      myOldLength -= ((TreeElement)treeElement).getNotCachedLength();
      myOldLength += changeByChild.getOldLength();
      break;
    case CONTENTS_CHANGED:
      myOldLength -= ((TreeElement)treeElement).getNotCachedLength();
      myOldLength += changeByChild.getOldLength();
      break;
  }
}
项目:intellij-ce-playground    文件:PomModelImpl.java   
@Nullable
private static PsiFile getContainingFileByTree(@NotNull final PsiElement changeScope) {
  // there could be pseudo physical trees (JSPX/JSP/etc.) which must not translate
  // any changes to document and not to fire any PSI events
  final PsiFile psiFile;
  final ASTNode node = changeScope.getNode();
  if (node == null) {
    psiFile = changeScope.getContainingFile();
  }
  else {
    final FileElement fileElement = TreeUtil.getFileElement((TreeElement)node);
    // assert fileElement != null : "Can't find file element for node: " + node;
    // Hack. the containing tree can be invalidated if updating supplementary trees like HTML in JSP.
    if (fileElement == null) return null;

    psiFile = (PsiFile)fileElement.getPsi();
  }
  return psiFile.getNode() != null ? psiFile : null;
}
项目:intellij-ce-playground    文件:DummyHolder.java   
public DummyHolder(@NotNull PsiManager manager, @Nullable TreeElement contentElement, @Nullable PsiElement context, @Nullable CharTable table, @Nullable Boolean validity, Language language) {
  super(TokenType.DUMMY_HOLDER, TokenType.DUMMY_HOLDER, new DummyHolderViewProvider(manager));
  myLanguage = language;
  ((DummyHolderViewProvider)getViewProvider()).setDummyHolder(this);
  myContext = context;
  myTable = table != null ? table : IdentityCharTable.INSTANCE;
  if (contentElement instanceof FileElement) {
    myFileElement = (FileElement)contentElement;
    myFileElement.setPsi(this);
    myFileElement.setCharTable(myTable);
  }
  else if (contentElement != null) {
    getTreeElement().rawAddChildren(contentElement);
    clearCaches();
  }
  myExplicitlyValid = validity;
}
项目:intellij-ce-playground    文件:DiffLog.java   
@Override
void doActualPsiChange(@NotNull PsiFile file, @NotNull ASTDiffBuilder astDiffBuilder) {
  ASTNode child = myOldNode;
  ASTNode parent = myOldParent;

  PsiElement psiParent = parent.getPsi();
  PsiElement psiChild = file.isPhysical() ? child.getPsi() : null;

  if (psiParent != null && psiChild != null) {
    PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(file.getManager());
    event.setParent(psiParent);
    event.setChild(psiChild);
    event.setFile(file);
    ((PsiManagerEx)file.getManager()).beforeChildRemoval(event);
  }

  astDiffBuilder.nodeDeleted(parent, child);

  ((TreeElement)child).rawRemove();
  ((CompositeElement)parent).subtreeChanged();

  DebugUtil.checkTreeStructure(parent);
}
项目:intellij-ce-playground    文件:CodeEditUtil.java   
private static void markToReformatBeforeOrInsertWhitespace(final ASTNode left, @NotNull final ASTNode right) {
  final Language leftLang = left != null ? PsiUtilCore.getNotAnyLanguage(left) : null;
  final Language rightLang = PsiUtilCore.getNotAnyLanguage(right);

  ASTNode generatedWhitespace = null;
  if (leftLang != null && leftLang.isKindOf(rightLang)) {
    generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(leftLang).generateWhitespaceBetweenTokens(left, right);
  }
  else if (rightLang.isKindOf(leftLang)) {
    generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(rightLang).generateWhitespaceBetweenTokens(left, right);
  }

  if (generatedWhitespace != null) {
    final TreeUtil.CommonParentState parentState = new TreeUtil.CommonParentState();
    TreeUtil.prevLeaf((TreeElement)right, parentState);
    parentState.nextLeafBranchStart.getTreeParent().addChild(generatedWhitespace, parentState.nextLeafBranchStart);
  }
  else {
    markToReformatBefore(right, true);
  }
}
项目:intellij-ce-playground    文件:GroovyChangeUtilSupport.java   
@Override
public void encodeInformation(final TreeElement element, final ASTNode original, final Map<Object, Object> encodingState) {
  if (original instanceof CompositeElement) {
    if (original.getElementType() == GroovyElementTypes.REFERENCE_ELEMENT ||
        original.getElementType() == GroovyElementTypes.REFERENCE_EXPRESSION) {
      PsiElement psi = original.getPsi();
      if (!PsiUtil.isThisOrSuperRef(psi)) {
        final GroovyResolveResult result = ((GrReferenceElement)psi).advancedResolve();
        if (result != null) {
          final PsiElement target = result.getElement();

          if (target instanceof PsiClass ||
              (target instanceof PsiMethod || target instanceof PsiField) &&
              ((PsiMember)target).hasModifierProperty(PsiModifier.STATIC) &&
              result.getCurrentFileResolveContext() instanceof GrImportStatement) {
            element.putCopyableUserData(REFERENCED_MEMBER_KEY, (PsiMember)target);
          }
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:PsiFileFactoryImpl.java   
@Nullable
public PsiElement createElementFromText(@Nullable final String text,
                                        @NotNull final Language language,
                                        @NotNull final IElementType type,
                                        @Nullable final PsiElement context) {
  if (text == null) return null;
  final DummyHolder result = DummyHolderFactory.createHolder(myManager, language, context);
  final FileElement holder = result.getTreeElement();

  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
  if (parserDefinition == null) {
    throw new AssertionError("No parser definition for " + language);
  }
  final Project project = myManager.getProject();
  final Lexer lexer = parserDefinition.createLexer(project);
  final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
  final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
  holder.rawAddChildren((TreeElement)node);
  markGenerated(result);
  return node.getPsi();
}
项目:intellij-ce-playground    文件:UnwrapHandler.java   
private void restoreCaretPosition(final PsiFile file) {
  ((TreeElement)file.getNode()).acceptTree(new RecursiveTreeElementWalkingVisitor() {
    @Override
    protected void visitNode(TreeElement element) {
      PsiElement el = element.getPsi();
      Integer offset = el.getCopyableUserData(CARET_POS_KEY);

      // continue;
      if (offset != null) {
        myEditor.getCaretModel().moveToOffset(el.getTextOffset() + offset);
        el.putCopyableUserData(CARET_POS_KEY, null);
        return;
      }
      super.visitNode(element);
    }
  });
}
项目:intellij-ce-playground    文件:XmlElementImpl.java   
public XmlElement findElementByTokenType(final IElementType type){
  final XmlElement[] result = new XmlElement[1];
  result[0] = null;

  processElements(new PsiElementProcessor(){
    @Override
    public boolean execute(@NotNull PsiElement element){
      if(element instanceof TreeElement && ((ASTNode)element).getElementType() == type){
        result[0] = (XmlElement)element;
        return false;
      }
      return true;
    }
  }, this);

  return result[0];
}
项目:intellij-ce-playground    文件:ClsFileImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  PsiElement mirrorElement = SourceTreeToPsiMap.treeToPsiNotNull(element);
  if (!(mirrorElement instanceof PsiJavaFile)) {
    throw new InvalidMirrorException("Unexpected mirror file: " + mirrorElement);
  }

  PsiJavaFile mirrorFile = (PsiJavaFile)mirrorElement;
  setMirrorIfPresent(getPackageStatement(), mirrorFile.getPackageStatement());
  setMirrors(getClasses(), mirrorFile.getClasses());
}
项目:intellij-ce-playground    文件:ClsAnnotationImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);
  PsiAnnotation mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
  setMirror(getNameReferenceElement(), mirror.getNameReferenceElement());
  setMirror(getParameterList(), mirror.getParameterList());
}
项目:intellij-ce-playground    文件:ClsNameValuePairImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiNameValuePair mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
  setMirrorIfPresent(getNameIdentifier(), mirror.getNameIdentifier());
  setMirrorIfPresent(getValue(), mirror.getValue());
}
项目:intellij-ce-playground    文件:ClsElementImpl.java   
protected void setMirrorCheckingType(@NotNull TreeElement element, @Nullable IElementType type) throws InvalidMirrorException {
  // uncomment for extended consistency check
  //if (myMirror != null) {
  //  throw new InvalidMirrorException("Mirror should be null: " + myMirror);
  //}

  if (type != null && element.getElementType() != type) {
    throw new InvalidMirrorException(element.getElementType() + " != " + type);
  }

  element.getPsi().putUserData(COMPILED_ELEMENT, this);
  myMirror = element;
}
项目:intellij-ce-playground    文件:TagNameReference.java   
@Override
public TextRange getRangeInElement() {
  final ASTNode nameElement = getNameElement();
  if (nameElement == null){
    return TextRange.EMPTY_RANGE;
  }

  int colon = nameElement.getText().indexOf(':') + 1;
  if (myStartTagFlag) {
    final int parentOffset = ((TreeElement)nameElement).getStartOffsetInParent();
    return new TextRange(parentOffset + colon, parentOffset + nameElement.getTextLength());
  }
  else {
    final PsiElement element = getElement();
    if (element == myNameElement) return new TextRange(colon, myNameElement.getTextLength());

    final int elementLength = element.getTextLength();
    int diffFromEnd = 0;

    for(ASTNode node = element.getNode().getLastChildNode(); node != nameElement && node != null; node = node.getTreePrev()) {
      diffFromEnd += node.getTextLength();
    }

    final int nameEnd = elementLength - diffFromEnd;
    return new TextRange(nameEnd - nameElement.getTextLength() + colon, nameEnd);
  }
}
项目:intellij-ce-playground    文件:ClsAnnotationValueImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiAnnotation mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
  setMirror(getNameReferenceElement(), mirror.getNameReferenceElement());
  setMirror(getParameterList(), mirror.getParameterList());
}
项目:intellij-ce-playground    文件:ClsFieldImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiField mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
  setMirrorIfPresent(getDocComment(), mirror.getDocComment());
  setMirror(getModifierList(), mirror.getModifierList());
  setMirror(getTypeElement(), mirror.getTypeElement());
  setMirror(getNameIdentifier(), mirror.getNameIdentifier());
}
项目:intellij-ce-playground    文件:ClsParameterImpl.java   
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
  setMirrorCheckingType(element, null);

  PsiParameter mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
  setMirror(getModifierList(), mirror.getModifierList());
  setMirror(getTypeElement(), mirror.getTypeElement());
}
项目:intellij-ce-playground    文件:JavaFileElement.java   
@Override
public void replaceChildInternal(@NotNull ASTNode child, @NotNull TreeElement newElement) {
  if (newElement.getElementType() == JavaElementType.IMPORT_LIST) {
    LOG.assertTrue(child.getElementType() == JavaElementType.IMPORT_LIST);
    if (newElement.getFirstChildNode() == null) { //empty import list
      ASTNode next = child.getTreeNext();
      if (next != null && next.getElementType() == TokenType.WHITE_SPACE) {
        removeChild(next);
      }
    }
  }
  super.replaceChildInternal(child, newElement);
}
项目:intellij-ce-playground    文件:ImportListElement.java   
@Override
public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before){
  if (before == null){
    if (first == last && (first.getElementType() == JavaElementType.IMPORT_STATEMENT || first.getElementType() == JavaElementType.IMPORT_STATIC_STATEMENT)){
      final PsiImportList list = (PsiImportList)SourceTreeToPsiMap.treeElementToPsi(this);
      final PsiImportStatementBase statement = (PsiImportStatementBase)SourceTreeToPsiMap.treeElementToPsi(first);
      final JavaPsiImplementationHelper instance = JavaPsiImplementationHelper.getInstance(list.getProject());
      if (instance != null) {
        anchor = instance.getDefaultImportAnchor(list, statement);
      }
      before = Boolean.TRUE;
    }
  }
  return super.addInternal(first, last, anchor, before);
}
项目:intellij-ce-playground    文件:PsiTypeElementImpl.java   
@Override
public PsiJavaCodeReferenceElement getInnermostComponentReferenceElement() {
  TreeElement firstChildNode = getFirstChildNode();
  if (firstChildNode == null) return null;
  if (firstChildNode.getElementType() == JavaElementType.TYPE) {
    return SourceTreeToPsiMap.<PsiTypeElement>treeToPsiNotNull(firstChildNode).getInnermostComponentReferenceElement();
  }
  else {
    return getReferenceElement();
  }
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
  CheckUtil.checkWritable(this);
  TreeElement elementCopy = ChangeUtil.copyToElement(element);
  calcTreeElement().addInternal(elementCopy, elementCopy, null, null);
  elementCopy = ChangeUtil.decodeInformation(elementCopy);
  return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
  CheckUtil.checkWritable(this);
  TreeElement elementCopy = ChangeUtil.copyToElement(element);
  calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.TRUE);
  elementCopy = ChangeUtil.decodeInformation(elementCopy);
  return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
public PsiElement addAfter(@NotNull PsiElement element, @Nullable PsiElement anchor) throws IncorrectOperationException {
  CheckUtil.checkWritable(this);
  TreeElement elementCopy = ChangeUtil.copyToElement(element);
  calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE);
  elementCopy = ChangeUtil.decodeInformation(elementCopy);
  return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
项目:intellij-ce-playground    文件:DaemonAnalyzerTestCase.java   
@NotNull
protected Collection<HighlightInfo> checkHighlighting(@NotNull final ExpectedHighlightingData data) {
  data.init();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  //to load text
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      TreeUtil.clearCaches((TreeElement)myFile.getNode());
    }
  });


  //to initialize caches
  if (!DumbService.isDumb(getProject())) {
    CacheManager.SERVICE.getInstance(myProject).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true);
  }
  final JavaPsiFacadeEx facade = getJavaFacade();
  if (facade != null) {
    facade.setAssertOnFileLoadingFilter(myVirtualFileFilter, myTestRootDisposable); // check repository work
  }

  try {
    Collection<HighlightInfo> infos = doHighlighting();

    String text = myEditor.getDocument().getText();
    data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text);
    data.checkResult(infos, text);
    return infos;
  }
  finally {
    if (facade != null) {
      facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
    }
  }
}
项目:intellij-ce-playground    文件:JavaFormattingModelBuilder.java   
@Override
@NotNull
  public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
  final FileElement fileElement = TreeUtil.getFileElement((TreeElement)SourceTreeToPsiMap.psiElementToTree(element));
  LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
  CommonCodeStyleSettings commonSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
  JavaCodeStyleSettings customJavaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
  Block block = AbstractJavaBlock.newJavaBlock(fileElement, commonSettings, customJavaSettings);
  FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
  return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), block, model);
}
项目:intellij-ce-playground    文件:LowLevelSearchUtil.java   
public static boolean processElementsContainingWordInElement(@NotNull final TextOccurenceProcessor processor,
                                                             @NotNull final PsiElement scope,
                                                             @NotNull final StringSearcher searcher,
                                                             final boolean processInjectedPsi,
                                                             final ProgressIndicator progress) {
  if (progress != null) progress.checkCanceled();

  PsiFile file = scope.getContainingFile();
  FileViewProvider viewProvider = file.getViewProvider();
  final CharSequence buffer = viewProvider.getContents();

  TextRange range = scope.getTextRange();
  if (range == null) {
    LOG.error("Element " + scope + " of class " + scope.getClass() + " has null range");
    return true;
  }

  final int scopeStart = range.getStartOffset();
  final int startOffset = scopeStart;
  int endOffset = range.getEndOffset();
  if (endOffset > buffer.length()) {
    diagnoseInvalidRange(scope, file, viewProvider, buffer, range);
    return true;
  }

  final Project project = file.getProject();
  final TreeElement[] lastElement = {null};
  return processTextOccurrences(buffer, startOffset, endOffset, searcher, progress, new TIntProcedure() {
    @Override
    public boolean execute(int offset) {
      if (progress != null) progress.checkCanceled();
      lastElement[0] = processTreeUp(project, processor, scope, searcher, offset - scopeStart, processInjectedPsi, progress,
                                     lastElement[0]);
      return lastElement[0] != null;
    }
  });
}
项目:intellij-ce-playground    文件:TreeChangeImpl.java   
@Override
@NotNull
public TreeElement[] getAffectedChildren() {
  final TreeElement[] treeElements = new TreeElement[myChanges.size()];
  int index = 0;
  for (final Pair<ASTNode, Integer> pair : mySortedChanges) {
    treeElements[index++] = (TreeElement)pair.getFirst();
  }
  return treeElements;
}
项目:intellij-ce-playground    文件:AbstractXmlBlock.java   
@Nullable
protected static ASTNode findChildAfter(@NotNull final ASTNode child, final int endOffset) {
  TreeElement fileNode = TreeUtil.getFileElement((TreeElement)child);
  final LeafElement leaf = fileNode.findLeafElementAt(endOffset);
  if (leaf != null && leaf.getStartOffset() == endOffset && endOffset > 0) {
    return fileNode.findLeafElementAt(endOffset - 1);
  }
  return leaf;
}
项目:intellij-ce-playground    文件:ASTDelegatePsiElement.java   
private PsiElement addInnerBefore(final PsiElement element, final PsiElement anchor) throws IncorrectOperationException {
  CheckUtil.checkWritable(this);
  TreeElement elementCopy = ChangeUtil.copyToElement(element);
  ASTNode treeElement = addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.TRUE);
  if (treeElement != null) {
    if (treeElement instanceof TreeElement) {
      return ChangeUtil.decodeInformation((TreeElement) treeElement).getPsi();
    }
    return treeElement.getPsi();
  }
  throw new IncorrectOperationException("Element cannot be added");
}
项目:intellij-ce-playground    文件:XmlDocumentImpl.java   
@Override
public void replaceChildInternal(@NotNull final ASTNode child, @NotNull final TreeElement newElement) {
  final PomModel model = PomManager.getModel(getProject());
  final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
  try{
    model.runTransaction(new PomTransactionBase(this, aspect) {
      @Override
      public PomModelEvent runInner() {
        XmlDocumentImpl.super.replaceChildInternal(child, newElement);
        return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
      }
    });
  }
  catch(IncorrectOperationException ignored){}
}