@Test public void testSmooshNoClose() { final List<String> text = Arrays.asList("subroutine (incomplete_sub (arg1=i4, arg2=i4)=", "null"); InvalidSubroutineException e = assertThrows(InvalidSubroutineException.class, () -> { smoosher.smoosh(0, text); }); assertThat(e.getMessage()).startsWith("Unable to find close to subroutine definition: " + text.get(0)); }
@Override public String smoosh(final int startingIndex, final List<String> list) { if (startingIndex < 0) { throw new IllegalArgumentException("Starting index cannot be negative."); } if (list == null) { throw new IllegalArgumentException("List cannot be null."); } if (list.isEmpty()) { throw new IllegalArgumentException("List cannot be empty."); } if (startingIndex >= list.size()) { throw new IllegalArgumentException("Starting index exceeds list size; index = " + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size())); } final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)"); try { endingIndex = startingIndex; final String firstLine = uncomment(list.get(startingIndex)).trim(); int leftCount = matchCount(firstLine, PATTERN_LEFT_PAREN); int rightCount = matchCount(firstLine, PATTERN_RIGTH_PAREN); if (leftCount == rightCount) { return firstLine; } final StringBuilder definitionBuilder = new StringBuilder(firstLine); int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); leftCount += matchCount(currentLine, PATTERN_LEFT_PAREN); rightCount += matchCount(currentLine, PATTERN_RIGTH_PAREN); definitionBuilder.append(" ").append(currentLine.trim()); if (leftCount == rightCount) { break; } } if (leftCount != rightCount) { throw new InvalidSubroutineException( "Unable to find close to subroutine definition: " + definitionBuilder.toString()); } return definitionBuilder.toString().trim(); } finally { point.collect(); } }
InlineSubroutineDeclarationSmoosher implements IndexedSmoosher<String> { @Override public String smoosh(final int startingIndex, final List<String> list) { if (startingIndex < 0) { throw new IllegalArgumentException("Starting index cannot be negative."); } if (list == null) { throw new IllegalArgumentException("List cannot be null."); } if (list.isEmpty()) { throw new IllegalArgumentException("List cannot be empty."); } if (startingIndex >= list.size()) { throw new IllegalArgumentException("Starting index exceeds list size; index = " + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size())); } final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)"); try { endingIndex = startingIndex; final String firstLine = uncomment(list.get(startingIndex)).trim(); int leftCount = matchCount(firstLine, PATTERN_LEFT_PAREN); int rightCount = matchCount(firstLine, PATTERN_RIGTH_PAREN); if (leftCount == rightCount) { return firstLine; } final StringBuilder definitionBuilder = new StringBuilder(firstLine); int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); leftCount += matchCount(currentLine, PATTERN_LEFT_PAREN); rightCount += matchCount(currentLine, PATTERN_RIGTH_PAREN); definitionBuilder.append(" ").append(currentLine.trim()); if (leftCount == rightCount) { break; } } if (leftCount != rightCount) { throw new InvalidSubroutineException( "Unable to find close to subroutine definition: " + definitionBuilder.toString()); } return definitionBuilder.toString().trim(); } finally { point.collect(); } } }
InlineSubroutineDeclarationSmoosher implements IndexedSmoosher<String> { @Override public String smoosh(final int startingIndex, final List<String> list) { if (startingIndex < 0) { throw new IllegalArgumentException("Starting index cannot be negative."); } if (list == null) { throw new IllegalArgumentException("List cannot be null."); } if (list.isEmpty()) { throw new IllegalArgumentException("List cannot be empty."); } if (startingIndex >= list.size()) { throw new IllegalArgumentException("Starting index exceeds list size; index = " + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size())); } final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)"); try { endingIndex = startingIndex; final String firstLine = uncomment(list.get(startingIndex)).trim(); int leftCount = matchCount(firstLine, PATTERN_LEFT_PAREN); int rightCount = matchCount(firstLine, PATTERN_RIGTH_PAREN); if (leftCount == rightCount) { return firstLine; } final StringBuilder definitionBuilder = new StringBuilder(firstLine); int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); leftCount += matchCount(currentLine, PATTERN_LEFT_PAREN); rightCount += matchCount(currentLine, PATTERN_RIGTH_PAREN); definitionBuilder.append(" ").append(currentLine.trim()); if (leftCount == rightCount) { break; } } if (leftCount != rightCount) { throw new InvalidSubroutineException( "Unable to find close to subroutine definition: " + definitionBuilder.toString()); } return definitionBuilder.toString().trim(); } finally { point.collect(); } }  }
InlineSubroutineDeclarationSmoosher implements IndexedSmoosher<String> { @Override public String smoosh(final int startingIndex, final List<String> list) { if (startingIndex < 0) { throw new IllegalArgumentException("Starting index cannot be negative."); } if (list == null) { throw new IllegalArgumentException("List cannot be null."); } if (list.isEmpty()) { throw new IllegalArgumentException("List cannot be empty."); } if (startingIndex >= list.size()) { throw new IllegalArgumentException("Starting index exceeds list size; index = " + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size())); } final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)"); try { endingIndex = startingIndex; final String firstLine = uncomment(list.get(startingIndex)).trim(); int leftCount = matchCount(firstLine, PATTERN_LEFT_PAREN); int rightCount = matchCount(firstLine, PATTERN_RIGTH_PAREN); if (leftCount == rightCount) { return firstLine; } final StringBuilder definitionBuilder = new StringBuilder(firstLine); int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); leftCount += matchCount(currentLine, PATTERN_LEFT_PAREN); rightCount += matchCount(currentLine, PATTERN_RIGTH_PAREN); definitionBuilder.append(" ").append(currentLine.trim()); if (leftCount == rightCount) { break; } } if (leftCount != rightCount) { throw new InvalidSubroutineException( "Unable to find close to subroutine definition: " + definitionBuilder.toString()); } return definitionBuilder.toString().trim(); } finally { point.collect(); } }  @Override boolean canSmoosh(final String line); @Override int getEndingIndex(); @Override String smoosh(final int startingIndex, final List<String> list); }
InlineSubroutineDeclarationSmoosher implements IndexedSmoosher<String> { @Override public String smoosh(final int startingIndex, final List<String> list) { if (startingIndex < 0) { throw new IllegalArgumentException("Starting index cannot be negative."); } if (list == null) { throw new IllegalArgumentException("List cannot be null."); } if (list.isEmpty()) { throw new IllegalArgumentException("List cannot be empty."); } if (startingIndex >= list.size()) { throw new IllegalArgumentException("Starting index exceeds list size; index = " + Integer.toString(startingIndex) + "; size = " + Integer.toString(list.size())); } final EtmPoint point = PointFactory.getPoint(getClass(), "smoosh(int, List)"); try { endingIndex = startingIndex; final String firstLine = uncomment(list.get(startingIndex)).trim(); int leftCount = matchCount(firstLine, PATTERN_LEFT_PAREN); int rightCount = matchCount(firstLine, PATTERN_RIGTH_PAREN); if (leftCount == rightCount) { return firstLine; } final StringBuilder definitionBuilder = new StringBuilder(firstLine); int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); leftCount += matchCount(currentLine, PATTERN_LEFT_PAREN); rightCount += matchCount(currentLine, PATTERN_RIGTH_PAREN); definitionBuilder.append(" ").append(currentLine.trim()); if (leftCount == rightCount) { break; } } if (leftCount != rightCount) { throw new InvalidSubroutineException( "Unable to find close to subroutine definition: " + definitionBuilder.toString()); } return definitionBuilder.toString().trim(); } finally { point.collect(); } }  @Override boolean canSmoosh(final String line); @Override int getEndingIndex(); @Override String smoosh(final int startingIndex, final List<String> list);  }