예제 #1
0
 public ClassEntry(IClass cls, FileEntry fileEntry, NamespaceEntry namespaceRef)
 {
     this.cls = cls;
     this.fileEntry = fileEntry;
     this.namespaceRef = namespaceRef;
     this.name = cls.Name;
     position = -1;
 }
        bool GetBestNamespaceEntry(string[] path, int length, bool createPath, bool caseSensitive, out NamespaceEntry lastEntry, out int numMatched)
        {
            lastEntry = rootNamespace;

            if (length == 0 || (length == 1 && path[0] == "")) {
                numMatched = length;
                return true;
            }
            else
            {
                for (int n=0; n<length; n++) {
                    NamespaceEntry nh = lastEntry.GetNamespace (path[n], caseSensitive);
                    if (nh == null) {
                        if (!createPath) {
                            numMatched = n;
                            return false;
                        }

                        nh = new NamespaceEntry ();
                        lastEntry.Add (path[n], nh);
                    }
                    lastEntry = nh;
                }
                numMatched = length;
                return true;
            }
        }
        public ClassUpdateInformation UpdateClassInformation(ClassCollection newClasses, string fileName)
        {
            lock (rwlock)
            {
                ClassUpdateInformation res = new ClassUpdateInformation ();

                FileEntry fe = files [fileName] as FileEntry;
                if (fe == null) return null;

                bool[] added = new bool [newClasses.Count];
                NamespaceEntry[] newNss = new NamespaceEntry [newClasses.Count];
                for (int n=0; n<newClasses.Count; n++) {
                    string[] path = newClasses[n].Namespace.Split ('.');
                    newNss[n] = GetNamespaceEntry (path, path.Length, true, true);
                }

                ArrayList newFileClasses = new ArrayList ();

                if (fe != null)
                {
                    ClassEntry ce = fe.FirstClass;
                    while (ce != null)
                    {
                        IClass newClass = null;
                        for (int n=0; n<newClasses.Count && newClass == null; n++) {
                            IClass uc = newClasses [n];
                            if (uc.Name == ce.Name && newNss[n] == ce.NamespaceRef) {
                                newClass = uc;
                                added[n] = true;
                            }
                        }

                        if (newClass != null) {
                            // Class found, replace it
                            ce.Class = CopyClass (newClass);
                            ce.LastGetTime = currentGetTime++;
                            newFileClasses.Add (ce);
                            res.Modified.Add (ce.Class);
                        }
                        else {
                            // Class not found, it has to be deleted, unless it has
                            // been added in another file
                            if (ce.FileEntry == fe) {
                                IClass c = ce.Class;
                                if (c == null) c = ReadClass (ce);
                                res.Removed.Add (c);
                                ce.NamespaceRef.Remove (ce.Name);
                            }
                        }
                        ce = ce.NextInFile;
                    }
                }

                if (fe == null) {
                    fe = new FileEntry (fileName);
                    files [fileName] = fe;
                }

                for (int n=0; n<newClasses.Count; n++) {
                    if (!added[n]) {
                        IClass c = CopyClass (newClasses[n]);
                        ClassEntry ce = new ClassEntry (c, fe, newNss[n]);
                        ce.LastGetTime = currentGetTime++;
                        newNss[n].Add (c.Name, ce);
                        newFileClasses.Add (ce);
                        res.Added.Add (c);
                    }
                }

                fe.SetClasses (newFileClasses);
                rootNamespace.Clean ();
                fe.LastParseTime = DateTime.Now;
                modified = true;
                Flush ();

                return res;
            }
        }
        public virtual void Read()
        {
            if (basePath == null)
                throw new InvalidOperationException ("Location not set");

            if (!File.Exists (dataFile)) return;

            lock (rwlock)
            {
                FileStream ifile = null;
                try
                {
                    modified = false;
                    currentGetTime = 0;
                    CloseReader ();

                    Runtime.LoggingService.Info ("Reading " + dataFile);
                    ifile = new FileStream (dataFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                    BinaryFormatter bf = new BinaryFormatter ();

                    // Read the headers
                    headers = (Hashtable) bf.Deserialize (ifile);
                    int ver = (int) headers["Version"];
                    if (ver != FORMAT_VERSION)
                        throw new Exception ("Expected version " + FORMAT_VERSION + ", found version " + ver);

                    // Move to the index offset and read the index
                    BinaryReader br = new BinaryReader (ifile);
                    long indexOffset = br.ReadInt64 ();
                    ifile.Position = indexOffset;

                    object[] data = (object[]) bf.Deserialize (ifile);
                    Queue dataQueue = new Queue (data);
                    references = (ArrayList) dataQueue.Dequeue ();
                    rootNamespace = (NamespaceEntry)  dataQueue.Dequeue ();
                    files = (Hashtable)  dataQueue.Dequeue ();
                    DeserializeData (dataQueue);

                    ifile.Close ();

                }
                catch (Exception ex)
                {
                    if (ifile != null) ifile.Close ();
                    Runtime.LoggingService.Info ("PIDB file '" + dataFile + "' couldn not be loaded: '" + ex.Message + "'. The file will be recreated");
                    rootNamespace = new NamespaceEntry ();
                    files = new Hashtable ();
                    references = new ArrayList ();
                    headers = new Hashtable ();
                }
            }
        }
 public void Clear()
 {
     rootNamespace = new NamespaceEntry ();
     files = new Hashtable ();
     references = new ArrayList ();
     headers = new Hashtable ();
 }
 public CodeCompletionDatabase(ParserDatabase parserDatabase)
 {
     this.parserDatabase = parserDatabase;
     rootNamespace = new NamespaceEntry ();
     files = new Hashtable ();
     references = new ArrayList ();
     headers = new Hashtable ();
 }