use of java.util.Stack in project tesb-studio-se by Talend.
the class SpringConfigurationStyledText method searchNearestOpenedTag.
private String searchNearestOpenedTag(int lastOffset) {
Stack<String> closeTagStack = new Stack<String>();
boolean hasSingleEndTag = false;
for (int i = lastOffset; i >= 0; i--) {
String currentChar = getText(i, i);
if (isCommentBlock(i)) {
continue;
}
if (">".equals(currentChar)) {
if (hasSingleEndTag) {
return null;
}
if (i > 0 && "/".equals(getText(i - 1, i - 1))) {
hasSingleEndTag = true;
i--;
}
continue;
}
if ("<".equals(currentChar)) {
if (hasSingleEndTag) {
hasSingleEndTag = false;
continue;
}
String nextChar = getText(i + 1, i + 1);
if ("/".equals(nextChar)) {
String searchTagName = searchTagName(i + 2, lastOffset);
if (!searchTagName.isEmpty()) {
closeTagStack.push(searchTagName);
}
continue;
}
String currentTagName = searchTagName(i + 1, lastOffset);
if (closeTagStack.isEmpty()) {
return currentTagName.isEmpty() ? null : currentTagName + ">";
} else {
String pop = closeTagStack.pop();
if (!currentTagName.equals(pop)) {
return null;
}
}
}
}
return null;
}
use of java.util.Stack in project voltdb by VoltDB.
the class PlannerTestCase method assertTopDownTree.
/**
* Assert that a plan node tree contains the expected types of plan nodes
* in the order listed, assuming a top-down left-to-right depth-first
* traversal through the child vector. A null plan node type in the list
* will match any plan node or subtree at the corresponding position.
**/
protected static void assertTopDownTree(AbstractPlanNode start, PlanNodeType... nodeTypes) {
Stack<AbstractPlanNode> stack = new Stack<>();
stack.push(start);
for (PlanNodeType type : nodeTypes) {
// Process each node before its children or later siblings.
AbstractPlanNode parent;
try {
parent = stack.pop();
} catch (EmptyStackException ese) {
fail("No node was found in the tree to match node type " + type);
// This dead code hushes warnings.
return;
}
int childCount = parent.getChildCount();
if (type == null) {
// A null type wildcard matches any child TREE or NODE.
System.out.println("DEBUG: Suggestion -- expect " + parent.getPlanNodeType() + " with " + childCount + " direct children.");
continue;
}
assertEquals(type, parent.getPlanNodeType());
// Iterate from the last child to the first.
while (childCount > 0) {
// Push each child to be processed before its parent's
// or its own later (already pushed) siblings.
stack.push(parent.getChild(--childCount));
}
}
assertTrue("Extra plan node(s) (" + stack.size() + ") were found in the tree with no node type to match", stack.isEmpty());
}
use of java.util.Stack in project voltdb by VoltDB.
the class PlannerTestCase method assertExprTopDownTree.
/**
* Assert that an expression tree contains the expected types of expressions
* in the order listed, assuming a top-down left-to-right depth-first
* traversal through left, right, and args children.
* A null expression type in the list will match any expression
* node or tree at the corresponding position.
**/
protected static void assertExprTopDownTree(AbstractExpression start, ExpressionType... exprTypes) {
assertNotNull(start);
Stack<AbstractExpression> stack = new Stack<>();
stack.push(start);
for (ExpressionType type : exprTypes) {
// Process each node before its children or later siblings.
AbstractExpression parent;
try {
parent = stack.pop();
} catch (EmptyStackException ese) {
fail("No expression was found in the tree to match type " + type);
// This dead code hushes warnings.
return;
}
List<AbstractExpression> args = parent.getArgs();
AbstractExpression rightExpr = parent.getRight();
AbstractExpression leftExpr = parent.getLeft();
int argCount = (args == null) ? 0 : args.size();
int childCount = argCount + (rightExpr == null ? 0 : 1) + (leftExpr == null ? 0 : 1);
if (type == null) {
// A null type wildcard matches any child TREE or NODE.
System.out.println("DEBUG: Suggestion -- expect " + parent.getExpressionType() + " with " + childCount + " direct children.");
continue;
}
assertEquals(type, parent.getExpressionType());
// Iterate from the last child to the first.
while (argCount > 0) {
// Push each child to be processed before its parent's
// or its own later siblings (already pushed).
stack.push(parent.getArgs().get(--argCount));
}
if (rightExpr != null) {
stack.push(rightExpr);
}
if (leftExpr != null) {
stack.push(leftExpr);
}
}
assertTrue("Extra expression node(s) (" + stack.size() + ") were found in the tree with no expression type to match", stack.isEmpty());
}
use of java.util.Stack in project enclojure by EricThorsen.
the class ClojureFoldManager method getTopLevelFolds.
public static List<FoldInfo> getTopLevelFolds(BaseDocument doc) {
ArrayList<FoldInfo> foldList = new ArrayList<FoldInfo>();
Stack stack = new Stack();
int start = 0;
int end = 0;
String foldDesc = EMPTY_STRING;
String foldTypeDesc = EMPTY_STRING;
boolean readName = false;
StringBuilder foldText = new StringBuilder();
TokenSequence tokens = TokenHierarchy.get(doc).tokenSequence();
tokens.moveStart();
while (tokens.moveNext()) {
String tk = tokens.token().id().name();
String tkn = tokens.token().toString();
foldText.append(tkn);
if (tk.equals(LIST_START)) {
stack.push(tk);
if (stack.size() == 1)
start = tokens.offset();
} else if (tk.equals(LIST_END)) {
if (!stack.isEmpty())
stack.pop();
if (stack.empty()) {
end = tokens.offset() + 1;
foldList.add(getFoldInfo(start, end, getFoldType(foldTypeDesc), getFoldString(foldText, foldDesc, MAX_FOLD_DESC_LEN)));
start = 0;
end = 0;
foldTypeDesc = EMPTY_STRING;
foldDesc = EMPTY_STRING;
foldText = foldText.replace(0, foldText.length() - 1, EMPTY_STRING);
}
} else if (tkn.equals(DEF) || tkn.equals(DEFN) || tkn.equals(DEFMACRO)) {
foldTypeDesc = tkn;
readName = true;
} else if (readName) {
foldDesc = getFoldDescription(foldTypeDesc, tkn);
readName = false;
}
}
return foldList;
}
use of java.util.Stack in project blog by BayesianLogic.
the class Type method getStrictAncestors.
/**
* Returns the types that are strict ancestors of this type in the type graph.
* The type graph contains a node for each type, with an edge from type sigma
* to type tau if sigma is the return type of some origin function for tau.
* Note that this graph may be cyclic and may even include self-loops. The
* strict ancestors of a this type are those types tau such that there is a
* nonzero-length directed path from tau to this type.
*
* @return a Set of Type objects
*/
public Set getStrictAncestors() {
Set strictAncestors = new HashSet();
// Find ancestors by depth-first search with repeated-node checking
Stack stack = new Stack();
stack.push(this);
while (!stack.isEmpty()) {
Type curType = (Type) stack.pop();
for (Iterator iter = curType.getOriginFunctions().iterator(); iter.hasNext(); ) {
Type parentType = ((Function) iter.next()).getRetType();
if (!strictAncestors.contains(parentType)) {
strictAncestors.add(parentType);
stack.push(parentType);
}
}
}
return strictAncestors;
}
Aggregations