Beispiel #1
0
        public static object GetDefaultValue(SvgElement element, string attributename)
        {
            string  text1;
            DomType type1 = DomTypeFunc.GetTypeOfAttributeName(attributename);

            if ((text1 = attributename) != null)
            {
                text1 = string.IsInterned(text1);
                if (((text1 == "fill-opacity") || (text1 == "opacity")) || (((text1 == "stroke-opacity") || (text1 == "stroke-width")) || (text1 == "stop-opacity")))
                {
                    return(1f);
                }
            }
            switch (type1)
            {
            case DomType.SvgNumber:
            {
                return(0f);
            }

            case DomType.SvgString:
            {
                return(string.Empty);
            }

            case DomType.SvgColor:
            {
                return(string.Empty);
            }
            }
            return(string.Empty);
        }
Beispiel #2
0
        /// <summary>
        /// Create an IMember from a LanguageItem,
        /// using the source document to locate declaration bounds.
        /// </summary>
        /// <param name="pi">
        /// A <see cref="ProjectInformation"/> for the current project.
        /// </param>
        /// <param name="item">
        /// A <see cref="LanguageItem"/>: The item to convert.
        /// </param>
        /// <param name="contentLines">
        /// A <see cref="System.String[]"/>: The document in which item is defined.
        /// </param>
        static IMember LanguageItemToIMember(ProjectInformation pi, LanguageItem item, string[] contentLines)
        {
            if (item is Class || item is Structure)
            {
                DomType klass = new DomType(new CompilationUnit(item.File), ClassType.Class, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new List <IMember> ());

                foreach (LanguageItem li in pi.AllItems())
                {
                    if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File))
                    {
                        klass.Add(LanguageItemToIMember(pi, li, contentLines));
                    }
                }
                return(klass);
            }
            if (item is Enumeration)
            {
                return(new DomType(new CompilationUnit(item.File), ClassType.Enum, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, (int)item.Line + 1), new List <IMember> ()));
            }
            if (item is Function)
            {
                return(new DomMethod(item.Name, Modifiers.None, MethodModifier.None, new DomLocation((int)item.Line, 1), new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new DomReturnType()));
            }
            if (item is Member)
            {
                return(new DomField(item.Name, Modifiers.None, new DomLocation((int)item.Line, 1), new DomReturnType()));
            }
            return(null);
        }
        internal static int ResolveTypes(ProjectDom db, ICompilationUnit unit, IList <IType> types, out List <IType> result)
        {
            TypeResolverVisitor tr = new TypeResolverVisitor(db, unit);

            int unresolvedCount = 0;

            result = new List <IType> ();
            foreach (IType c in types)
            {
                tr.UnresolvedCount = 0;
                DomType rc = (DomType)c.AcceptVisitor(tr, null);
                rc.Resolved = true;

                if (tr.UnresolvedCount == 0 && c.FullName != "System.Object")
                {
                    // If the class has no base classes, make sure it subclasses System.Object
                    if (rc.BaseType == null)
                    {
                        rc.BaseType = new DomReturnType("System.Object");
                    }
                }

                result.Add(rc);
                unresolvedCount += tr.UnresolvedCount;
            }

            return(unresolvedCount);
        }
Beispiel #4
0
        IEnumerable <IType> BuildClasses(IEnumerable <PythonClass> classes)
        {
            foreach (PythonClass pyClass in classes)
            {
                var domType = new DomType()
                {
                    Name          = pyClass.Name,
                    Documentation = pyClass.Documentation,
                    ClassType     = ClassType.Class,
                    BodyRegion    = pyClass.Region,
                    Location      = new DomLocation(pyClass.Region.Start.Line - 1, 0),
                };
                m_AllWrapped.Add(domType);

                // class functions
                foreach (IMethod method in BuildFunctions(pyClass.Functions))
                {
                    domType.Add(method);
                }

                // class attributes
                foreach (IField field in BuildAttributes(pyClass.Attributes))
                {
                    domType.Add(field);
                }

                yield return(domType);
            }
        }
Beispiel #5
0
        public IType GetArrayType(IReturnType elementType, MonoDevelop.Projects.Dom.Output.Ambience ambience)
        {
            // Create a fake class which sublcasses System.Array and implements IList<T>
            DomType t = new DomType(ambience.GetString(elementType, MonoDevelop.Projects.Dom.Output.OutputFlags.UseFullName) + "[]");

            // set the compilation unit of the array type to that of the element type - it's required for jumping to the declaration of the type.
            IType eType = GetType(elementType);

            if (eType != null)
            {
                t.CompilationUnit = eType.CompilationUnit;
            }

            t.Resolved         = true;
            t.BaseType         = new DomReturnType("System.Array");
            t.ClassType        = ClassType.Class;
            t.Modifiers        = Modifiers.Public;
            t.SourceProjectDom = this;
            DomProperty indexer = new DomProperty();

            indexer.Name              = "Item";
            indexer.SetterModifier    = indexer.GetterModifier = Modifiers.Public;
            indexer.PropertyModifier |= PropertyModifier.IsIndexer;
            indexer.Add(new DomParameter(indexer, "index", DomReturnType.Int32));
            indexer.ReturnType = elementType;
            t.Add(indexer);
            DomReturnType listType = new DomReturnType("System.Collections.Generic.IList", false, new IReturnType [] { elementType });

            t.AddInterfaceImplementation(listType);
            return(t);
        }
Beispiel #6
0
        public void TestDomReadWriteResourceCreateWithPersonResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var personResourceType       = serviceModel.GetResourceType <Person>();
            var personResourceIdentity   = personResourceType.ResourceIdentityInfo;
            var personFirstNameAttribute = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.FirstName));
            var personLastNameAttribute  = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.LastName));
            var personTwitterAttribute   = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.Twitter));

            var expected = ApiSampleData.PersonResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(personResourceType),
                DomId.CreateFromApiResourceIdentity(personResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(personFirstNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personLastNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personTwitterAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.PersonToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.PersonToCommentsHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
Beispiel #7
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private void CreateAndAddDomReadWriteResourceIdentifierCollectionIfNeeded(int count)
        {
            Contract.Requires(count > 0);

            if (this.DomReadWriteResourceIdentifierCollection != null)
            {
                return;
            }

            var clrResourceType = typeof(TResource);
            var resourceType    = this.ServiceModel.GetResourceType(clrResourceType);

            this.ResourceType = resourceType;

            var domContainerNode = this.DomContainerNode;
            var domReadWriteResourceIdentifierCollection = new List <DomReadWriteResourceIdentifier>(count);

            for (var i = 0; i < count; ++i)
            {
                var domResourceType = DomType.CreateFromResourceType(resourceType);
                var domReadWriteResourceIdentifier = DomReadWriteResourceIdentifier.Create(domResourceType);

                domContainerNode.Add(domReadWriteResourceIdentifier);
                domReadWriteResourceIdentifierCollection.Add(domReadWriteResourceIdentifier);
            }

            this.DomReadWriteResourceIdentifierCollection = domReadWriteResourceIdentifierCollection;
        }
Beispiel #8
0
        public void TestDomReadWriteResourceCreateWithCommentResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var commentResourceType     = serviceModel.GetResourceType <Comment>();
            var commentResourceIdentity = commentResourceType.ResourceIdentityInfo;
            var commentBodyAttribute    = commentResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Comment>(x => x.Body));

            var expected = ApiSampleData.CommentResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(commentResourceType),
                DomId.CreateFromApiResourceIdentity(commentResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(commentBodyAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.CommentToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.CommentToAuthorHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
Beispiel #9
0
        public void TestDomReadWriteResourceCreateWithBlogResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var blogResourceType     = serviceModel.GetResourceType <Blog>();
            var blogResourceIdentity = blogResourceType.ResourceIdentityInfo;
            var blogNameAttribute    = blogResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Blog>(x => x.Name));

            var expectedBlog = ApiSampleData.BlogResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(blogResourceType),
                DomId.CreateFromApiResourceIdentity(blogResourceType, expectedBlog),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(blogNameAttribute, expectedBlog)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.BlogToArticlesRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogToRelationshipsToArticlesHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.BlogToArticlesHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedBlog, actual);
        }
