public override void Execute(EditorRefactoringContext context)
		{
			CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;
			if (parseInformation != null) {
				SyntaxTree st = parseInformation.SyntaxTree;
				Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
				if (identifier == null)
					return;
				TypeDeclaration interfaceTypeDeclaration = identifier.Parent as TypeDeclaration;
				if (interfaceTypeDeclaration != null) {
					// Generate abstract class from interface and abstract members from interface members
					TypeDeclaration abstractClassTypeNode = (TypeDeclaration) interfaceTypeDeclaration.Clone();
					abstractClassTypeNode.ClassType = ClassType.Class;
					abstractClassTypeNode.Modifiers |= Modifiers.Abstract;
					foreach (var entity in abstractClassTypeNode.Children.OfType<EntityDeclaration>()) {
						entity.Modifiers |= Modifiers.Abstract | Modifiers.Public;
					}
					
					var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
					using (Script script = refactoringContext.StartScript()) {
						// Replace interface node with node of abstract class
						script.Replace(interfaceTypeDeclaration, abstractClassTypeNode);
					}
				}
			}
		}
Esempio n. 2
0
        public override void Execute(EditorRefactoringContext context)
        {
            AlFullParseInformation parseInformation = context.GetParseInformation() as AlFullParseInformation;

            if (parseInformation != null)
            {
                SyntaxTree st         = parseInformation.SyntaxTree;
                Identifier identifier = (Identifier)st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
                if (identifier == null)
                {
                    return;
                }
                TypeDeclaration interfaceTypeDeclaration = identifier.Parent as TypeDeclaration;
                if (interfaceTypeDeclaration != null)
                {
                    // Generate abstract class from interface and abstract members from interface members
                    TypeDeclaration abstractClassTypeNode = (TypeDeclaration)interfaceTypeDeclaration.Clone();
                    abstractClassTypeNode.ClassType  = ClassType.Class;
                    abstractClassTypeNode.Modifiers |= Modifiers.Abstract;
                    foreach (var entity in abstractClassTypeNode.Children.OfType <EntityDeclaration>())
                    {
                        entity.Modifiers |= Modifiers.Abstract | Modifiers.Public;
                    }

                    var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
                    using (Script script = refactoringContext.StartScript()) {
                        // Replace interface node with node of abstract class
                        script.Replace(interfaceTypeDeclaration, abstractClassTypeNode);
                    }
                }
            }
        }
Esempio n. 3
0
        public override void Execute(EditorRefactoringContext context)
        {
            AlFullParseInformation parseInformation = context.GetParseInformation() as AlFullParseInformation;

            if (parseInformation != null)
            {
                SyntaxTree st         = parseInformation.SyntaxTree;
                Identifier identifier = (Identifier)st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
                if (identifier == null)
                {
                    return;
                }
                ParameterDeclaration parameterDeclaration = identifier.Parent as ParameterDeclaration;
                if (parameterDeclaration == null)
                {
                    return;
                }

                AstNode grandparent = identifier.Parent.Parent;
                if ((grandparent is MethodDeclaration) || (grandparent is ConstructorDeclaration))
                {
                    // Range check condition
                    var rangeCheck = new IfElseStatement(
                        new BinaryOperatorExpression(
                            new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.LessThan, new IdentifierExpression("lower")),
                            BinaryOperatorType.ConditionalOr,
                            new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.GreaterThan, new IdentifierExpression("upper"))
                            ),
                        new ThrowStatement(
                            new ObjectCreateExpression(
                                new SimpleType("ArgumentOutOfRangeException"),
                                new List <Expression>()
                    {
                        new PrimitiveExpression(identifier.Name, '"' + identifier.Name + '"'), new IdentifierExpression(identifier.Name), new BinaryOperatorExpression(new PrimitiveExpression("Value must be between "), BinaryOperatorType.Add, new BinaryOperatorExpression(new IdentifierExpression("lower"), BinaryOperatorType.Add, new BinaryOperatorExpression(new PrimitiveExpression(" and "), BinaryOperatorType.Add, new IdentifierExpression("upper"))))
                    }
                                )
                            )
                        );

                    // Add range check as first statement in method's/constructor's body
                    var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
                    using (Script script = refactoringContext.StartScript()) {
                        if (grandparent is MethodDeclaration)
                        {
                            var methodDeclaration = (MethodDeclaration)grandparent;
                            script.AddTo(methodDeclaration.Body, rangeCheck);
                        }
                        else if (grandparent is ConstructorDeclaration)
                        {
                            var ctorDeclaration = (ConstructorDeclaration)grandparent;
                            script.AddTo(ctorDeclaration.Body, rangeCheck);
                        }
                    }
                }
            }
        }
		public override string GetDisplayName(EditorRefactoringContext context)
		{
			CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;
			if (parseInformation != null) {
				SyntaxTree st = parseInformation.SyntaxTree;
				Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
				if (identifier == null)
					return DisplayName;
				
				return StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}",
				                          new StringTagPair("FileName", MakeValidFileName(identifier.Name)));
			}
			
			return DisplayName;
		}
		public override void Execute(EditorRefactoringContext context)
		{
			CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;
			if (parseInformation != null) {
				SyntaxTree st = parseInformation.SyntaxTree;
				Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
				if (identifier == null)
					return;
				
				ICompilation compilation = context.GetCompilation();
				IProject project = compilation.GetProject();
				RenameFile(project, context.FileName, Path.Combine(Path.GetDirectoryName(context.FileName), MakeValidFileName(identifier.Name)));
				if (project != null) {
					project.Save();
				}
			}
		}
