Exemplo n.º 1
0
 /// <summary>
 /// Constructor to create a method fullname from a class name (or nested 
 /// class name) and a bare method name.
 /// </summary>
 internal FullNameToken(FullNameToken parent, string methodName)
     : this(parent.NamespaceName, parent.ClassName, parent.NestedName, "::" + methodName)
 {
     if (parent._methodName != "") {
         throw new ApplicationException("Only FullNameToken without method name can be combined with a methodName");
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor to create a method fullname from a class name (or nested
 /// class name) and a bare method name.
 /// </summary>
 internal FullNameToken(FullNameToken parent, string methodName)
     : this(parent.NamespaceName, parent.ClassName, parent.NestedName, "::" + methodName)
 {
     if (parent._methodName != "")
     {
         throw new ApplicationException("Only FullNameToken without method name can be combined with a methodName");
     }
 }
Exemplo n.º 3
0
 internal Dependency(FullNameToken usingItem, FullNameToken usedItem, string fileName, uint startLine, uint startColumn,
                     uint endLine, uint endColumn)
     : this(usingItem.ToString(),
            usingItem.NamespaceName,
            usedItem.ToString(),
            usedItem.NamespaceName,
            fileName,
            startLine, startColumn, endLine, endColumn)
 {
     // empty
 }
Exemplo n.º 4
0
 internal Dependency(FullNameToken usingItem, FullNameToken usedItem, string fileName, uint startLine, uint startColumn,
                     uint endLine, uint endColumn)
     : this(usingItem.ToString(),
            usingItem.NamespaceName,
            usedItem.ToString(),
            usedItem.NamespaceName,
            fileName,
            startLine, startColumn, endLine, endColumn)
 {
     // empty
 }
Exemplo n.º 5
0
        private static IEnumerable <Dependency> GetDependencies(FullNameToken callingToken, TypeReference calledType,
                                                                string methodName,
                                                                SequencePoint sequencePoint)
        {
            if (calledType is TypeSpecification)
            {
                // E.g. the reference type System.Int32&, which is used for out parameters.
                // or an arraytype?!?
                calledType = ((TypeSpecification)calledType).ElementType;
            }
            if (!(calledType is GenericInstanceType) && !(calledType is GenericParameter))
            {
                // Currently, we do not look at generic type parameters; we would have to
                // untangle the usage of an actual (non-type-parameter) type's member
                // to get a useful dependency for the user.
                FullNameToken calledToken = GetFullnameToken(calledType, methodName);
                string        fileName    = null;
                uint          startLine   = 0;
                uint          startColumn = 0;
                uint          endLine     = 0;
                uint          endColumn   = 0;
                if (sequencePoint != null)
                {
                    fileName    = sequencePoint.Document.Url;
                    startLine   = (uint)sequencePoint.StartLine;
                    startColumn = (uint)sequencePoint.StartColumn;
                    endLine     = (uint)sequencePoint.EndLine;
                    endColumn   = (uint)sequencePoint.EndColumn;
                }
                yield return(new Dependency(callingToken, calledToken, fileName, startLine, startColumn, endLine, endColumn));
            }

            var genericInstanceType = calledType as GenericInstanceType;

            if (genericInstanceType != null)
            {
                foreach (TypeReference genericArgument in genericInstanceType.GenericArguments)
                {
                    foreach (
                        Dependency dependency in GetDependencies(callingToken, genericArgument, null, sequencePoint))
                    {
                        yield return(dependency);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static IEnumerable <Dependency> AnalyzeType(TypeDefinition type)
        {
            FullNameToken callingToken = GetFullnameToken(type);

            if (type.BaseType != null && !IsLinked(type.BaseType, type.DeclaringType))
            {
                foreach (Dependency dependency in GetDependencies(callingToken, type.BaseType, null, null))
                {
                    yield return(dependency);
                }
            }

            foreach (TypeReference interfaceRef in type.Interfaces)
            {
                foreach (Dependency dependency in GetDependencies(callingToken, interfaceRef, null, null))
                {
                    yield return(dependency);
                }
            }

            foreach (FieldDefinition field in type.Fields)
            {
                if (IsLinked(field.FieldType, type.DeclaringType))
                {
                    foreach (Dependency dependency in GetDependencies(callingToken, field.FieldType, null, null))
                    {
                        yield return(dependency);
                    }
                }
            }

            foreach (EventDefinition @event in type.Events)
            {
                foreach (Dependency dependency in GetDependencies(callingToken, @event.EventType, null, null))
                {
                    yield return(dependency);
                }
            }

            foreach (PropertyDefinition property in type.Properties)
            {
                if (!IsLinked(property.PropertyType, type.DeclaringType))
                {
                    foreach (Dependency dependency in GetDependencies(callingToken, property.PropertyType, null, null))
                    {
                        yield return(dependency);
                    }
                }
            }

            foreach (CustomAttribute customAttribute in type.CustomAttributes)
            {
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, customAttribute.Constructor.DeclaringType, null, null))
                {
                    yield return(dependency);
                }
            }

            foreach (MethodDefinition method in type.Methods)
            {
                callingToken = GetFullnameToken(type, method.Name);
                foreach (Dependency dependency in AnalyzeMethod(type, callingToken, method))
                {
                    yield return(dependency);
                }
            }

            foreach (TypeDefinition nestedType in type.NestedTypes)
            {
                foreach (Dependency dependency in AnalyzeType(nestedType))
                {
                    yield return(dependency);
                }
            }
        }
Exemplo n.º 7
0
        private static IEnumerable <Dependency> AnalyzeInstruction(TypeDefinition owner, FullNameToken callingToken,
                                                                   Instruction instruction, SequencePoint sequencePoint)
        {
            var methodReference = instruction.Operand as MethodReference;

            // Durch die !IsLinked-Bedingung wird der Test MainTests.Exit0Aspects mit den Calls
            // zwischen Nested-Klassen in NDepCheck.TestAssembly.cs - Klasse Class14.Class13EInner2, Methode SpecialMethodOfInnerClass
            // rot: Weil die Calls zwischen der Class14 und der Nested Class wegen IsLinked==true hier einfach ausgefiltert
            // werden ...
            // WIESO SOLL DAS SO SEIN? - bitte um Erklärung! ==> SIehe nun temporäre Änderung an IsLinked - IST DAS OK?
            if (methodReference != null && !IsLinked(methodReference.DeclaringType, owner))
            {
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, methodReference.DeclaringType, methodReference.Name, sequencePoint)
                    )
                {
                    yield return(dependency);
                }
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, methodReference.ReturnType, null, sequencePoint))
                {
                    yield return(dependency);
                }
            }

            var field = instruction.Operand as FieldDefinition;

            if (field != null && !IsLinked(field.DeclaringType, owner))
            {
                foreach (Dependency dependency in GetDependencies(callingToken, field.FieldType, null, sequencePoint))
                {
                    yield return(dependency);
                }
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, field.DeclaringType, field.Name, sequencePoint))
                {
                    yield return(dependency);
                }
            }

            var property = instruction.Operand as PropertyDefinition;

            if (property != null && !IsLinked(property.DeclaringType, owner))
            {
                foreach (
                    Dependency dependency in GetDependencies(callingToken, property.PropertyType, null, sequencePoint))
                {
                    yield return(dependency);
                }
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, property.DeclaringType, property.Name, sequencePoint))
                {
                    yield return(dependency);
                }
            }
        }
