Ejemplo n.º 1
0
		static public FileModel ParseFile(FileModel fileModel)
        {
            string src = "";
            // parse file
            if (fileModel.FileName.Length > 0)
            {
                if (File.Exists(fileModel.FileName))
                {
                    src = PluginCore.Helpers.FileHelper.ReadFile(fileModel.FileName);
                    ASFileParser parser = new ASFileParser();
                    fileModel.LastWriteTime = File.GetLastWriteTime(fileModel.FileName);
                    if (cachedPath != null)
                        cacheLastWriteTime = fileModel.LastWriteTime;
                    parser.ParseSrc(fileModel, src);
                }
                // the file is not available (for the moment?)
                else if (Path.GetExtension(fileModel.FileName).Length > 0)
                {
                    fileModel.OutOfDate = true;
                }
            }
            // this is a package
            else
            {
                // ignore
            }
            return fileModel;
        }
Ejemplo n.º 2
0
 public void ParseFile_SimpleClass()
 {
     using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.as3.SimpleClassTest.as"))
     {
         var srcModel = new FileModel(resourceFile.DestinationFile);
         srcModel.Context = new AS3Context.Context();
         var model = ASFileParser.ParseFile(srcModel);
         Assert.AreEqual(3, model.Version);
         Assert.IsTrue(model.HasPackage);
         Assert.AreEqual("test.test", model.Package);
         Assert.AreEqual(1, model.Classes.Count);
         var classModel = model.Classes[0];
         Assert.AreEqual("Test", classModel.Name);
         Assert.AreEqual("test.test.Test", classModel.QualifiedName);
         Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
         Assert.AreEqual(Visibility.Public, classModel.Access & Visibility.Public);
         Assert.AreEqual(2, classModel.LineFrom);
         Assert.AreEqual(7, classModel.LineTo);
         Assert.AreEqual(1, classModel.Members.Count);
         var memberModel = classModel.Members[0];
         Assert.AreEqual("Test", memberModel.Name);
         Assert.AreEqual(FlagType.Function, memberModel.Flags & FlagType.Function);
         Assert.AreEqual(FlagType.Constructor, memberModel.Flags & FlagType.Constructor);
         Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
         Assert.AreEqual(4, memberModel.LineFrom);
         Assert.AreEqual(6, memberModel.LineTo);
     }
 }
Ejemplo n.º 3
0
            public void ParseFile_IdentifiersWithUnicodeChars()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.as3.IdentifiersWithUnicodeCharsTest.as"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new AS3Context.Context(new AS3Context.AS3Settings());
                    var model = ASFileParser.ParseFile(srcModel);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.LineFrom);
                    Assert.AreEqual(9, classModel.LineTo);
                    Assert.AreEqual(2, classModel.Members.Count);

                    var memberModel = classModel.Members[0];
                    Assert.AreEqual("thísIsVälid", memberModel.Name);
                    Assert.AreEqual("String", memberModel.Type);
                    Assert.AreEqual(FlagType.Function, memberModel.Flags & FlagType.Function);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(4, memberModel.LineFrom);
                    Assert.AreEqual(6, memberModel.LineTo);

                    memberModel = classModel.Members[1];
                    Assert.AreEqual("日本語文字ヴァリアブル", memberModel.Name);
                    Assert.AreEqual("Dynamic", memberModel.Type);
                    Assert.AreEqual(FlagType.Variable, memberModel.Flags & FlagType.Variable);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(8, memberModel.LineFrom);
                    Assert.AreEqual(8, memberModel.LineTo);
                }
            }
Ejemplo n.º 4
0
 public void ParseFile_OverrideFunction()
 {
     using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.as3.OverrideFunctionTest.as"))
     {
         var srcModel = new FileModel(resourceFile.DestinationFile);
         srcModel.Context = new AS3Context.Context();
         var model = ASFileParser.ParseFile(srcModel);
         var classModel = model.Classes[0];
         Assert.AreEqual(2, classModel.Members.Count);
         var memberModel = classModel.Members[0];
         Assert.AreEqual("test1", memberModel.Name);
         var expectedFlags = FlagType.Function | FlagType.Override;
         Assert.AreEqual(expectedFlags, memberModel.Flags & expectedFlags);
         Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
         Assert.AreEqual(4, memberModel.LineFrom);
         Assert.AreEqual(7, memberModel.LineTo);
         memberModel = classModel.Members[1];
         Assert.AreEqual("test2", memberModel.Name);
         Assert.AreEqual(expectedFlags, memberModel.Flags & expectedFlags);
         Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
         Assert.AreEqual(9, memberModel.LineFrom);
         Assert.AreEqual(12, memberModel.LineTo);
     }
 }
Ejemplo n.º 5
0
        private static MemberModel ResolveDelegate(string type, FileModel inFile)
        {
            foreach (MemberModel def in inFile.Members)
                if (def.Name == type && (def.Flags & FlagType.Delegate) > 0)
                    return def;

            if (type.IndexOf('.') < 0)
            {
                string dotType = '.' + type;
                MemberList imports = ASContext.Context.ResolveImports(inFile);
                foreach (MemberModel import in imports)
                    if (import.Type.EndsWith(dotType))
                    {
                        type = import.Type;
                        break;
                    }
            }

            MemberList known = ASContext.Context.GetAllProjectClasses();
            foreach (MemberModel def in known)
                if (def.Type == type && (def.Flags & FlagType.Delegate) > 0)
                    return def;
            return null;
        }
Ejemplo n.º 6
0
        private static void GenerateVariableJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member,
            bool detach, ClassModel inClass)
        {
            int position = 0;
            MemberModel latest = null;
            bool isOtherClass = false;

            Visibility varVisi = job.Equals(GeneratorJobType.Variable) ? GetDefaultVisibility() : Visibility.Public;
            FlagType ft = job.Equals(GeneratorJobType.Constant) ? FlagType.Constant : FlagType.Variable;

            // evaluate, if the variable (or constant) should be generated in other class
            ASResult varResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));

            int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(Sci.CurrentPos, true));
            MemberModel isStatic = new MemberModel();
            if (contextOwnerPos != -1)
            {
                ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos);
                if (contextOwnerResult != null)
                {
                    if (contextOwnerResult.Member == null && contextOwnerResult.Type != null)
                    {
                        isStatic.Flags |= FlagType.Static;
                    }
                }
            }
            else if (member != null && (member.Flags & FlagType.Static) > 0)
            {
                isStatic.Flags |= FlagType.Static;
            }

            ASResult returnType = null;
            int lineNum = Sci.CurrentLine;
            string line = Sci.GetLine(lineNum);
            
            Match m = Regex.Match(line, "\\b" + Regex.Escape(contextToken) + "\\(");
            if (m.Success)
            {
                returnType = new ASResult();
                returnType.Type = ASContext.Context.ResolveType("Function", null);
            }
            else
            {
                m = Regex.Match(line, @"=\s*[^;\n\r}}]+");
                if (m.Success)
                {
                    int posLineStart = Sci.PositionFromLine(lineNum);
                    if (posLineStart + m.Index >= Sci.CurrentPos)
                    {
                        line = line.Substring(m.Index);
                        StatementReturnType rType = GetStatementReturnType(Sci, inClass, line, posLineStart + m.Index);
                        if (rType != null)
                        {
                            returnType = rType.resolve;
                        }
                    }
                }
            }

            if (varResult.RelClass != null && !varResult.RelClass.IsVoid() && !varResult.RelClass.Equals(inClass))
            {
                AddLookupPosition();
                lookupPosition = -1;

                ASContext.MainForm.OpenEditableDocument(varResult.RelClass.InFile.FileName, false);
                Sci = ASContext.CurSciControl;
                isOtherClass = true;

                FileModel fileModel = new FileModel();
                fileModel.Context = ASContext.Context;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(fileModel, Sci.Text);

                foreach (ClassModel cm in fileModel.Classes)
                {
                    if (cm.QualifiedName.Equals(varResult.RelClass.QualifiedName))
                    {
                        varResult.RelClass = cm;
                        break;
                    }
                }
                inClass = varResult.RelClass;

                ASContext.Context.UpdateContext(inClass.LineFrom);
            }

            latest = GetLatestMemberForVariable(job, inClass, varVisi, isStatic);
            
            // if we generate variable in current class..
            if (!isOtherClass && member == null)
            {
                detach = false;
                lookupPosition = -1;
                position = Sci.WordStartPosition(Sci.CurrentPos, true);
                Sci.SetSel(position, Sci.WordEndPosition(position, true));
            }
            else // if we generate variable in another class
            {
                if (latest != null)
                {
                    position = FindNewVarPosition(Sci, inClass, latest);
                }
                else
                {
                    position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
                    detach = false;
                }
                if (position <= 0) return;
                Sci.SetSel(position, position);
            }

            // if this is a constant, we assign a value to constant
            string returnTypeStr = null;
            string eventValue = null;
            if (job == GeneratorJobType.Constant && returnType == null)
            {
                isStatic.Flags |= FlagType.Static;
                eventValue = "String = \"" + Camelize(contextToken) + "\"";
            }
            else if (returnType != null)
            {
                ClassModel inClassForImport = null;
                if (returnType.InClass != null)
                {
                    inClassForImport = returnType.InClass;
                }
                else if (returnType.RelClass != null)
                {
                    inClassForImport = returnType.RelClass;
                }
                else
                {
                    inClassForImport = inClass;
                }
                List<String> imports = new List<string>();
                if (returnType.Member != null)
                {
                    if (returnType.Member.Type != ASContext.Context.Features.voidKey)
                    {
                        returnTypeStr = FormatType(GetShortType(returnType.Member.Type));
                        imports.Add(getQualifiedType(returnType.Member.Type, inClassForImport));
                    }
                }
                else if (returnType != null && returnType.Type != null)
                {
                    returnTypeStr = FormatType(GetShortType(returnType.Type.QualifiedName));
                    imports.Add(getQualifiedType(returnType.Type.QualifiedName, inClassForImport));
                }
                if (imports.Count > 0)
                {
                    position += AddImportsByName(imports, Sci.LineFromPosition(position));
                    Sci.SetSel(position, position);
                }
            }
            MemberModel newMember = NewMember(contextToken, isStatic, ft, varVisi);
            if (returnTypeStr != null)
            {
                newMember.Type = returnTypeStr;
            }
            else if (eventValue != null)
            {
                newMember.Type = eventValue;
            }
            GenerateVariable(newMember, position, detach);
        }
