1 /* 2 * Copyright 2016 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 static java.util.Objects.requireNonNull; 20 21 import com.google.common.collect.ImmutableList; 22 import com.google.errorprone.annotations.Immutable; 23 import com.google.turbine.binder.sym.ClassSymbol; 24 import com.google.turbine.binder.sym.Symbol; 25 import com.google.turbine.tree.Tree; 26 27 /** 28 * The result of a canonical type name lookup. 29 * 30 * <p>For example, a lookup of {@code java.util.HashMap.Entry} may result in the {@link ClassSymbol} 31 * for {@code java.util.HashMap}, and the remaining nested type name {@code Entry}. 32 */ 33 @Immutable 34 public class LookupResult { 35 36 /** A top-level class symbol. */ sym()37 public Symbol sym() { 38 return sym; 39 } 40 41 /** The remaining nested type names. */ remaining()42 public ImmutableList<Tree.Ident> remaining() { 43 return remaining; 44 } 45 46 private final Symbol sym; 47 private final ImmutableList<Tree.Ident> remaining; 48 LookupResult(Symbol sym, LookupKey remaining)49 public LookupResult(Symbol sym, LookupKey remaining) { 50 this.sym = requireNonNull(sym); 51 this.remaining = remaining.hasNext() ? remaining.rest().simpleNames() : ImmutableList.of(); 52 } 53 } 54