Beispiel #10
0
        public void ReadWriteTypeTestComplex()
        {
            DomType input = new DomType();

            input.Name      = "Test";
            input.ClassType = ClassType.Struct;
            input.BaseType  = new DomReturnType("BaseClass");
            input.AddInterfaceImplementation(new DomReturnType("Interface1"));
            input.AddInterfaceImplementation(new DomReturnType("Interface2"));

            input.Add(new DomMethod("TestMethod", Modifiers.None, MethodModifier.None, DomLocation.Empty, DomRegion.Empty));
            input.Add(new DomMethod(".ctor", Modifiers.None, MethodModifier.IsConstructor, DomLocation.Empty, DomRegion.Empty));

            input.Add(new DomField("TestField", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
            input.Add(new DomProperty("TestProperty", Modifiers.None, DomLocation.Empty, DomRegion.Empty, DomReturnType.Void));
            input.Add(new DomEvent("TestEvent", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            DomPersistence.Write(writer, DefaultNameEncoder, input);
            byte[] bytes = ms.ToArray();

            DomType result = DomPersistence.ReadType(CreateReader(bytes), DefaultNameDecoder, null);

            Assert.AreEqual("Test", result.Name);
            Assert.AreEqual(ClassType.Struct, result.ClassType);
            Assert.AreEqual("BaseClass", result.BaseType.Name);
            Assert.AreEqual(1, result.MethodCount);
            Assert.AreEqual(1, result.ConstructorCount);
            Assert.AreEqual(1, result.FieldCount);
            Assert.AreEqual(1, result.PropertyCount);
            Assert.AreEqual(1, result.EventCount);
        }
Beispiel #11
0
        public void ExtensionMethodPreserveParameterTest()
        {
            // build "T MyMethod<T, S> (T a, S b)"
            DomMethod method = new DomMethod();

            method.Name       = "MyMethod";
            method.ReturnType = new DomReturnType("T");
            method.AddTypeParameter(new TypeParameter("T"));
            method.AddTypeParameter(new TypeParameter("S"));

            method.Add(new DomParameter(method, "a", new DomReturnType("T")));
            method.Add(new DomParameter(method, "b", new DomReturnType("S")));

            // extend method
            List <IReturnType> genArgs = new List <IReturnType> ();
            List <IReturnType> args    = new List <IReturnType> ();
            DomType            extType = new DomType("MyType");

            ExtensionMethod extMethod = new ExtensionMethod(extType, method, genArgs, args);

            // check for MyType MyMethod<S> (S b)
            Assert.AreEqual("MyType", extMethod.ReturnType.FullName);
            Assert.AreEqual("S", extMethod.Parameters[0].ReturnType.FullName);
            Assert.AreEqual(1, extMethod.TypeParameters.Count);
            Assert.AreEqual("S", extMethod.TypeParameters[0].Name);
        }
Beispiel #12
0
        public string GetComponentTypeOf(Func <string, string> callback, string varName)
        {
            if (callback == null)
            {
                return("var");
            }

            string var = callback(varName);
            ITextEditorResolver textEditorResolver = CurrentContext.Document.GetContent <ITextEditorResolver> ();

            if (textEditorResolver != null)
            {
                ResolveResult result = textEditorResolver.GetLanguageItem(CurrentContext.Document.TextEditor.CursorPosition, var);
                if (result != null)
                {
                    IReturnType componentType = DomType.GetComponentType(CurrentContext.ProjectDom, result.ResolvedType);
                    if (componentType != null)
                    {
                        Ambience ambience = AmbienceService.GetAmbience(CurrentContext.Template.MimeType);
                        return(ambience != null?ambience.GetString(componentType, OutputFlags.IncludeGenerics) :  componentType.ToInvariantString());
                    }
                }
            }

            return("var");
        }
Beispiel #13
0
        public virtual IEnumerable <IType> GetInheritanceTree(IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            type = ResolveType(type);
            if (type == null)
            {
                yield break;
            }

            HashSet <string> alreadyTaken = new HashSet <string> ();
            Stack <IType>    types        = new Stack <IType> ();

            types.Push(type);
            while (types.Count > 0)
            {
                IType cur = types.Pop();
                if (cur == null)
                {
                    continue;
                }

                string fullName = DomType.GetNetFullName(cur);
                if (!alreadyTaken.Add(fullName))
                {
                    continue;
                }
                yield return(cur);

                foreach (IReturnType baseType in cur.BaseTypes)
                {
                    // There is no need to resolve baseType here, since 'cur' is an already resolved
                    // type, so all types it references are already resolved too
                    IType resolvedType = GetType(baseType);
                    if (resolvedType != null)
                    {
                        types.Push(resolvedType);
                    }
                }
                if (cur.BaseType == null && cur.FullName != "System.Object")
                {
                    if (cur.ClassType == ClassType.Enum)
                    {
                        types.Push(this.GetType(DomReturnType.Enum));
                    }
                    else if (cur.ClassType == ClassType.Struct)
                    {
                        types.Push(this.GetType(DomReturnType.ValueType));
                    }
                    else
                    {
                        types.Push(this.GetType(DomReturnType.Object));
                    }
                }
            }
        }
        public static List <string> GetResolveableNamespaces(RefactoringOptions options, out bool resolveDirect)
        {
            IReturnType            returnType  = null;
            INRefactoryASTProvider astProvider = RefactoringService.GetASTProvider(DesktopService.GetMimeTypeForUri(options.Document.FileName));

            if (options.ResolveResult != null && options.ResolveResult.ResolvedExpression != null)
            {
                if (astProvider != null)
                {
                    returnType = astProvider.ParseTypeReference(options.ResolveResult.ResolvedExpression.Expression).ConvertToReturnType();
                }
                if (returnType == null)
                {
                    returnType = DomReturnType.GetSharedReturnType(options.ResolveResult.ResolvedExpression.Expression);
                }
            }

            List <string> namespaces;

            if (options.ResolveResult is UnresolvedMemberResolveResult)
            {
                namespaces = new List <string> ();
                UnresolvedMemberResolveResult unresolvedMemberResolveResult = options.ResolveResult as UnresolvedMemberResolveResult;
                IType type = unresolvedMemberResolveResult.TargetResolveResult != null?options.Dom.GetType(unresolvedMemberResolveResult.TargetResolveResult.ResolvedType) : null;

                if (type != null)
                {
                    List <IType> allExtTypes = DomType.GetAccessibleExtensionTypes(options.Dom, null);
                    foreach (ExtensionMethod method in type.GetExtensionMethods(allExtTypes, unresolvedMemberResolveResult.MemberName))
                    {
                        string ns = method.OriginalMethod.DeclaringType.Namespace;
                        if (!namespaces.Contains(ns) && !options.Document.CompilationUnit.Usings.Any(u => u.Namespaces.Contains(ns)))
                        {
                            namespaces.Add(ns);
                        }
                    }
                }
                resolveDirect = false;
            }
            else
            {
                namespaces    = new List <string> (options.Dom.ResolvePossibleNamespaces(returnType));
                resolveDirect = true;
            }
            for (int i = 0; i < namespaces.Count; i++)
            {
                for (int j = i + 1; j < namespaces.Count; j++)
                {
                    if (namespaces[j] == namespaces[i])
                    {
                        namespaces.RemoveAt(j);
                        j--;
                    }
                }
            }
            return(namespaces);
        }
        void AddContentsFromClassAndMembers(ExpressionContext context, CSharpTextEditorCompletion.CompletionDataCollector col)
        {
            IMethod method = callingMember as IMethod;

            if (method != null && method.Parameters != null)
            {
                AddParameterList(col, method.Parameters);
            }
            IProperty property = callingMember as IProperty;

            if (property != null && property.Parameters != null)
            {
                AddParameterList(col, property.Parameters);
            }
            if (CallingType == null)
            {
                return;
            }

            AddContentsFromOuterClass(CallingType, context, col);
            IType callingType = CallingType is InstantiatedType ? ((InstantiatedType)CallingType).UninstantiatedType : CallingType;

            //bool isInStatic = CallingMember != null ? CallingMember.IsStatic : false;

            if (CallingMember == null || !CallingMember.IsStatic)
            {
                foreach (TypeParameter parameter in callingType.TypeParameters)
                {
                    col.Add(parameter.Name, "md-literal");
                }
            }

            if (context != ExpressionContext.TypeDeclaration && CallingMember != null)
            {
                bool includeProtected = DomType.IncludeProtected(dom, CallingType, CallingMember.DeclaringType);
                foreach (IType type in dom.GetInheritanceTree(CallingType))
                {
                    foreach (IMember member in type.Members)
                    {
                        if (!(member is IType) && CallingMember.IsStatic && !(member.IsStatic || member.IsConst))
                        {
                            continue;
                        }
                        if (member.IsAccessibleFrom(dom, CallingType, CallingMember, includeProtected))
                        {
                            if (context.FilterEntry(member))
                            {
                                continue;
                            }
                            col.Add(member);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        public virtual object GetAnimateResult(float time, DomType domtype)
        {
            if (time < this.Begin)
            {
                return(string.Empty);
            }
            object obj1 = this.FFT(time, domtype);

            this.pretime = (int)time;
            return(obj1);
        }
Beispiel #17
0
            public override object VisitEventDeclaration(ICSharpCode.OldNRefactory.Ast.EventDeclaration eventDeclaration, object data)
            {
                Debug.Assert(currentType.Count > 0);
                DomType type = currentType.Peek();

                type.Add(new DomEvent(eventDeclaration.Name,
                                      (Modifiers)eventDeclaration.Modifier,
                                      new DomLocation(eventDeclaration.StartLocation.Line, eventDeclaration.StartLocation.Column),
                                      TranslateTypeReference(eventDeclaration.TypeReference)));
                return(null);
            }
Beispiel #18
0
        // used for constructor completion
        public NRefactoryParameterDataProvider(MonoDevelop.Ide.Gui.TextEditor editor, NRefactoryResolver resolver, IType type)
        {
            this.editor = editor;

            if (type != null)
            {
                if (type.ClassType == ClassType.Delegate)
                {
                    IMethod invokeMethod = ExtractInvokeMethod(type);
                    if (type is InstantiatedType)
                    {
                        this.delegateName = ((InstantiatedType)type).UninstantiatedType.Name;
                    }
                    else
                    {
                        this.delegateName = type.Name;
                    }
                    if (invokeMethod != null)
                    {
                        methods.Add(invokeMethod);
                    }
                    else
                    {
                        // no invoke method -> tried to create an abstract delegate
                    }
                    return;
                }
                bool             includeProtected = DomType.IncludeProtected(resolver.Dom, type, resolver.CallingType);
                bool             constructorFound = false;
                HashSet <string> alreadyAdded     = new HashSet <string> ();
                foreach (IMethod method in type.Methods)
                {
                    constructorFound |= method.IsConstructor;
                    string str = ambience.GetString(method, OutputFlags.IncludeParameters);
                    if (alreadyAdded.Contains(str))
                    {
                        continue;
                    }
                    alreadyAdded.Add(str);
                    if ((method.IsConstructor && method.IsAccessibleFrom(resolver.Dom, type, resolver.CallingMember, includeProtected)))
                    {
                        methods.Add(method);
                    }
                }
                // No constructor - generating default
                if (!constructorFound && (type.TypeModifier & TypeModifier.HasOnlyHiddenConstructors) != TypeModifier.HasOnlyHiddenConstructors)
                {
                    DomMethod defaultConstructor = new DomMethod();
                    defaultConstructor.MethodModifier = MethodModifier.IsConstructor;
                    defaultConstructor.DeclaringType  = type;
                    methods.Add(defaultConstructor);
                }
            }
        }
Beispiel #19
0
 private object FFT(float time, DomType domtype)
 {
     if (time <= (this.Begin + this.RealDur))
     {
         return(this.FCumT(time, domtype));
     }
     if (this.GetAttribute("fill").Trim() == "freeze")
     {
         return(this.FCumT(this.Begin + this.RealDur, domtype));
     }
     return(null);
 }
Beispiel #20
0
            public override object VisitConstructorDeclaration(ICSharpCode.OldNRefactory.Ast.ConstructorDeclaration constructorDeclaration, object data)
            {
                Debug.Assert(currentType.Count > 0);
                DomType type = currentType.Peek();

                type.Add(new DomMethod(constructorDeclaration.Name,
                                       (Modifiers)constructorDeclaration.Modifier,
                                       MethodModifier.IsConstructor,
                                       new DomLocation(constructorDeclaration.StartLocation.Line, constructorDeclaration.StartLocation.Column),
                                       constructorDeclaration.Body != null ? TranslateRegion(constructorDeclaration.Body.StartLocation, constructorDeclaration.Body.EndLocation) : DomRegion.Empty));
                return(null);
            }
            public override object VisitPropertyDeclaration(ICSharpCode.NRefactory.Ast.PropertyDeclaration propertyDeclaration, object data)
            {
                Debug.Assert(currentType.Count > 0);
                DomType type = currentType.Peek();

                type.Add(new DomProperty(propertyDeclaration.Name,
                                         (MonoDevelop.Projects.Dom.Modifiers)propertyDeclaration.Modifier,
                                         new DomLocation(propertyDeclaration.StartLocation.Line, propertyDeclaration.StartLocation.Column),
                                         TranslateRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd),
                                         TranslateTypeReference(propertyDeclaration.TypeReference)));
                return(null);
            }
            public override object VisitMethodDeclaration(ICSharpCode.NRefactory.Ast.MethodDeclaration methodDeclaration, object data)
            {
                Debug.Assert(currentType.Count > 0);
                DomType type = currentType.Peek();

                type.Add(new DomMethod(methodDeclaration.Name,
                                       (MonoDevelop.Projects.Dom.Modifiers)methodDeclaration.Modifier,
                                       false,                   // isConstructor
                                       new DomLocation(methodDeclaration.StartLocation.Line, methodDeclaration.StartLocation.Column),
                                       methodDeclaration.Body != null ? TranslateRegion(methodDeclaration.Body.StartLocation, methodDeclaration.Body.EndLocation) : DomRegion.Empty));
                return(null);
            }
Beispiel #23
0
        public void TestDomReadWriteResourceCreateWithArticleResourceWithResourceLinkage()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var articleResourceType   = serviceModel.GetResourceType <Article>();
            var articleTitleAttribute = articleResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Article>(x => x.Title));

            var commentResourceType = serviceModel.GetResourceType <Comment>();
            var personResourceType  = serviceModel.GetResourceType <Person>();

            var expectedArticle  = ApiSampleData.ArticleResourceWithResourceLinkage;
            var expectedAuthor   = ApiSampleData.PersonResource;
            var expectedComment1 = ApiSampleData.CommentResource1;
            var expectedComment2 = ApiSampleData.CommentResource2;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(articleResourceType),
                DomId.CreateFromApiResourceIdentity(articleResourceType, expectedArticle),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(articleTitleAttribute, expectedArticle)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToAuthorHRef))),
                                                    DomData.CreateFromResourceIdentifier(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(personResourceType),
                                                            DomId.CreateFromApiResourceIdentity(personResourceType, expectedAuthor)))),
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToCommentsHRef))),
                                                    DomDataCollection.CreateFromResourceIdentifiers(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment1)),
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment2))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Canonical, DomHRef.Create(ApiSampleData.ArticleHRef)),
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedArticle, actual);
        }
