/// <summary>
        /// Retrieves a list of the code contexts for a given position in a source file.
        /// </summary>
        /// <param name="pDocPos">An IDebugDocumentPosition2 object representing an abstract position in a source file known to the IDE.</param>
        /// <param name="ppEnum">Returns an IEnumDebugCodeContexts2 object that contains a list of the code contexts.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// This method allows the session debug manager (SDM) or IDE to map a source file position into a code
        /// position. More than one code context is returned if the source generates multiple blocks of code (for
        /// example, C++ templates).
        /// </remarks>
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            if (pDocPos == null)
            {
                throw new ArgumentNullException("pDocPos");
            }

            string fileName   = pDocPos.GetFileName();
            int    lineNumber = pDocPos.GetRange().iStartLine + 1;

            List <IDebugCodeContext2>      codeContexts = new List <IDebugCodeContext2>();
            IEnumerable <JavaDebugProgram> programs     = DebugEngine.Programs.ToArray();

            foreach (var program in programs)
            {
                if (!program.IsLoaded)
                {
                    continue;
                }

                IVirtualMachine virtualMachine = program.VirtualMachine;
                ReadOnlyCollection <IReferenceType> classes = virtualMachine.GetAllClasses();
                foreach (var @class in classes)
                {
                    if ([email protected]())
                    {
                        continue;
                    }

                    ReadOnlyCollection <ILocation> locations = @class.GetLocationsOfLine(@class.GetDefaultStratum(), Path.GetFileName(fileName), lineNumber);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null)
                    {
                        codeContexts.Add(new JavaDebugCodeContext(this, bindLocation));
                    }
                }
            }

            if (codeContexts.Count == 0)
            {
                ppEnum = null;
                return(VSConstants.E_FAIL);
            }

            ppEnum = new EnumDebugCodeContexts(codeContexts);
            return(VSConstants.S_OK);
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves a list of the code contexts for a given position in a source file.
        /// </summary>
        /// <param name="pDocPos">An IDebugDocumentPosition2 object representing an abstract position in a source file known to the IDE.</param>
        /// <param name="ppEnum">Returns an IEnumDebugCodeContexts2 object that contains a list of the code contexts.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// This method allows the session debug manager (SDM) or IDE to map a source file position into a code
        /// position. More than one code context is returned if the source generates multiple blocks of code (for
        /// example, C++ templates).
        /// </remarks>
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            if (pDocPos == null)
                throw new ArgumentNullException("pDocPos");

            string fileName = pDocPos.GetFileName();
            int lineNumber = pDocPos.GetRange().iStartLine + 1;

            List<IDebugCodeContext2> codeContexts = new List<IDebugCodeContext2>();
            IEnumerable<JavaDebugProgram> programs = DebugEngine.Programs.ToArray();
            foreach (var program in programs)
            {
                if (!program.IsLoaded)
                    continue;

                IVirtualMachine virtualMachine = program.VirtualMachine;
                ReadOnlyCollection<IReferenceType> classes = virtualMachine.GetAllClasses();
                foreach (var @class in classes)
                {
                    if ([email protected]())
                        continue;

                    ReadOnlyCollection<ILocation> locations = @class.GetLocationsOfLine(@class.GetDefaultStratum(), Path.GetFileName(fileName), lineNumber);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null)
                        codeContexts.Add(new JavaDebugCodeContext(this, bindLocation));
                }
            }

            if (codeContexts.Count == 0)
            {
                ppEnum = null;
                return VSConstants.E_FAIL;
            }

            ppEnum = new EnumDebugCodeContexts(codeContexts);
            return VSConstants.S_OK;
        }