Example #1
0
        protected override Expression VisitNamespaceExpresson(NamespaceExpression expression)
        {
            if (expression.Header != null)
            {
                this.Visit(expression.Header);
                this.WriteLine();
                this.WriteLine();
            }

            if (string.IsNullOrEmpty(expression.NameSpace))
            {
                this.Visit(expression.Body);
            }
            else
            {
                this.Write("namespace ");
                this.WriteLine(expression.NameSpace);
                using (this.AcquireIndentationContext(BraceLanguageStyleIndentationOptions.IncludeBracesNewLineAfter))
                {
                    this.Visit(expression.Body);
                    this.WriteLine();
                }
            }

            return(expression);
        }
Example #2
0
        /// <summary>
        /// 定义命名空间切面
        /// </summary>
        /// <param name="namespace"></param>
        /// <returns></returns>
        public static INamespaceExpression FromNamespace(string @namespace)
        {
            var aspect = new NamespaceExpression(@namespace);

            Aspect.AspectRepository.Register(aspect.ToAspect());
            return(aspect);
        }
Example #3
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            currentTypeDefinition = expression;
            currentType           = expression.Type;
            var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(expression);

            referencedTypes.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

            var includeExpressions = new List <IncludeExpression>();

            var lookup = new HashSet <Type>(referencedTypes.Where(TypeSystem.IsPrimitiveType));

            if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.UUID"));
            }

            if (lookup.Contains(typeof(TimeSpan)) || lookup.Contains(typeof(TimeSpan?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.Date"));
            }

            var comment             = new CommentExpression("This file is AUTO GENERATED");
            var namespaceExpression = new NamespaceExpression(codeGenerationContext.Options.Namespace);

            var members = new List <Expression>()
            {
                this.Visit(expression.Body)
            };

            if (((FickleType)currentTypeDefinition.Type).ServiceClass.Properties.Count > 0)
            {
                includeExpressions.Add(FickleExpression.Include("android.util.JsonReader"));
                includeExpressions.Add(FickleExpression.Include("android.util.JsonToken"));
                includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.*"));
                includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.utils.*"));
                includeExpressions.Add(FickleExpression.Include("java.lang.Exception"));
                includeExpressions.Add(FickleExpression.Include("java.io.InputStream"));
                includeExpressions.Add(FickleExpression.Include("java.io.InputStreamReader"));
                includeExpressions.Add(FickleExpression.Include("java.util.ArrayList"));

                members.Add(CreateDeserializeStreamMethod());
                members.Add(CreateDeserializeReaderMethod());
                members.Add(CreateDeserializeElementMethod());
                members.Add(CreateSerializeMethod());
            }

            if (CurrentTypeIsResponseType())
            {
                members.Add(CreateCreateErrorResponseMethod());
            }

            var headerGroup = includeExpressions.ToStatementisedGroupedExpression();
            var header = new Expression[] { comment, namespaceExpression, headerGroup }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            var body = fieldDefinitionsForProperties.Concat(members).ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes));
        }
Example #4
0
        protected override Expression VisitNamespaceExpresson(NamespaceExpression expression)
        {
            this.Write("package ");
            this.Write(expression.NameSpace);
            this.WriteLine(';');

            return(expression);
        }
