Inheritance: AttributedNode
 private IList GetMethodsInParents(TypeDeclaration typeDeclaration, IList pmList, bool implemented)
 {
     ClassType classType;
     if (implemented)
         classType = ClassType.Class;
     else
         classType = ClassType.Interface;
     if (typeDeclaration.BaseTypes.Count > 0)
     {
         foreach (TypeReference parentType in typeDeclaration.BaseTypes)
         {
             string baseType = GetFullName(parentType);
             if (CodeBase.Types.Contains(baseType))
             {
                 TypeDeclaration parentTypeDeclaration = (TypeDeclaration) CodeBase.Types[baseType];
                 if (parentTypeDeclaration.Type == classType)
                 {
                     pmList = GetMethods(parentTypeDeclaration, pmList);
                     pmList = GetMethodsInParents(parentTypeDeclaration, pmList, implemented);
                 }
             }
         }
     }
     return pmList;
 }
        public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (IsDerivedFrom(typeDeclaration, "Comparator"))
            {
                IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));

                MethodDeclaration equalsMethod = new MethodDeclaration("equals",
                                                                       Modifiers.Public, AstUtil.GetTypeReference("bool", typeDeclaration), new List<ParameterDeclarationExpression>(), null);
                equalsMethod.Parent = typeDeclaration;

                TypeReference argTypeReference = AstUtil.GetTypeReference("java.lang.Object", equalsMethod);
                argTypeReference.RankSpecifier = new int[] {};
                equalsMethod.Parameters.Add(new ParameterDeclarationExpression(argTypeReference, "obj"));

                if (Contains(methods, equalsMethod))
                {
                    int index = IndexOf(methods, equalsMethod);
                    MethodDeclaration method = (MethodDeclaration) methods[index];
                    AstUtil.RemoveModifierFrom(method, Modifiers.Abstract);
                    method.TypeReference.Type = "bool";
                    CreateMethodImplementation(method);
                }
                else
                {
                    CreateMethodImplementation(equalsMethod);
                    typeDeclaration.Children.Add(equalsMethod);
                    equalsMethod.Parent = typeDeclaration;
                }
            }
            return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
        }
        public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (IsAbstractClass(typeDeclaration))
            {
                IList currentClassMethods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
                currentClassMethods = GetMethodsInParents(typeDeclaration, currentClassMethods, true);
                IList methodsInParents = new ArrayList();
                methodsInParents = GetMethodsInParents(typeDeclaration, methodsInParents, false);
                methodsInParents = FilterImplementedMethods(methodsInParents);
                IList abstractMethods = GetDiffList(currentClassMethods, methodsInParents);

                if (abstractMethods.Count > 0)
                {
                    TypeDeclaration replacedTypeDeclaration = typeDeclaration;
                    foreach (MethodDeclaration method in abstractMethods)
                    {
                        MethodDeclaration newMethod;
                        newMethod = new MethodDeclaration(method.Name,
                                                          Modifiers.Public | Modifiers.Abstract,
                                                          method.TypeReference,
                                                          method.Parameters,
                                                          method.Attributes);
                        newMethod.Parent = replacedTypeDeclaration;
                        replacedTypeDeclaration.Children.Add(newMethod);
                    }
                    ReplaceCurrentNode(replacedTypeDeclaration);
                }
            }
            return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
        }
