コード例 #1
0
 /// <summary>
 /// Only outbound references have a CodeRange. All outbound references should have a code range even if the
 /// range is unknown (-1), but inbound references have no range at all (null).
 /// </summary>
 public CodeReferenceEndpoint(
     CodeReferenceType type,
     CodebaseElementName endpoint)
 {
     Type     = type;
     Endpoint = endpoint;
 }
コード例 #2
0
        /// <summary>
        /// An element is also considered to contain itself.
        /// </summary>
        public bool IsContainedIn(CodebaseElementName container)
        {
            if (this == container)
            {
                return(true);
            }

            return(ContainmentParent != null &&
                   ContainmentParent.IsContainedIn(container));
        }
コード例 #3
0
        /// <summary>
        /// Called when method is loaded from a database or parsed from an analyzer
        /// </summary>
        public MethodName(
            CodebaseElementName parent,
            string methodName,
            string returnType,
            IEnumerable <Argument> argumentTypes,
            string overrideArgumentString = "")
        {
            ContainmentParent = parent;
            Package           = parent.Package;

            string paramString;

            if (!string.IsNullOrEmpty(overrideArgumentString))
            {
                paramString = overrideArgumentString;
                // get text between ()
                paramString = paramString.Substring(paramString.IndexOf('(') + 1);
                paramString = paramString.Substring(0, paramString.Length - 1);
            }
            else
            {
                paramString = argumentTypes.Aggregate("", // start with empty string to handle empty list case.
                                                      (current, next) => current + next.Type.FullyQualified + " " + next.Name + ", ");

                if (!string.IsNullOrEmpty(paramString))
                {
                    // trim last ", "
                    paramString = paramString.Substring(0, paramString.Length - 2);
                }
            }

            FullyQualified =
                $"{ContainmentParent.FullyQualified};" +
                $"{methodName}:" +
                $"({paramString}){returnType}";

            if (parent is ClassName className && !string.IsNullOrEmpty(className.JavaFullyQualified))
            {
                JavaFullyQualified =
                    $"{className.JavaFullyQualified}" +
                    $"{methodName}";
                // TODO information loss -> this should include the params and the return type but they aren't solved fully
                //$"{methodName}:{paramString}){returnType}";
            }

            // To the user, constructors are identified by their declaring class' names.
            ShortName =
                methodName == "<init>"
                    ? ContainmentParent.ShortName
                    : methodName;
        }
コード例 #4
0
        /// <summary>
        /// Determines package or directory name based on path of an element
        /// </summary>
        /// <param name="elementName">Should be a <see cref="ClassName"/> or <see cref="FileName"/></param>
        public PackageName(CodebaseElementName elementName)
        {
            char   separator;
            string path;

            switch (elementName.CodebaseElementType)
            {
            case CodebaseElementType.File:
                // the directory location is just the string before the last / in the FQN
                // eg dir1/dir2/file.ext
                separator = '/';
                path      = elementName.FullyQualified;
                break;

            case CodebaseElementType.Class:
                // the package location is after | and before the last . in the FQN
                // eg dir1/dir2/file.ext|package1.package2.class
                separator = '.';
                path      = elementName.FullyQualified.Substring(elementName.FullyQualified.IndexOf('|') + 1);
                break;

            case CodebaseElementType.Method:
            case CodebaseElementType.Field:
            case CodebaseElementType.Package:
            case CodebaseElementType.Unknown:
            default:
                throw new ArgumentOutOfRangeException();
            }

            if (path.Contains(separator))
            {
                FullyQualified = path
                                 .Substring(0, path.LastIndexOf(separator));

                ShortName = FullyQualified.Contains(separator)
                    ? FullyQualified.Substring(FullyQualified.LastIndexOf(separator) + 1)
                    : FullyQualified;

                ParentPackage = CreateParentPackage();
            }
            else
            {
                // Class or file does not have a package, default to 'zero' package
                FullyQualified = "";
                ShortName      = "";
            }
        }