Exemple #1
0
        public virtual ParameterInfo[] getParameters(string methodName, Type c)
        {
            ParameterInfo[] parameters = null;

            try
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                ClassReader cr      = new ClassReader(c.FullName.Replace('.', '/'));
                Method[]    methods = c.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                if (methods != null)
                {
                    AnalyzerClassVisitor cn = null;
                    for (int i = 0; i < methods.Length; i++)
                    {
                        if (methodName.Equals(methods[i].Name))
                        {
                            cn = new AnalyzerClassVisitor(methods[i]);
                            break;
                        }
                    }

                    if (cn != null)
                    {
                        cr.accept(cn, 0);
                        parameters = cn.Parameters;
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("Cannot read class", e);
            }

            return(parameters);
        }
Exemple #2
0
        public virtual Type specialize(string name, Type c, Dictionary <string, object> variables)
        {
            ClassWriter  cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
            ClassVisitor cv = cw;

            StringWriter debugOutput = null;

            if (log.TraceEnabled)
            {
                // Dump the class to be specialized (only once)
                if (!tracedClasses.Contains(c))
                {
                    StringWriter classTrace   = new StringWriter();
                    ClassVisitor classTraceCv = new TraceClassVisitor(new PrintWriter(classTrace));
                    try
                    {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        ClassReader cr = new ClassReader(c.FullName.Replace('.', '/'));
                        cr.accept(classTraceCv, 0);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        log.trace(string.Format("Dump of class to be specialized: {0}", c.FullName));
                        log.trace(classTrace);
                    }
                    catch (IOException)
                    {
                        // Ignore Exception
                    }
                    tracedClasses.Add(c);
                }

                log.trace(string.Format("Specializing class {0}", name));
                string[] variableNames = variables.Keys.toArray(new string[variables.Count]);
                Array.Sort(variableNames);
                foreach (string variableName in variableNames)
                {
                    log.trace(string.Format("Variable {0}={1}", variableName, variables[variableName]));
                }

                debugOutput = new StringWriter();
                PrintWriter debugPrintWriter = new PrintWriter(debugOutput);
                cv = new TraceClassVisitor(cv, debugPrintWriter);
                //cv = new TraceClassVisitor(debugPrintWriter);
            }

            try
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                ClassReader cr = new ClassReader(c.FullName.Replace('.', '/'));
                ClassNode   cn = new SpecializedClassVisitor(name, variables);
                cr.accept(cn, 0);
                cn.accept(cv);
            }
            catch (IOException e)
            {
                Console.WriteLine("Cannot read class", e);
            }

            if (debugOutput != null)
            {
                log.trace(debugOutput.ToString());
            }

            Type specializedClass = null;

            try
            {
                specializedClass = classLoader.defineClass(name, cw.toByteArray());
            }
            catch (ClassFormatError e)
            {
                Console.WriteLine("Error while defining specialized class", e);
            }

            return(specializedClass);
        }