示例#1
0
        protected virtual Class ParseClass(Type type)
        {
            Method[] methods = ReflectionUtility.GetMethodsOnType(type).Select(ParseMethod).ToArray();

            Indexer[] indexers = ReflectionUtility.GetIndexersOnType(type).Select(ParseIndexer).ToArray();

            Property[] properties = ReflectionUtility.GetPropertiesOnType(type).Select(ParseProperty).ToArray();

            AccessModifier accessModifier = ReflectionUtility.GetAccessModifier(type);

            string name = ReflectionUtility.GetGeneralizedTypeName(type);

            var parameters = new ClassParameters
            {
                Indexers       = indexers,
                Methods        = methods,
                Name           = name,
                Properties     = properties,
                RawType        = type,
                AccessModifier = accessModifier,
                FullName       = type.FullName
            };

            var @class = new Class(parameters);

            return(@class);
        }
示例#2
0
        public override object Execute(Reasoner ts, Unifier un, ITerm[] args)
        {
            CheckArguments(args);
            string name   = GetName(args);
            string source = GetSource(args);

            List <string> agArchClasses = GetAgArchClasses(args);

            string          agClass = null;
            ClassParameters bbPars  = null;

            if (args.Length > 2)
            {
                foreach (ITerm t in args[2] as IListTerm)
                {
                    if (t.IsStructure())
                    {
                        Structure s = t as Structure;
                        if (s.GetFunctor().Equals("beliefBaseClass"))
                        {
                            bbPars = new ClassParameters(TestString(s.GetTerm(0)));
                        }
                        else if (s.GetFunctor().Equals("agentClass"))
                        {
                            agClass = TestString(s.GetTerm(0)).ToString();
                        }
                    }
                }
            }
            IRuntimeServices rs = ts.GetUserAgArch().GetRuntimeServices();

            name = rs.CreateAgent(name, source, agClass, agArchClasses, GetSettings(), ts.GetAgent());
            rs.StartAgent(name);

            if (args[0].IsVar())
            {
                return(un.Unifies(new StringTermImpl(name), args[0]));
            }
            else
            {
                return(true);
            }
        }