Esempio n. 6
0
        public override string GetDisplayName(EditorRefactoringContext context)
        {
            CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;

            if (parseInformation != null)
            {
                SyntaxTree st         = parseInformation.SyntaxTree;
                Identifier identifier = (Identifier)st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
                if (identifier == null)
                {
                    return(DisplayName);
                }

                return(StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}",
                                          new StringTagPair("FileName", MakeValidFileName(identifier.Name))));
            }

            return(DisplayName);
        }
		public override void Execute(EditorRefactoringContext context)
		{
			CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;
			if (parseInformation != null) {
				SyntaxTree st = parseInformation.SyntaxTree;
				Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
				if (identifier == null)
					return;
				ParameterDeclaration parameterDeclaration = identifier.Parent as ParameterDeclaration;
				if (parameterDeclaration == null)
					return;
				
				AstNode grandparent = identifier.Parent.Parent;
				if ((grandparent is MethodDeclaration) || (grandparent is ConstructorDeclaration)) {
					// Range check condition
					var rangeCheck = new IfElseStatement(
						new BinaryOperatorExpression(
							new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.LessThan, new IdentifierExpression("lower")),
							BinaryOperatorType.ConditionalOr,
							new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.GreaterThan, new IdentifierExpression("upper"))
						),
						new ThrowStatement(
							new ObjectCreateExpression(
								new SimpleType("ArgumentOutOfRangeException"),
								new List<Expression>() { new PrimitiveExpression(identifier.Name, '"' + identifier.Name + '"'), new IdentifierExpression(identifier.Name), new BinaryOperatorExpression(new PrimitiveExpression("Value must be between "), BinaryOperatorType.Add, new BinaryOperatorExpression(new IdentifierExpression("lower"), BinaryOperatorType.Add, new BinaryOperatorExpression(new PrimitiveExpression(" and "), BinaryOperatorType.Add, new IdentifierExpression("upper")))) }
							)
						)
					);
					
					// Add range check as first statement in method's/constructor's body
					var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
					using (Script script = refactoringContext.StartScript()) {
						if (grandparent is MethodDeclaration) {
							var methodDeclaration = (MethodDeclaration) grandparent;
							script.AddTo(methodDeclaration.Body, rangeCheck);
						} else if (grandparent is ConstructorDeclaration) {
							var ctorDeclaration = (ConstructorDeclaration) grandparent;
							script.AddTo(ctorDeclaration.Body, rangeCheck);
						}
					}
				}
			}
		}
Esempio n. 8
0
        public override void Execute(EditorRefactoringContext context)
        {
            AlFullParseInformation parseInformation = context.GetParseInformation() as AlFullParseInformation;

            if (parseInformation != null)
            {
                SyntaxTree st         = parseInformation.SyntaxTree;
                Identifier identifier = (Identifier)st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
                if (identifier == null)
                {
                    return;
                }

                ICompilation compilation = context.GetCompilation();
                IProject     project     = compilation.GetProject();
                RenameFile(project, context.FileName, Path.Combine(Path.GetDirectoryName(context.FileName), MakeValidFileName(identifier.Name)));
                if (project != null)
                {
                    project.Save();
                }
            }
        }