protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { var parent = TsExpressionStatementNavigator.GetByExpression(TsCompoundExpressionNavigator.GetByExpression(_indexInvocation)); var arguments = _indexInvocation.Arguments.ToArray(); var info = new TsClass(); var contrName = arguments[0].GetText().Trim('"'); info.NameFull = contrName.Substring(0, 1).ToUpper() + contrName.Substring(1); ITsFunctionExpression function = null; var last = arguments[arguments.Length - 1]; if (last is ITsFunctionExpression) { function = last as ITsFunctionExpression; } else if (last is ITsArrayLiteral) { var arr = last as ITsArrayLiteral; function = arr.ArrayElements[arr.ArrayElements.Count - 1] as ITsFunctionExpression; } else { return null; } info.ConstructorFunction = new TsFunction(function); TsElementFactory factory = TsElementFactory.GetInstance(_indexInvocation); using (WriteLockCookie.Create()) { info.FindFieldsInsideFunction(info.ConstructorFunction.Block); info.FindAndMoveMethodsInsideFunction(info.ConstructorFunction.Block); info.FindAndMoveNgMethodsInsideFunction(info.ConstructorFunction.Block); info.CreateFieldsFromConstructorParams(); //Replace Ng Controller body to its class name ModificationUtil.ReplaceChild(function, factory.CreateRefenceName(info.NameFull)); //Insert ES6 class Before ModificationUtil.AddChildBefore(parent.Parent, parent, factory.CreateStatement(info.TransformForTypescript(true))); } return null; }
protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { ITreeNode parent = _index; while (true) { if (parent.Parent == null) { return null; } if (parent.Parent is ITsFileSection) { break; } parent = parent.Parent; } var info = new TsClass(); info.NameFull = "SomeNamespace.SomeClass"; info.ConstructorFunction = new TsFunction(_index); TsElementFactory factory = TsElementFactory.GetInstance(_index); using (WriteLockCookie.Create()) { info.FindFieldsInsideFunction(info.ConstructorFunction.Block); info.FindAndMoveMethodsInsideFunction(info.ConstructorFunction.Block); info.FindAndMoveNgMethodsInsideFunction(info.ConstructorFunction.Block); info.CreateFieldsFromConstructorParams(); //Replace Ng Controller body to its class name ModificationUtil.ReplaceChild(_index, factory.CreateRefenceName(info.NameFull)); //Insert ES6 class Before ModificationUtil.AddChildBefore(parent.Parent, parent, factory.CreateStatement(info.TransformForTypescript(true))); } return null; }