Beispiel #4
0
		public static string GenerateText(TypeDeclaration type, OrderedPartCollection<AbstractDynamicCompilationExtension> extensions)
		{
			var unit = new CompilationUnit();

			var namespaces = new HashSet<string>
			{
				typeof (SystemTime).Namespace,
				typeof (AbstractViewGenerator).Namespace,
				typeof (Enumerable).Namespace,
				typeof (IEnumerable<>).Namespace,
				typeof (IEnumerable).Namespace,
				typeof (int).Namespace,
				typeof (LinqOnDynamic).Namespace,
				typeof(Field).Namespace,
			};
			foreach (var extension in extensions)
			{
				foreach (var ns in extension.Value.GetNamespacesToImport())
				{
					namespaces.Add(ns);
				}
			}

			foreach (var ns in namespaces)
			{
				unit.AddChild(new Using(ns));
			}

			unit.AddChild(type);
			var output = new CSharpOutputVisitor();
			unit.AcceptVisitor(output, null);

			return output.Text;
		}
        protected override bool VerifyMethodCondition(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
        {
            IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
            string name = methodDeclaration.Name.Substring(3);

            if (Contains(methods, methodDeclaration))
            {
                IList innerTypes = AstUtil.GetChildrenWithType(typeDeclaration, typeof(TypeDeclaration));
                foreach (TypeDeclaration innerType in innerTypes)
                {
                    if (innerType.Name == name)
                        return true;
                }
                IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
                foreach (ConstructorDeclaration constructorDeclaration in constructors)
                {
                    if (constructorDeclaration.Name == name)
                        return true;
                }
                foreach (MethodDeclaration method in methods)
                {
                    if (method.Name == name || char.ToUpper(method.Name[0]) + method.Name.Substring(1) == name)
                        return true;
                }
            }
            else
            {
                IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
                return Contains(properties, name);
            }
            return false;
        }
 public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 {
     currentClass = currentNamepace + "." + typeDeclaration.Name;
     base.VisitTypeDeclaration(typeDeclaration, data);
     currentClass = null;
     return null;
 }
 void Check(TypeDeclaration td)
 {
     Assert.AreEqual("Lexer", td.Name);
     Assert.AreEqual(2, td.Children.Count);
     Assert.AreEqual(0, ((ConstructorDeclaration)td.Children[0]).Body.Children.Count);
     Assert.AreEqual(0, ((MethodDeclaration)td.Children[1]).Body.Children.Count);
 }
 internal static string Generate(ParametrizedNode methodToCall, TypeDeclaration parentType, 
     string returnVariableName)
 {
     var template = new MethodCallStub(methodToCall, parentType, returnVariableName);
     var text = template.TransformText();
     return text;
 }
		public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
		{
			Push();
			object result = base.VisitTypeDeclaration(typeDeclaration, data);
			Pop();
			return result;
		}
Beispiel #10
0
            public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
            {
                if (typeDeclaration.Type == ClassType.Class && typeDeclaration.Modifier.HasFlag(Modifiers.Abstract))
                    UnlockWith(typeDeclaration);

                return base.VisitTypeDeclaration(typeDeclaration, data);
            }
Beispiel #11
0
        protected bool IsMethodInExternalTypes(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
        {
            bool found = false;
            foreach (TypeReference baseType in typeDeclaration.BaseTypes)
            {
                string fullName = GetFullName(baseType);
                if (!found && CodeBase.Types.Contains(fullName))
                {
                    TypeDeclaration baseTypeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];

                    if (IsInExternalLibraries(fullName) || fullName.StartsWith("Helpers."))
                    {
                        IList methods = AstUtil.GetChildrenWithType(baseTypeDeclaration, typeof(MethodDeclaration));
                        if (ContainsMethod(methods, methodDeclaration))
                            found = true;
                        else
                            found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
                    }
                    else
                        found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
                    if (found)
                        break;
                }
            }
            return found;
        }
Beispiel #12
0
        public TypeDeclaration CreateType(TypeDefinition typeDef)
        {
            TypeDeclaration astType = new TypeDeclaration(ConvertModifiers(typeDef), new List<AttributeSection>());
            astType.Name = typeDef.Name;

            if (typeDef.IsEnum) {  // NB: Enum is value type
                astType.Type = ClassType.Enum;
            } else if (typeDef.IsValueType) {
                astType.Type = ClassType.Struct;
            } else if (typeDef.IsInterface) {
                astType.Type = ClassType.Interface;
            } else {
                astType.Type = ClassType.Class;
            }

            // Nested types
            foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
                astType.Children.Add(CreateType(nestedTypeDef));
            }

            // Base type
            if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != Constants.Object) {
                astType.BaseTypes.Add(new Ast.TypeReference(typeDef.BaseType.FullName));
            }

            AddTypeMembers(astType, typeDef);

            return astType;
        }
        public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (typeDeclaration.Type == ClassType.Class || typeDeclaration.Type == ClassType.Struct)
                Classes.Add(typeDeclaration.Name, typeDeclaration);

            return base.VisitTypeDeclaration(typeDeclaration, data);
        }
        // create
        public static TypeDeclaration add_Type(this NamespaceDeclaration namespaceDeclaration, IClass iClass)
        {
            // move to method IClass.typeDeclaration();
            var typeName = iClass.Name;

            var newType = namespaceDeclaration.type(typeName);		// check if already exists and if it does return it
            if (newType != null)
                return newType;

            const Modifiers modifiers = Modifiers.None | Modifiers.Public;
            newType = new TypeDeclaration(modifiers, new List<AttributeSection>());
            newType.Name = typeName;

            foreach (var baseType in iClass.BaseTypes)
            {
                if (baseType.FullyQualifiedName != "System.Object")  // no need to include this one
                    newType.BaseTypes.Add(new TypeReference(baseType.FullyQualifiedName));
            }

            namespaceDeclaration.AddChild(newType);

            return newType;

            //return namespaceDeclaration.add_Type(iClass.Name);
        }
