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); }
public void test_define_normal() { 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 outerScope = new EnclosedScope(rootScope); EnclosedScope innerScope = new EnclosedScope(outerScope); VariableElement element1 = localVariableElement(identifier("v1")); VariableElement element2 = localVariableElement(identifier("v2")); outerScope.define(element1); innerScope.define(element2); errorListener.assertNoErrors(); }