1 /* 2 * Copyright 2019 Google Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.turbine.binder.lookup; 18 19 import com.google.common.collect.Iterables; 20 import com.google.turbine.binder.sym.ClassSymbol; 21 import org.checkerframework.checker.nullness.qual.Nullable; 22 23 /** 24 * A scope that corresponds to a particular package, which supports iteration over its enclosed 25 * classes. 26 */ 27 public interface PackageScope extends Scope { 28 29 /** Returns the top-level classes enclosed by this package. */ classes()30 Iterable<ClassSymbol> classes(); 31 append(PackageScope next)32 default PackageScope append(PackageScope next) { 33 return concat(this, next); 34 } 35 concat(PackageScope base, PackageScope next)36 static PackageScope concat(PackageScope base, PackageScope next) { 37 return new PackageScope() { 38 @Override 39 public Iterable<ClassSymbol> classes() { 40 return Iterables.concat(base.classes(), next.classes()); 41 } 42 43 @Override 44 public @Nullable LookupResult lookup(LookupKey lookupKey) { 45 LookupResult result = base.lookup(lookupKey); 46 if (result != null) { 47 return result; 48 } 49 return next.lookup(lookupKey); 50 } 51 }; 52 } 53 } 54