Пример #1
0
        public override AnnotationVisitor VisitParameterAnnotation(int parameter, string
                                                                   descriptor, bool visible)
        {
            var annotation = new AnnotationNode(descriptor);

            if (visible)
            {
                if (visibleParameterAnnotations == null)
                {
                    var @params = Type.GetArgumentTypes(desc).Length;
                    visibleParameterAnnotations = new List <AnnotationNode> [@params]
                    ;
                }

                visibleParameterAnnotations[parameter] = Util.Add(visibleParameterAnnotations[parameter
                                                                  ], annotation);
            }
            else
            {
                if (invisibleParameterAnnotations == null)
                {
                    var @params = Type.GetArgumentTypes(desc).Length;
                    invisibleParameterAnnotations = new List <AnnotationNode> [@params
                                                    ];
                }

                invisibleParameterAnnotations[parameter] = Util.Add(invisibleParameterAnnotations
                                                                    [parameter], annotation);
            }

            return(annotation);
        }
Пример #2
0
        public override AnnotationVisitor VisitAnnotation(string name, string descriptor)
        {
            if (values == null)
            {
                values = new List <object>(desc != null ? 2 : 1);
            }
            if (desc != null)
            {
                values.Add(name);
            }
            var annotation = new AnnotationNode(descriptor);

            values.Add(annotation);
            return(annotation);
        }
Пример #3
0
        // -----------------------------------------------------------------------------------------------
        // Implementation of the FieldVisitor abstract class
        // -----------------------------------------------------------------------------------------------
        public override AnnotationVisitor VisitAnnotation(string descriptor, bool visible
                                                          )
        {
            var annotation = new AnnotationNode(descriptor);

            if (visible)
            {
                visibleAnnotations = Util.Add(visibleAnnotations, annotation);
            }
            else
            {
                invisibleAnnotations = Util.Add(invisibleAnnotations, annotation);
            }
            return(annotation);
        }
Пример #4
0
        /// <summary>Makes the given method visitor visit this method.</summary>
        /// <param name="methodVisitor">a method visitor.</param>
        public virtual void Accept(MethodVisitor methodVisitor)
        {
            // Visit the parameters.
            if (parameters != null)
            {
                for (int i = 0, n = parameters.Count; i < n; i++)
                {
                    parameters[i].Accept(methodVisitor);
                }
            }
            // Visit the annotations.
            if (annotationDefault != null)
            {
                var annotationVisitor = methodVisitor.VisitAnnotationDefault();
                AnnotationNode.Accept(annotationVisitor, null, annotationDefault);
                if (annotationVisitor != null)
                {
                    annotationVisitor.VisitEnd();
                }
            }

            if (visibleAnnotations != null)
            {
                for (int i = 0, n = visibleAnnotations.Count; i < n; ++i)
                {
                    var annotation = visibleAnnotations[i];
                    annotation.Accept(methodVisitor.VisitAnnotation(annotation.desc, true));
                }
            }

            if (invisibleAnnotations != null)
            {
                for (int i = 0, n = invisibleAnnotations.Count; i < n; ++i)
                {
                    var annotation = invisibleAnnotations[i];
                    annotation.Accept(methodVisitor.VisitAnnotation(annotation.desc, false));
                }
            }

            if (visibleTypeAnnotations != null)
            {
                for (int i = 0, n = visibleTypeAnnotations.Count; i < n; ++i)
                {
                    var typeAnnotation = visibleTypeAnnotations[i];
                    typeAnnotation.Accept(methodVisitor.VisitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation
                                                                            .typePath, typeAnnotation.desc, true));
                }
            }

            if (invisibleTypeAnnotations != null)
            {
                for (int i = 0, n = invisibleTypeAnnotations.Count; i < n; ++i)
                {
                    var typeAnnotation = invisibleTypeAnnotations[i];
                    typeAnnotation.Accept(methodVisitor.VisitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation
                                                                            .typePath, typeAnnotation.desc, false));
                }
            }

            if (visibleAnnotableParameterCount > 0)
            {
                methodVisitor.VisitAnnotableParameterCount(visibleAnnotableParameterCount, true);
            }
            if (visibleParameterAnnotations != null)
            {
                for (int i = 0, n = visibleParameterAnnotations.Length; i < n; ++i)
                {
                    IList <AnnotationNode> parameterAnnotations = visibleParameterAnnotations[i];
                    if (parameterAnnotations == null)
                    {
                        continue;
                    }
                    for (int j = 0, m = parameterAnnotations.Count; j < m; ++j)
                    {
                        var annotation = parameterAnnotations[j];
                        annotation.Accept(methodVisitor.VisitParameterAnnotation(i, annotation.desc, true
                                                                                 ));
                    }
                }
            }

            if (invisibleAnnotableParameterCount > 0)
            {
                methodVisitor.VisitAnnotableParameterCount(invisibleAnnotableParameterCount, false
                                                           );
            }
            if (invisibleParameterAnnotations != null)
            {
                for (int i = 0, n = invisibleParameterAnnotations.Length; i < n; ++i)
                {
                    IList <AnnotationNode> parameterAnnotations = invisibleParameterAnnotations[i];
                    if (parameterAnnotations == null)
                    {
                        continue;
                    }
                    for (int j = 0, m = parameterAnnotations.Count; j < m; ++j)
                    {
                        var annotation = parameterAnnotations[j];
                        annotation.Accept(methodVisitor.VisitParameterAnnotation(i, annotation.desc, false
                                                                                 ));
                    }
                }
            }

            // Visit the non standard attributes.
            if (visited)
            {
                instructions.ResetLabels();
            }
            if (attrs != null)
            {
                for (int i = 0, n = attrs.Count; i < n; ++i)
                {
                    methodVisitor.VisitAttribute(attrs[i]);
                }
            }
            // Visit the code.
            if (instructions.Size() > 0)
            {
                methodVisitor.VisitCode();
                // Visits the try catch blocks.
                if (tryCatchBlocks != null)
                {
                    for (int i = 0, n = tryCatchBlocks.Count; i < n; ++i)
                    {
                        tryCatchBlocks[i].UpdateIndex(i);
                        tryCatchBlocks[i].Accept(methodVisitor);
                    }
                }

                // Visit the instructions.
                instructions.Accept(methodVisitor);
                // Visits the local variables.
                if (localVariables != null)
                {
                    for (int i = 0, n = localVariables.Count; i < n; ++i)
                    {
                        localVariables[i].Accept(methodVisitor);
                    }
                }
                // Visits the local variable annotations.
                if (visibleLocalVariableAnnotations != null)
                {
                    for (int i = 0, n = visibleLocalVariableAnnotations.Count; i < n; ++i)
                    {
                        visibleLocalVariableAnnotations[i].Accept(methodVisitor, true);
                    }
                }
                if (invisibleLocalVariableAnnotations != null)
                {
                    for (int i = 0, n = invisibleLocalVariableAnnotations.Count; i < n; ++i)
                    {
                        invisibleLocalVariableAnnotations[i].Accept(methodVisitor, false);
                    }
                }
                methodVisitor.VisitMaxs(maxStack, maxLocals);
                visited = true;
            }

            methodVisitor.VisitEnd();
        }