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

项目:AppleScript-IDEA    文件:AppleScriptSpacingProcessor.java   
private void _init(@Nullable final ASTNode child) {
  if (child == null) return;

  ASTNode treePrev = child.getTreePrev();
  while (treePrev != null && isWhiteSpace(treePrev)) {
    treePrev = treePrev.getTreePrev();
  }

  if (treePrev == null) {
    _init(child.getTreeParent());
  } else {
    myChild2 = child;
    myType2 = myChild2.getElementType();

    myChild1 = treePrev;
    myType1 = myChild1.getElementType();
    final CompositeElement parent = (CompositeElement) treePrev.getTreeParent();
    myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
  }
}
项目:intellij-ce-playground    文件:StubBasedPsiElementBase.java   
private String dumpCreationTraces(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();
}
项目:intellij-ce-playground    文件:ASTDelegatePsiElement.java   
@Override
public void delete() throws IncorrectOperationException {
  PsiElement parent = getParent();
  if (parent instanceof ASTDelegatePsiElement) {
    CheckUtil.checkWritable(this);
    ((ASTDelegatePsiElement)parent).deleteChildInternal(getNode());
  }
  else if (parent instanceof CompositeElement) {
    CheckUtil.checkWritable(this);
    ((CompositeElement)parent).deleteChildInternal(getNode());
  }
  else if (parent instanceof PsiFile) {
    CheckUtil.checkWritable(this);
    parent.deleteChildRange(this, this);
  }
  else {
    throw new UnsupportedOperationException(getClass().getName() + " under " + (parent == null ? "null" : parent.getClass().getName()));
  }
}
项目: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    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      @Override
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目: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    文件: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    文件:GroovySpacingProcessor.java   
private void _init(@Nullable final ASTNode child) {
  if (child == null) return;

  ASTNode treePrev = child.getTreePrev();
  while (treePrev != null && isWhiteSpace(treePrev)) {
    treePrev = treePrev.getTreePrev();
  }

  if (treePrev == null) {
    _init(child.getTreeParent());
  }
  else {
    myChild2 = child;
    myType2 = myChild2.getElementType();

    myChild1 = treePrev;
    myType1 = myChild1.getElementType();
    final CompositeElement parent = (CompositeElement)treePrev.getTreeParent();
    myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
  }
}
项目:tools-idea    文件:PsiImplUtil.java   
@Nullable
public static ASTNode skipWhitespaceAndCommentsBack(final ASTNode node) {
  if (node == null) return null;
  if (!isWhitespaceOrComment(node)) return node;

  ASTNode parent = node.getTreeParent();
  ASTNode prev = node;
  while (prev instanceof CompositeElement) {
    if (!isWhitespaceOrComment(prev)) return prev;
    prev = prev.getTreePrev();
  }
  if (prev == null) return null;
  ASTNode firstChildNode = parent.getFirstChildNode();
  ASTNode lastRelevant = null;
  while (firstChildNode != prev) {
    if (!isWhitespaceOrComment(firstChildNode)) lastRelevant = firstChildNode;
    firstChildNode = firstChildNode.getTreeNext();
  }
  return lastRelevant;
}
项目:tools-idea    文件:PsiImplUtil.java   
public static PsiStatement[] getChildStatements(CompositeElement psiCodeBlock) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  // no lock is needed because all chameleons are expanded already
  int count = 0;
  for (ASTNode child1 = psiCodeBlock.getFirstChildNode(); child1 != null; child1 = child1.getTreeNext()) {
    if (child1.getPsi() instanceof PsiStatement) {
      count++;
    }
  }

  PsiStatement[] result = PsiStatement.ARRAY_FACTORY.create(count);
  if (count == 0) return result;
  int idx = 0;
  for (ASTNode child = psiCodeBlock.getFirstChildNode(); child != null && idx < count; child = child.getTreeNext()) {
    if (child.getPsi() instanceof PsiStatement) {
      PsiStatement element = (PsiStatement)child.getPsi();
      LOG.assertTrue(element != null, child);
      result[idx++] = element;
    }
  }
  return result;
}
项目:tools-idea    文件:StubBasedPsiElementBase.java   
private String dumpCreationTraces(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.toString()).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();
}
项目:tools-idea    文件: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);

}
项目:tools-idea    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目:tools-idea    文件:GroovySpacingProcessor.java   
private void _init(@Nullable final ASTNode child) {
  if (child == null) return;

  ASTNode treePrev = child.getTreePrev();
  while (treePrev != null && isWhiteSpace(treePrev)) {
    treePrev = treePrev.getTreePrev();
  }

  if (treePrev == null) {
    _init(child.getTreeParent());
  }
  else {
    myChild2 = child;
    myType2 = myChild2.getElementType();

    myChild1 = treePrev;
    myType1 = myChild1.getElementType();
    final CompositeElement parent = (CompositeElement)treePrev.getTreeParent();
    myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
  }
}
项目:tools-idea    文件:GroovyChangeUtilSupport.java   
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;
}
项目:tools-idea    文件:GroovyChangeUtilSupport.java   
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);
          }
        }
      }
    }
  }
}
项目:buck    文件:BuckFoldingBuilder.java   
@Nullable
@Override
public String getPlaceholderText(@NotNull ASTNode astNode) {
  if (!(astNode instanceof CompositeElement)) {
    return null;
  }

  CompositeElement compositeElement = (CompositeElement) astNode;
  IElementType type = compositeElement.getElementType();

  if (type.equals(BuckTypes.VALUE_ARRAY)) {
    return getArrayPlaceholderText(compositeElement);
  } else if (type.equals(BuckTypes.RULE_BLOCK)) {
    return getRulePlaceholderText(compositeElement);
  } else {
    return null;
  }
}
项目:buck    文件:BuckFoldingBuilder.java   
private String getRulePlaceholderText(CompositeElement compositeElement) {
  PsiElement psiElement = compositeElement.getPsi();
  BuckRuleNameImpl buckRuleName = PsiTreeUtil.findChildOfType(psiElement, BuckRuleNameImpl.class);
  if (buckRuleName == null) {
    return null;
  }

  String name = null;
  Collection<BuckPropertyLvalueImpl> lvalues =
      PsiTreeUtil.findChildrenOfType(psiElement, BuckPropertyLvalueImpl.class);
  for (BuckPropertyLvalueImpl lvalue : lvalues) {
    if (lvalue.getText().equals("name")) {
      PsiElement element = lvalue;
      do {
        element = element.getNextSibling();
      } while (!(element instanceof BuckExpressionImpl));
      name = element.getText();
      break;
    }
  }

  return String.format(isNullOrEmpty(name) ? "%s" : "%s(%s)", buckRuleName.getText(), name);
}
项目: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);
  }
}
项目: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();
}
项目:consulo-xml    文件:XmlUtil.java   
public static void expandTag(@NotNull XmlTag tag)
{
    XmlTag newTag = XmlElementFactory.getInstance(tag.getProject()).createTagFromText('<' + tag.getName() + "></" + tag.getName() + '>');

    ASTNode node = tag.getNode();
    if(!(node instanceof CompositeElement))
    {
        return;
    }
    CompositeElement compositeElement = (CompositeElement) node;

    final LeafElement emptyTagEnd = (LeafElement) XmlChildRole.EMPTY_TAG_END_FINDER.findChild(compositeElement);
    if(emptyTagEnd == null)
    {
        return;
    }

    compositeElement.removeChild(emptyTagEnd);
    PsiElement[] children = newTag.getChildren();

    compositeElement.addChildren(children[2].getNode(), null, null);
}
项目:consulo-xml    文件:HtmlUtil.java   
private static boolean containsOuterLanguageElements(@NotNull PsiElement element)
{
    PsiElement child = element.getFirstChild();
    while(child != null)
    {
        if(child instanceof CompositeElement)
        {
            return containsOuterLanguageElements(child);
        }
        else if(child instanceof OuterLanguageElement)
        {
            return true;
        }
        child = child.getNextSibling();
    }
    return false;
}
项目:consulo-xml    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目:consulo-java    文件:PsiImportStaticReferenceElementImpl.java   
@Override
public PsiImportStaticStatement bindToTargetClass(final PsiClass aClass) throws IncorrectOperationException {
  final String qualifiedName = aClass.getQualifiedName();
  if (qualifiedName == null) throw new IncorrectOperationException();
  final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
  final CompositeElement newRef = (CompositeElement)parserFacade.createReferenceFromText(qualifiedName, null).getNode();
  if (getQualifier() != null) {
    replaceChildInternal(findChildByRole(ChildRole.QUALIFIER), newRef);
    return (PsiImportStaticStatement)getParent();
  }
  else {
    final LeafElement dot = Factory.createSingleLeafElement(JavaTokenType.DOT, ".", 0, 1, SharedImplUtil.findCharTableByTree(newRef), getManager());
    newRef.rawInsertAfterMe(dot);
    final CompositeElement errorElement = Factory.createErrorElement(JavaErrorMessages.message("import.statement.identifier.or.asterisk.expected."));
    dot.rawInsertAfterMe(errorElement);
    final CompositeElement parentComposite = (CompositeElement)SourceTreeToPsiMap.psiElementToTree(getParent());
    parentComposite.addInternal(newRef, errorElement, this, Boolean.TRUE);
    parentComposite.deleteChildInternal(this);
    return (PsiImportStaticStatement)SourceTreeToPsiMap.treeElementToPsi(parentComposite);
  }
}
项目:consulo-java    文件:PsiJavaCodeReferenceElementImpl.java   
private void diagnoseUnknownParent()
{
    CompositeElement parent = getTreeParent();
    IElementType i = parent.getElementType();
    String message = "Unknown parent for java code reference: '" + parent + "'; Type: " + i + ";\n";
    while(parent != null && parent.getPsi() instanceof PsiExpression)
    {
        parent = parent.getTreeParent();
        message += " Parent: '" + parent + "'; \n";
    }
    if(parent != null)
    {
        message += DebugUtil.treeToString(parent, false);
    }
    LOG.error(message);
}
项目:consulo-java    文件:PsiReferenceExpressionImpl.java   
@NotNull
@Override
public ResolveResult[] resolve(@NotNull PsiJavaReference ref, @NotNull PsiFile containingFile, boolean incompleteCode)
{
    PsiReferenceExpressionImpl expression = (PsiReferenceExpressionImpl) ref;
    CompositeElement treeParent = expression.getTreeParent();
    IElementType parentType = treeParent == null ? null : treeParent.getElementType();

    List<ResolveResult[]> qualifiers = resolveAllQualifiers(expression, containingFile);
    JavaResolveResult[] result = expression.resolve(parentType, containingFile);

    if(result.length == 0 && incompleteCode && parentType != JavaElementType.REFERENCE_EXPRESSION)
    {
        result = expression.resolve(JavaElementType.REFERENCE_EXPRESSION, containingFile);
    }

    JavaResolveUtil.substituteResults(expression, result);

    qualifiers.clear(); // hold qualifier target list until this moment to avoid psi elements inside to GC

    return result;
}
项目:consulo-java    文件:JavaStubPsiElement.java   
@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException
{
    CheckUtil.checkWritable(this);
    if(first == null)
    {
        LOG.assertTrue(last == null);
        return;
    }
    ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
    ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
    CompositeElement treeElement = calcTreeElement();
    LOG.assertTrue(firstElement.getTreeParent() == treeElement);
    LOG.assertTrue(lastElement.getTreeParent() == treeElement);
    CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
}
项目:consulo-java    文件:PsiFieldImpl.java   
private PsiField findFirstFieldByTree()
{
    CompositeElement treeElement = getNode();

    ASTNode modifierList = treeElement.findChildByRole(ChildRole.MODIFIER_LIST);
    if(modifierList == null)
    {
        ASTNode prevField = treeElement.getTreePrev();
        while(prevField != null && prevField.getElementType() != JavaElementType.FIELD)
        {
            prevField = prevField.getTreePrev();
        }
        if(prevField == null)
        {
            return this;
        }
        return ((PsiFieldImpl) SourceTreeToPsiMap.treeElementToPsi(prevField)).findFirstFieldInDeclaration();
    }
    else
    {
        return this;
    }
}
项目:consulo-java    文件:PsiFieldImpl.java   
@Override
public PsiDocComment getDocComment()
{
    final PsiFieldStub stub = getGreenStub();
    if(stub != null && !stub.hasDocComment())
    {
        return null;
    }

    CompositeElement treeElement = getNode();
    if(getTypeElement() != null)
    {
        PsiElement element = treeElement.findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
        return element instanceof PsiDocComment ? (PsiDocComment) element : null;
    }
    else
    {
        ASTNode prevField = treeElement.getTreePrev();
        while(prevField.getElementType() != JavaElementType.FIELD)
        {
            prevField = prevField.getTreePrev();
        }
        return ((PsiField) SourceTreeToPsiMap.treeElementToPsi(prevField)).getDocComment();
    }
}
项目:consulo-java    文件:PsiImplUtil.java   
@Nullable
public static ASTNode findDocComment(@NotNull CompositeElement element)
{
    TreeElement node = element.getFirstChildNode();
    while(node != null && (isWhitespaceOrComment(node) && !(node.getPsi() instanceof PsiDocComment)))
    {
        node = node.getTreeNext();
    }

    if(node != null && node.getElementType() == JavaDocElementType.DOC_COMMENT)
    {
        return node;
    }
    else
    {
        return null;
    }
}
项目:consulo-java    文件:JavaReferenceAdjuster.java   
private static void deQualifyImpl(@NotNull CompositeElement reference)
{
    ASTNode qualifier = reference.findChildByRole(ChildRole.QUALIFIER);
    if(qualifier != null)
    {
        ASTNode firstChildNode = qualifier.getFirstChildNode();
        boolean markToReformatBefore = firstChildNode instanceof TreeElement && CodeEditUtil
                .isMarkedToReformatBefore((TreeElement) firstChildNode);
        reference.deleteChildInternal(qualifier);
        if(markToReformatBefore)
        {
            firstChildNode = reference.getFirstChildNode();
            if(firstChildNode != null)
            {
                CodeEditUtil.markToReformatBefore(firstChildNode, true);
            }
        }
    }
}
项目:lua-for-idea    文件:LuaSpacingProcessor.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);
  }
}
项目:intellij-ce-playground    文件:PsiSwitchLabelStatementImpl.java   
@Override
public PsiSwitchStatement getEnclosingSwitchStatement() {
  final CompositeElement guessedSwitch = getTreeParent().getTreeParent();
  return guessedSwitch != null && guessedSwitch.getElementType() == SWITCH_STATEMENT
         ? (PsiSwitchStatement)SourceTreeToPsiMap.treeElementToPsi(guessedSwitch)
         : null;
}
项目:intellij-ce-playground    文件:PsiBreakStatementImpl.java   
@Override
public PsiStatement findExitedStatement() {
  PsiIdentifier label = getLabelIdentifier();
  if (label == null){
    for(ASTNode parent = getTreeParent(); parent != null; parent = parent.getTreeParent()){
      IElementType i = parent.getElementType();
      if (i == FOR_STATEMENT || i == WHILE_STATEMENT || i == DO_WHILE_STATEMENT || i == SWITCH_STATEMENT || i == FOREACH_STATEMENT) {
        return (PsiStatement)SourceTreeToPsiMap.treeElementToPsi(parent);
      }
      else if (i == METHOD || i == CLASS_INITIALIZER) {
        return null; // do not pass through anonymous/local class
      }
    }
  }
  else{
    String labelName = label.getText();
    for(CompositeElement parent = getTreeParent(); parent != null; parent = parent.getTreeParent()){
      if (parent.getElementType() == LABELED_STATEMENT){
        ASTNode statementLabel = parent.findChildByRole(ChildRole.LABEL_NAME);
        if (statementLabel.getText().equals(labelName)){
          return ((PsiLabeledStatement)SourceTreeToPsiMap.treeElementToPsi(parent)).getStatement();
        }
      }

      if (parent.getElementType() == METHOD || parent.getElementType() == CLASS_INITIALIZER || parent.getElementType() == LAMBDA_EXPRESSION) return null; // do not pass through anonymous/local class
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
public void delete() throws IncorrectOperationException {
  ASTNode treeElement = calcTreeElement();
  LOG.assertTrue(treeElement.getTreeParent() != null);
  CheckUtil.checkWritable(this);
  ((CompositeElement)treeElement.getTreeParent()).deleteChildInternal(treeElement);
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException {
  CheckUtil.checkWritable(this);
  if (first == null) {
    LOG.assertTrue(last == null);
    return;
  }
  ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
  ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
  CompositeElement treeElement = calcTreeElement();
  LOG.assertTrue(firstElement.getTreeParent() == treeElement);
  LOG.assertTrue(lastElement.getTreeParent() == treeElement);
  CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
}
项目:intellij-ce-playground    文件:JavaStubPsiElement.java   
@Override
protected Object clone() {
  CompositeElement treeElement = calcTreeElement();
  CompositeElement treeElementClone
    = (CompositeElement)(treeElement.getTreeParent() != null ? treeElement.copyElement() : (ASTNode)treeElement.clone());
  /*
  if (treeElementClone.getPsiElement() != null) {
    return treeElementClone.getPsiElement();
  }
  */
  return cloneImpl(treeElementClone);
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testCopyableUserDataChild() throws Exception {
  final PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
  assertNotNull(aClass);
  final PsiFile containingFile = aClass.getContainingFile();
  final CompositeElement element = ((PsiFileImpl)containingFile).calcTreeElement();
  aClass.putCopyableUserData(TEST_KEY, "TEST");
  final PsiJavaFile fileCopy = (PsiJavaFile)containingFile.copy();
  final PsiClass[] classesCopy = fileCopy.getClasses();
  assertEquals(1, classesCopy.length);
  assertNotNull(element);
  assertEquals("TEST", classesCopy[0].getCopyableUserData(TEST_KEY));
}
项目:intellij-ce-playground    文件:IElementTypeTest.java   
public void testManipulatorRegistered() {
  LanguageExtensionPoint[] extensions =
    Extensions.getExtensions(new ExtensionPointName<LanguageExtensionPoint>("com.intellij.lang.parserDefinition"));
  Set<String> classes = new HashSet<String>();
  List<String> failures = new ArrayList<String>();
  int total = 0;
  for (LanguageExtensionPoint e : extensions) {
    ParserDefinition definition = (ParserDefinition)e.getInstance();

    for (IElementType type : IElementType.enumerate(IElementType.TRUE)) {
      if (type instanceof ILeafElementType) continue;
      try {
        CompositeElement treeElement = ASTFactory.composite(type);
        total++;
        PsiElement element = treeElement instanceof PsiElement? (PsiElement)treeElement : definition.createElement(treeElement);
        if (element instanceof PsiLanguageInjectionHost && classes.add(element.getClass().getName())) {
          boolean ok = ElementManipulators.getManipulator(element) != null;
          System.out.println((ok ? "OK  " : "FAIL") + " " + element.getClass().getSimpleName() + " [" + definition.getClass().getSimpleName() + "]");
          if (!ok) failures.add(element.getClass().getName());
        }
      }
      catch (Throwable ignored) {
      }
    }
  }
  System.out.println("count: " + classes.size() + ", total: " + total);
  assertEmpty("PsiLanguageInjectionHost requires " + ElementManipulators.EP_NAME, failures);
}
项目:intellij-ce-playground    文件:ASTDelegatePsiElement.java   
@Override
@NotNull
public PsiElement[] getChildren() {
  PsiElement psiChild = getFirstChild();
  if (psiChild == null) return PsiElement.EMPTY_ARRAY;

  List<PsiElement> result = new ArrayList<PsiElement>();
  while (psiChild != null) {
    if (psiChild.getNode() instanceof CompositeElement) {
      result.add(psiChild);
    }
    psiChild = psiChild.getNextSibling();
  }
  return PsiUtilCore.toPsiElementArray(result);
}