@Test public void shouldDelegateToParentWhenQualifyingSymbolThisIsNotDefinedLocally() { childScope.qualify(unqualified("fn")); verify(parentScope).qualify(unqualified("fn")); }
@Override public Optional<Symbol> qualify(Symbol symbol) { return symbol.accept(new SymbolVisitor<Optional<Symbol>>() { @Override public Optional<Symbol> visit(QualifiedSymbol symbol) { if (moduleName.equals(symbol.getModuleName()) && entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } @Override public Optional<Symbol> visit(UnqualifiedSymbol symbol) { if (entries.containsKey(symbol.qualifyWith(moduleName))) { return Optional.of(symbol.qualifyWith(moduleName)); } else if (entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } }); }
ChildScope extends BlockScope { @Override public Optional<Symbol> qualify(Symbol symbol) { return symbol.accept(new SymbolVisitor<Optional<Symbol>>() { @Override public Optional<Symbol> visit(QualifiedSymbol symbol) { if (moduleName.equals(symbol.getModuleName()) && entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } @Override public Optional<Symbol> visit(UnqualifiedSymbol symbol) { if (entries.containsKey(symbol.qualifyWith(moduleName))) { return Optional.of(symbol.qualifyWith(moduleName)); } else if (entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } }); } }
ChildScope extends BlockScope { @Override public Optional<Symbol> qualify(Symbol symbol) { return symbol.accept(new SymbolVisitor<Optional<Symbol>>() { @Override public Optional<Symbol> visit(QualifiedSymbol symbol) { if (moduleName.equals(symbol.getModuleName()) && entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } @Override public Optional<Symbol> visit(UnqualifiedSymbol symbol) { if (entries.containsKey(symbol.qualifyWith(moduleName))) { return Optional.of(symbol.qualifyWith(moduleName)); } else if (entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } }); } ChildScope(Scope parent, TypeScope types, SymbolResolver resolver, SymbolGenerator symbolGenerator, String moduleName); }
ChildScope extends BlockScope { @Override public Optional<Symbol> qualify(Symbol symbol) { return symbol.accept(new SymbolVisitor<Optional<Symbol>>() { @Override public Optional<Symbol> visit(QualifiedSymbol symbol) { if (moduleName.equals(symbol.getModuleName()) && entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } @Override public Optional<Symbol> visit(UnqualifiedSymbol symbol) { if (entries.containsKey(symbol.qualifyWith(moduleName))) { return Optional.of(symbol.qualifyWith(moduleName)); } else if (entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } }); } ChildScope(Scope parent, TypeScope types, SymbolResolver resolver, SymbolGenerator symbolGenerator, String moduleName); @Override void addLocal(String argument); @Override void capture(String argument); @Override Scope enterScope(); @Override List<String> getCaptures(); @Override Set<Symbol> getContext(Type type); @Override List<String> getLocals(); @Override Optional<TypeClassDescriptor> getMemberOf(ValueReference valueRef); @Override Optional<Operator> getOperator(Symbol symbol); @Override Optional<Type> getRawValue(Symbol symbol); @Override void insertChild(Scope newChild); @Override boolean isDefined(Symbol symbol); @Override void prependLocals(List<String> locals); @Override Optional<Symbol> qualify(Symbol symbol); @Override void setParent(Scope newParent); }
ChildScope extends BlockScope { @Override public Optional<Symbol> qualify(Symbol symbol) { return symbol.accept(new SymbolVisitor<Optional<Symbol>>() { @Override public Optional<Symbol> visit(QualifiedSymbol symbol) { if (moduleName.equals(symbol.getModuleName()) && entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } @Override public Optional<Symbol> visit(UnqualifiedSymbol symbol) { if (entries.containsKey(symbol.qualifyWith(moduleName))) { return Optional.of(symbol.qualifyWith(moduleName)); } else if (entries.containsKey(symbol)) { return Optional.of(symbol); } else { return parent.qualify(symbol); } } }); } ChildScope(Scope parent, TypeScope types, SymbolResolver resolver, SymbolGenerator symbolGenerator, String moduleName); @Override void addLocal(String argument); @Override void capture(String argument); @Override Scope enterScope(); @Override List<String> getCaptures(); @Override Set<Symbol> getContext(Type type); @Override List<String> getLocals(); @Override Optional<TypeClassDescriptor> getMemberOf(ValueReference valueRef); @Override Optional<Operator> getOperator(Symbol symbol); @Override Optional<Type> getRawValue(Symbol symbol); @Override void insertChild(Scope newChild); @Override boolean isDefined(Symbol symbol); @Override void prependLocals(List<String> locals); @Override Optional<Symbol> qualify(Symbol symbol); @Override void setParent(Scope newParent);  }