Beispiel #24
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(string expected, DomType actual)
        {
            if (String.IsNullOrWhiteSpace(expected))
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            var actualApiType = actual.ApiType;

            Assert.Equal(expected, actualApiType);
        }
        /// <summary>
        /// Create an IMember from a LanguageItem,
        /// using the source document to locate declaration bounds.
        /// </summary>
        /// <param name="pi">
        /// A <see cref="ProjectInformation"/> for the current project.
        /// </param>
        /// <param name="item">
        /// A <see cref="LanguageItem"/>: The item to convert.
        /// </param>
        /// <param name="contentLines">
        /// A <see cref="System.String[]"/>: The document in which item is defined.
        /// </param>
        static IMember LanguageItemToIMember(ProjectInformation pi, LanguageItem item, string[] contentLines)
        {
            if (item is Class || item is Structure)
            {
                DomType klass = new DomType(new CompilationUnit(item.File), ClassType.Class, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new List <IMember> ());

                foreach (LanguageItem li in pi.AllItems())
                {
                    if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File))
                    {
                        klass.Add(LanguageItemToIMember(pi, li, contentLines));
                    }
                }
                return(klass);
            }
            if (item is Enumeration)
            {
                return(new DomType(new CompilationUnit(item.File), ClassType.Enum, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, (int)item.Line + 1), new List <IMember> ()));
            }
            if (item is Function)
            {
                DomMethod         method   = new DomMethod(item.Name, Modifiers.None, MethodModifier.None, new DomLocation((int)item.Line, 1), new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new DomReturnType());
                Function          function = (Function)item;
                Match             match;
                bool              abort      = false;
                List <IParameter> parameters = new List <IParameter> ();

                foreach (string parameter in function.Parameters)
                {
                    match = paramExpression.Match(parameter);
                    if (null == match)
                    {
                        abort = true;
                        break;
                    }
                    DomParameter p = (new DomParameter(method, match.Groups["name"].Value,
                                                       new DomReturnType(string.Format("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value))));
                    parameters.Add(p);
                }
                if (!abort)
                {
                    method.Add(parameters);
                }
                return(method);
            }
            if (item is Member)
            {
                return(new DomField(item.Name, Modifiers.None, new DomLocation((int)item.Line, 1), new DomReturnType()));
            }
            return(null);
        }
Beispiel #26
0
            public override object VisitFieldDeclaration(ICSharpCode.OldNRefactory.Ast.FieldDeclaration fieldDeclaration, object data)
            {
                Debug.Assert(currentType.Count > 0);
                DomType type = currentType.Peek();

                foreach (ICSharpCode.OldNRefactory.Ast.VariableDeclaration field in fieldDeclaration.Fields)
                {
                    type.Add(new DomField(field.Name,
                                          (Modifiers)fieldDeclaration.Modifier,
                                          new DomLocation(fieldDeclaration.StartLocation.Line, fieldDeclaration.StartLocation.Column),
                                          TranslateTypeReference(fieldDeclaration.TypeReference)));
                }
                return(null);
            }
Beispiel #27
0
        bool HasAnyOverloadWithParameters(IMethod method)
        {
            var          type = method.DeclaringType;
            List <IType> accessibleExtTypes = DomType.GetAccessibleExtensionTypes(editorCompletion.Dom, editorCompletion.GetDocument().CompilationUnit);

            foreach (var t in type.SourceProjectDom.GetInheritanceTree(type))
            {
                if (t.Methods.Concat(t.GetExtensionMethods(accessibleExtTypes, method.Name)).Any(m => m.Parameters.Count > 0))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #28
0
        }        // CanParse

        public override ParsedDocument Parse(ProjectDom dom, string fileName, string content)
        {
            ParsedDocument doc = new ParsedDocument(fileName);

            doc.Flags |= ParsedDocumentFlags.NonSerializable;
            Project p = (null == dom || null == dom.Project)?
                        IdeApp.Workspace.GetProjectContainingFile(fileName):
                        dom.Project;
            ProjectInformation pi = ProjectInformationManager.Instance.Get(p);
            CompilationUnit    cu;

            doc.CompilationUnit = cu = new CompilationUnit(fileName);
            IType   tmp;
            IMember member;

            string[] contentLines = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            DomType  globals      = new DomType(cu, ClassType.Unknown, GettextCatalog.GetString("(Global Scope)"), new DomLocation(1, 1), string.Empty, new DomRegion(1, int.MaxValue), new List <IMember> ());

            lock (pi) {
                // Add containers to type list
                foreach (LanguageItem li in pi.Containers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        tmp = LanguageItemToIMember(pi, li, contentLines) as IType;
                        if (null != tmp)
                        {
                            cu.Add(tmp);
                        }
                    }
                }

                // Add global category for unscoped symbols
                foreach (LanguageItem li in pi.InstanceMembers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        member = LanguageItemToIMember(pi, li, contentLines);
                        if (null != member)
                        {
                            globals.Add(member);
                        }
                    }
                }
            }

            cu.Add(globals);

            return(doc);
        }
Beispiel #29
0
        public void ReadWriteDelegateTest()
        {
            DomType input = DomType.CreateDelegate(null, "TestDelegate", new DomLocation(10, 10), DomReturnType.Void, new List <IParameter> ());

            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            DomPersistence.Write(writer, DefaultNameEncoder, input);
            byte[] bytes = ms.ToArray();

            DomType result = DomPersistence.ReadType(CreateReader(bytes), DefaultNameDecoder, null);

            Assert.AreEqual("TestDelegate", result.Name);
            Assert.AreEqual(ClassType.Delegate, result.ClassType);
        }
Beispiel #30
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private void CreateAndAddDomReadWriteResourceIdentifierIfNeeded()
        {
            if (this.DomReadWriteResourceIdentifier != null)
            {
                return;
            }

            var domResourceType = DomType.CreateFromResourceType(this.ResourceType);
            var domReadWriteResourceIdentifier = DomReadWriteResourceIdentifier.Create(domResourceType);

            var domContainerNode = this.DomContainerNode;

            domContainerNode.Add(domReadWriteResourceIdentifier);

            this.DomReadWriteResourceIdentifier = domReadWriteResourceIdentifier;
        }
		void TestCreateInterface (string interfacecode, string outputString)
		{
			var dom = new SimpleProjectDom ();
			
			var parser = new McsParser ();
			var unit = parser.Parse (dom, "Interface.cs", interfacecode);
			
			DomType stubType = new DomType ("Stub");
			stubType.SourceProjectDom = dom;
			stubType.CompilationUnit = new CompilationUnit ("Stub.cs");
			var iface = unit.CompilationUnit.Types[0];
			var gen = new CSharpCodeGenerator ();
			gen.EolMarker = "\n";
			string generated = gen.CreateInterfaceImplementation (stubType, iface, false);
			// crop #region
			generated = generated.Substring (generated.IndexOf ("implementation") + "implementation".Length);
			generated = generated.Substring (0, generated.LastIndexOf ("#"));
			generated = generated.Trim ();
			System.Console.WriteLine (generated);
			Assert.AreEqual (outputString, generated);
		}
Beispiel #32
0
 public override object FT(float time, DomType domtype)
 {
     if (time < base.Begin)
     {
         return null;
     }
     if ((time < base.Begin) || (time > (base.Begin + base.Duration)))
     {
         return null;
     }
     string text1 = base.ToWhat;
     switch (domtype)
     {
         case DomType.SvgMatrix:
         {
             return new Transf(this.Type + "(" + text1.Trim() + ")").Matrix;
         }
         case DomType.SvgNumber:
         {
             return ItopVector.Core.Func.Number.parseToFloat(text1.Trim(), (SvgElement) this.ParentNode, ItopVector.Core.Func.SvgLengthDirection.Horizontal);
         }
         case DomType.SvgString:
         {
             return text1.Trim();
         }
         case DomType.SvgColor:
         {
             return text1.Trim();
         }
         case DomType.SvgPath:
         {
             return PathFunc.PathDataParse(text1);
         }
         case DomType.SvgPoints:
         {
             return PointsFunc.PointsParse(text1);
         }
     }
     return base.ToWhat;
 }
		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			ParsedDocument doc = new ParsedDocument (fileName);
			doc.Flags |= ParsedDocumentFlags.NonSerializable;
			Project p = (null == dom || null == dom.Project)? 
				IdeApp.Workspace.GetProjectContainingFile (fileName):
				dom.Project;
			ProjectInformation pi = ProjectInformationManager.Instance.Get (p);
			CompilationUnit cu;
			doc.CompilationUnit = cu = new CompilationUnit (fileName);
			IType tmp;
			IMember member;
			string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
			DomType globals = new DomType (cu, ClassType.Unknown, GettextCatalog.GetString ("(Global Scope)"), new DomLocation (1, 1), string.Empty, new DomRegion (1, int.MaxValue), new List<IMember> ());
			
			lock (pi) {
				// Add containers to type list
				foreach (LanguageItem li in pi.Containers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						tmp = LanguageItemToIMember (pi, li, contentLines) as IType;
						if (null != tmp){ cu.Add (tmp); }
					}
				}
				
				// Add global category for unscoped symbols
				foreach (LanguageItem li in pi.InstanceMembers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						member = LanguageItemToIMember (pi, li, contentLines);
						if (null != member) { 
							globals.Add (member); 
						}
					}
				}
			}
			
			cu.Add (globals);
			
			return doc;
		}
		static void GenerateCU (XmlParsedDocument doc)
		{
			if (doc.XDocument == null || doc.XDocument.RootElement == null) {
				doc.Add (new Error (ErrorType.Error, 1, 1, "No root node found."));
				return;
			}

			XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
			if (rootClass == null) {
				doc.Add (new Error (ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
				return;
			}

			bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
			
			string rootNamespace, rootType, rootAssembly;
			XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);
			
			CompilationUnit cu = new CompilationUnit (doc.FileName);
			doc.CompilationUnit = cu;

			DomRegion rootRegion = doc.XDocument.RootElement.Region;
			if (doc.XDocument.RootElement.IsClosed)
				rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
			
			DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
			                                doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);
			cu.Add (declType);
			
			DomMethod initcomp = new DomMethod ();
			initcomp.Name = "InitializeComponent";
			initcomp.Modifiers = Modifiers.Public;
			initcomp.ReturnType = DomReturnType.Void;
			declType.Add (initcomp);
			
			DomField _contentLoaded = new DomField ("_contentLoaded");
			_contentLoaded.ReturnType = new DomReturnType ("System.Boolean");

			if (isApplication)
				return;
			
			cu.Add (new DomUsing (DomRegion.Empty, "System"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
			
//			Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
//			namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
			
			XName nameAtt = new XName ("x", "Name");
			
			foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
				XAttribute name = el.Attributes [nameAtt];
				if (name != null && name.IsComplete) {
					string type = ResolveType (el);
					if (type == null || type.Length == 0)
						doc.Add (new Error (ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
					else
						declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type)));
				}
			}
		}
