@Test(description = "Test get callable unit name", dataProvider = "positionData") public void getCallableItemNameTest(Position position, String funcName) throws URISyntaxException, IOException { Path fileLocation = FileUtils.RES_DIR.resolve("signature").resolve("util").resolve("testUtil.bal"); String stringContent = new String(Files.readAllBytes(fileLocation)); LSServiceOperationContext serviceContext = new LSServiceOperationContext(); SignatureHelpUtil.captureCallableItemInfo(position, stringContent, serviceContext); String capturedFunctionName = serviceContext.get(SignatureKeys.CALLABLE_ITEM_NAME); Assert.assertEquals(funcName, capturedFunctionName); }
public static void captureCallableItemInfo(Position position, String fileContent, LSServiceOperationContext serviceContext) { int lineNumber = position.getLine(); int character = position.getCharacter(); int paramCounter = 0; String[] lineTokens = fileContent.split("\\r?\\n", lineNumber + 2); String line = lineTokens[lineNumber]; int backTrackPosition = character - 1; Stack<String> closeBracketStack = new Stack<>(); while (true) { if (backTrackPosition < 0) { break; } String currentToken = Character.toString(line.charAt(backTrackPosition)); if (COMMA.equals(currentToken)) { paramCounter++; } else if (CLOSE_BRACKET.equals(currentToken)) { closeBracketStack.push(CLOSE_BRACKET); } else if (OPEN_BRACKET.equals(currentToken)) { if (!closeBracketStack.isEmpty()) { closeBracketStack.pop(); paramCounter = 0; } else { setItemInfo(line, backTrackPosition - 1, serviceContext); } } backTrackPosition--; } serviceContext.put(SignatureKeys.PARAMETER_COUNT, paramCounter); }
SignatureHelpUtil { public static void captureCallableItemInfo(Position position, String fileContent, LSServiceOperationContext serviceContext) { int lineNumber = position.getLine(); int character = position.getCharacter(); int paramCounter = 0; String[] lineTokens = fileContent.split("\\r?\\n", lineNumber + 2); String line = lineTokens[lineNumber]; int backTrackPosition = character - 1; Stack<String> closeBracketStack = new Stack<>(); while (true) { if (backTrackPosition < 0) { break; } String currentToken = Character.toString(line.charAt(backTrackPosition)); if (COMMA.equals(currentToken)) { paramCounter++; } else if (CLOSE_BRACKET.equals(currentToken)) { closeBracketStack.push(CLOSE_BRACKET); } else if (OPEN_BRACKET.equals(currentToken)) { if (!closeBracketStack.isEmpty()) { closeBracketStack.pop(); paramCounter = 0; } else { setItemInfo(line, backTrackPosition - 1, serviceContext); } } backTrackPosition--; } serviceContext.put(SignatureKeys.PARAMETER_COUNT, paramCounter); } }
SignatureHelpUtil { public static void captureCallableItemInfo(Position position, String fileContent, LSServiceOperationContext serviceContext) { int lineNumber = position.getLine(); int character = position.getCharacter(); int paramCounter = 0; String[] lineTokens = fileContent.split("\\r?\\n", lineNumber + 2); String line = lineTokens[lineNumber]; int backTrackPosition = character - 1; Stack<String> closeBracketStack = new Stack<>(); while (true) { if (backTrackPosition < 0) { break; } String currentToken = Character.toString(line.charAt(backTrackPosition)); if (COMMA.equals(currentToken)) { paramCounter++; } else if (CLOSE_BRACKET.equals(currentToken)) { closeBracketStack.push(CLOSE_BRACKET); } else if (OPEN_BRACKET.equals(currentToken)) { if (!closeBracketStack.isEmpty()) { closeBracketStack.pop(); paramCounter = 0; } else { setItemInfo(line, backTrackPosition - 1, serviceContext); } } backTrackPosition--; } serviceContext.put(SignatureKeys.PARAMETER_COUNT, paramCounter); }  }
SignatureHelpUtil { public static void captureCallableItemInfo(Position position, String fileContent, LSServiceOperationContext serviceContext) { int lineNumber = position.getLine(); int character = position.getCharacter(); int paramCounter = 0; String[] lineTokens = fileContent.split("\\r?\\n", lineNumber + 2); String line = lineTokens[lineNumber]; int backTrackPosition = character - 1; Stack<String> closeBracketStack = new Stack<>(); while (true) { if (backTrackPosition < 0) { break; } String currentToken = Character.toString(line.charAt(backTrackPosition)); if (COMMA.equals(currentToken)) { paramCounter++; } else if (CLOSE_BRACKET.equals(currentToken)) { closeBracketStack.push(CLOSE_BRACKET); } else if (OPEN_BRACKET.equals(currentToken)) { if (!closeBracketStack.isEmpty()) { closeBracketStack.pop(); paramCounter = 0; } else { setItemInfo(line, backTrackPosition - 1, serviceContext); } } backTrackPosition--; } serviceContext.put(SignatureKeys.PARAMETER_COUNT, paramCounter); }  static void captureCallableItemInfo(Position position, String fileContent,
                                               LSServiceOperationContext serviceContext); static SignatureHelp getFunctionSignatureHelp(LSServiceOperationContext ctx); }
SignatureHelpUtil { public static void captureCallableItemInfo(Position position, String fileContent, LSServiceOperationContext serviceContext) { int lineNumber = position.getLine(); int character = position.getCharacter(); int paramCounter = 0; String[] lineTokens = fileContent.split("\\r?\\n", lineNumber + 2); String line = lineTokens[lineNumber]; int backTrackPosition = character - 1; Stack<String> closeBracketStack = new Stack<>(); while (true) { if (backTrackPosition < 0) { break; } String currentToken = Character.toString(line.charAt(backTrackPosition)); if (COMMA.equals(currentToken)) { paramCounter++; } else if (CLOSE_BRACKET.equals(currentToken)) { closeBracketStack.push(CLOSE_BRACKET); } else if (OPEN_BRACKET.equals(currentToken)) { if (!closeBracketStack.isEmpty()) { closeBracketStack.pop(); paramCounter = 0; } else { setItemInfo(line, backTrackPosition - 1, serviceContext); } } backTrackPosition--; } serviceContext.put(SignatureKeys.PARAMETER_COUNT, paramCounter); }  static void captureCallableItemInfo(Position position, String fileContent,
                                               LSServiceOperationContext serviceContext); static SignatureHelp getFunctionSignatureHelp(LSServiceOperationContext ctx);  }