示例#3
0
 public EnvironmentInfraTier(ClassParameters userEnvArgs, BaseCentralisedMAS masRunner)
 {
     this.masRunner = masRunner;
     if (userEnvArgs != null)
     {
         try
         {
             userEnv = (Environment)Activator.CreateInstance(typeof(Environment));
             userEnv.SetEnvironmentInfraTier(this);
             userEnv.Init(userEnvArgs.GetParametersArray());
         }
         catch (Exception e)
         {
             Debug.Log("Error in Centralised MAS environment creation");
             Debug.Log(e);
             throw new JasonityException("The user environment class instantiation '" + userEnvArgs + "' has failed!" + e.Message);
         }
     }
 }
        private ClassDeclarationSyntax AddPrint(ClassDeclarationSyntax node, ClassParameters parameters)
        {
            var parts           = new List <InterpolatedStringContentSyntax>();
            var includedMembers = parameters.Members.Where(m => m.Include).ToArray();

            for (var i = 0; i < includedMembers.Length; i++)
            {
                var stringStartPart = $"{ includedMembers[i].Name}: '";
                var stringEndPart   = i == includedMembers.Length - 1 ? "';" : "'; ";
                parts.Add(InterpolatedStringText(Token(TriviaList(), SyntaxKind.InterpolatedStringTextToken, stringStartPart, stringStartPart, TriviaList())));
                parts.Add(Interpolation(IdentifierName(includedMembers[i].Name)));
                parts.Add(InterpolatedStringText(Token(TriviaList(), SyntaxKind.InterpolatedStringTextToken, stringEndPart, stringEndPart, TriviaList())));
            }

            var printMethod = MethodDeclaration(ParseTypeName(typeof(string).ToString()), this.settings.PrintMethodName)
                              .WithBody(
                Block(
                    List(new StatementSyntax[] {
                ReturnStatement(
                    InterpolatedStringExpression(
                        Token(SyntaxKind.InterpolatedStringStartToken),
                        List(parts)))
            })))
                              .WithModifiers(TokenList(new SyntaxToken[]
            {
                Token(SyntaxKind.PublicKeyword),
                Token(SyntaxKind.VirtualKeyword)
            }))
                              .WithAdditionalAnnotations(new SyntaxAnnotation(this.AnnotationKey));

            if (parameters.Override)
            {
                printMethod = printMethod.WithModifiers(TokenList(new SyntaxToken[]
                {
                    Token(SyntaxKind.PublicKeyword),
                    Token(SyntaxKind.OverrideKeyword)
                }));
            }

            return(node.AddMembers(printMethod));
        }
        public Parameters GenerateParameters(
            CodeFileCSharp input,
            Settings pluginSettings,
            IMetadataReader metadataReader,
            ILogger logger,
            IFileGroup <CodeFileCSharp, GroupItemDetails> fileGroup = null)
        {
            var onlyTypesToInclude = pluginSettings
                                     .OnlyTypesToInclude?
                                     .Select(t => input.SemanticModel.Compilation.GetTypeByMetadataName(t)
                                             ?? throw new InvalidOperationException($"Unable to resolve '{t}' from {Settings.OnlyTypesToIncludeKey} list in plugin configuration.")).ToArray();
            var typesToExclude = pluginSettings
                                 .TypesToExclude?
                                 .Select(t => input.SemanticModel.Compilation.GetTypeByMetadataName(t)
                                         ?? throw new InvalidOperationException($"Unable to resolve '{t}' from {Settings.TypesToExcludeKey} list in plugin configuration.")).ToArray();

            var result = new Parameters();

            foreach (var classDeclaration in input.SyntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>())
            {
                var declaredSymbol = input.SemanticModel.GetDeclaredSymbol(classDeclaration);
                var typeName       = declaredSymbol.GetFullMetadataName();

                ClassParameters classParams = new ClassParameters(typeName);

                Func <INamedTypeSymbol, bool> typeIsDefinedInInputGroup = (baseType) =>
                                                                          fileGroup
                                                                          .Files
                                                                          .Any(inputFile =>
                                                                               inputFile.Key.SyntaxTree
                                                                               .GetRoot()
                                                                               .DescendantNodes()
                                                                               .OfType <ClassDeclarationSyntax>()
                                                                               .Any(inputClass => SymbolEqualityComparer.Default.Equals(inputFile.Key.SemanticModel.GetDeclaredSymbol(inputClass), baseType)));

                Func <INamedTypeSymbol, bool> typeContainsOverridableTargetMethod = (type) =>
                                                                                    type != null &&
                                                                                    type.GetAllSymbols <IMethodSymbol>(SymbolKind.Method, Accessibility.Public)
                                                                                    .Any(m => m.Name == pluginSettings.PrintMethodName &&
                                                                                         m.Parameters.Length == 0 &&
                                                                                         SymbolEqualityComparer.Default.Equals(m.ReturnType, input.SemanticModel.Compilation.GetTypeByMetadataName(typeof(string).ToString())) &&
                                                                                         (m.IsVirtual || m.IsAbstract));

                classParams.Override =
                    (fileGroup != null &&
                     declaredSymbol
                     .GetBaseTypes()
                     .Any(baseType => typeIsDefinedInInputGroup(baseType))) ||
                    typeContainsOverridableTargetMethod(declaredSymbol.BaseType);

                foreach (var prop in declaredSymbol.GetAllSymbols <IPropertySymbol>(SymbolKind.Property, Accessibility.Public))
                {
                    classParams.Members.Add(new MemberParameters(prop.Name, this.Filter(onlyTypesToInclude, typesToExclude, prop.Type)));
                }

                foreach (var field in declaredSymbol.GetAllSymbols <IFieldSymbol>(SymbolKind.Field, Accessibility.Public))
                {
                    classParams.Members.Add(new MemberParameters(field.Name, this.Filter(onlyTypesToInclude, typesToExclude, field.Type)));
                }

                result.Classes.Add(classParams);
            }

            return(result);
        }
示例#6
0
 public Class(ClassParameters parameters) : base(parameters)
 {
     Methods    = parameters.Methods;
     Properties = parameters.Properties;
     Indexers   = parameters.Indexers;
 }