public override bool IsAvailable(IUserDataHolder cache) { var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider); _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider); _selectedElement = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false); _block = _dataProvider.GetSelectedElement <IBlock>(); _classBody = _dataProvider.GetSelectedElement <IClassBody>(); _classDeclaration = _classBody?.GetContainingTypeDeclaration() as IClassLikeDeclaration; if (_classDeclaration == null || _block == null || _selectedElement == null) { return(false); } if (!(_selectedElement.TypeReference?.Resolve().DeclaredElement is IClass c)) { return(false); } _parameterNumber = _selectedElement.ArgumentList.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN); _constructor = c.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > _parameterNumber); if (_constructor == null) { return(false); } return(testProjectProvider.IsTestProject(_dataProvider.PsiModule)); }
public override bool IsAvailable(IUserDataHolder cache) { var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider); _selectedElement = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false); _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider); return(testProjectProvider.IsTestProject(_dataProvider.PsiModule) && _selectedElement != null && _selectedElement.Arguments.Count == 0); }
public override bool IsAvailable(IUserDataHolder cache) { var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider); if (!testProjectProvider.IsTestProject(_dataProvider.PsiModule)) { return(false); } _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider); _selectedElement = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false); _block = _dataProvider.GetSelectedElement <IBlock>(); _classBody = _dataProvider.GetSelectedElement <IClassBody>(); _classDeclaration = _classBody?.GetContainingTypeDeclaration() as IClassLikeDeclaration; if (_classDeclaration == null || _block == null || _selectedElement == null) { return(false); } if (!(_selectedElement.TypeReference?.Resolve().DeclaredElement is IClass c)) { return(false); } var parameterCount = _selectedElement.ArgumentList.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN); _constructor = c.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > parameterCount); if (_constructor == null) { return(false); } var previousTokenType = _dataProvider.TokenBeforeCaret?.NodeType as ITokenNodeType; var nextTokenType = _dataProvider.TokenAfterCaret?.NodeType as ITokenNodeType; if (previousTokenType == null || nextTokenType == null) { return(false); } if (previousTokenType.TokenRepresentation == " ") { previousTokenType = _dataProvider.PsiFile.FindTokenAt(_dataProvider.TokenBeforeCaret.GetTreeStartOffset() - 1)?.NodeType as ITokenNodeType; } if (nextTokenType.TokenRepresentation == " ") { nextTokenType = _dataProvider.PsiFile.FindTokenAt(_dataProvider.TokenBeforeCaret.GetTreeEndOffset() + 1)?.NodeType as ITokenNodeType; } if (previousTokenType == null || nextTokenType == null) { return(false); } if (previousTokenType.TokenRepresentation == "(") { return(nextTokenType.TokenRepresentation == ")" || nextTokenType.TokenRepresentation == ","); } if (previousTokenType.TokenRepresentation == ",") { return(!nextTokenType.IsIdentifier); } return(false); }