org.antlr.runtime.tree.Tree.getChildIndex()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.antlr.runtime.tree.Tree.getChildIndex()方法的一些代码示例,展示了Tree.getChildIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tree.getChildIndex()方法的具体详情如下:
包路径:org.antlr.runtime.tree.Tree
类名称:Tree
方法名:getChildIndex

Tree.getChildIndex介绍

[英]This node is what child index? 0..n-1
[中]

代码示例

代码示例来源:origin: antlr/antlr3

@Override
public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr-runtime

@Override
public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: antlr/antlr3

@Override
public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@Override
public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

@Override
public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

public int getChildIndex(Object t) {
  if ( t==null ) return 0;
  return ((Tree)t).getChildIndex();
}

代码示例来源:origin: org.antlr/antlr4

public boolean deleteChild(org.antlr.runtime.tree.Tree t) {
  for (int i=0; i<children.size(); i++) {
    Object c = children.get(i);
    if ( c == t ) {
      deleteChild(t.getChildIndex());
      return true;
    }
  }
  return false;
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public boolean deleteChild(org.antlr.runtime.tree.Tree t) {
  for (int i=0; i<children.size(); i++) {
    Object c = children.get(i);
    if ( c == t ) {
      deleteChild(t.getChildIndex());
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.tunnelvisionlabs/antlr4

public boolean deleteChild(org.antlr.runtime.tree.Tree t) {
  for (int i=0; i<children.size(); i++) {
    Object c = children.get(i);
    if ( c == t ) {
      deleteChild(t.getChildIndex());
      return true;
    }
  }
  return false;
}

代码示例来源:origin: uk.co.nichesolutions/antlr4

public boolean deleteChild(org.antlr.runtime.tree.Tree t) {
  for (int i=0; i<children.size(); i++) {
    Object c = children.get(i);
    if ( c == t ) {
      deleteChild(t.getChildIndex());
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public boolean deleteChild(org.antlr.runtime.tree.Tree t) {
  for (int i=0; i<children.size(); i++) {
    Object c = children.get(i);
    if ( c == t ) {
      deleteChild(t.getChildIndex());
      return true;
    }
  }
  return false;
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

private boolean isSimpleStatementNode(Tree node) {
 int nodeCode = node.getType();
 // special case for 'break' statement, since it went to
 // 'usedKeywordsAsNames' rule and now
 // it is recognized as TkIdentifier
 if (nodeCode == LexerMetrics.IDENT.toMetrics() && "break".equalsIgnoreCase(node.getText())) {
  return true;
 } else if (nodeCode == LexerMetrics.FOR.toMetrics()) {
  // special case for "for" statement
  statementIndex.pop();
  statementIndex.push(node.getChildIndex() + 1);
  lastStatementText = node.getText();
  return true;
 }
 for (LexerMetrics code : STATEMENT_NODES) {
  if (code.toMetrics() == nodeCode) {
   lastStatementText = node.getText();
   return true;
  }
 }
 return false;
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

private String getArgumentTypes(Tree nameNode) {
 Tree typeNode = nameNode.getParent().getChild(nameNode.getChildIndex() + 1);
 if (typeNode.getChildCount() > 0) {
  return typeNode.getChild(0).getText();
 }
 return UNTYPED_PARAMETER_NAME;
}

代码示例来源:origin: org.apache.pig/pig

@SuppressWarnings({ "unchecked", "rawtypes" })
static void replaceNodeWithNodeList(Tree oldNode, CommonTree newTree,
    String fileName) {
  int idx = oldNode.getChildIndex();
  CommonTree parent = (CommonTree) oldNode.getParent();
  int count = parent.getChildCount();
  List childList = new ArrayList(parent.getChildren());
  List macroList = newTree.getChildren();
  while (parent.getChildCount() > 0) {
    parent.deleteChild(0);
  }
  for (int i = 0; i < count; i++) {
    if (i == idx) {
      // add only there is something to add
      if (macroList != null) {
        parent.addChildren(macroList);
      }
    } else {
      parent.addChild((Tree) childList.get(i));
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public void removeOrderBy() {
  Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
  if (orderBy != null) {
    queryTree.getAstTree().deleteChild(orderBy.getChildIndex());
  }
  queryTree.getAstTree().freshenParentAndChildIndexes();
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

@Override
 public CodeNode<Tree> execute(Tree node) {
  if (node == null) {
   return new CodeNode<Tree>(null);
  }

  Tree parent = node.getParent();
  if (parent == null) {
   return new CodeNode<Tree>(null);
  }

  Tree nextNode = parent.getChild(node.getChildIndex() + 1);
  if (nextNode != null) {
   return new CodeNode<Tree>(nextNode);
  }

  // No child found, trace back again
  return execute(parent);
 }
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

public boolean verify(Tree node) {
 CommonTree nextNode = (CommonTree) node.getParent().getChild(node.getChildIndex() + 1);
 // if we are on a ident token and it is not last
 if (node.getType() == LexerMetrics.IDENT.toMetrics()
  && nextNode != null
  && (nextNode.getType() == LexerMetrics.LPAREN.toMetrics() || nextNode.getType() == LexerMetrics.SEMI.toMetrics())) {
  String functionName = node.getText().toLowerCase();
  List<UnitInterface> unitsToLook = new ArrayList<UnitInterface>();
  // first we look in current unit for function reference
  unitsToLook.add(results.getActiveUnit());
  unitsToLook.addAll(results.getActiveUnit().getIncludedUnits(results.getCachedUnits()));
  for (UnitInterface unit : unitsToLook) {
   FunctionInterface[] functions = unit.getAllFunctions();
   for (FunctionInterface func : functions) {
    if (func.getShortName().equalsIgnoreCase(functionName)) {
     calledFunction = func;
     isUnresolved = false;
     return true;
    }
   }
  }
  // create a new unresolved function
  calledFunction = new DelphiFunction(node.getText().toLowerCase());
  // no function found, but this was a function call
  isUnresolved = true;
  // so we return true
  return true;
 }
 return false; // not a function call (not like "foo(args);" or "foo;"
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

return false;
int childIndex = node.getChildIndex();
if (childIndex <= statementIndex.peek()) {

代码示例来源:origin: fabriciocolombo/sonar-delphi

private int extractLine(Tree currentCodeNode) {
 Tree parent = currentCodeNode.getParent();
 for (int i = currentCodeNode.getChildIndex() - 1; i >= 0; i--) {
  Tree child = parent.getChild(i);
  if (child.getType() == DelphiLexer.FUNCTION
   || child.getType() == DelphiLexer.PROCEDURE
   || child.getType() == DelphiLexer.CONSTRUCTOR
   || child.getType() == DelphiLexer.DESTRUCTOR
   || child.getType() == DelphiLexer.OPERATOR) {
   return child.getLine();
  }
 }
 return -1;
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public void replaceWithCount(Tree node) {
  Tree selectedItems = queryTree.getAstSelectedItemsNode();
  boolean isDistinct = "distinct".equalsIgnoreCase(selectedItems.getChild(0).getText());
  if (!(isDistinct && selectedItems.getChildCount() == 2 ||
      selectedItems.getChildCount() == 1))
    throw new IllegalStateException("Cannot replace with count if multiple fields selected");
  SelectedItemNode selectedItemNode;
  if (isDistinct)
    selectedItems.deleteChild(0);
  selectedItemNode = (SelectedItemNode) selectedItems.getChild(0);
  AggregateExpressionNode countNode = createCountNode(node, isDistinct);
  selectedItemNode.deleteChild(0);
  selectedItemNode.addChild(countNode);
  Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
  if (orderBy != null) {
    queryTree.getAstTree().deleteChild(orderBy.getChildIndex());
  }
  queryTree.getAstTree().freshenParentAndChildIndexes();
}

相关文章