Home | History | Annotate | Download | only in dex
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      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 signature.converter.dex;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.assertSame;
     21 import dex.reader.DexTestsCommon;
     22 import dex.reader.util.JavaSource;
     23 import dex.reader.util.JavaSourceToDexUtil;
     24 import dex.structure.DexClass;
     25 import dex.structure.DexFile;
     26 
     27 import org.junit.Before;
     28 import org.junit.Test;
     29 
     30 import signature.converter.dex.DexToSigConverter;
     31 import signature.converter.dex.DexUtil;
     32 import signature.converter.dex.GenericSignatureParser;
     33 import signature.model.impl.SigClassDefinition;
     34 import signature.model.util.TypePool;
     35 
     36 import java.io.IOException;
     37 
     38 public class GenericSignatureParserTest extends DexTestsCommon{
     39 
     40     private DexToSigConverter converter;
     41     private JavaSourceToDexUtil dexUtil;
     42     private GenericSignatureParser parser;
     43 
     44     @Before
     45     public void setupConverter(){
     46         converter = new DexToSigConverter();
     47         dexUtil = new JavaSourceToDexUtil();
     48         parser = new GenericSignatureParser(new TypePool(), converter);
     49     }
     50 
     51     @Test
     52     public void getGenericSignatureTest() throws IOException {
     53         DexFile  dexFile =  dexUtil.getFrom(new JavaSource("B", "public class B<T>{}"));
     54         DexClass dexClass = getClass(dexFile, "LB;");
     55         assertEquals("<T:Ljava/lang/Object;>Ljava/lang/Object;", DexUtil.getGenericSignature(dexClass));
     56         SigClassDefinition sigClass = converter.convertClass(dexClass);
     57 
     58         parser.parseForClass(sigClass, DexUtil.getGenericSignature(dexClass));
     59         //type parameter name
     60         assertEquals(1, parser.formalTypeParameters.size());
     61         assertEquals("T", parser.formalTypeParameters.get(0).getName());
     62         //type parameter declaration
     63         assertSame(sigClass, parser.formalTypeParameters.get(0).getGenericDeclaration());
     64         //type parameter upper bounds
     65         assertEquals(1, parser.formalTypeParameters.get(0).getUpperBounds().size());
     66 //        IType type = parser.formalTypeParameters.get(0).getUpperBounds().get(0);
     67 
     68     }
     69 }
     70