public virtual int GetOffset(int index)
 {
     return(collinstr.GetKey(index));
 }
Exemple #2
0
        private void RenameClassIdentifiers(StructClass cl, Dictionary <string, string> names
                                            )
        {
            // all classes are already renamed
            string classOldFullName = cl.qualifiedName;
            string classNewFullName = interceptor.GetName(classOldFullName);

            if (classNewFullName == null)
            {
                classNewFullName = classOldFullName;
            }
            // methods
            HashSet <string> setMethodNames = new HashSet <string>();

            foreach (StructMethod md in cl.GetMethods())
            {
                setMethodNames.Add(md.GetName());
            }
            VBStyleCollection <StructMethod, string> methods = cl.GetMethods();

            for (int i = 0; i < methods.Count; i++)
            {
                StructMethod mt        = methods[i];
                string       key       = methods.GetKey(i);
                bool         isPrivate = mt.HasModifier(ICodeConstants.Acc_Private);
                string       name      = mt.GetName();
                if (!cl.IsOwn() || mt.HasModifier(ICodeConstants.Acc_Native))
                {
                    // external and native methods must not be renamed
                    if (!isPrivate)
                    {
                        Sharpen.Collections.Put(names, key, name);
                    }
                }
                else if (helper.ToBeRenamed(IIdentifierRenamer.Type.Element_Method, classOldFullName
                                            , name, mt.GetDescriptor()))
                {
                    if (isPrivate || !names.ContainsKey(key))
                    {
                        do
                        {
                            name = helper.GetNextMethodName(classOldFullName, name, mt.GetDescriptor());
                        }while (setMethodNames.Contains(name));
                        if (!isPrivate)
                        {
                            Sharpen.Collections.Put(names, key, name);
                        }
                    }
                    else
                    {
                        name = names.GetOrNull(key);
                    }
                    interceptor.AddName(classOldFullName + " " + mt.GetName() + " " + mt.GetDescriptor
                                            (), classNewFullName + " " + name + " " + BuildNewDescriptor(false, mt.GetDescriptor
                                                                                                             ()));
                }
            }
            // external fields are not being renamed
            if (!cl.IsOwn())
            {
                return;
            }
            // fields
            // FIXME: should overloaded fields become the same name?
            HashSet <string> setFieldNames = new HashSet <string>();

            foreach (StructField fd in cl.GetFields())
            {
                setFieldNames.Add(fd.GetName());
            }
            foreach (StructField fd in cl.GetFields())
            {
                if (helper.ToBeRenamed(IIdentifierRenamer.Type.Element_Field, classOldFullName, fd
                                       .GetName(), fd.GetDescriptor()))
                {
                    string newName;
                    do
                    {
                        newName = helper.GetNextFieldName(classOldFullName, fd.GetName(), fd.GetDescriptor
                                                              ());
                    }while (setFieldNames.Contains(newName));
                    interceptor.AddName(classOldFullName + " " + fd.GetName() + " " + fd.GetDescriptor
                                            (), classNewFullName + " " + newName + " " + BuildNewDescriptor(true, fd.GetDescriptor
                                                                                                                ()));
                }
            }
        }