Java Stack Usage resolveOneLineExpression(String line, String space, List target)

Here you can find the source of resolveOneLineExpression(String line, String space, List target)

Description

resolve One Line Expression

License

Open Source License

Declaration

private static void resolveOneLineExpression(String line, String space, List<String> target) 

Method Source Code

//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;
    }
}

Related

  1. isDoubleQuote(Stack bufStack)
  2. normalizeAbsolutePath(String curDir)
  3. removeBackets(String cont)
  4. removeDotSegments(String relativePath)
  5. removeParenthesis(String text)
  6. resolveSeparateIfSentence(List lines, int cursor, List target, String space)
  7. split(final String str)
  8. split(String string, String token)