Example #5
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            currentTypeDefinitionExpression = expression;
            currentReturnTypes = new HashSet <Type>(ReturnTypesCollector.CollectReturnTypes(expression));

            var includeExpressions = new List <IncludeExpression>
            {
                FickleExpression.Include("java.util.ArrayList"),
                FickleExpression.Include("com.jaigo.androiddevkit.DefaultJsonBuilder"),
                FickleExpression.Include("com.jaigo.androiddevkit.RequestCallback"),
                FickleExpression.Include("com.jaigo.androiddevkit.utils.ConvertUtils"),
                FickleExpression.Include("com.jaigo.androiddevkit.WebServiceClient")
            };

            var comment = new CommentExpression("This file is AUTO GENERATED");

            var client = new FieldDefinitionExpression("webServiceClient", webServiceClientType, AccessModifiers.Private | AccessModifiers.Constant);

            var body = GroupedExpressionsExpression.FlatConcat
                       (
                GroupedExpressionsExpressionStyle.Wide,
                client,
                CreateDefaultConstructor(),
                CreateParameterisedConstructor(),
                this.Visit(expression.Body)
                       );

            var singleValueResponseTypes = currentReturnTypes.Where(c => c.GetUnwrappedNullableType().IsPrimitive).Select(c => FickleType.Define(JavaBinderHelpers.GetValueResponseWrapperTypeName(c))).ToList();

            var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(body).Concat(singleValueResponseTypes).Distinct().ToList();

            referencedTypes.Sort((x, y) => String.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

            var lookup = new HashSet <Type>(referencedTypes.Where(TypeSystem.IsPrimitiveType));

            if (lookup.Contains(typeof(FickleListType)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.ArrayList"));
            }

            if (lookup.Contains(typeof(Guid)) || lookup.Contains(typeof(Guid?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.UUID"));
            }

            if (lookup.Contains(typeof(DateTime)) || lookup.Contains(typeof(DateTime?)))
            {
                includeExpressions.Add(FickleExpression.Include("java.util.Date"));
            }

            var headerGroup         = includeExpressions.Sorted(IncludeExpression.Compare).ToGroupedExpression();
            var namespaceExpression = new NamespaceExpression(CodeGenerationContext.Options.Namespace);

            var header = new Expression[] { comment, namespaceExpression, headerGroup }.ToGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

            return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes));
        }
Example #6
0
 public override void Define(NamespaceContainer ctx)
 {
     //
     // The namespace-or-type-name of a using-alias-directive is resolved as if
     // the immediately containing compilation unit or namespace body had no
     // using-directives. A using-alias-directive may however be affected
     // by extern-alias-directives in the immediately containing compilation
     // unit or namespace body
     //
     // We achieve that by introducing alias-context which redirect any local
     // namespace or type resolve calls to parent namespace
     //
     resolved = NamespaceExpression.ResolveAsTypeOrNamespace(new AliasContext(ctx));
 }
Example #7
0
        protected override Expression VisitTypeDefinitionExpression(TypeDefinitionExpression expression)
        {
            try
            {
                currentTypeDefinition = expression;
                currentType           = expression.Type;

                enumValueField = new FieldDefinitionExpression("value", typeof(int), AccessModifiers.Private | AccessModifiers.Constant);

                var includeExpressions = new List <Expression>()
                {
                    FickleExpression.Include("android.util.JsonReader"),
                    FickleExpression.Include("com.jaigo.androiddevkit.DefaultJsonBuilder"),
                    FickleExpression.Include("java.util.ArrayList")
                };

                var referencedTypes = ReferencedTypesCollector.CollectReferencedTypes(expression);
                referencedTypes.Sort((x, y) => String.Compare(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase));

                if (!codeGenerationContext.Options.SerializeEnumsAsStrings)
                {
                    includeExpressions.Add(FickleExpression.Include("com.jaigo.androiddevkit.utils.ConvertUtils"));
                }

                var includeStatements = includeExpressions.ToStatementisedGroupedExpression();

                var comment = new CommentExpression("This file is AUTO GENERATED");
                var namespaceExpression = new NamespaceExpression(codeGenerationContext.Options.Namespace);
                var header = new Expression[] { comment, namespaceExpression, includeStatements }.ToStatementisedGroupedExpression(GroupedExpressionsExpressionStyle.Wide);

                var bodyExpressions = new List <Expression>()
                {
                    expression.Body,
                    enumValueField,
                    CreateConstructor(),
                    CreateDeserializeMethod(),
                    CreateDeserializeArrayMethod(),
                    CreateSerializeMethod(),
                    JavaBinderHelpers.CreateSerializeArrayMethod(currentType)
                };

                var body = new GroupedExpressionsExpression(bodyExpressions);

                return(new TypeDefinitionExpression(expression.Type, header, body, false, expression.Attributes, expression.InterfaceTypes));
            }
            finally
            {
                currentTypeDefinition = null;
            }
        }
        public void NamespaceExpressionShouldCreateFullyQualifiedNameFromNamespaceExpressionAndNameString()
        {
            NamespaceExpression ns1 = "namespace1";
            ProductionExpression
                S = ns1 + "S",
                A = ns1 + "A";

            S.Rule = A;
            A.Rule = 'a';

            var symbolS = S.ProductionModel.LeftHandSide;

            Assert.IsNotNull(symbolS);
            Assert.AreEqual(ns1.Namespace, symbolS.NonTerminal.FullyQualifiedName.Namespace);
            Assert.AreEqual(S.ProductionModel.LeftHandSide.NonTerminal.FullyQualifiedName.Name, symbolS.NonTerminal.FullyQualifiedName.Name);

            var symbolA = A.ProductionModel.LeftHandSide;

            Assert.IsNotNull(symbolA);
            Assert.AreEqual(ns1.Namespace, symbolA.NonTerminal.FullyQualifiedName.Namespace);
            Assert.AreEqual(A.ProductionModel.LeftHandSide.NonTerminal.FullyQualifiedName.Name, symbolA.NonTerminal.FullyQualifiedName.Name);
        }
        public override void Define(NamespaceContainer ctx)
        {
            var ns = ctx.Module.GetRootNamespace (Alias.Value);
            if (ns == null) {
                ctx.Module.Compiler.Report.Error (430, Location,
                    "The extern alias `{0}' was not specified in -reference option",
                    Alias.Value);
                return;
            }

            resolved = new NamespaceExpression (ns, Location);
        }
Example #10
0
        private FullNamedExpression LookupNamespaceOrType(NamespaceTracker ns, string name, SourceSpan location, bool ignoreAmbiguousReferences, int genericArity = 0)
        {
            MemberTracker       tracker;
            FullNamedExpression fne = null;

            bool found;

            var trackerGroup = ns as NamespaceGroupTracker;

            if (trackerGroup != null)
            {
                found = trackerGroup.TryGetValue((SymbolId)name, out tracker);
            }
            else
            {
                found = ns.TryGetValue((SymbolId)name, out tracker);
            }

            if (found)
            {
                var namespaceTracker = tracker as NamespaceTracker;
                if (namespaceTracker != null)
                {
                    fne = new NamespaceExpression(namespaceTracker);
                }
                else
                {
                    var typeGroup = tracker as TypeGroup;
                    if (typeGroup != null)
                    {
                        fne = new TypeExpression(typeGroup.GetTypeForArity(genericArity).Type, location);
                    }
                    else
                    {
                        fne = new TypeExpression(((TypeTracker)tracker).Type);
                    }
                }
            }

            if (fne != null)
            {
                return(fne);
            }

            //
            // Check using entries.
            //
            var conflicts = _importedNamespaces
                            .Select(importedNamespace => LookupNamespaceOrType(importedNamespace, name, location, true))
                            .Where(match => (match != null) && (match is TypeExpression));

            foreach (var conflict in conflicts)
            {
                if (fne != null)
                {
                    if (!ignoreAmbiguousReferences)
                    {
                        OnErrorAmbiguousTypeReference(location, name, fne, conflict);
                    }
                    return(null);
                }

                fne = conflict;
            }

            return(fne);
        }
 protected virtual Expression VisitNamespaceExpresson(NamespaceExpression expression)
 {
     return(expression);
 }