Ejemplo n.º 7
0
        public void ParseSrc(FileModel fileModel, string ba, bool allowBaReExtract)
        {
            //TraceManager.Add("Parsing " + Path.GetFileName(fileModel.FileName));
            model = fileModel;
            model.OutOfDate = false;
            model.CachedModel = false;
            if (model.Context != null) features = model.Context.Features;
            if (features != null && features.hasModules)
                model.Module = Path.GetFileNameWithoutExtension(model.FileName);

            // pre-filtering
            if (allowBaReExtract && model.HasFiltering && model.Context != null)
                ba = model.Context.FilterSource(fileModel.FileName, ba);

            model.InlinedIn = null;
            model.InlinedRanges = null;

            // language features
            model.Imports.Clear();
            model.Classes.Clear();
            model.Members.Clear();
            model.Namespaces.Clear();
            model.Regions.Clear();
            model.PrivateSectionIndex = 0;
            model.Package = "";
            model.MetaDatas = null;

            // state
            int len = ba.Length;
            if (len < 0)
                return;
            int i = 0;
            line = 0;

            // when parsing cache file including multiple files
            resetParser:

            char c1;
            char c2;
            int matching = 0;
            bool isInString = false;
            int inString = 0;
            int braceCount = 0;
            bool inCode = true;

            // comments
            char[] commentBuffer = new char[COMMENTS_BUFFER];
            int commentLength = 0;
            lastComment = null;
            curComment = null;

            // tokenisation
            tryPackage = true;
            hasPackageSection = false;
            haXe = model.haXe;
            TypeCommentUtils.ObjectType = haXe ? "Dynamic" : "Object";
            version = (haXe) ? 4 : 1;
            curToken = new Token();
            prevToken = new Token();
            int tokPos = 0;
            int tokLine = 0;
            curMethod = null;
            curMember = null;
            valueKeyword = null;
            valueMember = null;
            curModifiers = 0;
            curNamespace = "internal";
            curAccess = 0;

            char[] buffer = new char[TOKEN_BUFFER];
            int length = 0;
            char[] valueBuffer = new char[VALUE_BUFFER];
            int valueLength = 0;
            int paramBraceCount = 0;
            int paramTempCount = 0;
            int paramParCount = 0;
            int paramSqCount = 0;

            bool hadWS = true;
            bool hadDot = false;
            inParams = false;
            inEnum = false;
            inTypedef = false;
            inAbstract = false;
            inValue = false;
            inConst = false;
            inType = false;
            inGeneric = false;
            inAnonType = false;

            bool addChar = false;
            int evalToken = 0;
            //bool evalKeyword = true;
            context = 0;
            modifiers = 0;
            foundColon = false;

            bool handleDirectives = features.hasDirectives || cachedPath != null;
            bool inlineDirective = false;

            while (i < len)
            {
                c1 = ba[i++];
                isInString = (inString > 0);

                /* MATCH COMMENTS / STRING LITERALS */

                switch (matching)
                {
                    // look for comment block/line and preprocessor commands
                    case 0:
                        if (!isInString)
                        {
                            // new comment
                            if (c1 == '/' && i < len)
                            {
                                c2 = ba[i];
                                if (c2 == '/')
                                {
                                    // Check if this this is a /// comment
                                    if (i + 1 < len && ba[i + 1] == '/')
                                    {
                                        // This is a /// comment
                                        matching = 4;
                                        isBlockComment = true;
                                        i++;
                                    }
                                    else
                                    {
                                        // This is a regular comment
                                        matching = 1;
                                        isBlockComment = false;
                                    }
                                    inCode = false;
                                    i++;
                                    continue;
                                }
                                else if (c2 == '*')
                                {
                                    isBlockComment = (i + 1 < len && ba[i + 1] == '*');
                                    matching = 2;
                                    inCode = false;
                                    i++;
                                    while (i < len - 1)
                                    {
                                        c2 = ba[i];
                                        if (c2 == '*' && ba[i + 1] != '/') i++;
                                        else break;
                                    }
                                    continue;
                                }
                            }
                            // don't look for comments in strings
                            else if (c1 == '"')
                            {
                                isInString = true;
                                inString = 1;
                            }
                            else if (c1 == '\'')
                            {
                                isInString = true;
                                inString = 2;
                            }
                            // preprocessor statements
                            else if (c1 == '#' && handleDirectives)
                            {
                                int ls = i - 2;
                                inlineDirective = false;
                                while (ls > 0)
                                {
                                    c2 = ba[ls--];
                                    if (c2 == 10 || c2 == 13) break;
                                    else if (c2 > 32) { inlineDirective = true; break; }
                                }
                                c2 = ba[i];
                                if (i < 2 || ba[i - 2] < 33 && c2 >= 'a' && c2 <= 'z')
                                {
                                    matching = 3;
                                    inCode = false;
                                    continue;
                                }
                            }
                        }
                        // end of string
                        else if (isInString)
                        {
                            if (c1 == '\\') { i++; continue; }
                            else if (c1 == 10 || c1 == 13) inString = 0;
                            else if ((inString == 1) && (c1 == '"')) inString = 0;
                            else if ((inString == 2) && (c1 == '\'')) inString = 0;

                            // extract "include" declarations
                            if (inString == 0 && length == 7 && context == 0)
                            {
                                string token = new string(buffer, 0, length);
                                if (token == "include")
                                {
                                    string inc = ba.Substring(tokPos, i - tokPos);
                                    if (model.MetaDatas == null) model.MetaDatas = new List<ASMetaData>();
                                    ASMetaData meta = new ASMetaData("Include");
                                    meta.ParseParams(inc);
                                    model.MetaDatas.Add(meta);
                                }
                            }
                        }
                        break;

                    // skip commented line
                    case 1:
                        if (c1 == 10 || c1 == 13)
                        {
                            // ignore single comments
                            commentLength = 0;
                            inCode = true;
                            matching = 0;
                        }
                        break;

                    // skip commented block
                    case 2:
                        if (c1 == '*')
                        {
                            bool end = false;
                            while (i < len)
                            {
                                c2 = ba[i];
                                if (c2 == '\\') { i++; continue; }
                                if (c2 == '/')
                                {
                                    end = true;
                                    break;
                                }
                                else if (c2 == '*') i++;
                                else break;
                            }
                            if (end)
                            {
                                lastComment = (commentLength > 0) ? new string(commentBuffer, 0, commentLength) : null;
                                // TODO  parse for TODO statements?
                                commentLength = 0;
                                inCode = true;
                                matching = 0;
                                i++;
                                continue;
                            }
                        }
                        break;

                    // directive/preprocessor statement
                    case 3:
                        if (c1 == 10 || c1 == 13 || (inlineDirective && c1 <= 32))
                        {
                            if (commentLength > 0)
                            {
                                string directive = new string(commentBuffer, 0, commentLength);
                                if (directive.StartsWith("if"))
                                {
                                    inCode = true;
                                }
                                else if (directive.StartsWith("else"))
                                {
                                    inCode = true;
                                }
                                else if (directive.StartsWith("end"))
                                {
                                    inCode = true; // directive end
                                    matching = 0;
                                }
                                else inCode = true;

                                // FD cache custom directive
                                if (cachedPath != null && directive.StartsWith("file-cache "))
                                {
                                    // parsing done!
                                    FinalizeModel();

                                    // next model
                                    string realFile = directive.Substring(11);
                                    FileModel newModel = model.Context != null ? model.Context.CreateFileModel(realFile) : new FileModel(realFile);
                                    newModel.LastWriteTime = cacheLastWriteTime;
                                    newModel.CachedModel = true;
                                    if (features != null && features.hasModules)
                                        newModel.Module = Path.GetFileNameWithoutExtension(realFile);
                                    haXe = newModel.haXe;
                                    if (!cachedPath.HasFile(realFile) && File.Exists(realFile))
                                    {
                                        newModel.OutOfDate = (File.GetLastWriteTime(realFile) > cacheLastWriteTime);
                                        cachedPath.AddFile(newModel);
                                    }
                                    model = newModel;
                                    goto resetParser; // loop
                                }
                            }
                            else inCode = true;
                            commentLength = 0;
                            matching = 0;
                        }

                        break;

                    // We are inside a /// comment
                    case 4:
                        {
                            bool end = false;
                            bool skipAhead = false;

                            // See if we just ended a line
                            if (2 <= i && (ba[i - 2] == 10 || ba[i - 2] == 13))
                            {
                                // Check ahead to the next line, see if it has a /// comment on it too.
                                // If it does, we want to continue the comment with that line.  If it
                                // doesn't, then this comment is finished and we will set end to true.
                                for (int j = i + 1; j < len; ++j)
                                {
                                    // Skip whitespace
                                    char twoBack = ba[j - 2];
                                    if (' ' != twoBack && '\t' != twoBack)
                                    {
                                        if ('/' == twoBack && '/' == ba[j - 1] && '/' == ba[j])
                                        {
                                            // There is a comment ahead.  Move up to it so we can gather the
                                            // rest of the comment
                                            i = j + 1;
                                            skipAhead = true;
                                            break;
                                        }
                                        else
                                        {
                                            // Not a comment!  We're done!
                                            end = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (end)
                            {
                                // The comment is over and we want to write it out
                                lastComment = (commentLength > 0) ? new string(commentBuffer, 0, commentLength).Trim() : null;
                                commentLength = 0;
                                inCode = true;
                                matching = 0;

                                // Back up i so we can start gathering comments from right after the line break
                                --i;
                                continue;
                            }
                            if (skipAhead)
                            {
                                // We just hit another /// and are skipping up to right after it.
                                continue;
                            }
                            break;
                        }
                }

                /* LINE/COLUMN NUMBER */

                if (c1 == 10 || c1 == 13)
                {
                    if (cachedPath == null) line++; // cache breaks line count
                    if (c1 == 13 && i < len && ba[i] == 10) i++;
                }

                /* SKIP CONTENT */

                if (!inCode)
                {
                    // store comments
                    if (matching == 2 || (matching == 3 && handleDirectives) || matching == 4)
                    {
                        if (commentLength < COMMENTS_BUFFER) commentBuffer[commentLength++] = c1;
                    }
                    else if (matching == 1 && (c1 == '#' || c1 == '{'))
                    {
                        commentBuffer[commentLength++] = c1;
                        while (i < len)
                        {
                            c2 = ba[i];
                            if (commentLength < COMMENTS_BUFFER) commentBuffer[commentLength++] = c2;
                            if (c2 == 10 || c2 == 13)
                                break;
                            i++;
                        }

                        string comment = new String(commentBuffer, 0, commentLength);
                        Match match = ASFileParserRegexes.Region.Match(comment);
                        if (match.Success)
                        {
                            string regionName = match.Groups["name"].Value.Trim();
                            MemberModel region = new MemberModel(regionName, String.Empty, FlagType.Declaration, Visibility.Default);
                            region.LineFrom = region.LineTo = line;
                            model.Regions.Add(region);
                        }
                    }
                    continue;
                }
                else if (isInString)
                {
                    // store parameter default value
                    if (inValue && valueLength < VALUE_BUFFER)
                        valueBuffer[valueLength++] = c1;
                    continue;
                }
                if (braceCount > 0 && !inValue)
                {
                    if (c1 == '/')
                    {
                        LookupRegex(ref ba, ref i);
                    }
                    else if (c1 == '}')
                    {
                        lastComment = null;
                        braceCount--;
                        if (braceCount == 0 && curMethod != null)
                        {
                            curMethod.LineTo = line;
                            curMethod = null;
                        }
                    }
                    else if (c1 == '{') braceCount++;
                    // escape next char
                    else if (c1 == '\\') i++;
                    continue;
                }

                /* PARSE DECLARATION VALUES/TYPES */

                if (inValue)
                {
                    bool stopParser = false;
                    bool valueError = false;
                    if (inType && !inAnonType && !inGeneric && !Char.IsLetterOrDigit(c1) && ".{}-><".IndexOf(c1) < 0)
                    {
                        inType = false;
                        inValue = false;
                        inGeneric = false;
                        valueLength = 0;
                        length = 0;
                        context = 0;
                    }
                    else if (c1 == '{')
                    {
                        if (!inType || valueLength == 0 || valueBuffer[valueLength - 1] == '<' || paramBraceCount > 0)
                        {
                            paramBraceCount++;
                            stopParser = true;
                        }
                    }
                    else if (c1 == '}')
                    {
                        if (paramBraceCount > 0) { paramBraceCount--; stopParser = true; }
                        else valueError = true;
                    }
                    else if (c1 == '(')
                    {
                        paramParCount++;
                        stopParser = true;
                    }
                    else if (c1 == ')')
                    {
                        if (paramParCount > 0) { paramParCount--; stopParser = true; }
                        else valueError = true;
                    }
                    else if (c1 == '[') paramSqCount++;
                    else if (c1 == ']')
                    {
                        if (paramSqCount > 0) { paramSqCount--; stopParser = true; }
                        else valueError = true;
                    }
                    else if (c1 == '<')
                    {
                        if (i > 1 && ba[i - 2] == '<') paramTempCount = 0; // a << b
                        else
                        {
                            if (inType) inGeneric = true;
                            paramTempCount++;
                        }
                    }
                    else if (c1 == '>')
                    {
                        if (ba[i - 2] == '-') { /*haxe method signatures*/ }
                        else if (paramTempCount > 0)
                        {
                            paramTempCount--;
                            stopParser = true;
                        }
                        else valueError = true;
                    }
                    else if (c1 == '/')
                    {
                        int i0 = i;
                        if (LookupRegex(ref ba, ref i) && valueLength < VALUE_BUFFER - 3)
                        {
                            valueBuffer[valueLength++] = '/';
                            for (; i0 < i; i0++)
                                if (valueLength < VALUE_BUFFER - 2) valueBuffer[valueLength++] = ba[i0];
                            valueBuffer[valueLength++] = '/';
                            continue;
                        }
                    }
                    else if (inValue && (inParams || inType || inConst)
                        && c1 == '/' && valueLength == 0) // lookup native regex
                    {
                        int itemp = i;
                        valueBuffer[valueLength++] = '/';
                        while (valueLength < VALUE_BUFFER && i < len)
                        {
                            c1 = ba[i++];
                            if (c1 == '\n' || c1 == '\r')
                            {
                                valueLength = 0;
                                i = itemp;
                                break;
                            }
                            valueBuffer[valueLength++] = c1;
                            if (c1 == '\\' && i < len)
                            {
                                c1 = ba[i++];
                                valueBuffer[valueLength++] = c1;
                            }
                            else if (c1 == '/') break;
                        }
                    }
                    else if ((c1 == ':' || c1 == ',') && paramBraceCount > 0) stopParser = true;

                    // end of value
                    if ((valueError || (!stopParser && paramBraceCount == 0 && paramParCount == 0 && paramSqCount == 0 && paramTempCount == 0))
                        && (c1 == ',' || c1 == ';' || c1 == '}' || c1 == '\r' || c1 == '\n' || (inParams && c1 == ')') || inType))
                    {
                        if (!inType && (!inValue || c1 != ','))
                        {
                            length = 0;
                            context = 0;
                        }
                        inValue = false;
                        inGeneric = false;
                        //if (valueLength < VALUE_BUFFER) valueBuffer[valueLength++] = c1;
                    }

                    // in params, store the default value
                    else if ((inParams || inType || inConst) && valueLength < VALUE_BUFFER)
                    {
                        if (c1 <= 32)
                        {
                            if (valueLength > 0 && valueBuffer[valueLength - 1] != ' ')
                                valueBuffer[valueLength++] = ' ';
                        }
                        else valueBuffer[valueLength++] = c1;
                    }

                    // detect keywords
                    if (!Char.IsLetterOrDigit(c1))
                    {
                        // escape next char
                        if (c1 == '\\' && i < len)
                        {
                            c1 = ba[i++];
                            if (valueLength < VALUE_BUFFER) valueBuffer[valueLength++] = c1;
                            continue;
                        }
                        if (stopParser) continue;
                        else if (valueError && c1 == ')') inValue = false;
                        else if (inType && inGeneric && (c1 == '<' || c1 == '.')) continue;
                        else if (inAnonType) continue;
                        hadWS = true;
                    }
                }

                // store type / parameter value
                if (!inValue && valueLength > 0)
                {
                    string param = /*(valueBuffer[0] == '{' && valueBuffer[0] != '[') ? "..."
                        :*/ new string(valueBuffer, 0, valueLength);

                    // get text before the last keyword found
                    if (valueKeyword != null)
                    {
                        int p = param.LastIndexOf(valueKeyword.Text);
                        if (p > 0) param = param.Substring(0, p).TrimEnd();
                    }

                    if (curMember == null)
                    {
                        if (inType)
                        {
                            prevToken.Text = curToken.Text;
                            prevToken.Line = curToken.Line;
                            prevToken.Position = curToken.Position;
                            curToken.Text = param;
                            curToken.Line = tokLine;
                            curToken.Position = tokPos;
                            EvalToken(true, true/*false*/, i - 1 - valueLength);
                            evalToken = 0;
                        }
                    }
                    else if (inType)
                    {
                        foundColon = false;
                        if (haXe)
                        {
                            if (param.EndsWith("}") || param.Contains(">"))
                            {
                                param = ASFileParserRegexes.Spaces.Replace(param, "");
                                param = param.Replace(",", ", ");
                                param = param.Replace("->", " -> ");
                            }
                        }
                        curMember.Type = param;
                    }
                    // AS3 const or method parameter's default value
                    else if (version > 2 && (curMember.Flags & FlagType.Variable) > 0)
                    {
                        if (inParams || inConst) curMember.Value = param;
                        curMember.LineTo = line;
                        if (c1 == '\r' || c1 == '\n') curMember.LineTo--;
                        if (inConst && c1 != ',')
                        {
                            context = 0;
                            inConst = false;
                        }
                    }
                    //
                    valueLength = 0;
                    valueMember = null;
                    if (!inParams && !(inConst && context != 0) && c1 != '{') continue;
                    else length = 0;
                }

                /* TOKENIZATION */

                // whitespace
                if (c1 <= 32)
                {
                    hadWS = true;
                    continue;
                }
                // a dot can be in an identifier
                if (c1 == '.')
                {
                    if (length > 0 || (inParams && version == 3))
                    {
                        hadWS = false;
                        hadDot = true;
                        addChar = true;
                        if (!inValue && context == FlagType.Variable && !foundColon)
                        {
                            bool keepContext = inParams && (length == 0 || buffer[0] == '.');
                            if (!keepContext) context = 0;
                        }
                    }
                    else continue;
                }
                else
                {
                    // should we evaluate the token?
                    if (hadWS && !hadDot && !inGeneric && length > 0)
                    {
                        evalToken = 1;
                    }
                    hadWS = false;
                    hadDot = false;
                    bool shortcut = true;

                    // valid char for keyword
                    if (c1 >= 'a' && c1 <= 'z')
                    {
                        addChar = true;
                    }
                    else
                    {
                        // valid chars for identifiers
                        if (c1 >= 'A' && c1 <= 'Z')
                        {
                            addChar = true;
                        }
                        else if (c1 == '$' || c1 == '_')
                        {
                            addChar = true;
                        }
                        else if (length > 0)
                        {
                            if (c1 >= '0' && c1 <= '9')
                            {
                                addChar = true;
                            }
                            else if (c1 == '*' && context == FlagType.Import)
                            {
                                addChar = true;
                            }
                            // AS3/haXe generics
                            else if (features.hasGenerics && c1 == '<')
                            {
                                if (!inValue && i > 2 && length > 1 && i < len - 3
                                    && Char.IsLetterOrDigit(ba[i - 3]) && (Char.IsLetter(ba[i]) || (haXe && ba[i] == '{'))
                                    && (Char.IsLetter(buffer[0]) || buffer[0] == '_'))
                                {
                                    if (curMember == null)
                                    {
                                        evalToken = 0;
                                        if (inGeneric) paramTempCount++;
                                        else
                                        {
                                            paramTempCount = 1;
                                            inGeneric = true;
                                        }
                                        addChar = true;
                                    }
                                    else
                                    {
                                        evalToken = 0;
                                        inGeneric = true;
                                        inValue = true;
                                        inType = true;
                                        inAnonType = false;
                                        valueLength = 0;
                                        for (int j = 0; j < length; j++)
                                            valueBuffer[valueLength++] = buffer[j];
                                        valueBuffer[valueLength++] = c1;
                                        length = 0;
                                        paramBraceCount = 0;
                                        paramParCount = 0;
                                        paramSqCount = 0;
                                        paramTempCount = 1;
                                        continue;
                                    }
                                }
                            }
                            else if (inGeneric && (c1 == ',' || c1 == '.' || c1 == '-' || c1 == '>' || c1 == ':'))
                            {
                                hadWS = false;
                                hadDot = false;
                                evalToken = 0;
                                if (!inValue)
                                {
                                    addChar = true;
                                    if (c1 == '>' && inGeneric)
                                    {
                                        if (paramTempCount > 0) paramTempCount--;
                                        if (paramTempCount == 0 && paramBraceCount == 0
                                            && paramSqCount == 0 && paramParCount == 0) inGeneric = false;
                                    }
                                }
                            }
                            else
                            {
                                evalToken = 2;
                                shortcut = false;
                            }
                        }
                        // star is valid in import statements
                        else if (c1 == '*' && version == 3)
                        {
                            addChar = true;
                        }
                        // conditional haXe parameter
                        else if (c1 == '?' && haXe && inParams && length == 0)
                        {
                            addChar = true;
                        }
                        else shortcut = false;
                    }

                    // eval this word
                    if (evalToken > 0)
                    {
                        prevToken.Text = curToken.Text;
                        prevToken.Line = curToken.Line;
                        prevToken.Position = curToken.Position;
                        curToken.Text = new string(buffer, 0, length);
                        curToken.Line = tokLine;
                        curToken.Position = tokPos;
                        EvalToken(!inValue, (c1 != '=' && c1 != ','), i - 1 - length);
                        length = 0;
                        evalToken = 0;
                    }

                    if (!shortcut)
                        // start of block
                        if (c1 == '{')
                        {
                            if (context == FlagType.Package || context == FlagType.Class) // parse package/class block
                            {
                                context = 0;
                            }
                            else if (context == FlagType.Enum) // parse enum block
                            {
                                if (curClass != null && (curClass.Flags & FlagType.Enum) > 0)
                                    inEnum = true;
                                else
                                {
                                    context = 0;
                                    curModifiers = 0;
                                    braceCount++; // ignore block
                                }
                            }
                            else if (context == FlagType.TypeDef) // parse typedef block
                            {
                                if (curClass != null && (curClass.Flags & FlagType.TypeDef) > 0)
                                {
                                    inTypedef = true;
                                    if (i < len && ba[i] == '>')
                                    {
                                        buffer[0] = 'e'; buffer[1] = 'x'; buffer[2] = 't'; buffer[3] = 'e'; buffer[4] = 'n'; buffer[5] = 'd'; buffer[6] = 's';
                                        length = 7;
                                        context = FlagType.Class;
                                    }
                                }
                                else
                                {
                                    context = 0;
                                    curModifiers = 0;
                                    braceCount++; // ignore block
                                }
                            }
                            else if (context == FlagType.Abstract) // parse abstract block
                            {
                                if (curClass != null && (curClass.Flags & FlagType.Abstract) > 0)
                                    inAbstract = true;
                                else
                                {
                                    context = 0;
                                    curModifiers = 0;
                                    braceCount++; // ignore block
                                }
                            }
                            else if (foundColon && haXe && length == 0) // copy haXe anonymous type
                            {
                                inValue = true;
                                inType = true;
                                inAnonType = true;
                                valueLength = 0;
                                valueBuffer[valueLength++] = c1;
                                paramBraceCount = 1;
                                paramParCount = 0;
                                paramSqCount = 0;
                                paramTempCount = 0;
                                continue;
                            }
                            else if (foundConstant) // start config block
                            {
                                flattenNextBlock++;
                                foundConstant = false;
                                context = 0;
                            }
                            else if (ScriptMode) // not in a class, parse if/for/while/do blocks
                            {
                                context = 0;
                            }
                            else braceCount++; // ignore block
                        }

                        // end of block
                        else if (c1 == '}')
                        {
                            curComment = null;
                            foundColon = false;
                            foundConstant = false;

                            if (flattenNextBlock > 0) // content of this block was parsed
                            {
                                flattenNextBlock--;
                            }

                            // outside of a method, the '}' ends the current class
                            else if (curClass != null)
                            {
                                if (curClass != null) curClass.LineTo = line;
                                curClass = null;
                                inEnum = false;
                                inTypedef = false;
                                inAbstract = false;
                            }
                            else
                            {
                                if (hasPackageSection && model.PrivateSectionIndex == 0) model.PrivateSectionIndex = line + 1;
                            }
                        }

                        // member type declaration
                        else if (c1 == ':' && !inValue && !inGeneric)
                        {
                            foundColon = curMember != null && curMember.Type == null;
                            // recognize compiler config block
                            if (!foundColon && braceCount == 0
                                && i < len - 2 && ba[i] == ':' && Char.IsLetter(ba[i + 1]))
                                foundConstant = true;
                        }

                        // next variable declaration
                        else if (c1 == ',')
                        {
                            if ((context == FlagType.Variable || context == FlagType.TypeDef) && curMember != null)
                            {
                                curAccess = curMember.Access;
                                foundKeyword = FlagType.Variable;
                                foundColon = false;
                                lastComment = null;
                            }
                            else if (context == FlagType.Class && prevToken.Text == "implements")
                            {
                                curToken.Text = "implements";
                                foundKeyword = FlagType.Implements;
                            }
                        }

                        else if (c1 == '(')
                        {
                            if (!inValue && context == FlagType.Variable && curToken.Text != "catch" && (!haXe || curToken.Text != "for"))
                                if (haXe && curMember != null && valueLength == 0) // haXe properties
                                {
                                    curMember.Flags -= FlagType.Variable;
                                    curMember.Flags |= FlagType.Getter | FlagType.Setter;
                                    context = FlagType.Function;
                                }
                                else context = 0;

                            // beginning of method parameters
                            if (context == FlagType.Function)
                            {
                                context = FlagType.Variable;
                                inParams = true;
                                inGeneric = false;
                                if (valueMember != null && curMember == null)
                                {
                                    valueLength = 0;
                                    //valueMember.Flags -= FlagType.Variable; ???
                                    valueMember.Flags = FlagType.Function;
                                    curMethod = curMember = valueMember;
                                    valueMember = null;
                                }
                                else if (curMember == null)
                                {
                                    context = FlagType.Function;
                                    if ((curModifiers & FlagType.Getter) > 0)
                                    {
                                        curModifiers -= FlagType.Getter;
                                        EvalToken(true, false, i);
                                        curMethod = curMember;
                                        context = FlagType.Variable;
                                    }
                                    else if ((curModifiers & FlagType.Setter) > 0)
                                    {
                                        curModifiers -= FlagType.Setter;
                                        EvalToken(true, false, i);
                                        curMethod = curMember;
                                        context = FlagType.Variable;
                                    }
                                    else
                                    {
                                        inParams = false;
                                        context = 0;
                                    }
                                }
                                else
                                {
                                    curMethod = curMember;
                                }
                            }

                            // an Enum value with parameters
                            else if (inEnum && curToken != null)
                            {
                                context = FlagType.Variable;
                                inParams = true;
                                curMethod = curMember ?? new MemberModel();
                                curMethod.Name = curToken.Text;
                                curMethod.Flags = curModifiers | FlagType.Function | FlagType.Static;
                                curMethod.Parameters = new List<MemberModel>();
                                //
                                if (curClass != null && curMember == null) curClass.Members.Add(curMethod);
                            }

                            // a TypeDef method with parameters
                            else if (inTypedef && curToken != null)
                            {
                                context = FlagType.Variable;
                                inParams = true;
                                curMethod = curMember ?? new MemberModel();
                                curMethod.Name = curToken.Text;
                                curMethod.Flags = curModifiers | FlagType.Function;
                                curMethod.Parameters = new List<MemberModel>();
                                //
                                if (curClass != null && curMember == null) curClass.Members.Add(curMethod);
                            }

                            // an Abstract "opaque type"
                            else if (context == FlagType.Abstract && prevToken.Text == "abstract")
                            {
                                foundKeyword = FlagType.Class;
                                curModifiers = FlagType.Extends;
                            }

                            else if (curMember == null && curToken.Text != "catch" && (!haXe || curToken.Text != "for"))
                            {
                                context = 0;
                                inGeneric = false;
                            }
                        }

                        // end of statement
                        else if (c1 == ';')
                        {
                            context = (inEnum) ? FlagType.Enum : 0;
                            inGeneric = false;
                            modifiers = 0;
                            inParams = false;
                            curMember = null;
                        }

                        // end of method parameters
                        else if (c1 == ')' && inParams)
                        {
                            context = 0;
                            if (inEnum) context = FlagType.Enum;
                            else if (inTypedef) context = FlagType.TypeDef;
                            modifiers = 0;
                            inParams = false;
                            curMember = curMethod;
                        }

                        // skip value of a declared variable
                        else if (c1 == '=')
                        {
                            if (context == FlagType.Variable || (context == FlagType.Enum && inEnum))
                            {
                                if (!inValue && curMember != null)
                                {
                                    inValue = true;
                                    inConst = (curMember.Flags & FlagType.Constant) > 0;
                                    inType = false;
                                    inGeneric = false;
                                    paramBraceCount = 0;
                                    paramParCount = 0;
                                    paramSqCount = 0;
                                    paramTempCount = 0;
                                    valueLength = 0;
                                    valueMember = curMember;
                                }
                            }
                        }

                        // metadata
                        else if (!inValue && c1 == '[')
                        {
                            if (version == 3) LookupMeta(ref ba, ref i);
                            else if (features.hasCArrays && curMember != null && curMember.Type != null)
                            {
                                if (ba[i] == ']') curMember.Type = features.CArrayTemplate + "@" + curMember.Type;
                            }
                        }

                        // haXe signatures: T -> T -> T
                        else if (haXe && c1 == '-' && curMember != null)
                        {
                            if (ba[i] == '>' && curMember.Type != null)
                            {
                                curMember.Type += " ->";
                                foundColon = true;
                            }
                        }

                        // escape next char
                        else if (c1 == '\\') { i++; continue; }

                        // literal regex
                        else if (c1 == '/' && version == 3)
                        {
                            if (LookupRegex(ref ba, ref i))
                                continue;
                        }
                }

                // put in buffer
                if (addChar)
                {
                    if (length < TOKEN_BUFFER) buffer[length++] = c1;

                    if (length == 1)
                    {
                        tokPos = i - 1;
                        tokLine = line;
                    }
                    addChar = false;
                }
            }

            // parsing done!
            FinalizeModel();

            // post-filtering
            if (cachedPath == null && model.HasFiltering && model.Context != null)
                model.Context.FilterSource(model);

            //	Debug.WriteLine("out model: " + model.GenerateIntrinsic(false));
        }
Ejemplo n.º 8
0
 private void AddClass(FileModel model, ClassModel curClass)
 {
     // avoid empty duplicates due to Haxe directives
     foreach(ClassModel aClass in model.Classes)
         if (aClass.Name == curClass.Name)
         {
             if (aClass.Members.Count == 0)
             {
                 model.Classes.Remove(aClass);
                 break;
             }
             else return;
         }
     model.Classes.Add(curClass);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Prepare Loom intrinsic known vars/methods/classes
        /// </summary>
        protected override void InitTopLevelElements()
        {
            string filename = "toplevel.ls";
            topLevel = new FileModel(filename);

            if (topLevel.Members.Search("this", 0, 0) == null)
                topLevel.Members.Add(new MemberModel("this", "", FlagType.Variable | FlagType.Intrinsic, Visibility.Public));
            if (topLevel.Members.Search("super", 0, 0) == null)
                topLevel.Members.Add(new MemberModel("super", "", FlagType.Variable | FlagType.Intrinsic, Visibility.Public));
            if (topLevel.Members.Search(features.voidKey, 0, 0) == null)
                topLevel.Members.Add(new MemberModel(features.voidKey, "", FlagType.Intrinsic, Visibility.Public));
            topLevel.Members.Sort();
        }
Ejemplo n.º 10
0
        private static void AddEvents(FileModel aFile, BlockModel docModel, bool targetAIR, bool targetFP10)
        {
            aFile.MetaDatas = new List<ASMetaData>();
            foreach (EventModel ev in docModel.Events)
            {
                if (!targetAIR && ev.IsAIR) continue;
                if (!targetFP10 && ev.IsFP10) continue;

                int p = ev.EventType.LastIndexOf('.');
                string type = ev.EventType.Substring(0, p);
                string pname = ev.EventType.Substring(p + 1);
                ClassModel eClass = getClass(type);
                if (eClass.IsVoid()) continue;
                string value = '"' + ev.Name + '"';
                if (eClass.Members.Items.Any<MemberModel>(item => item.Name == pname))
                {
                    ASMetaData meta = new ASMetaData("Event");
                    if (ev.Comment != null)
                        meta.Comments = "\r\n\t * " + ev.Comment + "\r\n\t * @eventType " + ev.EventType;
                    meta.ParseParams(String.Format("name=\"{0}\", type=\"{1}\"", ev.Name, type));
                    aFile.MetaDatas.Add(meta);
                }
            }
        }
Ejemplo n.º 11
0
            public void ParseFile_GenericsWithObjectConstraints()
            {
                using (
                    var resourceFile =
                        new TestFile("ASCompletion.Test_Files.parser.haxe.GenericsObjectConstraintTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(3, model.Classes.Count);

                    var objectConstraintGeneric = model.Classes[0];
                    Assert.AreEqual(2, objectConstraintGeneric.LineFrom);
                    Assert.AreEqual(11, objectConstraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, objectConstraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestObjectConstraint<T:({},Measurable)>", objectConstraintGeneric.FullName);
                    Assert.AreEqual("TestObjectConstraint", objectConstraintGeneric.Name);
                    Assert.AreEqual("<T:({},Measurable)>", objectConstraintGeneric.Template);
                    Assert.AreEqual(2, objectConstraintGeneric.Members.Count);
                    var member = objectConstraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(6, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    var arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    member = objectConstraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:({},Measurable)>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:({},Measurable)>", member.Template);
                    Assert.AreEqual(8, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("K", arg.Type);

                    var fullConstraintGeneric = model.Classes[1];
                    Assert.AreEqual(13, fullConstraintGeneric.LineFrom);
                    Assert.AreEqual(22, fullConstraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, fullConstraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestFullConstraint<T:({},Measurable),Z:(Iterable<String>,Measurable)>",
                        fullConstraintGeneric.FullName);
                    Assert.AreEqual("TestFullConstraint", fullConstraintGeneric.Name);
                    Assert.AreEqual("<T:({},Measurable),Z:(Iterable<String>,Measurable)>",
                        fullConstraintGeneric.Template);
                    Assert.AreEqual(2, fullConstraintGeneric.Members.Count);
                    member = fullConstraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(15, member.LineFrom);
                    Assert.AreEqual(17, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("Z", arg.Type);
                    member = fullConstraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:({},Measurable),V:(Iterable<String>,Measurable)>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:({},Measurable),V:(Iterable<String>,Measurable)>", member.Template);
                    Assert.AreEqual(19, member.LineFrom);
                    Assert.AreEqual(21, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("V", arg.Type);

                    // TODO: There should be a space between 'function' and 'new'! There should be a separate test covering this error
                    var typeDefConstraintGeneric = model.Classes[2];
                    Assert.AreEqual(24, typeDefConstraintGeneric.LineFrom);
                    Assert.AreEqual(33, typeDefConstraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, typeDefConstraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestTypeDefConstraint<T:({functionnew():Void;},Measurable)>", typeDefConstraintGeneric.FullName);
                    Assert.AreEqual("TestTypeDefConstraint", typeDefConstraintGeneric.Name);
                    Assert.AreEqual("<T:({functionnew():Void;},Measurable)>", typeDefConstraintGeneric.Template);
                    Assert.AreEqual(2, typeDefConstraintGeneric.Members.Count);
                    member = typeDefConstraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(26, member.LineFrom);
                    Assert.AreEqual(28, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    member = typeDefConstraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:({functionnew():Void;},Measurable)>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:({functionnew():Void;},Measurable)>", member.Template);
                    Assert.AreEqual(30, member.LineFrom);
                    Assert.AreEqual(32, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("K", arg.Type);

                }
            }
Ejemplo n.º 12
0
            public void ParseFile_TypeDefs()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.TypeDefsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(7, model.Classes.Count);

                    var aliasTypeDef = model.Classes[0];
                    Assert.AreEqual(2, aliasTypeDef.LineFrom);
                    Assert.AreEqual(2, aliasTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, aliasTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("Array<Int>", aliasTypeDef.ExtendsType);
                    Assert.AreEqual("Alias", aliasTypeDef.FullName);

                    var iterableTypeDef = model.Classes[1];
                    Assert.AreEqual(4, iterableTypeDef.LineFrom);
                    Assert.AreEqual(6, iterableTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, iterableTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("Iterable<T>", iterableTypeDef.FullName);
                    Assert.AreEqual("Iterable", iterableTypeDef.Name);
                    Assert.AreEqual("<T>", iterableTypeDef.Template);
                    Assert.AreEqual(1, iterableTypeDef.Members.Count);
                    var member = iterableTypeDef.Members[0];
                    Assert.AreEqual("iterator", member.Name);
                    Assert.AreEqual(5, member.LineFrom);
                    Assert.AreEqual(5, member.LineTo);
                    Assert.AreEqual("Iterator<T>", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);

                    var typeWithOptionalATypeDef = model.Classes[2];
                    Assert.AreEqual(8, typeWithOptionalATypeDef.LineFrom);
                    Assert.AreEqual(12, typeWithOptionalATypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, typeWithOptionalATypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("TypeWithOptionalA", typeWithOptionalATypeDef.FullName);
                    Assert.AreEqual(3, typeWithOptionalATypeDef.Members.Count);
                    member = typeWithOptionalATypeDef.Members[0];
                    Assert.AreEqual("age", member.Name);
                    Assert.AreEqual(9, member.LineFrom);
                    Assert.AreEqual(9, member.LineTo);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = typeWithOptionalATypeDef.Members[1];
                    Assert.AreEqual("name", member.Name);
                    Assert.AreEqual(10, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = typeWithOptionalATypeDef.Members[2];
                    Assert.AreEqual("phoneNumber", member.Name);
                    Assert.AreEqual(11, member.LineFrom);
                    Assert.AreEqual(11, member.LineTo);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    var typeWithOptionalBTypeDef = model.Classes[3];
                    Assert.AreEqual(14, typeWithOptionalBTypeDef.LineFrom);
                    Assert.AreEqual(17, typeWithOptionalBTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, typeWithOptionalBTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("TypeWithOptionalB", typeWithOptionalBTypeDef.FullName);
                    Assert.AreEqual(2, typeWithOptionalBTypeDef.Members.Count);
                    member = typeWithOptionalBTypeDef.Members[0];
                    Assert.AreEqual("optionalString", member.Name);
                    Assert.AreEqual(15, member.LineFrom);
                    Assert.AreEqual(15, member.LineTo);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = typeWithOptionalBTypeDef.Members[1];
                    Assert.AreEqual("requiredInt", member.Name);
                    Assert.AreEqual(16, member.LineFrom);
                    Assert.AreEqual(16, member.LineTo);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    var singleLineTypeDef = model.Classes[4];
                    Assert.AreEqual(19, singleLineTypeDef.LineFrom);
                    Assert.AreEqual(19, singleLineTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, singleLineTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("SingleLine", singleLineTypeDef.FullName);
                    Assert.AreEqual(2, singleLineTypeDef.Members.Count);
                    member = singleLineTypeDef.Members[0];
                    Assert.AreEqual("x", member.Name);
                    Assert.AreEqual(19, member.LineFrom);
                    Assert.AreEqual(19, member.LineTo);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = singleLineTypeDef.Members[1];
                    Assert.AreEqual("y", member.Name);
                    Assert.AreEqual(19, member.LineFrom);
                    Assert.AreEqual(19, member.LineTo);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    var normalDefTypeDef = model.Classes[5];
                    Assert.AreEqual(21, normalDefTypeDef.LineFrom);
                    Assert.AreEqual(24, normalDefTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, normalDefTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("NormalDef", normalDefTypeDef.FullName);
                    Assert.AreEqual(2, normalDefTypeDef.Members.Count);
                    member = normalDefTypeDef.Members[0];
                    Assert.AreEqual("aliases", member.Name);
                    Assert.AreEqual(22, member.LineFrom);
                    Assert.AreEqual(22, member.LineTo);
                    Assert.AreEqual("Array<String>", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = normalDefTypeDef.Members[1];
                    Assert.AreEqual("processFunction", member.Name);
                    Assert.AreEqual(23, member.LineFrom);
                    Assert.AreEqual(23, member.LineTo);
                    Assert.AreEqual("Dynamic", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    var shortDefTypeDef = model.Classes[6];
                    Assert.AreEqual(26, shortDefTypeDef.LineFrom);
                    Assert.AreEqual(29, shortDefTypeDef.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, shortDefTypeDef.Flags & FlagType.TypeDef);
                    Assert.AreEqual("ShortDef", shortDefTypeDef.FullName);
                    Assert.AreEqual(2, shortDefTypeDef.Members.Count);
                    member = shortDefTypeDef.Members[0];
                    Assert.AreEqual("aliases", member.Name);
                    Assert.AreEqual(27, member.LineFrom);
                    Assert.AreEqual(27, member.LineTo);
                    Assert.AreEqual("Array<String>", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = shortDefTypeDef.Members[1];
                    Assert.AreEqual("processFunction", member.Name);
                    Assert.AreEqual(28, member.LineFrom);
                    Assert.AreEqual(28, member.LineTo);
                    Assert.AreEqual("Dynamic", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                }
            }
Ejemplo n.º 13
0
            public void ParseFile_StringWithEscapedChars()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.EscapedStringsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);

                    Assert.AreEqual(1, model.Classes.Count);
                    var classModel = model.Classes[0];

                    Assert.AreEqual(1, classModel.Members.Count);
                    var member = classModel.Members[0];
                    Assert.AreEqual("test", member.Name);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(6, member.LineTo);
                    Assert.AreEqual(2, member.Parameters.Count);
                    var param = member.Parameters[0];
                    Assert.AreEqual("arg", param.Name);
                    Assert.AreEqual("String", param.Type);
                    Assert.AreEqual("\"hello \\t\\r\\n\\\\\\\"\\\\\"", param.Value);
                    Assert.AreEqual(4, param.LineFrom);
                    Assert.AreEqual(4, param.LineTo);
                    param = member.Parameters[1];
                    Assert.AreEqual("arg2", param.Name);
                    Assert.AreEqual("String", param.Type);
                    Assert.AreEqual(@"'hello \t\r\n\\\\'", param.Value);
                    Assert.AreEqual(4, param.LineFrom);
                    Assert.AreEqual(4, param.LineTo);
                }
            }
Ejemplo n.º 14
0
            public void ParseFile_SpecialClassesComments()
            {
                using (
                    var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.SpecialClassesCommentsTest.hx")
                    )
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(3, model.Classes.Count);

                    var classModel = model.Classes[0];
                    Assert.AreEqual("TypedefTest", classModel.Name);
                    Assert.AreEqual("\r * Some typedef custom comments\r ", classModel.Comments);
                    Assert.AreEqual(5, classModel.LineFrom);
                    Assert.AreEqual(11, classModel.LineTo);
                    Assert.AreEqual(FlagType.TypeDef, classModel.Flags & FlagType.TypeDef);
                    Assert.AreEqual(1, classModel.Members.Count);
                    var member = classModel.Members[0];
                    Assert.AreEqual(10, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual("age", member.Name);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual("Java Style comments", member.Comments);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    classModel = model.Classes[1];
                    Assert.AreEqual("EnumTest", classModel.Name);
                    Assert.AreEqual("\r * Some enum custom comments\r ", classModel.Comments);
                    Assert.AreEqual(16, classModel.LineFrom);
                    Assert.AreEqual(22, classModel.LineTo);
                    Assert.AreEqual(FlagType.Enum, classModel.Flags & FlagType.Enum);
                    Assert.AreEqual(1, classModel.Members.Count);
                    member = classModel.Members[0];
                    Assert.AreEqual(21, member.LineFrom);
                    Assert.AreEqual(21, member.LineTo);
                    Assert.AreEqual("Foo", member.Name);
                    //TODO: Add support for this!
                    //Assert.AreEqual("\r\t * Enum element comments\r\t ", member.Comments);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    classModel = model.Classes[2];
                    Assert.AreEqual("AbstractInt", classModel.Name);
                    Assert.AreEqual("\r * Some abstract custom comments\r ", classModel.Comments);
                    Assert.AreEqual("Int", classModel.ExtendsType);
                    Assert.AreEqual(27, classModel.LineFrom);
                    Assert.AreEqual(34, classModel.LineTo);
                    Assert.AreEqual(FlagType.Abstract, classModel.Flags & FlagType.Abstract);
                    Assert.AreEqual(1, classModel.Members.Count);
                    member = classModel.Members[0];
                    Assert.AreEqual(31, member.LineFrom);
                    Assert.AreEqual(33, member.LineTo);
                    Assert.AreEqual("new", member.Name);
                    Assert.AreEqual("Java Style comments", member.Comments);
                }
            }
Ejemplo n.º 15
0
            public void ParseFile_Regions()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.RegionsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(1, model.Classes.Count);
                    Assert.AreEqual(2, model.Regions.Count);

                    var region = model.Regions[0];
                    Assert.AreEqual("Fields", region.Name);
                    Assert.AreEqual(4, region.LineFrom);
                    Assert.AreEqual(6, region.LineTo);
                    region = model.Regions[1];
                    Assert.AreEqual("Complex stuff", region.Name);
                    Assert.AreEqual(14, region.LineFrom);
                    Assert.AreEqual(16, region.LineTo);

                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(2, classModel.LineFrom);
                    Assert.AreEqual(18, classModel.LineTo);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(3, classModel.Members.Count);
                    var member = classModel.Members[0];
                    Assert.AreEqual(5, member.LineFrom);
                    Assert.AreEqual(5, member.LineTo);
                    Assert.AreEqual("_test", member.Name);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual(Visibility.Private, member.Access & Visibility.Private);
                    member = classModel.Members[1];
                    Assert.AreEqual(9, member.LineFrom);
                    Assert.AreEqual(9, member.LineTo);
                    Assert.AreEqual("_test2", member.Name);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual(Visibility.Private, member.Access & Visibility.Private);
                    member = classModel.Members[2];
                    Assert.AreEqual(12, member.LineFrom);
                    Assert.AreEqual(17, member.LineTo);
                    Assert.AreEqual("regionInside", member.Name);
                    Assert.AreEqual("String", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(Visibility.Private, member.Access & Visibility.Private);
                }
            }
Ejemplo n.º 16
0
        private void DoScheduledOperations()
        {
            // copy scheduled paths
            string[] _toCheck;
            string[] _toExplore;
            if (toExplore.Count == 0)
            {
                return;
            }
            _toCheck   = new string[toExplore.Count];
            _toExplore = new string[toExplore.Count];
            for (int i = 0; i < _toExplore.Length; i++)
            {
                _toCheck[i]   = toExplore[i].ToUpper() + System.IO.Path.DirectorySeparatorChar;
                _toExplore[i] = toExplore[i];
            }
            toExplore.Clear();

            List <string> _toRemove;

            _toRemove = new List <string>(toRemove.Count);
            for (int i = 0; i < _toRemove.Count; i++)
            {
                _toRemove[i] = toRemove[i].ToUpper() + System.IO.Path.DirectorySeparatorChar;
            }
            toRemove.Clear();

            Dictionary <string, FileModel> newFiles = new Dictionary <string, FileModel>();

            // cleanup files
            foreach (string file in files.Keys)
            {
                bool drop = false;
                foreach (string remPath in _toRemove)
                {
                    if (file.StartsWithOrdinal(remPath))
                    {
                        //TraceManager.Add("drop: " + files[file].FileName);
                        drop = true;
                        break;
                    }
                }
                if (drop)
                {
                    continue;
                }

                FileModel model = files[file];
                foreach (string checkPath in _toCheck)
                {
                    if (!File.Exists(model.FileName))
                    {
                        if (!Directory.Exists(System.IO.Path.GetDirectoryName(model.FileName)))
                        {
                            string newRemPath = System.IO.Path.GetDirectoryName(model.FileName).ToUpper() + System.IO.Path.DirectorySeparatorChar;
                            _toRemove.Add(newRemPath);
                        }
                        //TraceManager.Add("drop2: " + files[file].FileName);
                        drop = true;
                        break;
                    }
                }
                if (drop)
                {
                    continue;
                }
                newFiles[file] = model;
            }
            files = newFiles;

            // add new files
            foreach (string path in _toExplore)
            {
                AddNewFilesIn(path);
            }
        }
Ejemplo n.º 17
0
            public void ParseFile_Generics()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.GenericsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(4, model.Classes.Count);

                    var simpleGeneric = model.Classes[0];
                    Assert.AreEqual(2, simpleGeneric.LineFrom);
                    Assert.AreEqual(11, simpleGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, simpleGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("Test<T>", simpleGeneric.FullName);
                    Assert.AreEqual("Test", simpleGeneric.Name);
                    Assert.AreEqual("<T>", simpleGeneric.Template);
                    Assert.AreEqual(2, simpleGeneric.Members.Count);
                    var member = simpleGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(6, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    var arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    member = simpleGeneric.Members[1];
                    Assert.AreEqual("test2<K>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K>", member.Template);
                    Assert.AreEqual(8, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("K", arg.Type);

                    var constraintGeneric = model.Classes[1];
                    Assert.AreEqual(13, constraintGeneric.LineFrom);
                    Assert.AreEqual(22, constraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, constraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestConstraint<T:Iterable<String>>", constraintGeneric.FullName);
                    Assert.AreEqual("TestConstraint", constraintGeneric.Name);
                    Assert.AreEqual("<T:Iterable<String>>", constraintGeneric.Template);
                    Assert.AreEqual(2, constraintGeneric.Members.Count);
                    member = constraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(15, member.LineFrom);
                    Assert.AreEqual(17, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    member = constraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:Iterable<String>>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:Iterable<String>>", member.Template);
                    Assert.AreEqual(19, member.LineFrom);
                    Assert.AreEqual(21, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("K", arg.Type);

                    var multipleConstraintGeneric = model.Classes[2];
                    Assert.AreEqual(24, multipleConstraintGeneric.LineFrom);
                    Assert.AreEqual(33, multipleConstraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, multipleConstraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestMultiple<T:(Iterable<String>,Measurable)>", multipleConstraintGeneric.FullName);
                    Assert.AreEqual("TestMultiple", multipleConstraintGeneric.Name);
                    Assert.AreEqual("<T:(Iterable<String>,Measurable)>", multipleConstraintGeneric.Template);
                    Assert.AreEqual(2, multipleConstraintGeneric.Members.Count);
                    member = multipleConstraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(26, member.LineFrom);
                    Assert.AreEqual(28, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    member = multipleConstraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:(Iterable<String>,Measurable)>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:(Iterable<String>,Measurable)>", member.Template);
                    Assert.AreEqual(30, member.LineFrom);
                    Assert.AreEqual(32, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("K", arg.Type);

                    var complexConstraintGeneric = model.Classes[3];
                    Assert.AreEqual(35, complexConstraintGeneric.LineFrom);
                    Assert.AreEqual(44, complexConstraintGeneric.LineTo);
                    Assert.AreEqual(FlagType.Class, complexConstraintGeneric.Flags & FlagType.Class);
                    Assert.AreEqual("TestFullConstraint<T:Measurable,Z:(Iterable<String>,Measurable)>",
                        complexConstraintGeneric.FullName);
                    Assert.AreEqual("TestFullConstraint", complexConstraintGeneric.Name);
                    Assert.AreEqual("<T:Measurable,Z:(Iterable<String>,Measurable)>", complexConstraintGeneric.Template);
                    Assert.AreEqual(2, complexConstraintGeneric.Members.Count);
                    member = complexConstraintGeneric.Members[0];
                    Assert.AreEqual("test1", member.Name);
                    Assert.AreEqual(37, member.LineFrom);
                    Assert.AreEqual(39, member.LineTo);
                    Assert.AreEqual("T", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(2, member.Parameters.Count);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("T", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("Z", arg.Type);
                    member = complexConstraintGeneric.Members[1];
                    Assert.AreEqual("test2<K:Measurable,V:(Iterable<String>,Measurable)>", member.FullName);
                    Assert.AreEqual("test2", member.Name);
                    Assert.AreEqual("<K:Measurable,V:(Iterable<String>,Measurable)>", member.Template);
                    Assert.AreEqual(41, member.LineFrom);
                    Assert.AreEqual(43, member.LineTo);
                    Assert.AreEqual("K", member.Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    arg = member.Parameters[0];
                    Assert.AreEqual("expected", arg.Name);
                    Assert.AreEqual("K", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("actual", arg.Name);
                    Assert.AreEqual("V", arg.Type);
                }
            }
Ejemplo n.º 18
0
            public void ParseFile_WrongSyntaxCompilerMetaAfterVarWithNoType()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.WrongSyntaxCompilerMetaAfterVarWithNoType.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("WrongSyntaxMetadataTest", classModel.Name);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.LineFrom);
                    //I'd say this should be possible
                    //Assert.AreEqual(9, classModel.LineTo);
                    Assert.AreEqual(2, classModel.Members.Count);

                    var memberModel = classModel.Members[0];
                    Assert.AreEqual("func", memberModel.Name);
                    Assert.AreEqual(null, memberModel.Type);
                    var flags = FlagType.Variable;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(6, memberModel.LineFrom);
                    Assert.AreEqual(6, memberModel.LineTo);
                    Assert.AreEqual(" Dummy data to make sure this method keeps values at the end of the parsing ", memberModel.Comments);
                    Assert.AreEqual("dummy", memberModel.MetaDatas[0].Name);
                }
            }
Ejemplo n.º 19
0
            public void ParseFile_IdentifiersWithUnicodeChars()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.IdentifiersWithUnicodeCharsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.LineFrom);
                    Assert.AreEqual(9, classModel.LineTo);
                    Assert.AreEqual(2, classModel.Members.Count);

                    var memberModel = classModel.Members[0];
                    Assert.AreNotEqual("thísIsVälid", memberModel.Name);
                    Assert.AreEqual(4, memberModel.LineFrom);
                    Assert.AreEqual(6, memberModel.LineTo);

                    memberModel = classModel.Members[1];
                    Assert.AreNotEqual("日本語文字ヴァリアブル", memberModel.Name);
                    Assert.AreEqual(8, memberModel.LineFrom);
                    Assert.AreEqual(8, memberModel.LineTo);
                }
            }
Ejemplo n.º 20
0
            public void ParseFile_AnonymousStructures()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.AnonymousStructuresTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);

                    Assert.AreEqual(1, model.Classes.Count);

                    var classModel = model.Classes[0];

                    Assert.AreEqual(2, classModel.Members.Count);

                    var member = classModel.Members[0];
                    Assert.AreEqual("start", member.Name);
                    Assert.AreEqual(1, member.LineFrom);
                    Assert.AreEqual(1, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("{x:Int, y:Int}", member.Type);

                    member = classModel.Members[1];
                    Assert.AreEqual("target", member.Name);
                    Assert.AreEqual(2, member.LineFrom);
                    Assert.AreEqual(2, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("{x:Int, y:Int}", member.Type);
                }
            }
Ejemplo n.º 21
0
        private void ExtractFilesFromArchive()
        {
            string[] masks = context.GetExplorerMask();
            for (int i = 0; i < masks.Length; i++)
                masks[i] = masks[i].Substring(masks[i].IndexOf('*') + 1);

            Stream fileStream = File.OpenRead(pathModel.Path);
            ZipFile zipFile = new ZipFile(fileStream);
            ASFileParser parser = new ASFileParser();
            Dictionary<string, FileModel> models = new Dictionary<string, FileModel>();

            foreach (ZipEntry entry in zipFile)
            {
                string ext = Path.GetExtension(entry.Name).ToLower();
                foreach (string mask in masks)
                    if (ext == mask)
                    {
                        string src = UnzipFile(zipFile, entry);
                        FileModel model = new FileModel(Path.Combine(pathModel.Path, entry.Name));
                        model.Context = pathModel.Owner;
                        parser.ParseSrc(model, src);
                        models.Add(model.FileName, model);
                    }
            }
            zipFile.Close();
            fileStream.Close();

            pathModel.SetFiles(models);
        }
Ejemplo n.º 22
0
            public void ParseFile_ClassImplements()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.ImplementClassTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);

                    Assert.AreEqual(2, model.Classes.Count);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(Visibility.Public, classModel.Access);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.That(classModel.Implements, Is.EquivalentTo(new[] {"ITest"}));

                    classModel = model.Classes[1];
                    Assert.AreEqual("MultipleTest", classModel.Name);
                    Assert.AreEqual(Visibility.Public, classModel.Access);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.That(classModel.Implements, Is.EquivalentTo(new[] {"ITest", "ITest2", "ITest3"}));
                }
            }
Ejemplo n.º 23
0
 public QType QualifiedName(FileModel InFile, string Name)
 {
     var qt = new QType();
     var type = Name;
     if (InFile.Package == "") type = Name;
     else if (InFile.Module == "" || InFile.Module == Name) type = InFile.Package + "." + Name;
     else type = InFile.Package + "." + InFile.Module + "." + Name;
     qt.Type = type;
     int p = Name.IndexOf('<');
     if (p > 0)
     {
         qt.Template = Name.Substring(p);
         if (Name[p - 1] == '.') p--;
         qt.Name = Name.Substring(0, p);
     }
     else qt.Name = Name;
     return qt;
 }
Ejemplo n.º 24
0
            public void ParseFile_Comments()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.CommentsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(1, model.Classes.Count);

                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual("\r * Some custom comments\r ", classModel.Comments);
                    Assert.AreEqual(5, classModel.LineFrom);
                    Assert.AreEqual(19, classModel.LineTo);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.Members.Count);
                    var member = classModel.Members[0];
                    Assert.AreEqual(10, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual("Test", member.Name);
                    Assert.AreEqual("Java Style comments", member.Comments);
                    Assert.AreEqual(FlagType.Constructor, member.Flags & FlagType.Constructor);
                    Assert.AreEqual(Visibility.Public, member.Access & Visibility.Public);
                    member = classModel.Members[1];
                    Assert.AreEqual(15, member.LineFrom);
                    Assert.AreEqual(18, member.LineTo);
                    Assert.AreEqual("testAdd", member.Name);
                    Assert.AreEqual("Int", member.Type);
                    Assert.AreEqual("\r\t * Some method documentation\r\t ", member.Comments);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(Visibility.Public, member.Access & Visibility.Public);
                    Assert.AreEqual(2, member.Parameters.Count);
                }
            }
Ejemplo n.º 25
0
 /// <summary>
 /// Rebuild a file model with the source provided
 /// </summary>
 /// <param name="fileModel">Model</param>
 /// <param name="ba">Source</param>
 ///
 public void ParseSrc(FileModel fileModel, string ba)
 {
     ParseSrc(fileModel, ba, true);
 }
Ejemplo n.º 26
0
            public void ParseFile_ComplexClass()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.ComplexClassTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.LineFrom);
                    Assert.AreEqual(49, classModel.LineTo);
                    Assert.AreEqual(15, classModel.Members.Count);

                    var memberModel = classModel.Members[0];
                    Assert.AreEqual("CONSTANT", memberModel.Name);
                    var flags = FlagType.Static | FlagType.Variable;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(4, memberModel.LineFrom);
                    Assert.AreEqual(4, memberModel.LineTo);

                    memberModel = classModel.Members[1];
                    Assert.AreEqual("id", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Variable;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(6, memberModel.LineFrom);
                    Assert.AreEqual(6, memberModel.LineTo);

                    memberModel = classModel.Members[2];
                    Assert.AreEqual("_name", memberModel.Name);
                    Assert.AreEqual("String", memberModel.Type);
                    flags = FlagType.Variable;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(8, memberModel.LineFrom);
                    Assert.AreEqual(8, memberModel.LineTo);

                    memberModel = classModel.Members[3];
                    Assert.AreEqual("ro", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Getter;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(10, memberModel.LineFrom);
                    Assert.AreEqual(10, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    Assert.AreEqual("default", memberModel.Parameters[0].Name);
                    Assert.AreEqual("null", memberModel.Parameters[1].Name);

                    memberModel = classModel.Members[4];
                    Assert.AreEqual("wo", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Getter;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(12, memberModel.LineFrom);
                    Assert.AreEqual(12, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    Assert.AreEqual("null", memberModel.Parameters[0].Name);
                    Assert.AreEqual("default", memberModel.Parameters[1].Name);

                    memberModel = classModel.Members[5];
                    Assert.AreEqual("x", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Getter;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(14, memberModel.LineFrom);
                    Assert.AreEqual(14, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    Assert.AreEqual("get", memberModel.Parameters[0].Name);
                    Assert.AreEqual("set", memberModel.Parameters[1].Name);

                    memberModel = classModel.Members[6];
                    Assert.AreEqual("get_x", memberModel.Name);
                    Assert.AreEqual(null, memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(15, memberModel.LineFrom);
                    Assert.AreEqual(18, memberModel.LineTo);
                    Assert.IsNull(memberModel.Parameters);

                    memberModel = classModel.Members[7];
                    Assert.AreEqual("set_x", memberModel.Name);
                    Assert.AreEqual(null, memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(19, memberModel.LineFrom);
                    Assert.AreEqual(22, memberModel.LineTo);
                    Assert.AreEqual(1, memberModel.Parameters.Count);
                    Assert.AreEqual("val", memberModel.Parameters[0].Name);
                    flags = FlagType.ParameterVar;
                    Assert.AreEqual(flags, memberModel.Parameters[0].Flags & flags);

                    memberModel = classModel.Members[8];
                    Assert.AreEqual("y", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Getter;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(24, memberModel.LineFrom);
                    Assert.AreEqual(24, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    Assert.AreEqual("get", memberModel.Parameters[0].Name);
                    Assert.AreEqual("never", memberModel.Parameters[1].Name);

                    memberModel = classModel.Members[9];
                    Assert.AreEqual("get_y", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(25, memberModel.LineFrom);
                    Assert.AreEqual(25, memberModel.LineTo);
                    Assert.IsNull(memberModel.Parameters);

                    memberModel = classModel.Members[10];
                    Assert.AreEqual("Test", memberModel.Name);
                    flags = FlagType.Function | FlagType.Constructor;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(27, memberModel.LineFrom);
                    Assert.AreEqual(29, memberModel.LineTo);
                    Assert.AreEqual(1, memberModel.Parameters.Count);
                    var param = memberModel.Parameters[0];
                    Assert.AreEqual("?ds", param.Name);
                    Assert.AreEqual("Iterable<String>", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);

                    memberModel = classModel.Members[11];
                    Assert.AreEqual("bar", memberModel.Name);
                    Assert.AreEqual("Void", memberModel.Type);
                    flags = FlagType.Static | FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access & Visibility.Private);
                    Assert.AreEqual(31, memberModel.LineFrom);
                    Assert.AreEqual(33, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    param = memberModel.Parameters[0];
                    Assert.AreEqual("s", param.Name);
                    Assert.AreEqual("String", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(31, param.LineFrom);
                    Assert.AreEqual(31, param.LineTo);
                    param = memberModel.Parameters[1];
                    Assert.AreEqual("v", param.Name);
                    Assert.AreEqual("Bool", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(31, param.LineFrom);
                    Assert.AreEqual(31, param.LineTo);

                    memberModel = classModel.Members[12];
                    Assert.AreEqual("foo", memberModel.Name);
                    Assert.AreEqual("Bool", memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(35, memberModel.LineFrom);
                    Assert.AreEqual(38, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    param = memberModel.Parameters[0];
                    Assert.AreEqual("?s", param.Name);
                    Assert.AreEqual("String", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(35, param.LineFrom);
                    Assert.AreEqual(35, param.LineTo);
                    param = memberModel.Parameters[1];
                    Assert.AreEqual("?v", param.Name);
                    Assert.AreEqual("Bool", param.Type);
                    Assert.AreEqual("true", param.Value);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(35, param.LineFrom);
                    Assert.AreEqual(35, param.LineTo);

                    memberModel = classModel.Members[13];
                    Assert.AreEqual("boz", memberModel.Name);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(40, memberModel.LineFrom);
                    Assert.AreEqual(44, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    param = memberModel.Parameters[0];
                    Assert.AreEqual("?s", param.Name);
                    Assert.AreEqual("String", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(40, param.LineFrom);
                    Assert.AreEqual(40, param.LineTo);
                    param = memberModel.Parameters[1];
                    Assert.AreEqual("?v", param.Name);
                    Assert.AreEqual("Bool", param.Type);
                    Assert.AreEqual("true", param.Value);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(41, param.LineFrom);
                    Assert.AreEqual(41, param.LineTo);

                    memberModel = classModel.Members[14];
                    Assert.AreEqual("nestedGenerics", memberModel.Name);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access & Visibility.Public);
                    Assert.AreEqual(46, memberModel.LineFrom);
                    Assert.AreEqual(48, memberModel.LineTo);
                    Assert.AreEqual(1, memberModel.Parameters.Count);
                    param = memberModel.Parameters[0];
                    Assert.AreEqual("s", param.Name);
                    Assert.AreEqual("Array<Array<Int>>", param.Type);
                    Assert.AreEqual(FlagType.ParameterVar, param.Flags & FlagType.ParameterVar);
                    Assert.AreEqual(46, param.LineFrom);
                    Assert.AreEqual(46, param.LineTo);
                }
            }
Ejemplo n.º 27
0
        private static void ChangeConstructorDecl(ScintillaNet.ScintillaControl Sci, MemberModel member, ClassModel inClass)
        {
            int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true);
            List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos);
            ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));

            if (funcResult == null || funcResult.Type == null) return;
            if (funcResult.Type != null && !funcResult.Type.Equals(inClass))
            {
                AddLookupPosition();
                lookupPosition = -1;

                DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.Type.InFile.FileName, true);
                Sci = ASContext.CurSciControl;

                FileModel fileModel = new FileModel(funcResult.Type.InFile.FileName);
                fileModel.Context = ASContext.Context;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(fileModel, Sci.Text);

                foreach (ClassModel cm in fileModel.Classes)
                {
                    if (cm.QualifiedName.Equals(funcResult.Type.QualifiedName))
                    {
                        funcResult.Type = cm;
                        break;
                    }
                }

                inClass = funcResult.Type;
                ASContext.Context.UpdateContext(inClass.LineFrom);
            }

            foreach (MemberModel m in inClass.Members)
            {
                if ((m.Flags & FlagType.Constructor) > 0)
                {
                    funcResult.Member = m;
                    break;
                }
            }

            if (funcResult.Member == null) return;
            if (isHaxe) funcResult.Member.Name = "new";

            ChangeDecl(Sci, funcResult.Member, functionParameters);
        }
Ejemplo n.º 28
0
            public void ParseFile_Enums()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.EnumsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    Assert.AreEqual(2, model.Classes.Count);

                    var simpleEnum = model.Classes[0];
                    Assert.AreEqual("SimpleEnum", simpleEnum.Name);
                    Assert.AreEqual(2, simpleEnum.LineFrom);
                    Assert.AreEqual(6, simpleEnum.LineTo);
                    Assert.AreEqual(FlagType.Enum, simpleEnum.Flags & FlagType.Enum);
                    Assert.AreEqual(3, simpleEnum.Members.Count);
                    var member = simpleEnum.Members[0];
                    Assert.AreEqual("Foo", member.Name);
                    Assert.AreEqual(3, member.LineFrom);
                    Assert.AreEqual(3, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = simpleEnum.Members[1];
                    Assert.AreEqual("Bar", member.Name);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(4, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    member = simpleEnum.Members[2];
                    Assert.AreEqual("Baz", member.Name);
                    Assert.AreEqual(5, member.LineFrom);
                    Assert.AreEqual(5, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);

                    var complexEnum = model.Classes[1];
                    Assert.AreEqual("ComplexEnum", complexEnum.Name);
                    Assert.AreEqual(8, complexEnum.LineFrom);
                    Assert.AreEqual(11, complexEnum.LineTo);
                    Assert.AreEqual(FlagType.Enum, complexEnum.Flags & FlagType.Enum);
                    Assert.AreEqual(2, complexEnum.Members.Count);
                    member = complexEnum.Members[0];
                    Assert.AreEqual("IntEnum", member.Name);
                    Assert.AreEqual(9, member.LineFrom);
                    Assert.AreEqual(9, member.LineTo);
                    Assert.AreEqual("i", member.Parameters[0].Name);
                    Assert.AreEqual("Int", member.Parameters[0].Type);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    member = complexEnum.Members[1];
                    Assert.AreEqual("MultiEnum", member.Name);
                    Assert.AreEqual(10, member.LineFrom);
                    Assert.AreEqual(10, member.LineTo);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual("i", member.Parameters[0].Name);
                    Assert.AreEqual("Int", member.Parameters[0].Type);
                    Assert.AreEqual("j", member.Parameters[1].Name);
                    Assert.AreEqual("String", member.Parameters[1].Type);
                    Assert.AreEqual("k", member.Parameters[2].Name);
                    Assert.AreEqual("Float", member.Parameters[2].Type);
                }
            }
Ejemplo n.º 29
0
        private static void GenerateFunctionJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member,
            bool detach, ClassModel inClass)
        {
            int position = 0;
            MemberModel latest = null;
            bool isOtherClass = false;

            Visibility funcVisi = job.Equals(GeneratorJobType.FunctionPublic) ? Visibility.Public : GetDefaultVisibility();
            int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true);
            List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos);

            // evaluate, if the function should be generated in other class
            ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));

            int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(Sci.CurrentPos, true));
            MemberModel isStatic = new MemberModel();
            if (contextOwnerPos != -1)
            {
                ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos);
                if (contextOwnerResult != null)
                {
                    if (contextOwnerResult.Member == null && contextOwnerResult.Type != null)
                    {
                        isStatic.Flags |= FlagType.Static;
                    }
                }
            }
            else if (member != null && (member.Flags & FlagType.Static) > 0)
            {
                isStatic.Flags |= FlagType.Static;
            }


            if (funcResult.RelClass != null && !funcResult.RelClass.IsVoid() && !funcResult.RelClass.Equals(inClass))
            {
                AddLookupPosition();
                lookupPosition = -1;

                DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.RelClass.InFile.FileName, true);
                Sci = ASContext.CurSciControl;
                isOtherClass = true;

                FileModel fileModel = new FileModel();
                fileModel.Context = ASContext.Context;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(fileModel, Sci.Text);

                foreach (ClassModel cm in fileModel.Classes)
                {
                    if (cm.QualifiedName.Equals(funcResult.RelClass.QualifiedName))
                    {
                        funcResult.RelClass = cm;
                        break;
                    }
                }
                inClass = funcResult.RelClass;

                ASContext.Context.UpdateContext(inClass.LineFrom);
            }

            string blockTmpl = null;
            if ((isStatic.Flags & FlagType.Static) > 0)
            {
                blockTmpl = TemplateUtils.GetBoundary("StaticMethods");
            }
            else if ((funcVisi & Visibility.Public) > 0)
            {
                blockTmpl = TemplateUtils.GetBoundary("PublicMethods");
            }
            else
            {
                blockTmpl = TemplateUtils.GetBoundary("PrivateMethods");
            }
            latest = TemplateUtils.GetTemplateBlockMember(Sci, blockTmpl);
            if (latest == null || (!isOtherClass && member == null))
            {
                latest = GetLatestMemberForFunction(inClass, funcVisi, isStatic);

                // if we generate function in current class..
                if (!isOtherClass)
                {
                    MethodsGenerationLocations location = ASContext.CommonSettings.MethodsGenerationLocations;
                    if (member == null)
                    {
                        detach = false;
                        lookupPosition = -1;
                        position = Sci.WordStartPosition(Sci.CurrentPos, true);
                        Sci.SetSel(position, Sci.WordEndPosition(position, true));
                    }
                    else if (latest != null && location == MethodsGenerationLocations.AfterSimilarAccessorMethod)
                    {
                        position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                        Sci.SetSel(position, position);
                    }
                    else
                    {
                        position = Sci.PositionFromLine(member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                        Sci.SetSel(position, position);
                    }
                }
                else // if we generate function in another class..
                {
                    if (latest != null)
                    {
                        position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                    }
                    else
                    {
                        position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
                        detach = false;
                    }
                    Sci.SetSel(position, position);
                }
            }
            else
            {
                position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                Sci.SetSel(position, position);
            }

            // add imports to function argument types
            if (functionParameters.Count > 0)
            {
                List<string> l = new List<string>();
                foreach (FunctionParameter fp in functionParameters)
                {
                    try
                    {
                        l.Add(fp.paramQualType);
                    }
                    catch (Exception) { }
                }
                int o = AddImportsByName(l, Sci.LineFromPosition(position));
                position += o;
                if (latest == null)
                    Sci.SetSel(position, Sci.WordEndPosition(position, true));
                else
                    Sci.SetSel(position, position);
            }
            
            List<MemberModel> parameters = new List<MemberModel>();
            for (int i = 0; i < functionParameters.Count; i++)
            {
                string name = functionParameters[i].paramName;
                string type = functionParameters[i].paramType;
                parameters.Add(new MemberModel(name, type, FlagType.ParameterVar, 0));
            }
            MemberModel newMember = NewMember(contextToken, isStatic, FlagType.Function, funcVisi);
            newMember.Parameters = parameters;
            GenerateFunction(newMember, position, detach, inClass);
        }
Ejemplo n.º 30
0
            public void ParseFile_FunctionTypesAsArguments()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.FunctionTypesAsArgumentsTest.hx"))
                {
                    var srcModel = new FileModel(resourceFile.DestinationFile);
                    srcModel.Context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    var model = ASFileParser.ParseFile(srcModel);
                    var classModel = model.Classes[0];
                    Assert.AreEqual("Test", classModel.Name);
                    Assert.AreEqual(FlagType.Class, classModel.Flags & FlagType.Class);
                    Assert.AreEqual(2, classModel.LineFrom);
                    Assert.AreEqual(15, classModel.LineTo);
                    Assert.AreEqual(3, classModel.Members.Count);

                    var memberModel = classModel.Members[0];
                    Assert.AreEqual("func1", memberModel.Name);
                    Assert.AreEqual("Array<Dynamic>", memberModel.Type);
                    var flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access);
                    Assert.AreEqual(4, memberModel.LineFrom);
                    Assert.AreEqual(6, memberModel.LineTo);
                    Assert.AreEqual(1, memberModel.Parameters.Count);
                    Assert.AreEqual("arg", memberModel.Parameters[0].Name);
                    Assert.AreEqual("(Float->Int)->(Int->Array<Dynamic>)", memberModel.Parameters[0].Type);

                    memberModel = classModel.Members[1];
                    Assert.AreEqual("func2", memberModel.Name);
                    Assert.AreEqual(null, memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Public, memberModel.Access);
                    Assert.AreEqual(8, memberModel.LineFrom);
                    Assert.AreEqual(10, memberModel.LineTo);
                    Assert.AreEqual(2, memberModel.Parameters.Count);
                    Assert.AreEqual("arg1", memberModel.Parameters[0].Name);
                    Assert.AreEqual("Int->Void", memberModel.Parameters[0].Type);
                    Assert.AreEqual("arg2", memberModel.Parameters[1].Name);
                    Assert.AreEqual("Dynamic", memberModel.Parameters[1].Type);

                    memberModel = classModel.Members[2];
                    Assert.AreEqual("func3", memberModel.Name);
                    Assert.AreEqual("Int", memberModel.Type);
                    flags = FlagType.Function;
                    Assert.AreEqual(flags, memberModel.Flags & flags);
                    Assert.AreEqual(Visibility.Private, memberModel.Access);
                    Assert.AreEqual(12, memberModel.LineFrom);
                    Assert.AreEqual(14, memberModel.LineTo);
                    Assert.AreEqual(1, memberModel.Parameters.Count);
                    Assert.AreEqual("arg", memberModel.Parameters[0].Name);
                    Assert.AreEqual("Float", memberModel.Parameters[0].Type);
                }
            }
Ejemplo n.º 31
0
        private void ReadType(JsonReader reader)
        {
            // root/modules/types
            FileModel cFile;
            ClassModel cClass;
            cFile = new FileModel();
            cFile.HasPackage = true;
            cFile.Version = 3;
            cFile.Context = context;
            cClass = new ClassModel();
            cClass.Flags = FlagType.Class;
            MemberModel cDelegate = new MemberModel();
            List<string> names;

            string prop = null;
            while (reader.Read())
            {
                if (reader.Token == JsonToken.ObjectEnd) break;
                if (reader.Token == JsonToken.PropertyName) prop = reader.Value.ToString();
                else if (reader.Token == JsonToken.String)
                {
                    string val = reader.Value.ToString();
                    switch (prop)
                    {
                        case "name": cClass.Name = val; break;
                        case "source":
                            if (val.IndexOf('/') > 0) val = val.Substring(val.IndexOf('/') + 1);
                            cFile.FileName = path.Path + "::" + val;
                            break;
                        case "package":
                            if (val.ToLower() == "cocos2d") val = "cocos2d"; // random casing through source
                            cFile.Package = val; 
                            break;
                        case "baseType": cClass.ExtendsType = val; break;
                        case "delegateReturnType": cDelegate.Type = CleanType(val); break;
                        case "type":
                            switch (val)
                            {
                                case "CLASS": break;
                                case "INTERFACE": cClass.Flags |= FlagType.Interface; break;
                                case "STRUCT": cClass.Flags |= FlagType.Struct; break;
                                case "DELEGATE": cDelegate.Name = cClass.Name; break;
                            }
                            break;
                        case "docstring": cClass.Comments = ExtractDoc(val); break;
                    }
                }
                else if (reader.Token == JsonToken.ArrayStart)
                {
                    switch (prop)
                    {
                        case "classattributes": ReadAttributes(reader, cClass); break;
                        case "fields": ReadFields(reader, cClass); break;
                        case "methods": ReadMethods(reader, cClass); break;
                        case "properties": ReadProperties(reader, cClass); break;
                        case "metainfo": ReadMetas(reader, cClass); break;
                        case "imports": 
                            names = ReadNames(reader);
                            foreach (string name in names)
                                cFile.Imports.Add(new MemberModel(name, name, FlagType.Import, Visibility.Public)); 
                            break;
                        case "interfaces": ReadInterfaces(reader, cClass); break;
                        case "delegateTypes":
                            names = ReadNames(reader);
                            if (names.Count > 0)
                            {
                                cDelegate.Parameters = new List<MemberModel>();
                                foreach (string argType in names)
                                {
                                    cDelegate.Parameters.Add(
                                        new MemberModel("p" + cDelegate.Parameters.Count, argType, FlagType.ParameterVar, Visibility.Public));
                                }
                            }
                            break;
                        default: reader.SkipArray(); break;
                    }
                }
                else if (reader.Token == JsonToken.ObjectStart)
                {
                    switch (prop)
                    {
                        case "constructor": 
                            MemberModel ctor = ReadMethod(reader, cClass);
                            cClass.Constructor = ctor.Name;
                            break;
                        default: reader.SkipObject(); break;
                    }
                }
            }

            if (cFile.FileName == null) return;
            string key = cFile.FileName.ToUpper();
            if (files.ContainsKey(key)) cFile = files[key];
            else files.Add(key, cFile);

            if (cFile.Package.ToLower() == "system") // System classes tweaks
            {
                cFile.Package = "";
                if (cClass.Name == "Vector") cClass.Name = "Vector.<T>";
                if (cClass.Name == "Object") cClass.ExtendsType = "void";
            }
            if (cClass.Access == Visibility.Private) cClass.Access = Visibility.Public;

            if (cDelegate.Name != null)
            {
                if (cDelegate.Parameters == null) cDelegate.Parameters = new List<MemberModel>();
                cDelegate.Access = Visibility.Public;
                cDelegate.Flags = FlagType.Function | FlagType.Delegate;
                cDelegate.InFile = cFile;
                cDelegate.IsPackageLevel = true;
                cFile.Members.Add(cDelegate);
            }
            else
            {
                cClass.Type = CleanType(String.IsNullOrEmpty(cFile.Package) ? cClass.Name : cFile.Package + "." + cClass.Name);
                cClass.InFile = cFile;
                cFile.Classes.Add(cClass);
            }
        }
Ejemplo n.º 32
0
        private bool ParseFoundFiles()
        {
            bool writeCache = false;

            // parse files
            int n = foundFiles.Count;

            NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), 0, n);
            FileModel aFile = null;
            int       cpt   = 0;
            string    filename;

            for (int i = 0; i < n; i++)
            {
                if (stopExploration)
                {
                    return(writeCache);
                }
                // parse
                filename = foundFiles[i];
                if (!File.Exists(filename))
                {
                    continue;
                }
                if (pathModel.HasFile(filename))
                {
                    FileModel cachedModel = pathModel.GetFile(filename);
                    if (cachedModel.OutOfDate)
                    {
                        cachedModel.Check();
                        writeCache = true;
                    }
                    continue;
                }
                else
                {
                    writeCache = true;
                }

                aFile = GetFileModel(filename);

                if (aFile == null || pathModel.HasFile(filename))
                {
                    continue;
                }
                // store model
                if (aFile.Context.IsModelValid(aFile, pathModel))
                {
                    pathModel.AddFile(aFile);
                }
                aFile = null;
                cpt++;
                // update status
                if (stopExploration)
                {
                    return(writeCache);
                }
                if (i % 10 == 0)
                {
                    NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), n), i, n);
                }
                Thread.Sleep(1);
            }
            return(writeCache);
        }