Java 类com.intellij.lang.LighterASTNode 实例源码

项目:intellij-ce-playground    文件:JavaNameValuePairType.java   
@Override
public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  String name = null;
  String value = null;
  List<LighterASTNode> children = tree.getChildren(node);
  for (LighterASTNode child : children) {
    if (child.getTokenType() == JavaTokenType.IDENTIFIER) {
      name = RecordUtil.intern(tree.getCharTable(), child);
    }
    else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) {
      value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0));
      value = StringUtil.unquoteString(value);
    }
  }
  return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value));
}
项目:intellij-ce-playground    文件:JavaImportStatementElementType.java   
@Override
public PsiImportStatementStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  boolean isOnDemand = false;
  String refText = null;

  for (LighterASTNode child : tree.getChildren(node)) {
    IElementType type = child.getTokenType();
    if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) {
      refText = JavaSourceUtil.getReferenceText(tree, child);
    }
    else if (type == JavaTokenType.ASTERISK) {
      isOnDemand = true;
    }
  }

  byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT);
  return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
项目:intellij-ce-playground    文件:RecordUtil.java   
public static boolean isDeprecatedByAnnotation(@NotNull LighterAST tree, @NotNull LighterASTNode modList) {
  for (final LighterASTNode child : tree.getChildren(modList)) {
    if (child.getTokenType() == JavaElementType.ANNOTATION) {
      final LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, child, JavaElementType.JAVA_CODE_REFERENCE);
      if (ref != null) {
        final LighterASTNode id = LightTreeUtil.firstChildOfType(tree, ref, JavaTokenType.IDENTIFIER);
        if (id != null) {
          final String name = intern(tree.getCharTable(), id);
          if (DEPRECATED_ANNOTATION_NAME.equals(name)) return true;
        }
      }
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaLightStubBuilder.java   
@NotNull
@Override
protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree) {
  if (!(file instanceof PsiJavaFile)) {
    return super.createStubForFile(file, tree);
  }

  String refText = "";
  LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT);
  if (pkg != null) {
    LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
    if (ref != null) {
      refText = JavaSourceUtil.getReferenceText(tree, ref);
    }
  }
  return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false);
}
项目:intellij-ce-playground    文件:LightTreeUtil.java   
public static void toBuffer(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StringBuilder buffer, @Nullable TokenSet skipTypes) {
  if (skipTypes != null && skipTypes.contains(node.getTokenType())) {
    return;
  }

  if (node instanceof LighterASTTokenNode) {
    buffer.append(((LighterASTTokenNode)node).getText());
    return;
  }

  if (node instanceof LighterLazyParseableNode) {
    buffer.append(((LighterLazyParseableNode)node).getText());
    return;
  }

  List<LighterASTNode> children = tree.getChildren(node);
  for (int i = 0, size = children.size(); i < size; ++i) {
    toBuffer(tree, children.get(i), buffer, skipTypes);
  }
  tree.disposeChildren(children);
}
项目:intellij-ce-playground    文件:RecursiveLighterASTNodeWalkingVisitor.java   
@Override
public IndexedLighterASTNode getFirstChild(@NotNull IndexedLighterASTNode element) {
  List<LighterASTNode> children = ast.getChildren(element.node);
  IndexedLighterASTNode[] indexedChildren = children.isEmpty() ? IndexedLighterASTNode.EMPTY_ARRAY : new IndexedLighterASTNode[children.size()];
  for (int i = 0; i < children.size(); i++) {
    LighterASTNode child = children.get(i);
    IndexedLighterASTNode indexedNode = new IndexedLighterASTNode(child, i == 0 ? null : indexedChildren[i - 1]);
    indexedChildren[i] = indexedNode;
    if (i != 0) {
      indexedChildren[i-1].next = indexedNode;
    }
  }
  childrenStack.push(indexedChildren);
  parentStack.push(element);
  return children.isEmpty() ? null : indexedChildren[0];
}
项目:tools-idea    文件:JavaNameValuePairType.java   
@Override
public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  String name = null;
  String value = null;
  List<LighterASTNode> children = tree.getChildren(node);
  for (LighterASTNode child : children) {
    if (child.getTokenType() == JavaTokenType.IDENTIFIER) {
      name = RecordUtil.intern(tree.getCharTable(), child);
    }
    else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) {
      value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0));
      value = StringUtil.stripQuotesAroundValue(value);
    }
  }
  return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value));
}
项目:tools-idea    文件:JavaImportStatementElementType.java   
@Override
public PsiImportStatementStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  boolean isOnDemand = false;
  String refText = null;

  for (LighterASTNode child : tree.getChildren(node)) {
    IElementType type = child.getTokenType();
    if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) {
      refText = SourceUtil.getReferenceText(tree, child);
    }
    else if (type == JavaTokenType.ASTERISK) {
      isOnDemand = true;
    }
  }

  byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT);
  return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
