@Test public void lines_of_code() { SourceFile file = ObjectiveCAstScanner.scanSingleFile(new File("src/test/resources/objcSample.h")); Assert.assertThat(file.getInt(ObjectiveCMetric.LINES_OF_CODE), Matchers.is(5)); }
public static SourceFile scanSingleFile(File file) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(ObjectiveCConfiguration.create(Charset.defaultCharset())); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned."); } return (SourceFile) sources.iterator().next(); }
ObjectiveCAstScanner { public static SourceFile scanSingleFile(File file) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(ObjectiveCConfiguration.create(Charset.defaultCharset())); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned."); } return (SourceFile) sources.iterator().next(); } }
ObjectiveCAstScanner { public static SourceFile scanSingleFile(File file) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(ObjectiveCConfiguration.create(Charset.defaultCharset())); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned."); } return (SourceFile) sources.iterator().next(); } private  ObjectiveCAstScanner(); }
ObjectiveCAstScanner { public static SourceFile scanSingleFile(File file) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(ObjectiveCConfiguration.create(Charset.defaultCharset())); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned."); } return (SourceFile) sources.iterator().next(); } private  ObjectiveCAstScanner(); static SourceFile scanSingleFile(File file); static AstScanner<ObjectiveCGrammar> create(ObjectiveCConfiguration conf); }
ObjectiveCAstScanner { public static SourceFile scanSingleFile(File file) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(ObjectiveCConfiguration.create(Charset.defaultCharset())); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned."); } return (SourceFile) sources.iterator().next(); } private  ObjectiveCAstScanner(); static SourceFile scanSingleFile(File file); static AstScanner<ObjectiveCGrammar> create(ObjectiveCConfiguration conf);  }