@Test public void testSplitFromInlineComment() { String[][] beforeToAfter = { { "import facets.rcf;", "# import the facets" }, { "import facets.rcf;", "\t# import the facets" }, { "import facets.rcf;", "#" }, { "import facets.rcf;", "" }, { "import facets.rcf; ", "" }, { "import facets.rcf;", " #### import the facets" }, { "", " #### import the facets" }, { "", " # " }, { "", "#" } }; for( String[] line : beforeToAfter ) { FileDefinitionParser parser = new FileDefinitionParser( null, false ); String theLine = line[ 0 ] + line[ 1 ]; String[] parts = parser.splitFromInlineComment( theLine ); Assert.assertEquals( "Test failed for '" + theLine + "'", line[ 0 ], parts[ 0 ]); Assert.assertEquals( "Test failed for '" + theLine + "'", line[ 1 ], parts[ 1 ]); } for( String[] line : beforeToAfter ) { FileDefinitionParser parser = new FileDefinitionParser( null, true ); String theLine = line[ 0 ] + line[ 1 ]; String[] parts = parser.splitFromInlineComment( theLine ); Assert.assertEquals( "Test failed for '" + theLine + "'", line[ 0 ], parts[ 0 ]); Assert.assertEquals( "Comment should be empty for '" + theLine + "'", "", parts[ 1 ]); } }
String[] splitFromInlineComment( String line ) { String[] result = new String[] { line, "" }; int index = line.indexOf( ParsingConstants.COMMENT_DELIMITER ); if( index >= 0 ) { result[ 0 ] = line.substring( 0, index ); if( ! this.ignoreComments ) { Matcher m = Pattern.compile( "(\\s+)$" ).matcher( result[ 0 ]); String prefix = ""; if( m.find()) prefix = m.group( 1 ); result[ 1 ] = prefix + line.substring( index ); } result[ 0 ] = result[ 0 ].trim(); } return result; }
FileDefinitionParser { String[] splitFromInlineComment( String line ) { String[] result = new String[] { line, "" }; int index = line.indexOf( ParsingConstants.COMMENT_DELIMITER ); if( index >= 0 ) { result[ 0 ] = line.substring( 0, index ); if( ! this.ignoreComments ) { Matcher m = Pattern.compile( "(\\s+)$" ).matcher( result[ 0 ]); String prefix = ""; if( m.find()) prefix = m.group( 1 ); result[ 1 ] = prefix + line.substring( index ); } result[ 0 ] = result[ 0 ].trim(); } return result; } }
FileDefinitionParser { String[] splitFromInlineComment( String line ) { String[] result = new String[] { line, "" }; int index = line.indexOf( ParsingConstants.COMMENT_DELIMITER ); if( index >= 0 ) { result[ 0 ] = line.substring( 0, index ); if( ! this.ignoreComments ) { Matcher m = Pattern.compile( "(\\s+)$" ).matcher( result[ 0 ]); String prefix = ""; if( m.find()) prefix = m.group( 1 ); result[ 1 ] = prefix + line.substring( index ); } result[ 0 ] = result[ 0 ].trim(); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); }
FileDefinitionParser { String[] splitFromInlineComment( String line ) { String[] result = new String[] { line, "" }; int index = line.indexOf( ParsingConstants.COMMENT_DELIMITER ); if( index >= 0 ) { result[ 0 ] = line.substring( 0, index ); if( ! this.ignoreComments ) { Matcher m = Pattern.compile( "(\\s+)$" ).matcher( result[ 0 ]); String prefix = ""; if( m.find()) prefix = m.group( 1 ); result[ 1 ] = prefix + line.substring( index ); } result[ 0 ] = result[ 0 ].trim(); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); FileDefinition read(); }
FileDefinitionParser { String[] splitFromInlineComment( String line ) { String[] result = new String[] { line, "" }; int index = line.indexOf( ParsingConstants.COMMENT_DELIMITER ); if( index >= 0 ) { result[ 0 ] = line.substring( 0, index ); if( ! this.ignoreComments ) { Matcher m = Pattern.compile( "(\\s+)$" ).matcher( result[ 0 ]); String prefix = ""; if( m.find()) prefix = m.group( 1 ); result[ 1 ] = prefix + line.substring( index ); } result[ 0 ] = result[ 0 ].trim(); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); FileDefinition read();  }