项目:tools-idea    文件:RecordUtil.java   
public static boolean isDeprecatedByAnnotation(@NotNull LighterAST tree, @NotNull LighterASTNode modList) {
  for (final LighterASTNode child : tree.getChildren(modList)) {
    if (child.getTokenType() == JavaElementType.ANNOTATION) {
      final LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, child, JavaElementType.JAVA_CODE_REFERENCE);
      if (ref != null) {
        final LighterASTNode id = LightTreeUtil.firstChildOfType(tree, ref, JavaTokenType.IDENTIFIER);
        if (id != null) {
          final String name = intern(tree.getCharTable(), id);
          if (DEPRECATED_ANNOTATION_NAME.equals(name)) return true;
        }
      }
    }
  }

  return false;
}
项目:tools-idea    文件:JavaLightStubBuilder.java   
@NotNull
@Override
protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree) {
  if (!(file instanceof PsiJavaFile)) {
    return super.createStubForFile(file, tree);
  }

  String refText = "";
  LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT);
  if (pkg != null) {
    LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
    if (ref != null) {
      refText = SourceUtil.getReferenceText(tree, ref);
    }
  }
  return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false);
}
项目:tools-idea    文件:LightTreeUtil.java   
public static void toBuffer(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StringBuilder buffer, @Nullable TokenSet skipTypes) {
  if (skipTypes != null && skipTypes.contains(node.getTokenType())) return;

  if (node instanceof LighterASTTokenNode) {
    buffer.append(((LighterASTTokenNode)node).getText());
    return;
  }

  if (node instanceof LighterLazyParseableNode) {
    buffer.append(((LighterLazyParseableNode)node).getText());
    return;
  }

  List<LighterASTNode> children = tree.getChildren(node);
  for (int i = 0, size = children.size(); i < size; ++i) {
    toBuffer(tree, children.get(i), buffer, skipTypes);
  }
}
项目:DeftIDEA    文件:DylanParser.java   
public static boolean definition_macro_call(PsiBuilder builder_, int level_) {
  if (!recursion_guard_(builder_, level_, "definition_macro_call")) return false;
  if (!nextTokenIs(builder_, DEFINE)) return false;
  boolean result_ = false;
  int start_ = builder_.getCurrentOffset();
  Marker marker_ = builder_.mark();
  result_ = definition_macro_call_0(builder_, level_ + 1);
  if (!result_) result_ = definition_macro_call_1(builder_, level_ + 1);
  LighterASTNode last_ = result_? builder_.getLatestDoneMarker() : null;
  if (last_ != null && last_.getStartOffset() == start_ && type_extends_(last_.getTokenType(), DEFINITION_MACRO_CALL)) {
    marker_.drop();
  }
  else if (result_) {
    marker_.done(DEFINITION_MACRO_CALL);
  }
  else {
    marker_.rollbackTo();
  }
  return result_;
}
项目:consulo-java    文件:JavaNullMethodArgumentIndex.java   
@Nullable
private static IntArrayList getNullParameterIndices(LighterAST lighterAst, @NotNull LighterASTNode methodCall)
{
    final LighterASTNode node = LightTreeUtil.firstChildOfType(lighterAst, methodCall, EXPRESSION_LIST);
    if(node == null)
    {
        return null;
    }
    final List<LighterASTNode> parameters = JavaLightTreeUtil.getExpressionChildren(lighterAst, node);
    IntArrayList indices = new IntArrayList(1);
    for(int idx = 0; idx < parameters.size(); idx++)
    {
        if(isNullLiteral(lighterAst, parameters.get(idx)))
        {
            indices.add(idx);
        }
    }
    return indices;
}
项目:DeftIDEA    文件:DylanParser.java   
public static boolean suite_component(PsiBuilder builder_, int level_) {
  if (!recursion_guard_(builder_, level_, "suite_component")) return false;
  if (!nextTokenIs(builder_, SUITE) && !nextTokenIs(builder_, TEST)
      && replaceVariants(builder_, 2, "<suite component>")) return false;
  boolean result_ = false;
  int start_ = builder_.getCurrentOffset();
  Marker marker_ = builder_.mark();
  enterErrorRecordingSection(builder_, level_, _SECTION_GENERAL_, "<suite component>");
  result_ = test_suite_component(builder_, level_ + 1);
  if (!result_) result_ = suite_suite_component(builder_, level_ + 1);
  LighterASTNode last_ = result_? builder_.getLatestDoneMarker() : null;
  if (last_ != null && last_.getStartOffset() == start_ && type_extends_(last_.getTokenType(), SUITE_COMPONENT)) {
    marker_.drop();
  }
  else if (result_) {
    marker_.done(SUITE_COMPONENT);
  }
  else {
    marker_.rollbackTo();
  }
  result_ = exitErrorRecordingSection(builder_, level_, result_, false, _SECTION_GENERAL_, null);
  return result_;
}
项目:consulo    文件:LightTreeUtil.java   
public static void toBuffer(@Nonnull LighterAST tree, @Nonnull LighterASTNode node, @Nonnull StringBuilder buffer, @Nullable TokenSet skipTypes) {
  if (skipTypes != null && skipTypes.contains(node.getTokenType())) {
    return;
  }

  if (node instanceof LighterASTTokenNode) {
    buffer.append(((LighterASTTokenNode)node).getText());
    return;
  }

  if (node instanceof LighterLazyParseableNode) {
    buffer.append(((LighterLazyParseableNode)node).getText());
    return;
  }

  List<LighterASTNode> children = tree.getChildren(node);
  for (int i = 0, size = children.size(); i < size; ++i) {
    toBuffer(tree, children.get(i), buffer, skipTypes);
  }
}
项目:consulo    文件:RecursiveLighterASTNodeWalkingVisitor.java   
@Override
public IndexedLighterASTNode getFirstChild(@Nonnull IndexedLighterASTNode element) {
  List<LighterASTNode> children = ast.getChildren(element.node);
  IndexedLighterASTNode[] indexedChildren = children.isEmpty() ? IndexedLighterASTNode.EMPTY_ARRAY : new IndexedLighterASTNode[children.size()];
  for (int i = 0; i < children.size(); i++) {
    LighterASTNode child = children.get(i);
    IndexedLighterASTNode indexedNode = new IndexedLighterASTNode(child, i == 0 ? null : indexedChildren[i - 1]);
    indexedChildren[i] = indexedNode;
    if (i != 0) {
      indexedChildren[i-1].next = indexedNode;
    }
  }
  childrenStack.push(indexedChildren);
  parentStack.push(element);
  return children.isEmpty() ? null : indexedChildren[0];
}
项目:consulo-java    文件:ContractInferenceIndexKt.java   
@Nullable
private static MethodData calcData(LighterAST tree, LighterASTNode method)
{
    LighterASTNode body = LightTreeUtil.firstChildOfType(tree, method, JavaElementType.CODE_BLOCK);
    if(body == null)
    {
        return null;
    }
    List<LighterASTNode> statements = ContractInferenceInterpreter.getStatements(body, tree);
    List<PreContract> contracts = new ContractInferenceInterpreter(tree, method, body).inferContracts(statements);
    NullityInference.NullityInferenceVisitor nullityVisitor = new NullityInference.NullityInferenceVisitor(tree, body);
    PurityInference.PurityInferenceVisitor purityVisitor = new PurityInference.PurityInferenceVisitor(tree, body);

    for(LighterASTNode statement : statements)
    {
        walkMethodBody(tree, statement, it ->
        {
            nullityVisitor.visitNode(it);
            purityVisitor.visitNode(it);
        });
    }
    return createData(body, contracts, nullityVisitor.getResult(), purityVisitor.getResult());
}
项目:consulo-xml    文件:XmlParser.java   
@Override
public ThreeState fun(ASTNode oldNode,
                      LighterASTNode newNode,
                      FlyweightCapableTreeStructure<LighterASTNode> structure) {
  if (oldNode instanceof XmlTag && newNode.getTokenType() == XmlElementType.XML_TAG) {
    String oldName = ((XmlTag)oldNode).getName();
    Ref<LighterASTNode[]> childrenRef = Ref.create(null);
    int count = structure.getChildren(newNode, childrenRef);
    if (count < 3) return ThreeState.UNSURE;
    LighterASTNode[] children = childrenRef.get();
    if (children[0].getTokenType() != XmlTokenType.XML_START_TAG_START) return ThreeState.UNSURE;
    if (children[1].getTokenType() != XmlTokenType.XML_NAME) return ThreeState.UNSURE;
    if (children[2].getTokenType() != XmlTokenType.XML_TAG_END) return ThreeState.UNSURE;
    LighterASTTokenNode name = (LighterASTTokenNode)children[1];
    CharSequence newName = name.getText();
    if (!oldName.equals(newName)) return ThreeState.NO;
  }

  return ThreeState.UNSURE;
}
项目:consulo-xml    文件:XmlBuilderDriver.java   
public void build(XmlBuilder builder) {
  PsiBuilder b = createBuilderAndParse();

  FlyweightCapableTreeStructure<LighterASTNode> structure = b.getLightTree();

  LighterASTNode root = structure.getRoot();
  root = structure.prepareForGetChildren(root);

  final Ref<LighterASTNode[]> childrenRef = Ref.create(null);
  final int count = structure.getChildren(root, childrenRef);
  LighterASTNode[] children = childrenRef.get();

  for (int i = 0; i < count; i++) {
    LighterASTNode child = children[i];
    final IElementType tt = child.getTokenType();
    if (tt == XmlElementType.XML_TAG || tt == XmlElementType.HTML_TAG) {
      processTagNode(b, structure, child, builder);
    }
    else if (tt == XmlElementType.XML_PROLOG) {
      processPrologNode(b, builder, structure, child);
    }
  }

  structure.disposeChildren(children, count);
}
项目:consulo-xml    文件:XmlBuilderDriver.java   
private void processPrologNode(PsiBuilder psiBuilder,
                               XmlBuilder builder,
                               FlyweightCapableTreeStructure<LighterASTNode> structure,
                               LighterASTNode prolog) {
  final Ref<LighterASTNode[]> prologChildren = new Ref<LighterASTNode[]>(null);
  final int prologChildrenCount = structure.getChildren(structure.prepareForGetChildren(prolog), prologChildren);
  for (int i = 0; i < prologChildrenCount; i++) {
    LighterASTNode node = prologChildren.get()[i];
    IElementType type = node.getTokenType();
    if (type == XmlElementType.XML_DOCTYPE) {
      processDoctypeNode(builder, structure, node);
      break;
    }
    if (type == TokenType.ERROR_ELEMENT) {
      processErrorNode(psiBuilder, node, builder);
    }
  }
}
项目:consulo-java    文件:ContractInferenceIndexKt.java   
private static void walkMethodBody(LighterAST tree, LighterASTNode root, Consumer<LighterASTNode> processor)
{
    new RecursiveLighterASTNodeWalkingVisitor(tree)
    {
        @Override
        public void visitNode(@NotNull LighterASTNode element)
        {
            IElementType type = element.getTokenType();
            if(type == JavaElementType.CLASS || type == JavaElementType.FIELD || type == JavaElementType.METHOD || type == JavaElementType.ANNOTATION_METHOD || type == JavaElementType
                    .LAMBDA_EXPRESSION)
            {
                return;
            }
            processor.accept(element);
            super.visitNode(element);
        }
    }.visitNode(root);
}
项目:consulo-xml    文件:XmlBuilderDriver.java   
private CharSequence findTextByTokenType(LighterASTNode attrNode,
                                         FlyweightCapableTreeStructure<LighterASTNode> structure,
                                         IElementType tt) {
  attrNode = structure.prepareForGetChildren(attrNode);

  final Ref<LighterASTNode[]> childrenRef = Ref.create(null);
  final int count = structure.getChildren(attrNode, childrenRef);
  LighterASTNode[] children = childrenRef.get();

  CharSequence name = "";
  for (int i = 0; i < count; i++) {
    LighterASTNode child = children[i];
    if (child.getTokenType() == tt) {
      name = getTokenText(child);
      break;
    }
  }

  structure.disposeChildren(children, count);

  return name;
}
项目:consulo-java    文件:ContractInferenceInterpreter.java   
@Nullable
private List<PreContract> handleDelegation(@Nullable LighterASTNode expression, boolean negated)
{
    if(expression == null)
    {
        return null;
    }
    if(expression.getTokenType() == PARENTH_EXPRESSION)
    {
        return handleDelegation(findExpressionChild(myTree, expression), negated);
    }

    if(isNegationExpression(expression))
    {
        return handleDelegation(findExpressionChild(myTree, expression), !negated);
    }

    if(expression.getTokenType() == METHOD_CALL_EXPRESSION)
    {
        return singletonList(new DelegationContract(ExpressionRange.create(expression, myBody.getStartOffset()), negated));
    }

    return null;
}
项目:consulo-java    文件:JavaNullMethodArgumentIndex.java   
@NotNull
private static Set<LighterASTNode> findCallsWithNulls(LighterAST lighterAst, int[] nullOffsets)
{
    Set<LighterASTNode> calls = new HashSet<>();
    for(int offset : nullOffsets)
    {
        LighterASTNode leaf = LightTreeUtil.findLeafElementAt(lighterAst, offset);
        LighterASTNode literal = leaf == null ? null : lighterAst.getParent(leaf);
        if(isNullLiteral(lighterAst, literal))
        {
            LighterASTNode exprList = lighterAst.getParent(literal);
            if(exprList != null && exprList.getTokenType() == EXPRESSION_LIST)
            {
                ContainerUtil.addIfNotNull(calls, LightTreeUtil.getParentOfType(lighterAst, exprList, CALL_TYPES, ElementType.MEMBER_BIT_SET));
            }
        }
    }
    return calls;
}
项目:consulo-java    文件:ContractInferenceInterpreter.java   
private int resolveParameter(@Nullable LighterASTNode expr)
{
    if(expr != null && expr.getTokenType() == REFERENCE_EXPRESSION && findExpressionChild(myTree, expr) == null)
    {
        String name = JavaLightTreeUtil.getNameIdentifierText(myTree, expr);
        if(name == null)
        {
            return -1;
        }

        List<LighterASTNode> parameters = getParameters();
        for(int i = 0; i < parameters.size(); i++)
        {
            if(name.equals(JavaLightTreeUtil.getNameIdentifierText(myTree, parameters.get(i))))
            {
                return i;
            }
        }
    }
    return -1;
}
项目:consulo-java    文件:ContractInferenceInterpreter.java   
@NotNull
List<PreContract> inferContracts(List<LighterASTNode> statements)
{
    if(statements.isEmpty())
    {
        return emptyList();
    }

    if(statements.size() == 1)
    {
        List<PreContract> result = handleSingleStatement(statements.get(0));
        if(result != null)
        {
            return result;
        }
    }

    return visitStatements(singletonList(StandardMethodContract.createConstraintArray(getParameters().size())), statements);
}
项目:consulo-java    文件:JavaNameValuePairType.java   
@Override
public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  String name = null;
  String value = null;
  List<LighterASTNode> children = tree.getChildren(node);
  for (LighterASTNode child : children) {
    if (child.getTokenType() == JavaTokenType.IDENTIFIER) {
      name = RecordUtil.intern(tree.getCharTable(), child);
    }
    else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) {
      value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0));
      value = StringUtil.stripQuotesAroundValue(value);
    }
  }
  return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value));
}
项目:consulo-java    文件:NullityInference.java   
void visitNode(LighterASTNode element)
{
    IElementType type = element.getTokenType();

    if(type == TokenType.ERROR_ELEMENT)
    {
        hasErrors = true;
    }
    else if(type == RETURN_STATEMENT)
    {
        LighterASTNode value = JavaLightTreeUtil.findExpressionChild(tree, element);
        if(value == null)
        {
            hasErrors = true;
        }
        else
        {
            visitReturnedValue(value);
        }
    }
}
项目:consulo-java    文件:LambdaExpressionElementType.java   
private static void formatTypeParameters(LighterAST tree, LighterASTNode typeParameters, StringBuilder buf)
{
    final List<LighterASTNode> children = LightTreeUtil.getChildrenOfType(tree, typeParameters, JavaElementType.TYPE);
    if(children.isEmpty())
    {
        return;
    }
    buf.append('<');
    for(int i = 0; i < children.size(); i++)
    {
        LighterASTNode child = children.get(i);
        formatType(tree, child, buf);
        if(i != children.size() - 1)
        {
            buf.append(", ");
        }
    }
    buf.append('>');
}
项目:consulo-java    文件:JavaNullMethodArgumentIndex.java   
@Nullable
private static String getMethodName(LighterAST lighterAst, @NotNull LighterASTNode call, IElementType elementType)
{
    if(elementType == NEW_EXPRESSION || elementType == ANONYMOUS_CLASS)
    {
        final List<LighterASTNode> refs = LightTreeUtil.getChildrenOfType(lighterAst, call, JAVA_CODE_REFERENCE);
        if(refs.isEmpty())
        {
            return null;
        }
        final LighterASTNode lastRef = refs.get(refs.size() - 1);
        return JavaLightTreeUtil.getNameIdentifierText(lighterAst, lastRef);
    }

    LOG.assertTrue(elementType == METHOD_CALL_EXPRESSION);
    final LighterASTNode methodReference = lighterAst.getChildren(call).get(0);
    if(methodReference.getTokenType() == REFERENCE_EXPRESSION)
    {
        return JavaLightTreeUtil.getNameIdentifierText(lighterAst, methodReference);
    }
    return null;
}
项目:consulo-java    文件:PurityInference.java   
void visitNode(LighterASTNode element)
{
    IElementType type = element.getTokenType();
    if(type == ASSIGNMENT_EXPRESSION)
    {
        mutatedRefs.add(tree.getChildren(element).get(0));
    }
    else if(type == RETURN_STATEMENT && JavaLightTreeUtil.findExpressionChild(tree, element) != null)
    {
        hasReturns = true;
    }
    else if((type == PREFIX_EXPRESSION || type == POSTFIX_EXPRESSION) && isMutatingOperation(element))
    {
        ContainerUtil.addIfNotNull(mutatedRefs, JavaLightTreeUtil.findExpressionChild(tree, element));
    }
    else if(isCall(element, type))
    {
        calls.add(element);
    }
}
项目:consulo-java    文件:RecordUtil.java   
public static boolean isDeprecatedByDocComment(@NotNull LighterAST tree, @NotNull LighterASTNode comment)
{
    String text = LightTreeUtil.toFilteredString(tree, comment, null);
    if(text.contains(DEPRECATED_TAG))
    {
        JavaDocLexer lexer = new JavaDocLexer(LanguageLevel.HIGHEST);
        lexer.start(text);
        IElementType token;
        while((token = lexer.getTokenType()) != null)
        {
            if(token == JavaDocTokenType.DOC_TAG_NAME && DEPRECATED_TAG.equals(lexer.getTokenText()))
            {
                return true;
            }
            lexer.advance();
        }
    }

    return false;
}
项目:consulo-java    文件:JavaLightStubBuilder.java   
@NotNull
@Override
protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree)
{
    if(!(file instanceof PsiJavaFile))
    {
        return super.createStubForFile(file, tree);
    }

    String refText = "";
    LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT);
    if(pkg != null)
    {
        LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
        if(ref != null)
        {
            refText = JavaSourceUtil.getReferenceText(tree, ref);
        }
    }
    return new PsiJavaFileStubImpl((PsiJavaFile) file, refText, null, false);
}
项目:intellij-ce-playground    文件:JavaFieldStubElementType.java   
@Override
public PsiFieldStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
  final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);

  boolean isDeprecatedByComment = false;
  boolean hasDeprecatedAnnotation = false;
  boolean hasDocComment = false;
  String name = null;
  String initializer = null;

  boolean expectingInit = false;
  for (final LighterASTNode child : tree.getChildren(node)) {
    final IElementType type = child.getTokenType();
    if (type == JavaDocElementType.DOC_COMMENT) {
      hasDocComment = true;
      isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
    }
    else if (type == JavaElementType.MODIFIER_LIST) {
      hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
    }
    else if (type == JavaTokenType.IDENTIFIER) {
      name = RecordUtil.intern(tree.getCharTable(), child);
    }
    else if (type == JavaTokenType.EQ) {
      expectingInit = true;
    }
    else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
      initializer = encodeInitializer(tree, child);
      break;
    }
  }

  final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT;
  final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);

  return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags);
}
项目:intellij-ce-playground    文件:JavaFieldStubElementType.java   
private static String encodeInitializer(final LighterAST tree, final LighterASTNode initializer) {
  final IElementType type = initializer.getTokenType();
  if (type == JavaElementType.NEW_EXPRESSION || type == JavaElementType.METHOD_CALL_EXPRESSION) {
    return PsiFieldStub.INITIALIZER_NOT_STORED;
  }

  if (initializer.getEndOffset() - initializer.getStartOffset() > INITIALIZER_LENGTH_LIMIT) {
    return PsiFieldStub.INITIALIZER_TOO_LONG;
  }

  return LightTreeUtil.toFilteredString(tree, initializer, null);
}
项目:intellij-ce-playground    文件:JavaClassReferenceListElementType.java   
private static String[] getTexts(LighterAST tree, LighterASTNode node) {
  List<LighterASTNode> refs = LightTreeUtil.getChildrenOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
  String[] texts = ArrayUtil.newStringArray(refs.size());
  for (int i = 0; i < refs.size(); i++) {
    texts[i] = LightTreeUtil.toFilteredString(tree, refs.get(i), null);
  }
  return texts;
}
项目:intellij-ce-playground    文件:JavaParameterElementType.java   
@Override
public PsiParameterStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
  TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
  LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
  String name = RecordUtil.intern(tree.getCharTable(), id);
  return new PsiParameterStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis);
}
项目:intellij-ce-playground    文件:JavaLightStubBuilder.java   
@Override
protected boolean skipChildProcessingWhenBuildingStubs(@NotNull LighterAST tree, @NotNull LighterASTNode parent, @NotNull LighterASTNode node) {
  IElementType parentType = parent.getTokenType();
  IElementType nodeType = node.getTokenType();

  if (checkByTypes(parentType, nodeType)) return true;

  if (nodeType == JavaElementType.CODE_BLOCK) {
    CodeBlockVisitor visitor = new CodeBlockVisitor();
    ((LighterLazyParseableNode)node).accept(visitor);
    return visitor.result;
  }

  return false;
}
项目:intellij-ce-playground    文件:DebugUtil.java   
public static String lightTreeToString(@NotNull 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();
}
项目:intellij-ce-playground    文件:LightTreeUtil.java   
@Nullable
public static LighterASTNode firstChildOfType(@NotNull List<LighterASTNode> children, @NotNull IElementType type) {
  for (int i = 0; i < children.size(); ++i) {
    LighterASTNode child = children.get(i);
    if (child.getTokenType() == type) return child;
  }

  return null;
}