public static CanInstantiate CanInstantiateType([NotNull] ITypeElement typeElement, [NotNull] ITreeNode expression) { if (typeElement is IStruct || typeElement is IEnum || typeElement is IClass) { // filter out abstract classes var classType = typeElement as IClass; if (classType != null && classType.IsAbstract) { return(CanInstantiate.No); } // check type has any constructor accessible var accessContext = new ElementAccessContext(expression); var canInstantiate = CanInstantiate.No; foreach (var constructor in typeElement.Constructors) { if (constructor.IsStatic) { continue; } if (AccessUtil.IsSymbolAccessible(constructor, accessContext)) { var parametersCount = constructor.Parameters.Count; canInstantiate |= (parametersCount == 0) ? CanInstantiate.DefaultConstructor : CanInstantiate.ConstructorWithParameters; } } return(canInstantiate); } return(CanInstantiate.No); }
// Bug: Unix has one byte for exit code instead of Windows!!! // // Standard posix exit code meaning: // 1 - Catchall for general errors // 2 - Misuse of shell builtins (according to Bash documentation) // 126 - Command invoked cannot execute // 127 - “command not found” // 128 - Invalid argument to exit // 128+n - Fatal error signal “n” // 130 - Script terminated by Control-C // 255\* - Exit status out of range public static byte Main(Assembly mainAssembly, [NotNull] string[] args, MainMode mode) { try { var assemblyName = mainAssembly.GetName(); var toolName = assemblyName.Name; var toolVersion = assemblyName.Version !.ToString(3); var commandLine = new CommandLineApplication { FullName = toolName }; commandLine.HelpOption("-h|--help"); commandLine.VersionOption("--version", () => toolVersion); var dirOption = commandLine.Option("-d|--directory", "The local directory with symbol server storage.", CommandOptionType.SingleValue); var awsS3BucketNameOption = commandLine.Option("-a|--aws-s3", $"The AWS S3 bucket with symbol server storage. The access and private keys will be asked in console. Use {AccessUtil.AwsS3AccessKeyEnvironmentVariable}, {AccessUtil.AwsS3SecretKeyEnvironmentVariable} and {AccessUtil.AwsCloudFrontDistributionIdEnvironmentVariable} environment variables for unattended mode.", CommandOptionType.SingleValue); var awsS3RegionEndpointOption = commandLine.Option("-ar|--aws-s3-region", $"The AWS S3 region endpoint with symbol server storage. Default is {AccessUtil.DefaultAwsS3RegionEndpoint}.", CommandOptionType.SingleValue); if (mode == MainMode.Full) { commandLine.Command("validate", x => { x.HelpOption("-h|--help"); x.Description = "Storage inconsistency check and fix known issues by request"; var aclOption = x.Option("-r|--rights", "Validate access rights.", CommandOptionType.NoValue); var fixOption = x.Option("-f|--fix", "Fix known issues if possible.", CommandOptionType.NoValue); x.OnExecute(() => new ValidateCommand( ConsoleLogger.Instance, AccessUtil.GetStorage(dirOption.Value(), awsS3BucketNameOption.Value(), awsS3RegionEndpointOption.Value()), aclOption.HasValue(), fixOption.HasValue()).ExecuteAsync()); });
private ILookupItem CreateLookoutItem( CSharpCodeCompletionContext context, string name, IList <DeclaredElementInstance <IMethod> > methods, bool skipGenericArguments, bool includeFollowingExpression = true, bool setFunctionParameters = true) { var basicContext = context.BasicContext; var editorBrowsableProcessing = basicContext.EditorBrowsableProcessing; if (editorBrowsableProcessing != EditorBrowsableProcessingType.All) { methods = methods.Where(x => CodeInsightUtil.IsBrowsable(x.Element, showNever: false, showAdvanced: editorBrowsableProcessing == EditorBrowsableProcessingType.Advanced)).ToList(); } if (methods.IsEmpty()) { return(null); } var elements = methods.Select(_ => new Pair <IDeclaredElement, ISubstitution>(_.Element, _.Substitution)); var methodsInfo = new MethodsInfo(name, elements, CSharpLanguage.Instance, basicContext.LookupItemsOwner, context); methodsInfo.Ranges = context.CompletionRanges; methodsInfo.SkipGenericArguments = skipGenericArguments; methodsInfo.PutData(CompletionKeys.IsMethodsKey, new object()); if (methods.All(x => x.Element.IsExtensionMethod)) { methodsInfo.PutKey(CompletionKeys.IsExtensionMethodsKey); } var lookupItem = LookupItemFactory.CreateLookupItem(methodsInfo).WithPresentation(_gGetMethodsPresentation) .WithBehavior(_ => new NukeTasksBehaviour(_.Info)).WithMatcher(_getMethodsMatcher); var qualifiableReference = CSharpLookupItemFactory.GetQualifiableReference(context); var qualifier = qualifiableReference != null?qualifiableReference.GetQualifier() : null; var qualifierStaticness = qualifier == null ? new Staticness?() : AccessUtil.GetQualifierStaticness(qualifier); if (setFunctionParameters) { var functions = methodsInfo.AllDeclaredElements.Select(x => x.Element).OfType <IMethod>(); CSharpLookupItemFactory.Instance.SetFunctionParameters(context, functions, lookupItem, methodsInfo); } methodsInfo.Placement.OrderString = name; return(lookupItem); }