Beispiel #15
0
            public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
            {
                if(typeDeclaration.Type == ClassType.Interface)
                    UnlockWith(typeDeclaration);

                return base.VisitTypeDeclaration(typeDeclaration, data);
            }
 public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
 {
     PythonConstructorInfo pythonConstructorInfo;
     List<FieldDeclaration> fieldDeclarations = new List<FieldDeclaration>();
     ConstructorDeclaration constructorDeclaration = null;
     foreach (INode child in type.Children)
     {
         ConstructorDeclaration constructorDeclaration1 = child as ConstructorDeclaration;
         FieldDeclaration fieldDeclaration = child as FieldDeclaration;
         if (constructorDeclaration1 != null)
         {
             constructorDeclaration = constructorDeclaration1;
         }
         else if (fieldDeclaration != null)
         {
             fieldDeclarations.Add(fieldDeclaration);
         }
     }
     if ((fieldDeclarations.Count > 0 ? false : constructorDeclaration == null))
     {
         pythonConstructorInfo = null;
     }
     else
     {
         pythonConstructorInfo = new PythonConstructorInfo(constructorDeclaration, fieldDeclarations);
     }
     return pythonConstructorInfo;
 }
Beispiel #17
0
 public override object VisitTypeDeclaration (TypeDeclaration node, object data)
 {
     if (CurrentType != null) {
         Console.WriteLine ("Nested types are not supported");
         //throw CreateException (node, "Nested types are not supported");
     }
     if (IsHiddenClass (node))
         return null;
     
     if ((node.Modifier & Modifiers.Partial) > 0) {
         Console.WriteLine ("Partial classes are not supported: " + node);
         //throw CreateException (node, "Partial classes are not supported");
     }
     CurrentType = new JsTypeInfo { Name = GenericsHelper.GetScriptName (node), ClassType = node.Type, Namespace = Namespace, Usings = new HashSet<string> (Usings) };
     
     Usings = new HashSet<string> ();
     
     CurrentType.IsStatic = node.Type == ClassType.Enum || HasModifier (node.Modifier, Modifiers.Static);
     
     if (node.Type != ClassType.Interface)
         node.AcceptChildren (this, null);
     
     if (CachedCctor != null) {
         if (!ProcessCctor ())
             throw CreateException (node, "Static constructor may only contain primitive or array static field initializations");
         CachedCctor = null;
     }
     
     CollectedTypes.Add (CurrentType);
     CurrentType = null;
     
     return null;
 }
        public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            fields = AstUtil.GetChildrenWithType(typeDeclaration, typeof(FieldDeclaration));
            base.TrackedVisitTypeDeclaration(typeDeclaration, data);

            AddNotDeclaredAccessor(typeDeclaration);
            return null;
        }
		public static API_ASMX_Proxy add_Property_To_Type_Constructor(this API_ASMX_Proxy asmxProxy, TypeDeclaration targetType, string propertyName, TypeDeclaration propertyType)
		{
			targetType.add_Property(propertyName,propertyType)	
					  .add_Ctor()								
					  .body()									
					  .add_Assignment(propertyName, propertyType);
			return asmxProxy;
		}
		public void VisitTypeDeclaration_NotWizardStepPage_DoesNothing()
		{
			var type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>()) {Name = "SomeRandomType"};

			mocks.ReplayAll();
			visitor.VisitTypeDeclaration(type, null);
			mocks.VerifyAll();
		}
