@Test public void testSmooshNoDeclarationClose() { final List<String> text = Collections.singletonList("declare incomplete_sub(arg1 = f8)"); InvalidSubroutineException e = assertThrows(InvalidSubroutineException.class, () -> { smoosher.smoosh(0, text); }); assertThat(e.getMessage()).isEqualTo("Unable to find close to subroutine declaration: " + 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)); if (isSubroutineDeclarationClose(firstLine)) { return firstLine; } final StringBuilder declarationBuilder = new StringBuilder(firstLine); boolean hasClose = false; int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); hasClose = isSubroutineDeclarationClose(currentLine); declarationBuilder.append(" ").append(currentLine.trim()); if (hasClose) { break; } } if (!hasClose) { throw new InvalidSubroutineException( "Unable to find close to subroutine declaration: " + declarationBuilder.toString()); } return declarationBuilder.toString(); } finally { point.collect(); } }
SubroutineDeclarationSmoosher 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)); if (isSubroutineDeclarationClose(firstLine)) { return firstLine; } final StringBuilder declarationBuilder = new StringBuilder(firstLine); boolean hasClose = false; int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); hasClose = isSubroutineDeclarationClose(currentLine); declarationBuilder.append(" ").append(currentLine.trim()); if (hasClose) { break; } } if (!hasClose) { throw new InvalidSubroutineException( "Unable to find close to subroutine declaration: " + declarationBuilder.toString()); } return declarationBuilder.toString(); } finally { point.collect(); } } }
SubroutineDeclarationSmoosher 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)); if (isSubroutineDeclarationClose(firstLine)) { return firstLine; } final StringBuilder declarationBuilder = new StringBuilder(firstLine); boolean hasClose = false; int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); hasClose = isSubroutineDeclarationClose(currentLine); declarationBuilder.append(" ").append(currentLine.trim()); if (hasClose) { break; } } if (!hasClose) { throw new InvalidSubroutineException( "Unable to find close to subroutine declaration: " + declarationBuilder.toString()); } return declarationBuilder.toString(); } finally { point.collect(); } }  }
SubroutineDeclarationSmoosher 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)); if (isSubroutineDeclarationClose(firstLine)) { return firstLine; } final StringBuilder declarationBuilder = new StringBuilder(firstLine); boolean hasClose = false; int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); hasClose = isSubroutineDeclarationClose(currentLine); declarationBuilder.append(" ").append(currentLine.trim()); if (hasClose) { break; } } if (!hasClose) { throw new InvalidSubroutineException( "Unable to find close to subroutine declaration: " + declarationBuilder.toString()); } return declarationBuilder.toString(); } finally { point.collect(); } }  @Override boolean canSmoosh(final String line); @Override int getEndingIndex(); @Override String smoosh(final int startingIndex, final List<String> list); }
SubroutineDeclarationSmoosher 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)); if (isSubroutineDeclarationClose(firstLine)) { return firstLine; } final StringBuilder declarationBuilder = new StringBuilder(firstLine); boolean hasClose = false; int iterator = startingIndex + 1; for (final int size = list.size(); iterator < size; iterator++) { endingIndex = iterator; final String currentLine = uncomment(list.get(iterator)); hasClose = isSubroutineDeclarationClose(currentLine); declarationBuilder.append(" ").append(currentLine.trim()); if (hasClose) { break; } } if (!hasClose) { throw new InvalidSubroutineException( "Unable to find close to subroutine declaration: " + declarationBuilder.toString()); } return declarationBuilder.toString(); } finally { point.collect(); } }  @Override boolean canSmoosh(final String line); @Override int getEndingIndex(); @Override String smoosh(final int startingIndex, final List<String> list);  }