Beispiel #35
0
 private object FRT(float time, DomType domtype)
 {
     float single1 = this.Remainder(time, (float) this.Duration);
     return this.FT(single1, domtype);
 }
Beispiel #36
0
 private object FFT(float time, DomType domtype)
 {
     if (time <= (this.Begin + this.RealDur))
     {
         return this.FCumT(time, domtype);
     }
     if (this.GetAttribute("fill").Trim() == "freeze")
     {
         return this.FCumT(this.Begin + this.RealDur, domtype);
     }
     return null;
 }
Beispiel #37
0
		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			ParsedDocument doc = new ParsedDocument (fileName);
			if(null == doc.CompilationUnit)
				doc.CompilationUnit = new CompilationUnit (fileName);
			CompilationUnit cu = (CompilationUnit)doc.CompilationUnit;
			DomType currentFile = null;
			DomProperty currentRegion = null;
			
			string eol = Environment.NewLine;
			Match eolMatch = eolExpression.Match (content);
			if (eolMatch != null && eolMatch.Success)
				eol = eolMatch.Groups["eol"].Value;
			
			string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None);
			int linenum = 1;
			Match lineMatch;
			foreach (string line in lines)
			{
				lineMatch = fileHeaderExpression.Match (line.Trim());
				if (lineMatch != null && lineMatch.Success) {
					if (currentFile != null) // Close out previous file region
						currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.Start.Line,
						                                        currentFile.BodyRegion.Start.Column,
						                                        linenum-1, int.MaxValue);
					if (currentRegion != null) // Close out previous chunk region
						currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line,
						                                          currentRegion.BodyRegion.Start.Column,
						                                          linenum-1, int.MaxValue);
					
					// Create new file region
					currentFile = new DomType (cu, ClassType.Unknown, Modifiers.None, 
					                           lastToken (lineMatch.Groups["filepath"].Value),
					                           new DomLocation (linenum, 1), 
					                           string.Empty,
					                           new DomRegion (linenum, line.Length+1, linenum, int.MaxValue));
					cu.Add (currentFile);
				} else {
					lineMatch = chunkExpression.Match (line);
					if (lineMatch != null && lineMatch.Success) {
						if (currentRegion != null) // Close out previous chunk region
							currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line,
							                                          currentRegion.BodyRegion.Start.Column,
							                                          linenum-1, int.MaxValue);
						
						// Create new chunk region
						currentRegion = new DomProperty (lineMatch.Groups["chunk"].Value, Modifiers.None, 
						                                 new DomLocation (linenum, 1), 
						                                 new DomRegion (linenum, line.Length+1, linenum, int.MaxValue), null);
						currentFile.Add (currentRegion);
					}
				}
				++linenum;
			}
			
			// Close out trailing regions
			if (currentFile != null)
				currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.Start.Line,
				                                        currentFile.BodyRegion.Start.Column, 
				                                        Math.Max (1, linenum-2), int.MaxValue);
			if (currentRegion != null)
				currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.Start.Line,
				                                          currentRegion.BodyRegion.Start.Column, 
				                                          Math.Max (1, linenum-2), int.MaxValue);
			
			return doc;
		}