Beispiel #21
0
		private void TransformQueryToClass()
		{
			
			CSharpSafeName = "Index_"+ Regex.Replace(Name, @"[^\w\d]", "_");
			var type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>())
			{
				BaseTypes =
					{
						new TypeReference("AbstractViewGenerator")
					},
				Name = CSharpSafeName,
				Type = ClassType.Class
			};

			var ctor = new ConstructorDeclaration(CSharpSafeName,
			                                      Modifiers.Public,
			                                      new List<ParameterDeclarationExpression>(), null);
			type.Children.Add(ctor);
			ctor.Body = new BlockStatement();
		
			// this.ViewText = "96E65595-1C9E-4BFB-A0E5-80BF2D6FC185"; // Will be replaced later
			ctor.Body.AddChild(new ExpressionStatement(
			                   	new AssignmentExpression(
			                   		new MemberReferenceExpression(new ThisReferenceExpression(), "ViewText"),
			                   		AssignmentOperatorType.Assign,
			                   		new PrimitiveExpression(mapReduceTextToken, mapReduceTextToken))));

			foreach (var map in indexDefinition.Maps)
			{
				HandleMapFunction(ctor, map);
			}

			HandleTransformResults(ctor);

			HandleReduceDefintion(ctor);

		    AddAdditionalInformation(ctor);

			CompiledQueryText = QueryParsingUtils.GenerateText(type, extensions);
			var sb = new StringBuilder("@\"");
			foreach (var map in indexDefinition.Maps)
			{
				sb.AppendLine(map.Replace("\"", "\"\""));
			}
			if (indexDefinition.Reduce != null)
			{
				sb.AppendLine(indexDefinition.Reduce.Replace("\"", "\"\"")).AppendLine();
			}

			if (indexDefinition.TransformResults != null)
			{
				sb.AppendLine(indexDefinition.TransformResults.Replace("\"", "\"\"")).AppendLine();
			}

			sb.Append("\"");
			CompiledQueryText = CompiledQueryText.Replace("\"" + mapReduceTextToken + "\"",
			                                              sb.ToString());
		}
Beispiel #22
0
            public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
            {
                if (typeDeclaration.Type == ClassType.Enum)
                {
                    UnlockWith(typeDeclaration);
                }

                return(base.VisitTypeDeclaration(typeDeclaration, data));
            }
 private ConstructorDeclaration GetConstructor(ExpressionStatement expression, TypeDeclaration typeDeclaration)
 {
     ConstructorDeclaration constructorDeclaration;
     constructorDeclaration = new ConstructorDeclaration(typeDeclaration.Name, Modifiers.Public, null, null);
     constructorDeclaration.Body = new BlockStatement();
     constructorDeclaration.Body.Children.Add(expression);
     typeDeclaration.Children.Add(constructorDeclaration);
     return constructorDeclaration;
 }
 public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 {
     if (AstUtil.ContainsModifier(typeDeclaration, Modifiers.Final))
     {
         AstUtil.ReplaceModifiers(typeDeclaration, Modifiers.Final, Modifiers.Sealed);
         ReplaceCurrentNode(typeDeclaration);
     }
     return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
 }
		public void VisitTypeDeclaration_AControllerNoChildren_PushesAndPops()
		{
			var type = new TypeDeclaration(Modifiers.Public | Modifiers.Partial, new List<AttributeSection>()) { Name = ControllerName };

			visitor.VisitTypeDeclaration(type, null);

			treeService.AssertWasCalled(s => s.PushNode(Arg<ControllerTreeNode>.Matches(n => n.Name == ControllerName)));
			treeService.AssertWasCalled(s => s.PopNode());
		}
    public void VisitTypeDeclaration_AControllerNotPartial_DoesNothing()
    {
      TypeDeclaration type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>());
      type.Name = "SomeRandomController";

      _mocks.ReplayAll();
	  _visitor.VisitTypeDeclaration(type, null);
      _mocks.VerifyAll();
    }
