private LibraryElement buildLibrary(Source librarySource, ErrorCode... expectedErrorCodes) throws AnalysisException { GatheringErrorListener listener = new GatheringErrorListener(); LibraryElementBuilder builder = new LibraryElementBuilder(new AnalysisContextImpl(), listener); LibraryElement element = builder.buildLibrary(librarySource); listener.assertErrors(expectedErrorCodes); return element; }
public void test_define_duplicate() { final GatheringErrorListener errorListener = new GatheringErrorListener(); Scope rootScope = new Scope() { @Override public AnalysisErrorListener getErrorListener() { return errorListener; } @Override protected Element lookup( Identifier identifier, String name, LibraryElement referencingLibrary) { return null; } }; EnclosedScope scope = new EnclosedScope(rootScope); VariableElement element1 = localVariableElement(identifier("v1")); VariableElement element2 = localVariableElement(identifier("v1")); scope.define(element1); scope.define(element2); errorListener.assertErrors(ErrorSeverity.ERROR); }
/** * Assert that no errors have been gathered. * * @throws AssertionFailedError if any errors have been gathered */ public void assertNoErrors() { assertErrors(NO_ERRORS); }