Beispiel #38
0
		static DomType ReadTypeInternal (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
		{
			uint typeCount = ReadUInt (reader, 1000);
			if (typeCount > 1) {
				CompoundType compoundResult = new CompoundType ();
				while (typeCount-- > 0) {
					compoundResult.AddPart (ReadTypeInternal (reader, nameTable, objectTable));
				}
				
				return compoundResult;
			}
			
			DomType result = new DomType ();
			ReadMemberInformation (reader, nameTable, objectTable, result);
			//			bool verbose = result.Name == "CopyDelegate";
			//			if (verbose) System.Console.WriteLine("read type:" + result.Name);
			result.TypeModifier = (TypeModifier)reader.ReadUInt32 ();
			result.BodyRegion = ReadRegion (reader, nameTable);
			string compilationUnitFileName = ReadString (reader, nameTable);
			result.CompilationUnit = new CompilationUnit (compilationUnitFileName);
			
			result.Namespace = ReadString (reader, nameTable);
			result.ClassType = (ClassType)reader.ReadUInt32 ();
			result.BaseType = ReadReturnType (reader, nameTable, objectTable);
			
			// implemented interfaces
			long count = ReadUInt (reader, 5000);
			//			if (verbose) System.Console.WriteLine("impl. interfaces:" + count);
			while (count-- > 0) {
				result.AddInterfaceImplementation (ReadReturnType (reader, nameTable, objectTable));
			}
			
			// innerTypes
			//			if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position);
			count = ReadUInt (reader, 10000);
			//			if (verbose) System.Console.WriteLine("inner types:" + count);
			while (count-- > 0) {
				DomType innerType = ReadTypeInternal (reader, nameTable, objectTable);
				innerType.DeclaringType = result;
				result.Add (innerType);
			}
			
			// fields
			//			if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position);
			count = ReadUInt (reader, 10000);
			//			if (verbose) System.Console.WriteLine("fields:" + count);
			while (count-- > 0) {
				DomField field = ReadField (reader, nameTable, objectTable);
				field.DeclaringType = result;
				result.Add (field);
			}
			
			// methods
			//			if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position);
			count = ReadUInt (reader, 10000);
			//			if (verbose) System.Console.WriteLine("methods:" + count);
			while (count-- > 0) {
				DomMethod method = ReadMethod (reader, nameTable, objectTable);
				method.DeclaringType = result;
				result.Add (method);
			}
			
			// properties
			//			if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position);
			count = ReadUInt (reader, 10000);
			//			if (verbose) System.Console.WriteLine("properties:" + count);
			while (count-- > 0) {
				DomProperty property = ReadProperty (reader, nameTable, objectTable);
				property.DeclaringType = result;
				result.Add (property);
			}
			
			// events
			//			if (verbose) System.Console.WriteLine("pos:" + reader.BaseStream.Position);
			count = ReadUInt (reader, 10000);
			//			if (verbose) System.Console.WriteLine("events:" + count);
			while (count-- > 0) {
				DomEvent evt = ReadEvent (reader, nameTable, objectTable);
				evt.DeclaringType = result;
				result.Add (evt);
			}
			
			// type parameters
			count = ReadUInt (reader, 500);
			while (count-- > 0) {
				TypeParameter tp = ReadTypeParameter (reader, nameTable, objectTable);
				result.AddTypeParameter (tp);
			}
			return result;
		}
        protected virtual void OnButtonOkClicked(object sender, System.EventArgs e)
        {
            if (String.IsNullOrEmpty (typeName.Text)) {
                typeName.GrabFocus ();
                return;
            }

            if (newFileName.Sensitive && String.IsNullOrEmpty (newFileName.Text)) {
                newFileName.GrabFocus ();
                return;
            } else if (existingFileName.Sensitive && String.IsNullOrEmpty (existingFileName.Text)) {
                existingFileName.GrabFocus ();
                return;
            }

            var item = new DomType (typeName.Text);
            item.ClassType = type;

            if (accessModifier.ActiveText == "public")
                item.Modifiers = Modifiers.Public;

            //if (isAbstract)
            //	type.Modifiers &= Modifiers.Abstract;

            var figure = designer.Diagram.CreateTypeFigure (item);

            if (figure == null) {
                typeName.GrabFocus ();
                return;
            }

            figure.MoveTo (point.X, point.Y);
            designer.View.Add (figure);
            Destroy ();
        }
		public void ReadWriteTypeTestComplex ()
		{
			DomType input   = new DomType ();
			
			input.Name      = "Test";
			input.ClassType = ClassType.Struct;
			input.BaseType  = new DomReturnType ("BaseClass");
			input.AddInterfaceImplementation (new DomReturnType ("Interface1"));
			input.AddInterfaceImplementation (new DomReturnType ("Interface2"));
			
			input.Add (new DomMethod ("TestMethod", Modifiers.None, MethodModifier.None, DomLocation.Empty, DomRegion.Empty));
			input.Add (new DomMethod (".ctor", Modifiers.None, MethodModifier.IsConstructor, DomLocation.Empty, DomRegion.Empty));
			
			input.Add (new DomField ("TestField", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
			input.Add (new DomProperty ("TestProperty", Modifiers.None, DomLocation.Empty, DomRegion.Empty, DomReturnType.Void));
			input.Add (new DomEvent ("TestEvent", Modifiers.None, DomLocation.Empty, DomReturnType.Void));
			MemoryStream ms = new MemoryStream ();
			BinaryWriter writer = new BinaryWriter (ms);
			DomPersistence.Write (writer, DefaultNameEncoder, input);
			byte[] bytes = ms.ToArray ();
			
			DomType result = DomPersistence.ReadType (CreateReader (bytes), DefaultNameDecoder);
			Assert.AreEqual ("Test", result.Name);
			Assert.AreEqual (ClassType.Struct, result.ClassType);
			Assert.AreEqual ("BaseClass", result.BaseType.Name);
			Assert.AreEqual (1, result.MethodCount);
			Assert.AreEqual (1, result.ConstructorCount);
			Assert.AreEqual (1, result.FieldCount);
			Assert.AreEqual (1, result.PropertyCount);
			Assert.AreEqual (1, result.EventCount);
			
		}
Beispiel #41
0
		public void ExtensionMethodPreserveParameterTest ()
		{
			// build "T MyMethod<T, S> (T a, S b)"
			DomMethod method = new DomMethod ();
			method.Name = "MyMethod";
			method.ReturnType = new DomReturnType ("T");
			method.AddTypeParameter (new TypeParameter ("T"));
			method.AddTypeParameter (new TypeParameter ("S"));
			
			method.Add (new DomParameter (method, "a", new DomReturnType ("T")));
			method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
			
			// extend method
			List<IReturnType> genArgs = new List<IReturnType> ();
			List<IReturnType> args    = new List<IReturnType> ();
			DomType extType = new DomType ("MyType");
			
			ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
			
			// check for MyType MyMethod<S> (S b)
			Assert.AreEqual ("MyType", extMethod.ReturnType.FullName);
			Assert.AreEqual ("S", extMethod.Parameters[0].ReturnType.FullName);
			Assert.AreEqual (1, extMethod.TypeParameters.Count);
			Assert.AreEqual ("S", extMethod.TypeParameters[0].Name);
		}
			void VisitType (TypeContainer c, ClassType classType)
			{
				DomType newType = new DomType ();
				newType.SourceProjectDom = Dom;
				newType.CompilationUnit = Unit;
				if (typeStack.Count == 0 && !string.IsNullOrEmpty (currentNamespaceName))
					newType.Namespace = currentNamespaceName;
				
				newType.Name = ConvertQuoted (c.MemberName.Name);
				newType.Location = Convert (c.MemberName.Location);
				newType.ClassType = classType;
				var location = LocationsBag.GetMemberLocation (c);
				
				if (location != null && location.Count > 1) {
					var region = ConvertRegion (c.MemberName.Location, location[location.Count - 1]);
					region.Start = new DomLocation (region.Start.Line, region.Start.Column + c.MemberName.Name.Length);
					newType.BodyRegion =  region;
				} else {
					var region = ConvertRegion (c.MemberName.Location, c.MemberName.Location);
					region.Start = new DomLocation (region.Start.Line, region.Start.Column + c.MemberName.Name.Length);
					region.End = new DomLocation (int.MaxValue, int.MaxValue);
					newType.BodyRegion =  region;
				}
				
				newType.Modifiers = ConvertModifiers (c.ModFlags);
				AddAttributes (newType, c.OptAttributes, c);
				AddTypeParameter (newType, c);
				
				if (c.TypeBaseExpressions != null) {
					foreach (var type in c.TypeBaseExpressions) {
						var baseType = ConvertReturnType (type);
					//	Console.WriteLine (newType.Name + " -- " + baseType);
						if (newType.BaseType == null) {
							newType.BaseType = baseType;
						} else {
							newType.AddInterfaceImplementation (baseType);
						}
					}
				}
				
				AddType (newType);
				// visit members
				typeStack.Push (newType);
				foreach (MemberCore member in c.OrderedAllMembers) {
					member.Accept (this);
				}
				typeStack.Pop ();
			}
			public override object VisitTypeDeclaration (ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
			{
				DomType newType = new DomType ();
				newType.SourceProjectDom = dom;
				newType.Name = typeDeclaration.Name;
				newType.Documentation = RetrieveDocumentation (typeDeclaration.StartLocation.Line);
				newType.Location = ConvertLocation (typeDeclaration.StartLocation);
				newType.ClassType = ConvertClassType (typeDeclaration.Type);
				DomRegion region = ConvertRegion (typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
				region.End = new DomLocation (region.End.Line, region.End.Column);
				newType.BodyRegion = region;
				newType.Modifiers = ConvertModifiers (typeDeclaration.Modifier);
				
				
				AddAttributes (newType, typeDeclaration.Attributes);

				foreach (ICSharpCode.NRefactory.Ast.TemplateDefinition template in typeDeclaration.Templates) {
					TypeParameter parameter = ConvertTemplateDefinition (template);
					newType.AddTypeParameter (parameter);
				}

				if (typeDeclaration.BaseTypes != null) {

					foreach (ICSharpCode.NRefactory.Ast.TypeReference type in typeDeclaration.BaseTypes) {
						if (type == typeDeclaration.BaseTypes[0]) {
							newType.BaseType = ConvertReturnType (type);
						} else {
							newType.AddInterfaceImplementation (ConvertReturnType (type));
						}
					}
				}
				AddType (newType);

				// visit members
				typeStack.Push (newType);
				typeDeclaration.AcceptChildren (this, data);
				typeStack.Pop ();

				return null;
			}
Beispiel #44
0
 public virtual object GetAnimateResult(float time, DomType domtype)
 {
     if (time < this.Begin)
     {
         return string.Empty;
     }
     object obj1 = this.FFT(time, domtype);
     this.pretime = (int) time;
     return obj1;
 }
Beispiel #45
0
 public static object GetAnimateValue(SvgElement element, string attributename, DomType domtype, object orivalue)
 {
     PointF[] tfArray6;
     PointF[] tfArray7;
     PointF[] tfArray8;
     int num8;
     Matrix matrix1 = new Matrix();
     string text1 = string.Empty;
     GraphicsPath path1 = null;
     string text2 = string.Empty;
     PointF[] tfArray1 = null;
     bool flag1 = true;
     if (element.AnimateNameValues.ContainsKey(attributename))
     {
         AnimateInfo info1 = (AnimateInfo) element.AnimateNameValues[attributename];
         object[] objArray1 = info1.AnimateValues;
         bool[] flagArray1 = info1.ValueAdds;
         int num1 = 0;
         if ((domtype == DomType.SvgString) || (domtype == DomType.SvgLink))
         {
             for (int num2 = objArray1.Length - 1; num2 >= 0; num2--)
             {
                 if ((objArray1[num2] is string) && (objArray1[num2].ToString() != string.Empty))
                 {
                     if (element is ItopVector.Core.Figure.Image)
                     {
                         ((ItopVector.Core.Figure.Image) element).RefImage = ImageFunc.GetImageForURL(objArray1[num2].ToString(), element);
                     }
                     return objArray1[num2].ToString();
                 }
             }
             return orivalue;
         }
         object[] objArray2 = objArray1;
         for (int num10 = 0; num10 < objArray2.Length; num10++)
         {
             PointF[] tfArray2;
             float single3;
             GraphicsPath path2;
             PointF[] tfArray3;
             PointF[] tfArray4;
             PointF[] tfArray5;
             object obj1 = objArray2[num10];
             bool flag2 = flagArray1[num1];
             switch (domtype)
             {
                 case DomType.SvgMatrix:
                 {
                     Matrix matrix2 = new Matrix();
                     if ((obj1 != null) && (obj1.ToString() != string.Empty))
                     {
                         matrix2 = ((Matrix) obj1).Clone();
                     }
                     if (flag2)
                     {
                         matrix1.Multiply(matrix2);
                         goto Label_046F;
                     }
                     matrix1 = matrix2;
                     goto Label_046F;
                 }
                 case DomType.SvgNumber:
                 {
                     single3 = 0f;
                     if ((obj1 != null) && (obj1.ToString() != string.Empty))
                     {
                         single3 = (float) obj1;
                         if (!flag2 || (text1 == string.Empty))
                         {
                             goto Label_0246;
                         }
                         float single9 = float.Parse(text1) + single3;
                         text1 = single9.ToString();
                     }
                     goto Label_046F;
                 }
                 case DomType.SvgString:
                 {
                     goto Label_046F;
                 }
                 case DomType.SvgColor:
                 {
                     string text3 = string.Empty;
                     if ((obj1 != null) && (obj1.ToString() != string.Empty))
                     {
                         text3 = (string) obj1;
                     }
                     if (text3 != string.Empty)
                     {
                         if ((flag2 && (text2 != string.Empty)) && (!text2.Trim().StartsWith("url") && !text3.Trim().StartsWith("url")))
                         {
                             Color color1 = ColorFunc.ParseColor(text3);
                             Color color2 = ColorFunc.ParseColor(text2);
                             int num4 = (color1.R + color2.R) / 2;
                             int num5 = (color1.G + color2.G) / 2;
                             int num6 = (color1.B + color2.B) / 2;
                             string[] textArray1 = new string[7] { "rgb(", num4.ToString(), ",", num5.ToString(), ",", num6.ToString(), ")" } ;
                             text2 = string.Concat(textArray1);
                             goto Label_046F;
                         }
                         text2 = text3;
                     }
                     goto Label_046F;
                 }
                 case DomType.SvgPath:
                 {
                     if ((obj1 != null) && (obj1.ToString() != string.Empty))
                     {
                         path2 = (GraphicsPath) obj1;
                         if (!flag2 || (path1 == null))
                         {
                             goto Label_0460;
                         }
                         tfArray3 = path2.PathPoints;
                         tfArray4 = path1.PathPoints;
                         if (tfArray3.Length == tfArray4.Length)
                         {
                             goto Label_03B5;
                         }
                     }
                     goto Label_046F;
                 }
                 case DomType.SvgPoints:
                 {
                     tfArray2 = new PointF[0];
                     if (obj1 is PointF[])
                     {
                         tfArray2 = (PointF[]) obj1;
                     }
                     if (!flag2)
                     {
                         break;
                     }
                     if (tfArray1.Length == tfArray2.Length)
                     {
                         for (int num3 = 0; num3 < tfArray2.Length; num3++)
                         {
                             PointF tf1 = tfArray1[num3];
                             PointF tf2 = tfArray2[num3];
                             float single1 = (tf1.X + tf2.X) / 2f;
                             float single2 = (tf1.Y + tf2.Y) / 2f;
                             tfArray1[num3] = new PointF(single1, single2);
                         }
                     }
                     goto Label_046F;
                 }
                 default:
                 {
                     goto Label_046F;
                 }
             }
             tfArray1 = (PointF[]) tfArray2.Clone();
             goto Label_046F;
         Label_0246:
             text1 = single3.ToString();
             goto Label_046F;
         Label_03B5:
             tfArray5 = new PointF[tfArray4.Length];
             Array.Copy(tfArray3, tfArray1, tfArray5.Length);
             byte[] buffer1 = path2.PathTypes;
             byte[] buffer2 = path1.PathTypes;
             for (int num7 = 0; num7 < Math.Min(tfArray3.Length, tfArray4.Length); num7++)
             {
                 PointF tf3 = tfArray3[num7];
                 PointF tf4 = tfArray4[num7];
                 float single4 = tf3.X + tf4.X;
                 float single5 = tf3.Y + tf4.Y;
                 tfArray5[num7] = new PointF(single4, single5);
             }
             path1 = new GraphicsPath(tfArray5, path2.PathTypes);
             goto Label_046D;
         Label_0460:
             path1 = (GraphicsPath) path2.Clone();
         Label_046D:;
         Label_046F:;
         }
         if (flagArray1.Length > 0)
         {
             flag1 = flagArray1[flagArray1.Length - 1];
         }
     }
     switch (domtype)
     {
         case DomType.SvgMatrix:
         {
             Matrix matrix3 = new Matrix();
             if (orivalue != null)
             {
                 matrix3 = ((Matrix) orivalue).Clone();
             }
             if (flag1)
             {
                 matrix3.Multiply(matrix1);
             }
             else
             {
                 matrix3 = matrix1.Clone();
             }
             return matrix3.Clone();
         }
         case DomType.SvgNumber:
         {
             if ((flag1 && (orivalue != null)) && (orivalue.ToString() != string.Empty))
             {
                 float single6 = (float) orivalue;
                 if (text1 == string.Empty)
                 {
                     text1 = single6.ToString();
                     break;
                 }
                 float single10 = float.Parse(text1) + single6;
                 text1 = single10.ToString();
             }
             break;
         }
         case DomType.SvgString:
         {
             return orivalue;
         }
         case DomType.SvgColor:
         {
             if (text2 == string.Empty)
             {
                 return orivalue;
             }
             if ((flag1 && (orivalue != null)) && (!text2.Trim().StartsWith("url") && !((string) orivalue).Trim().StartsWith("url")))
             {
                 Color color3 = ColorFunc.ParseColor((string) orivalue);
                 Color color4 = ColorFunc.ParseColor(text2);
                 string[] textArray2 = new string[7];
                 textArray2[0] = "rgb(";
                 int num11 = (color3.R + color4.R) / 2;
                 textArray2[1] = num11.ToString();
                 textArray2[2] = ",";
                 int num12 = (color3.G + color4.G) / 2;
                 textArray2[3] = num12.ToString();
                 textArray2[4] = ",";
                 int num13 = (color3.B + color4.B) / 2;
                 textArray2[5] = num13.ToString();
                 textArray2[6] = ")";
                 text2 = string.Concat(textArray2);
             }
             return text2;
         }
         case DomType.SvgPath:
         {
             if (path1 == null)
             {
                 return orivalue;
             }
             if (!flag1 || (orivalue == null))
             {
                 return path1;
             }
             tfArray6 = ((GraphicsPath) orivalue).PathPoints;
             tfArray7 = path1.PathPoints;
             tfArray8 = new PointF[tfArray6.Length];
             Array.Copy(tfArray6, tfArray1, tfArray8.Length);
             num8 = 0;
             goto Label_0738;
         }
         case DomType.SvgPoints:
         {
             if (tfArray1.Length > 0)
             {
                 PointF[] tfArray9 = new PointF[0];
                 if (!(orivalue is PointF[]) || !flag1)
                 {
                     return tfArray1;
                 }
                 tfArray9 = (PointF[]) orivalue;
                 if (tfArray9.Length != tfArray1.Length)
                 {
                     return tfArray1;
                 }
                 for (int num9 = 0; num9 < tfArray1.Length; num9++)
                 {
                     tfArray1[num9] = new PointF((tfArray1[num9].X + tfArray9[num9].X) / 2f, (tfArray1[num9].Y + tfArray9[num9].Y) / 2f);
                 }
             }
             return tfArray1;
         }
         default:
         {
             return string.Empty;
         }
     }
     if (text1 != string.Empty)
     {
         return float.Parse(text1);
     }
     if ((orivalue.ToString() == string.Empty) || (orivalue == null))
     {
         return (float) AttributeFunc.GetDefaultValue(element, attributename);
     }
     return (float) orivalue;
     Label_0738:
     if (num8 >= Math.Min(tfArray6.Length, tfArray7.Length))
     {
         return new GraphicsPath(tfArray8, path1.PathTypes);
     }
     PointF tf5 = tfArray6[num8];
     PointF tf6 = tfArray7[num8];
     float single7 = tf5.X + tf6.X;
     float single8 = tf5.Y + tf6.Y;
     tfArray8[num8] = new PointF(single7, single8);
     num8++;
     goto Label_0738;
 }
		void BuildClass (XmlElement element, StringReader content)
		{
			var compUnit = this.CompilationUnit as PythonCompilationUnit;
			Console.WriteLine ("Class({0})", element.GetAttribute ("name"));

			var name   = element.GetAttribute ("name");
			var start  = GetDomLocation (element);
			var region = GetDomRegion (element);
			
			var fullName = PythonHelper.ModuleFromFilename (FileName);
			var klass = new DomType (fullName) {
				Name            = name,
				Location        = start,
				BodyRegion      = region,
				Modifiers       = Modifiers.Public,
				CompilationUnit = compUnit
			};

			compUnit.Add (klass);
		}
Beispiel #47
0
 public static string[] Linear(string startvalue, float starttime, string endvalue, float endtime, DomType domtype, int time)
 {
     int num2;
     int num5;
     char[] chArray1 = new char[2] { ' ', ',' } ;
     string[] textArray1 = startvalue.Split(chArray1);
     char[] chArray2 = new char[2] { ' ', ',' } ;
     string[] textArray2 = endvalue.Split(chArray2);
     string[] textArray3 = new string[Math.Min(textArray1.Length, textArray2.Length)];
     switch (domtype)
     {
         case DomType.SvgMatrix:
         case DomType.SvgNumber:
         {
             num2 = 0;
             goto Label_0217;
         }
         case DomType.SvgString:
         {
             goto Label_0762;
         }
         case DomType.SvgColor:
         {
             if ((!startvalue.Trim().StartsWith("url") && !endvalue.Trim().StartsWith("url")) && ((endvalue != "none") && (startvalue != "none")))
             {
                 Color color1 = ColorFunc.ParseColor(startvalue.Trim());
                 Color color2 = ColorFunc.ParseColor(endvalue.Trim());
                 float single5 = (float) Math.Round((double) AnimFunc.Linear((float) color1.R, starttime, (float) color2.R, endtime, (float) time), 2);
                 float single6 = (float) Math.Round((double) AnimFunc.Linear((float) color1.G, starttime, (float) color2.G, endtime, (float) time), 2);
                 float single7 = (float) Math.Round((double) AnimFunc.Linear((float) color1.B, starttime, (float) color2.B, endtime, (float) time), 2);
                 string[] textArray11 = new string[1];
                 string[] textArray12 = new string[7] { "rgb(", single5.ToString(), ",", single6.ToString(), ",", single7.ToString(), ")" } ;
                 textArray11[0] = string.Concat(textArray12);
                 return textArray11;
             }
             if (time < ((starttime / 2f) + (endtime / 2f)))
             {
                 return new string[1] { startvalue } ;
             }
             return new string[1] { endvalue } ;
         }
         case DomType.SvgPath:
         {
             PointInfoCollection collection1 = new PointInfoCollection();
             PointInfoCollection collection2 = new PointInfoCollection();
             GraphicsPath path1 = PathFunc.PathDataParse(startvalue, collection1);
             GraphicsPath path2 = PathFunc.PathDataParse(endvalue, collection2);
             if (collection1.Count == collection2.Count)
             {
                 string text4 = string.Empty;
                 for (int num3 = 0; num3 < collection1.Count; num3++)
                 {
                     PointInfo info1 = collection1[num3];
                     PointInfo info2 = collection2[num3];
                     if (((info1.Command.Trim().ToLower() != info2.Command.Trim().ToLower()) || (info1.IsStart != info2.IsStart)) || (info1.IsEnd != info2.IsEnd))
                     {
                         if ((time > ((starttime + endtime) / 2f)) && (time <= endtime))
                         {
                             return new string[1] { endvalue } ;
                         }
                         if ((time <= ((starttime + endtime) / 2f)) && (time >= starttime))
                         {
                             return new string[1] { startvalue } ;
                         }
                         return new string[1] { string.Empty } ;
                     }
                     text4 = text4 + info1.Command.Trim().ToUpper();
                     string text5 = info1.Command.Trim().ToUpper();
                     if (((text5 == "C") || (text5 == "Q")) || (((text5 == "A") || (text5 == "T")) || (text5 == "S")))
                     {
                         float single8 = AnimFunc.Linear(info1.FirstControl.X, starttime, info2.FirstControl.X, endtime, (float) time);
                         float single9 = AnimFunc.Linear(info1.FirstControl.Y, starttime, info2.FirstControl.Y, endtime, (float) time);
                         string text8 = text4;
                         string[] textArray19 = new string[5] { text8, single8.ToString(), " ", single9.ToString(), " " } ;
                         text4 = string.Concat(textArray19);
                         single8 = AnimFunc.Linear(info1.SecondControl.X, starttime, info2.SecondControl.X, endtime, (float) time);
                         single9 = AnimFunc.Linear(info1.SecondControl.Y, starttime, info2.SecondControl.Y, endtime, (float) time);
                         string text9 = text4;
                         string[] textArray20 = new string[5] { text9, single8.ToString(), " ", single9.ToString(), " " } ;
                         text4 = string.Concat(textArray20);
                     }
                     float single10 = AnimFunc.Linear(info1.MiddlePoint.X, starttime, info2.MiddlePoint.X, endtime, (float) time);
                     float single11 = AnimFunc.Linear(info1.MiddlePoint.Y, starttime, info2.MiddlePoint.Y, endtime, (float) time);
                     string text10 = text4;
                     string[] textArray21 = new string[5] { text10, single10.ToString(), " ", single11.ToString(), " " } ;
                     text4 = string.Concat(textArray21);
                     if (info1.IsEnd)
                     {
                         text4 = text4 + "Z";
                     }
                 }
                 return new string[1] { text4 } ;
             }
             if ((time > ((starttime + endtime) / 2f)) && (time <= endtime))
             {
                 return new string[1] { endvalue } ;
             }
             if ((time <= ((starttime + endtime) / 2f)) && (time >= starttime))
             {
                 return new string[1] { startvalue } ;
             }
             return new string[1] { string.Empty } ;
         }
         case DomType.SvgPoints:
         {
             PointF[] tfArray1 = PointsFunc.PointsParse(startvalue);
             PointF[] tfArray2 = PointsFunc.PointsParse(endvalue);
             if (tfArray1.Length == tfArray2.Length)
             {
                 string text1 = string.Empty;
                 for (int num1 = 0; num1 < tfArray1.Length; num1++)
                 {
                     PointF tf1 = tfArray1[num1];
                     PointF tf2 = tfArray2[num1];
                     float single1 = AnimFunc.Linear(tf1.X, starttime, tf2.X, endtime, (float) time);
                     float single2 = AnimFunc.Linear(tf1.Y, starttime, tf2.Y, endtime, (float) time);
                     text1 = text1 + single1.ToString() + " " + single2.ToString();
                     if (num1 < (tfArray1.Length - 1))
                     {
                         text1 = text1 + ",";
                     }
                 }
                 return new string[1] { text1 } ;
             }
             if ((time > ((starttime + endtime) / 2f)) && (time <= endtime))
             {
                 return new string[1] { endvalue } ;
             }
             if ((time <= ((starttime + endtime) / 2f)) && (time >= starttime))
             {
                 return new string[1] { startvalue } ;
             }
             return new string[1] { string.Empty } ;
         }
         default:
         {
             goto Label_0762;
         }
     }
     Label_0217:
     if (num2 >= textArray3.Length)
     {
         return textArray3;
     }
     string text2 = textArray1[num2];
     string text3 = textArray2[num2];
     float single3 = 0f;
     float single4 = 0f;
     try
     {
         single3 = ItopVector.Core.Func.Number.ParseFloatStr(text2);
         single4 = ItopVector.Core.Func.Number.ParseFloatStr(text3);
         double num6 = Math.Round((double) AnimFunc.Linear(single3, starttime, single4, endtime, (float) time), 2);
         textArray3[num2] = num6.ToString();
     }
     catch (Exception)
     {
     }
     num2++;
     goto Label_0217;
     Label_0762:
     num5 = 0;
     while (num5 < textArray3.Length)
     {
         string text6 = textArray1[num5];
         string text7 = textArray2[num5];
         if (time >= ((endtime / 2f) + (starttime / 2f)))
         {
             textArray3[num5] = text7;
         }
         else if (time >= starttime)
         {
             textArray3[num5] = text6;
         }
         else
         {
             textArray3[num5] = string.Empty;
         }
         num5++;
     }
     return textArray3;
 }
        IEnumerable<IType> BuildClasses(IEnumerable<PythonClass> classes)
        {
            foreach (PythonClass pyClass in classes)
            {
                var domType = new DomType () {
                    Name          = pyClass.Name,
                    Documentation = pyClass.Documentation,
                    ClassType     = ClassType.Class,
                    BodyRegion    = pyClass.Region,
                    Location      = new DomLocation (pyClass.Region.Start.Line - 1, 0),
                };
                m_AllWrapped.Add (domType);

                // class functions
                foreach (IMethod method in BuildFunctions (pyClass.Functions))
                    domType.Add (method);

                // class attributes
                foreach (IField field in BuildAttributes (pyClass.Attributes))
                    domType.Add (field);

                yield return domType;
            }
        }
Beispiel #49
0
        public static MonoDevelop.Projects.Dom.INode ConvertDParserToDomNode(D_Parser.Dom.INode n, ParsedDocument doc)
        {
            //TODO: DDoc comments!

            if (n is DMethod)
            {
                var dm = n as DMethod;

                var domMethod = new DomMethod(
                    n.Name,
                    GetNodeModifiers(dm),
                    dm.SpecialType == DMethod.MethodType.Constructor ? MethodModifier.IsConstructor : MethodModifier.None,
                    FromCodeLocation(n.StartLocation),
                    GetBlockBodyRegion(dm),
                    GetReturnType(n));

                foreach (var pn in dm.Parameters)
                    domMethod.Add(new DomParameter(domMethod, pn.Name, GetReturnType(pn)));

                domMethod.AddTypeParameter(GetTypeParameters(dm));

                foreach (var subNode in dm) domMethod.AddChild(ConvertDParserToDomNode(subNode, doc));

                return domMethod;
            }
            else if (n is DEnum)
            {
                var de = n as DEnum;

                var domType = new DomType(
                    doc.CompilationUnit,
                    ClassType.Enum,
                    GetNodeModifiers(de),
                    n.Name,
                    FromCodeLocation(n.StartLocation),
                    BuildTypeNamespace(n), GetBlockBodyRegion(de));

                foreach (var subNode in de)
                    domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember);
                return domType;
            }
            else if (n is DClassLike)
            {
                var dc = n as DClassLike;

                ClassType ct = ClassType.Unknown;

                switch (dc.ClassType)
                {
                    case DTokens.Template:
                    case DTokens.Class:
                        ct = ClassType.Class;
                        break;
                    case DTokens.Interface:
                        ct = ClassType.Interface;
                        break;
                    case DTokens.Union:
                    case DTokens.Struct:
                        ct = ClassType.Struct;
                        break;
                }

                var domType = new DomType(
                    doc.CompilationUnit,
                    ct,
                    GetNodeModifiers(dc),
                    n.Name,
                    FromCodeLocation(n.StartLocation),
                    BuildTypeNamespace(n),
                    GetBlockBodyRegion(dc));

                domType.AddTypeParameter(GetTypeParameters(dc));
                foreach (var subNode in dc)
                    domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember);
                return domType;
            }
            else if (n is DVariable)
            {
                var dv = n as DVariable;
                return new DomField(n.Name, GetNodeModifiers(dv), FromCodeLocation(n.StartLocation), GetReturnType(n));
            }
            return null;
        }
		public void ReadWriteTypeTest ()
		{
			DomType input     = new DomType ();
			input.Name         = "Test";
			input.ClassType    = ClassType.Struct;
			input.BaseType     = new DomReturnType ("BaseClass");
			
			MemoryStream ms = new MemoryStream ();
			BinaryWriter writer = new BinaryWriter (ms);
			DomPersistence.Write (writer, DefaultNameEncoder, input);
			byte[] bytes = ms.ToArray ();
			
			DomType result = DomPersistence.ReadType (CreateReader (bytes), DefaultNameDecoder);
			Assert.AreEqual ("Test", result.Name);
			Assert.AreEqual (ClassType.Struct, result.ClassType);
			Assert.AreEqual ("BaseClass", result.BaseType.Name);
		}
Beispiel #51
0
 public override object GetAnimateResult(float time, DomType domtype)
 {
     if (this.FileName != string.Empty)
     {
         if ((time < base.Begin) || (time > (base.Begin + base.Duration)))
         {
             if (this.m_CurrentStatus == MediaStatus.Running)
             {
                 this.m_objMediaControl.Stop();
                 this.m_objMediaPosition.CurrentPosition = 0;
                 this.m_CurrentStatus = MediaStatus.Stopped;
                 this.timer.Stop();
             }
         }
         else if (time != this.oldtime)
         {
             if (this.m_CurrentStatus == MediaStatus.None)
             {
                 this.m_objMediaControl.Run();
                 this.m_objMediaPosition.CurrentPosition = (time - base.Begin) * 1.2f;
                 this.timer.Start();
             }
             else if (this.m_CurrentStatus == MediaStatus.Stopped)
             {
                 this.m_objMediaPosition.CurrentPosition = (time - base.Begin) * 1.2f;
                 this.m_objMediaControl.Run();
                 this.timer.Start();
             }
             this.m_CurrentStatus = MediaStatus.Running;
         }
         else if (this.m_CurrentStatus == MediaStatus.Running)
         {
             this.m_objMediaControl.Stop();
             this.m_objMediaPosition.CurrentPosition = 0;
             this.m_CurrentStatus = MediaStatus.Stopped;
             this.timer.Stop();
         }
     }
     this.oldtime = time;
     return null;
 }
Beispiel #52
0
 private object FCumT(float time, DomType domtype)
 {
     if (time <= (this.Begin + this.Duration))
     {
         return this.FT(time, domtype);
     }
     int num1 = (int) Math.Floor((double) ((time - this.Begin) / ((float) this.Duration)));
     float single1 = (time - (num1 * this.Duration)) - this.Begin;
     string text1 = string.Empty;
     if (this.GetAttribute("accumulate").Trim() == "sum")
     {
         return this.FT(this.Begin + single1, domtype);
     }
     return this.FT(this.Begin + single1, domtype);
 }
			void AddType (DomType type)
			{
				// add type to compilation unit or outer type
				if (typeStack.Count > 0) {
					// Nested types are private by default
					if ((type.Modifiers & Modifiers.VisibilityMask) == 0)
						type.Modifiers |= Modifiers.Private;
					DomType outerType = typeStack.Peek ();
					type.DeclaringType = outerType;
					outerType.Add (type);
				} else {
					// Types are internal by default
					if ((type.Modifiers & Modifiers.VisibilityMask) == 0)
						type.Modifiers |= Modifiers.Internal;
					if (namespaceStack.Count > 0)
						type.Namespace = namespaceStack.Peek ();
					((CompilationUnit)result.CompilationUnit).Add (type);
				}
			}
Beispiel #54
0
 public virtual object FT(float time, DomType domtype)
 {
     if ((time < this.Begin) || (time > (this.Begin + this.Duration)))
     {
         return null;
     }
     ArrayList list1 = (ArrayList) this.Values.Clone();
     ArrayList list2 = (ArrayList) this.KeyTimes.Clone();
     float single1 = 0f;
     float single2 = 1f;
     float single3 = this.Begin;
     float single4 = this.Duration;
     if (single4 == 0f)
     {
         single4 = 0.1f;
     }
     if (list1.Count == 0)
     {
         list1.Add(this.FromWhat);
         list2.Add(single3.ToString());
         list1.Add(this.ToWhat);
         float single7 = single3 + single4;
         list2.Add(single7.ToString());
     }
     int num1 = -1;
     float single5 = 0f;
     float single6 = 0f;
     for (int num2 = 1; num2 < list2.Count; num2++)
     {
         single5 = float.Parse(((string) list2[num2 - 1]).Trim());
         single6 = float.Parse(((string) list2[num2]).Trim());
         if ((time >= single5) && (time <= single6))
         {
             num1 = num2 - 1;
             break;
         }
     }
     string text1 = (string) list1[num1];
     string text2 = (string) list1[num1 + 1];
     if (list2[num1] != null)
     {
         single1 = float.Parse((string) list2[num1]);
     }
     if (list2[num1 + 1] != null)
     {
         single2 = float.Parse((string) list2[num1 + 1]);
     }
     string text3 = string.Empty;
     string[] textArray1 = AnimFunc.Linear(text1.Trim(), single1, text2.Trim(), single2, domtype, (int) time);
     string[] textArray2 = textArray1;
     for (int num3 = 0; num3 < textArray2.Length; num3++)
     {
         string text4 = textArray2[num3];
         text3 = text3 + text4 + " ";
     }
     switch (domtype)
     {
         case DomType.SvgMatrix:
         {
             return new Transf(this.Type + "(" + text3.Trim() + ")").Matrix;
         }
         case DomType.SvgNumber:
         {
             return ItopVector.Core.Func.Number.parseToFloat(text3.Trim(), (SvgElement) this.ParentNode, ItopVector.Core.Func.SvgLengthDirection.Horizontal);
         }
         case DomType.SvgColor:
         {
             return text3.Trim();
         }
         case DomType.SvgPath:
         {
             SvgElement element1 = this.RefElement;
             if (element1 is IPath)
             {
                 return PathFunc.PathDataParse(text3, ((IPath) element1).PointsInfo);
             }
             return PathFunc.PathDataParse(text3);
         }
         case DomType.SvgPoints:
         {
             return PointsFunc.PointsParse(text3);
         }
     }
     return text3.Trim();
 }
			public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
			{
				DomType type = new DomType (cu, 
				                            TranslateClassType (typeDeclaration.Type),
				                            (MonoDevelop.Projects.Dom.Modifiers)typeDeclaration.Modifier, 
				                            typeDeclaration.Name,
				                            new DomLocation (typeDeclaration.StartLocation.Line, typeDeclaration.StartLocation.Column), 
				                            currentNamespace.Count > 0 ? currentNamespace.Peek() : "",
				                            TranslateRegion (typeDeclaration.StartLocation, typeDeclaration.EndLocation));
				
				if (currentType.Count > 0) {
					currentType.Peek().Add (type);
				} else {
					cu.Add (type);
				}
				
				if (typeDeclaration.BaseTypes != null) {
					foreach (ICSharpCode.NRefactory.Ast.TypeReference baseType in typeDeclaration.BaseTypes) {
						if (type.BaseType == null) {
							type.BaseType = TranslateTypeReference (baseType);
						} else {
							type.AddInterfaceImplementation (TranslateTypeReference (baseType));
						}
					}
				}
				currentType.Push (type);
				typeDeclaration.AcceptChildren (this, data);
				currentType.Pop();
				
				return null;
			}
Beispiel #56
0
 public override object FT(float time, DomType domtype)
 {
     string text2;
     string text1 = string.Empty;
     Matrix matrix1 = new Matrix();
     float single1 = 0f;
     float single2 = 0f;
     float single3 = 0f;
     GraphicsPath path1 = this.GPath;
     bool flag1 = true;
     if (path1 == null)
     {
         flag1 = false;
     }
     else if (path1.PointCount <= 0)
     {
         flag1 = false;
     }
     if (flag1)
     {
         PointF[] tfArray1;
         GraphicsPath path2 = (GraphicsPath) this.motionPath.Clone();
         path2.Flatten(new Matrix(), 0.01f);
         if (path2.PathTypes[path2.PathTypes.Length - 1] >= 0x80)
         {
             tfArray1 = new PointF[path2.PathPoints.Length + 1];
             path2.PathPoints.CopyTo(tfArray1, 0);
             tfArray1[tfArray1.Length - 1] = path2.PathPoints[0];
         }
         else
         {
             tfArray1 = path2.PathPoints;
         }
         int num1 = tfArray1.Length;
         int num2 = base.Begin;
         float single4 = base.Duration;
         float single5 = single4 / ((float) (num1 - 1));
         int num3 = (int) ((time - num2) / single5);
         if ((num3 + 1) >= num1)
         {
             single1 = tfArray1[num3].X;
             single2 = tfArray1[num3].Y;
             if ((num3 - 1) >= 0)
             {
                 PointF tf1 = tfArray1[num3 - 1];
                 if (tf1.X == single1)
                 {
                     single3 = 0f;
                 }
                 else
                 {
                     single3 = (float) ((Math.Atan((double) ((tf1.Y - single2) / (tf1.X - single1))) / 3.1415926535897931) * 180);
                 }
             }
             goto Label_02C5;
         }
         PointF tf2 = tfArray1[num3];
         PointF tf3 = tfArray1[num3 + 1];
         float single6 = base.Begin + (num3 * single5);
         float single7 = base.Begin + ((num3 + 1) * single5);
         if (tf3.X == tf2.X)
         {
             single3 = 0f;
         }
         else
         {
             single3 = (float) ((Math.Atan((double) ((tf3.Y - tf2.Y) / (tf3.X - tf2.X))) / 3.1415926535897931) * 180);
         }
         switch (this.CalcMode)
         {
             case CalcMode.linear:
             {
                 single1 = AnimFunc.Linear(tf2.X, single6, tf3.X, single7, time);
                 single2 = AnimFunc.Linear(tf2.Y, single6, tf3.Y, single7, time);
                 goto Label_02C5;
             }
             case CalcMode.paced:
             {
                 goto Label_02C5;
             }
             case CalcMode.spline:
             {
                 goto Label_02C5;
             }
             case CalcMode.discrete:
             {
                 text1 = tfArray1[num3].X.ToString() + " " + tfArray1[num3].Y.ToString();
                 goto Label_02C5;
             }
         }
         goto Label_02C5;
     }
     matrix1 = (Matrix) base.FT(time, DomType.SvgMatrix);
     Label_02C5:
     text2 = this.GetAttribute("rotate").Trim();
     if ((text2 == null) || (text2 == string.Empty))
     {
         text2 = "0";
     }
     if (text2 == "auto")
     {
         matrix1.Rotate(single3, MatrixOrder.Append);
         matrix1.Translate(single1, single2, MatrixOrder.Append);
         return matrix1;
     }
     if (text2 == "auto-reverse")
     {
         single3 -= 180f;
         matrix1.Rotate(single3, MatrixOrder.Append);
         matrix1.Translate(single1, single2, MatrixOrder.Append);
         return matrix1;
     }
     try
     {
         single3 = float.Parse(text2);
         matrix1.Rotate(single3);
     }
     catch (Exception)
     {
     }
     matrix1.Translate(single1, single2, MatrixOrder.Append);
     return matrix1;
 }
		/// <summary>
		/// Create an IMember from a LanguageItem,
		/// using the source document to locate declaration bounds.
		/// </summary>
		/// <param name="pi">
		/// A <see cref="ProjectInformation"/> for the current project.
		/// </param>
		/// <param name="item">
		/// A <see cref="LanguageItem"/>: The item to convert.
		/// </param>
		/// <param name="contentLines">
		/// A <see cref="System.String[]"/>: The document in which item is defined.
		/// </param>
		static IMember LanguageItemToIMember (ProjectInformation pi, LanguageItem item, string[] contentLines)
		{
			if (item is Class || item is Structure) {
				DomType klass = new DomType (new CompilationUnit (item.File), ClassType.Class, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new List<IMember> ());
				
				foreach (LanguageItem li in pi.AllItems ()) {
					if (klass.Equals (li.Parent) && FilePath.Equals (li.File, item.File)) {
						klass.Add (LanguageItemToIMember (pi, li, contentLines));
					}
				}
				return klass;
			}
			if (item is Enumeration) {
				return new DomType (new CompilationUnit (item.File), ClassType.Enum, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, (int)item.Line+1), new List<IMember> ());
			}
			if (item is Function) {
				return new DomMethod (item.Name, Modifiers.None, MethodModifier.None, new DomLocation ((int)item.Line, 1), new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new DomReturnType ());
			}
			if (item is Member) {
				return new DomField (item.Name, Modifiers.None, new DomLocation ((int)item.Line, 1), new DomReturnType ());
			}
			return null;
		}
Beispiel #58
0
		public void ExtensionMethodTest ()
		{
			// build "T MyMethod<T, S> (this KeyValuePair<T, S> a, S b)"
			DomMethod method = new DomMethod ();
			method.Name = "MyMethod";
			method.ReturnType = new DomReturnType ("T");
			method.AddTypeParameter (new TypeParameter ("T"));
			method.AddTypeParameter (new TypeParameter ("S"));
			
			DomReturnType returnType = new DomReturnType ("KeyValuePair");
			returnType.AddTypeParameter (new DomReturnType ("T"));
			returnType.AddTypeParameter (new DomReturnType ("S"));
			method.Add (new DomParameter (method, "a", returnType));
			method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
			
			// Build extendet type KeyValuePair<int, object>
			DomType type = new DomType ("KeyValuePair");
			type.AddTypeParameter (new TypeParameter ("T"));
			type.AddTypeParameter (new TypeParameter ("S"));
			IType extType = DomType.CreateInstantiatedGenericTypeInternal (type, new IReturnType[] { DomReturnType.Int32, DomReturnType.Object });
			Console.WriteLine (extType);
			
			// extend method
			List<IReturnType> genArgs = new List<IReturnType> ();
			List<IReturnType> args    = new List<IReturnType> ();
			
			ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
			
			Console.WriteLine (extMethod);
			// check 
			Assert.AreEqual (DomReturnType.Int32.FullName, extMethod.ReturnType.FullName);
			Assert.AreEqual (DomReturnType.Object.FullName, extMethod.Parameters[0].ReturnType.FullName);
		}
Beispiel #59
0
		public IType GetArrayType (IReturnType elementType, MonoDevelop.Projects.Dom.Output.Ambience ambience)
		{
			// Create a fake class which sublcasses System.Array and implements IList<T>
			DomType t = new DomType (ambience.GetString (elementType, MonoDevelop.Projects.Dom.Output.OutputFlags.UseFullName) + "[]");
			
			// set the compilation unit of the array type to that of the element type - it's required for jumping to the declaration of the type.
			IType eType = GetType (elementType);
			if (eType != null)
				t.CompilationUnit = eType.CompilationUnit;
			
			t.Resolved = true;
			t.BaseType = new DomReturnType ("System.Array");
			t.ClassType = ClassType.Class;
			t.Modifiers = Modifiers.Public;
			t.SourceProjectDom = this;
			DomProperty indexer = new DomProperty ();
			indexer.Name = "Item";
			indexer.SetterModifier = indexer.GetterModifier = Modifiers.Public;
			indexer.PropertyModifier |= PropertyModifier.IsIndexer;
			indexer.Add (new DomParameter(indexer, "index", DomReturnType.Int32));
			indexer.ReturnType = elementType;
			t.Add (indexer);
			DomReturnType listType = new DomReturnType ("System.Collections.Generic.IList", false, new IReturnType [] { elementType });
			
			t.AddInterfaceImplementation (listType);
			return t;
		}
Beispiel #60
0
        public override ParsedDocument Parse(MonoDevelop.Projects.Dom.Parser.ProjectDom dom, string fileName, string content)
        {
            string basepath = (null == dom || null == dom.Project)?
                Path.GetDirectoryName (fileName):
                (string)dom.Project.BaseDirectory.FullPath;
            List<Error> errors = RubyCompletion.CheckForErrors (basepath, content);

            if (null != errors && 0 < errors.Count) {
                ParsedDocument doc = successfulParses.ContainsKey (fileName)?
                    successfulParses[fileName]:
                    new ParsedDocument (fileName);
                doc.Errors.Clear ();
                foreach (Error err in errors) {
                    doc.Add (err);
                }
                return doc;
            }// Got parse errors - flag and return with last successful parse result

            lock (this) {
                string[] lines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);

                methods = new Dictionary<int, RubyDeclaration> ();
                classes = new Dictionary<int, RubyDeclaration> ();
                modules = new Dictionary<int, RubyDeclaration> ();

                if (!RunStack (lines)) {
                    return successfulParses.ContainsKey (fileName)? successfulParses[fileName]: new ParsedDocument (fileName);
                }

                ParsedDocument doc = new ParsedDocument (fileName);
                if(null == doc.CompilationUnit){ doc.CompilationUnit = new CompilationUnit (fileName); }
                CompilationUnit cu = (CompilationUnit)doc.CompilationUnit;

                PopulateModules (cu);
                PopulateClasses (cu);

                if (0 < methods.Count) {
                    DomType glob = new DomType (cu, ClassType.Unknown, GettextCatalog.GetString ("(Global Methods)"), new DomLocation (1, 1), string.Empty, new DomRegion (1, lines.Length), new List<IMember> ());
                    PopulateMethods (glob);
                    cu.Add (glob);
                }// Add global methods

                return successfulParses[fileName] = doc;
            }// Populate dom/cu for quickfinder
        }