Beispiel #27
0
            public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
            {
                if (typeDeclaration.Type == ClassType.Class && typeDeclaration.Modifier.HasFlag(Modifiers.Abstract))
                {
                    UnlockWith(typeDeclaration);
                }

                return(base.VisitTypeDeclaration(typeDeclaration, data));
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodCallStub"/> parameterized template with the specified
 /// <paramref name="methodToCall"/> and <paramref name="parentType"/>.
 /// </summary>
 /// 
 /// <param name="methodToCall">
 /// The <see cref="ParametrizedNode"/> representing the method or constructor for which a call stub is to be
 /// written.
 /// </param>
 /// 
 /// <param name="parentType">
 /// The <see cref="TypeDeclaration"/> that contains <paramref name="methodToCall"/>.
 /// </param>
 /// 
 /// <param name="variableName">
 /// The name of the variable to which the result of the method will be assigned, if appropriate.
 /// </param>
 public MethodCallStub (ParametrizedNode methodToCall, TypeDeclaration parentType, string variableName) 
     : base (methodToCall, parentType)
 {
     VariableName = variableName ?? "result";
     InstanceOrClass = NeedsInstance ? DetermineInstanceVariableName(parentType) : parentType.Name;
     Invocation = methodToCall is MethodDeclaration 
         ? InstanceOrClass + "." + methodToCall.Name
         : "new " + parentType.Name;
 }
		public void VisitTypeDeclaration_AWizardStepPageNotPartial_DoesNothing()
		{
			var type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>()) {Name = "SomeRandomWizardStepPage"};
			type.BaseTypes.Add(new TypeReference("WizardStepPage"));

			mocks.ReplayAll();
			visitor.VisitTypeDeclaration(type, null);
			mocks.VerifyAll();
		}
    public void VisitTypeDeclaration_NotViewComponent_DoesNothing()
    {
      TypeDeclaration type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>());
      type.Name = "SomeRandomType";

      _mocks.ReplayAll();
	  _visitor.VisitTypeDeclaration(type, null);
      _mocks.VerifyAll();
    }
 public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 {
     stubMembers.AddRange(Members.Split(','));
     if (Inherit == null)
         return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
     typeDeclaration.Children.Clear();
     typeDeclaration.BaseTypes.Clear();
     typeDeclaration.BaseTypes.Add(new TypeReference(Inherit));
     return null;
 }
 public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 {
     string parentType;
     if (HasExcludedMethod(typeDeclaration, out parentType))
     {
         methods = (IList) ParentTypes[parentType];
         return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
     }
     return null;
 }
            public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
            {
                if (typeDeclaration.Type == ClassType.Enum)
                {
                    foreach (var child in typeDeclaration.Children)
                    {
                        FieldDeclaration variablef = child as FieldDeclaration;
                        foreach (var field in variablef.Fields)
                        {
                            if (!field.Initializer.IsNull)
                            {
                                UnlockWith(typeDeclaration);
                            }
                        }
                    }
                }

                return(base.VisitTypeDeclaration(typeDeclaration, data));
            }
 //DC
 public void mapType(NRefactoryAST.TypeDeclaration typeDeclaration, IClass iClass)
 {
     TypeDeclarationToIClass.Add(typeDeclaration, iClass);
     IClassToTypeDeclaration.Add(iClass, typeDeclaration);
 }
        internal void ExecuteIntroduceMethod(UnknownMethodResolveResult rr, Ast.Expression invocationExpr, ITextEditor editor, bool isNew, object result)
        {
            IClass targetClass = IsEqualClass(rr.CallingClass, rr.Target.GetUnderlyingClass()) ? rr.CallingClass
                                : rr.Target.GetUnderlyingClass();

            CodeGenerator gen      = targetClass.ProjectContent.Language.CodeGenerator;
            IAmbience     ambience = targetClass.ProjectContent.Language.GetAmbience();

            ClassFinder finder = new ClassFinder(rr.CallingMember);

            ModifierEnum modifiers = ModifierEnum.None;

            bool isExtension = !targetClass.IsUserCode();

            if (IsEqualClass(rr.CallingClass, targetClass))
            {
                if (rr.CallingMember != null)
                {
                    modifiers |= (rr.CallingMember.Modifiers & ModifierEnum.Static);
                }
            }
            else
            {
                if (isExtension)
                {
                    if (isNew)
                    {
                        targetClass = rr.CallingClass;
                    }
                    else
                    {
                        targetClass = result as IClass;
                    }
                }
                // exclude in Unit Test mode
                if (WorkbenchSingleton.Workbench != null)
                {
                    editor = (FileService.OpenFile(targetClass.CompilationUnit.FileName) as ITextEditorProvider).TextEditor;
                }
                if (targetClass.ClassType != ClassType.Interface)
                {
                    modifiers |= ModifierEnum.Public;
                }
                if (rr.IsStaticContext)
                {
                    modifiers |= ModifierEnum.Static;
                }
            }

            NRefactoryResolver resolver = Extensions.CreateResolverForContext(targetClass.ProjectContent.Language, editor);

            IReturnType type = resolver.GetExpectedTypeFromContext(invocationExpr);

            Ast.TypeReference typeRef = CodeGenerator.ConvertType(type, finder);

            if (typeRef.IsNull)
            {
                if (invocationExpr.Parent is Ast.ExpressionStatement)
                {
                    typeRef = new Ast.TypeReference("void", true);
                }
                else
                {
                    typeRef = new Ast.TypeReference("object", true);
                }
            }

            Ast.MethodDeclaration method = new Ast.MethodDeclaration {
                Name          = rr.CallName,
                Modifier      = CodeGenerator.ConvertModifier(modifiers, finder),
                TypeReference = typeRef,
                Parameters    = CreateParameters(rr, finder, invocationExpr as Ast.InvocationExpression).ToList(),
            };

            if (targetClass.ClassType != ClassType.Interface)
            {
                method.Body = CodeGenerator.CreateNotImplementedBlock();
            }

            RefactoringDocumentAdapter documentWrapper = new RefactoringDocumentAdapter(editor.Document);

            if (isExtension)
            {
                method.Parameters.Insert(0, new Ast.ParameterDeclarationExpression(CodeGenerator.ConvertType(rr.Target, finder), "thisInstance"));
                method.IsExtensionMethod = true;
                method.Modifier         |= Ast.Modifiers.Static;
            }

            if (isNew)
            {
                Ast.TypeDeclaration newType = new Ast.TypeDeclaration(isExtension ? Ast.Modifiers.Static : Ast.Modifiers.None, null);
                newType.Name = result as string;
                newType.AddChild(method);
                gen.InsertCodeAfter(targetClass, documentWrapper, newType);
            }
            else
            {
                if (IsEqualClass(rr.CallingClass, targetClass))
                {
                    gen.InsertCodeAfter(rr.CallingMember, documentWrapper, method);
                }
                else
                {
                    gen.InsertCodeAtEnd(targetClass.BodyRegion, documentWrapper, method);
                }
            }

            if (targetClass.ClassType == ClassType.Interface)
            {
                return;
            }

            ParseInformation info = ParserService.ParseFile(targetClass.CompilationUnit.FileName);

            if (info != null)
            {
                IMember newMember;

                if (isNew)
                {
                    targetClass = info.CompilationUnit.Classes.FirstOrDefault(c => c.DotNetName == c.Namespace + "." + (result as string));
                }
                else
                {
                    targetClass = info.CompilationUnit.Classes.Flatten(c => c.InnerClasses).FirstOrDefault(c => c.DotNetName == targetClass.DotNetName);
                }

                if (targetClass == null)
                {
                    return;
                }

                if (IsEqualClass(rr.CallingClass, targetClass))
                {
                    newMember = targetClass.GetInnermostMember(editor.Caret.Line, editor.Caret.Column);
                    newMember = targetClass.AllMembers
                                .OrderBy(m => m.BodyRegion.BeginLine)
                                .ThenBy(m2 => m2.BodyRegion.BeginColumn)
                                .First(m3 => m3.BodyRegion.BeginLine > newMember.BodyRegion.BeginLine);
                }
                else
                {
                    newMember = targetClass.Methods.Last();
                }

                IDocumentLine line         = editor.Document.GetLine(newMember.BodyRegion.BeginLine + 2);
                int           indentLength = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset).Length;
                editor.Select(line.Offset + indentLength, "throw new NotImplementedException();".Length);
            }
        }
