src/share/classes/com/sun/tools/javac/jvm/ClassReader.java

changeset 1473
31780dd06ec7
parent 1452
de1ec6fc93fe
child 1521
71f35e4b93a5
child 1569
475eb15dfdad
equal deleted inserted replaced
1472:0c244701188e 1473:31780dd06ec7
214 214
215 /** 215 /**
216 * Whether or not any parameter names have been found. 216 * Whether or not any parameter names have been found.
217 */ 217 */
218 boolean haveParameterNameIndices; 218 boolean haveParameterNameIndices;
219
220 /** Set this to false every time we start reading a method
221 * and are saving parameter names. Set it to true when we see
222 * MethodParameters, if it's set when we see a LocalVariableTable,
223 * then we ignore the parameter names from the LVT.
224 */
225 boolean sawMethodParameters;
219 226
220 /** 227 /**
221 * The set of attribute names for which warnings have been generated for the current class 228 * The set of attribute names for which warnings have been generated for the current class
222 */ 229 */
223 Set<Name> warnedAttrs = new HashSet<Name>(); 230 Set<Name> warnedAttrs = new HashSet<Name>();
982 }, 989 },
983 990
984 new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) { 991 new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
985 protected void read(Symbol sym, int attrLen) { 992 protected void read(Symbol sym, int attrLen) {
986 int newbp = bp + attrLen; 993 int newbp = bp + attrLen;
987 if (saveParameterNames) { 994 if (saveParameterNames && !sawMethodParameters) {
988 // Pick up parameter names from the variable table. 995 // Pick up parameter names from the variable table.
989 // Parameter names are not explicitly identified as such, 996 // Parameter names are not explicitly identified as such,
990 // but all parameter name entries in the LocalVariableTable 997 // but all parameter name entries in the LocalVariableTable
991 // have a start_pc of 0. Therefore, we record the name 998 // have a start_pc of 0. Therefore, we record the name
992 // indicies of all slots with a start_pc of zero in the 999 // indicies of all slots with a start_pc of zero in the
1014 } 1021 }
1015 } 1022 }
1016 bp = newbp; 1023 bp = newbp;
1017 } 1024 }
1018 }, 1025 },
1026
1027 new AttributeReader(names.MethodParameters, V52, MEMBER_ATTRIBUTE) {
1028 protected void read(Symbol sym, int attrlen) {
1029 int newbp = bp + attrlen;
1030 if (saveParameterNames) {
1031 sawMethodParameters = true;
1032 int numEntries = nextByte();
1033 parameterNameIndices = new int[numEntries];
1034 haveParameterNameIndices = true;
1035 for (int i = 0; i < numEntries; i++) {
1036 int nameIndex = nextChar();
1037 int flags = nextInt();
1038 parameterNameIndices[i] = nameIndex;
1039 }
1040 }
1041 bp = newbp;
1042 }
1043 },
1044
1019 1045
1020 new AttributeReader(names.SourceFile, V45_3, CLASS_ATTRIBUTE) { 1046 new AttributeReader(names.SourceFile, V45_3, CLASS_ATTRIBUTE) {
1021 protected void read(Symbol sym, int attrLen) { 1047 protected void read(Symbol sym, int attrLen) {
1022 ClassSymbol c = (ClassSymbol) sym; 1048 ClassSymbol c = (ClassSymbol) sym;
1023 Name n = readName(nextChar()); 1049 Name n = readName(nextChar());
1824 || parameterNameIndices.length < expectedParameterSlots) { 1850 || parameterNameIndices.length < expectedParameterSlots) {
1825 parameterNameIndices = new int[expectedParameterSlots]; 1851 parameterNameIndices = new int[expectedParameterSlots];
1826 } else 1852 } else
1827 Arrays.fill(parameterNameIndices, 0); 1853 Arrays.fill(parameterNameIndices, 0);
1828 haveParameterNameIndices = false; 1854 haveParameterNameIndices = false;
1855 sawMethodParameters = false;
1829 } 1856 }
1830 1857
1831 /** 1858 /**
1832 * Set the parameter names for a symbol from the name index in the 1859 * Set the parameter names for a symbol from the name index in the
1833 * parameterNameIndicies array. The type of the symbol may have changed 1860 * parameterNameIndicies array. The type of the symbol may have changed
1843 */ 1870 */
1844 void setParameterNames(MethodSymbol sym, Type jvmType) { 1871 void setParameterNames(MethodSymbol sym, Type jvmType) {
1845 // if no names were found in the class file, there's nothing more to do 1872 // if no names were found in the class file, there's nothing more to do
1846 if (!haveParameterNameIndices) 1873 if (!haveParameterNameIndices)
1847 return; 1874 return;
1848 1875 // If we get parameter names from MethodParameters, then we
1849 int firstParam = ((sym.flags() & STATIC) == 0) ? 1 : 0; 1876 // don't need to skip.
1850 // the code in readMethod may have skipped the first parameter when 1877 int firstParam = 0;
1851 // setting up the MethodType. If so, we make a corresponding allowance 1878 if (!sawMethodParameters) {
1852 // here for the position of the first parameter. Note that this 1879 firstParam = ((sym.flags() & STATIC) == 0) ? 1 : 0;
1853 // assumes the skipped parameter has a width of 1 -- i.e. it is not 1880 // the code in readMethod may have skipped the first
1881 // parameter when setting up the MethodType. If so, we
1882 // make a corresponding allowance here for the position of
1883 // the first parameter. Note that this assumes the
1884 // skipped parameter has a width of 1 -- i.e. it is not
1854 // a double width type (long or double.) 1885 // a double width type (long or double.)
1855 if (sym.name == names.init && currentOwner.hasOuterInstance()) { 1886 if (sym.name == names.init && currentOwner.hasOuterInstance()) {
1856 // Sometimes anonymous classes don't have an outer 1887 // Sometimes anonymous classes don't have an outer
1857 // instance, however, there is no reliable way to tell so 1888 // instance, however, there is no reliable way to tell so
1858 // we never strip this$n 1889 // we never strip this$n
1859 if (!currentOwner.name.isEmpty()) 1890 if (!currentOwner.name.isEmpty())
1860 firstParam += 1; 1891 firstParam += 1;
1861 } 1892 }
1862 1893
1863 if (sym.type != jvmType) { 1894 if (sym.type != jvmType) {
1864 // reading the method attributes has caused the symbol's type to 1895 // reading the method attributes has caused the
1865 // be changed. (i.e. the Signature attribute.) This may happen if 1896 // symbol's type to be changed. (i.e. the Signature
1866 // there are hidden (synthetic) parameters in the descriptor, but 1897 // attribute.) This may happen if there are hidden
1867 // not in the Signature. The position of these hidden parameters 1898 // (synthetic) parameters in the descriptor, but not
1868 // is unspecified; for now, assume they are at the beginning, and 1899 // in the Signature. The position of these hidden
1869 // so skip over them. The primary case for this is two hidden 1900 // parameters is unspecified; for now, assume they are
1870 // parameters passed into Enum constructors. 1901 // at the beginning, and so skip over them. The
1902 // primary case for this is two hidden parameters
1903 // passed into Enum constructors.
1871 int skip = Code.width(jvmType.getParameterTypes()) 1904 int skip = Code.width(jvmType.getParameterTypes())
1872 - Code.width(sym.type.getParameterTypes()); 1905 - Code.width(sym.type.getParameterTypes());
1873 firstParam += skip; 1906 firstParam += skip;
1907 }
1874 } 1908 }
1875 List<Name> paramNames = List.nil(); 1909 List<Name> paramNames = List.nil();
1876 int index = firstParam; 1910 int index = firstParam;
1877 for (Type t: sym.type.getParameterTypes()) { 1911 for (Type t: sym.type.getParameterTypes()) {
1878 int nameIdx = (index < parameterNameIndices.length 1912 int nameIdx = (index < parameterNameIndices.length

mercurial