Here you can find the source of resolveOneLineExpression(String line, String space, List
private static void resolveOneLineExpression(String line, String space, List<String> target)
//package com.java2s; import java.util.List; import java.util.Stack; public class Main { private static void resolveOneLineExpression(String line, String space, List<String> target) { Stack<Character> stack = new Stack<>(); String expr = removeComments(line); boolean flag = false; int index = 0; for (char c : line.toCharArray()) { ++index;// w w w. j av a 2 s . com if (c == '(') { if (!flag) { flag = true; } stack.push(c); } else if (c == ')') { stack.pop(); } if (flag && stack.isEmpty()) { break; } } target.add(expr.substring(0, index) + " {"); target.add(space + "\t" + expr.substring(index)); target.add(space + "}"); } private static String removeComments(String line) { int index = line.indexOf("//"); if (index != -1) { return line.substring(0, index); } return line; } }