Beispiel #36
0
        public override object VisitTypeDeclaration(AST.TypeDeclaration typeDeclaration, object data)
        {
            DomRegion region     = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
            DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);

            DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertTypeModifier(typeDeclaration.Modifier), region, GetCurrentClass());

            c.BodyRegion = bodyRegion;
            ConvertAttributes(typeDeclaration, c);
            c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);

            if (currentClass.Count > 0)
            {
                DefaultClass cur = GetCurrentClass();
                cur.InnerClasses.Add(c);
                c.FullyQualifiedName = cur.FullyQualifiedName + '.' + typeDeclaration.Name;
            }
            else
            {
                c.FullyQualifiedName = PrependCurrentNamespace(typeDeclaration.Name);
                cu.Classes.Add(c);
            }
            c.UsingScope = currentNamespace;
            currentClass.Push(c);

            ConvertTemplates(typeDeclaration.Templates, c);             // resolve constrains in context of the class
            // templates must be converted before base types because base types may refer to generic types

            if (c.ClassType != ClassType.Enum && typeDeclaration.BaseTypes != null)
            {
                foreach (AST.TypeReference type in typeDeclaration.BaseTypes)
                {
                    IReturnType rt = CreateReturnType(type, null, TypeVisitor.ReturnTypeOptions.BaseTypeReference);
                    if (rt != null)
                    {
                        c.BaseTypes.Add(rt);
                    }
                }
            }

            object ret = typeDeclaration.AcceptChildren(this, data);

            currentClass.Pop();

            if (c.ClassType == ClassType.Module)
            {
                foreach (DefaultField f in c.Fields)
                {
                    f.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultMethod m in c.Methods)
                {
                    m.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultProperty p in c.Properties)
                {
                    p.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultEvent e in c.Events)
                {
                    e.Modifiers |= ModifierEnum.Static;
                }
            }

            return(ret);
        }