Exemplo n.º 8
0
        private static IEnumerable <Dependency> AnalyzeMethod(TypeDefinition owner, FullNameToken callingToken,
                                                              MethodDefinition method)
        {
            foreach (CustomAttribute customAttribute in method.CustomAttributes)
            {
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, customAttribute.Constructor.DeclaringType, null, null))
                {
                    yield return(dependency);
                }
                foreach (
                    Dependency dependency in
                    GetDependencies(callingToken, customAttribute.Constructor.DeclaringType,
                                    customAttribute.Constructor.Name, null))
                {
                    yield return(dependency);
                }
            }

            foreach (ParameterDefinition parameter in method.Parameters)
            {
                foreach (Dependency dependency in GetDependencies(callingToken, parameter.ParameterType, null, null))
                {
                    yield return(dependency);
                }
            }

            if (method.ReturnType != null && !IsLinked(method.ReturnType, method.DeclaringType.DeclaringType))
            {
                foreach (
                    Dependency dependency in GetDependencies(callingToken, method.ReturnType, null, null))
                {
                    yield return(dependency);
                }
            }

            if (method.HasBody)
            {
                foreach (VariableDefinition variable in method.Body.Variables)
                {
                    if (!IsLinked(variable.VariableType, method.DeclaringType.DeclaringType))
                    {
                        foreach (
                            Dependency dependency in GetDependencies(callingToken, variable.VariableType, null, null))
                        {
                            yield return(dependency);
                        }
                    }
                }

                SequencePoint mostRecentSeqPoint = null;
                foreach (Instruction instruction in method.Body.Instructions)
                {
                    if (instruction.SequencePoint != null)
                    {
                        mostRecentSeqPoint = instruction.SequencePoint;
                    }
                    foreach (
                        Dependency dependency in
                        AnalyzeInstruction(owner, callingToken, instruction, mostRecentSeqPoint))
                    {
                        yield return(dependency);
                    }
                }
            }
        }