119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall/* 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * Copyright (C) 2012 The Guava Authors 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * Licensed under the Apache License, Version 2.0 (the "License"); 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * you may not use this file except in compliance with the License. 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * You may obtain a copy of the License at 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * http://www.apache.org/licenses/LICENSE-2.0 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 1019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall * Unless required by applicable law or agreed to in writing, software 1119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall * distributed under the License is distributed on an "AS IS" BASIS, 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * See the License for the specific language governing permissions and 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * limitations under the License. 15176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines */ 16176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpackage com.google.common.reflect; 188f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner 1987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarimport static com.google.common.base.Preconditions.checkArgument; 200a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 210d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenkoimport java.lang.reflect.ParameterizedType; 22624421f98d8fcb8ed8ebc406da41217682159aa8Aaron Ballmanimport java.lang.reflect.Type; 23651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2430a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth/** 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * Captures the actual type of {@code T}. 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * @author Ben Yu 280b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall */ 298f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattnerabstract class TypeCapture<T> { 30ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall 311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /** Returns the captured type. */ 320a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor final Type capture() { 330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Type superclass = getClass().getGenericSuperclass(); 340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor checkArgument(superclass instanceof ParameterizedType, 350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor "%s isn't parameterized", superclass); 360a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return ((ParameterizedType) superclass).getActualTypeArguments()[0]; 370a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor} 390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor