public virtual object Visit(TypeDeclaration typeDeclaration, object data)
 {
     foreach (AttributeSection section in typeDeclaration.Attributes) {
         section.AcceptVisitor(this, data);
     }
     return typeDeclaration.AcceptChildren(this, data);
 }
        public override object Visit(TypeDeclaration typeDeclaration, object data)
        {
            ProcessSpecials(typeDeclaration.Specials);

            this.currentTypeDeclaration = typeDeclaration;
            CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration(typeDeclaration.Name);
            codeTypeDeclaration.IsClass     = typeDeclaration.Type == Types.Class;
            codeTypeDeclaration.IsEnum      = typeDeclaration.Type == Types.Enum;
            codeTypeDeclaration.IsInterface = typeDeclaration.Type == Types.Interface;
            codeTypeDeclaration.IsStruct    = typeDeclaration.Type == Types.Struct;

            if (typeDeclaration.BaseTypes != null) {
                foreach (object o in typeDeclaration.BaseTypes) {
                    codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(o.ToString()));
                }
            }

            typeDeclarations.Push(codeTypeDeclaration);
            typeDeclaration.AcceptChildren(this,data);
            //			((INode)typeDeclaration.Children[0]).(this, data);

            typeDeclarations.Pop();

            ((CodeNamespace)namespaceDeclarations.Peek()).Types.Add(codeTypeDeclaration);

            return null;
        }
        public override object Visit(TypeDeclaration typeDeclaration, object data)
        {
            DebugOutput(typeDeclaration);
            AppendNewLine();
            generateAttributeUnderScore = true;
            AppendAttributes(typeDeclaration.Attributes);
            string modifier =  GetModifier(typeDeclaration.Modifier);
            string type = String.Empty;

            switch (typeDeclaration.Type) {
                case Types.Class:
                    type = "Class ";
                    break;
                case Types.Enum:
                    type = "Enum ";
                    break;
                case Types.Interface:
                    type = "Interface ";
                    break;
                case Types.Struct:
                    // this should be better in VBNetRefactory class because it is an AST transformation, but currently I'm too lazy
                    if (TypeHasOnlyStaticMembers(typeDeclaration)) {
                        goto case Types.Class;
                    }
                    type = "Structure ";
                    break;
            }
            AppendIndentation();sourceText.Append(modifier);
            sourceText.Append(type);
            sourceText.Append(typeDeclaration.Name);
            AppendNewLine();

            if (typeDeclaration.BaseTypes != null) {
                foreach (string baseType in typeDeclaration.BaseTypes) {
                    AppendIndentation();

                    bool baseTypeIsInterface = baseType.StartsWith("I") && (baseType.Length <= 1 || Char.IsUpper(baseType[1]));

                    if (!baseTypeIsInterface || typeDeclaration.Type == Types.Interface) {
                        sourceText.Append("Inherits ");
                    } else {
                        sourceText.Append("Implements ");
                    }
                    sourceText.Append(baseType);
                    AppendNewLine();
                }
            }

            ++indentLevel;
            TypeDeclaration oldType = currentType;
            currentType = typeDeclaration;
            typeDeclaration.AcceptChildren(this, data);
            currentType = oldType;
            --indentLevel;
            AppendIndentation();sourceText.Append("End ");
            sourceText.Append(type);
            AppendNewLine();
            generateAttributeUnderScore = false;
            return null;
        }
 bool TypeHasOnlyStaticMembers(TypeDeclaration typeDeclaration)
 {
     foreach (object o in typeDeclaration.Children) {
         if (o is MethodDeclaration) {
             if ((((MethodDeclaration)o).Modifier & Modifier.Static) != Modifier.Static) {
                 return false;
             }
         } else if (o is PropertyDeclaration) {
             if ((((PropertyDeclaration)o).Modifier & Modifier.Static) != Modifier.Static) {
                 return false;
             }
         } else if (o is FieldDeclaration) {
             if ((((FieldDeclaration)o).Modifier & Modifier.Static) != Modifier.Static) {
                 return false;
             }
         }else if (o is EventDeclaration) {
             if ((((EventDeclaration)o).Modifier & Modifier.Static) != Modifier.Static) {
                 return false;
             }
         }
     }
     return true;
 }
 public override object Visit(TypeDeclaration typeDeclaration, object data)
 {
     Console.WriteLine(typeDeclaration.ToString());
     return typeDeclaration.AcceptChildren(this, data);
 }
Пример #6
0
	void TypeDecl(
#line  691 "cs.ATG" 
Modifiers m, ArrayList attributes, bool partial) {

#line  693 "cs.ATG" 
		TypeReference type;
		StringCollection names;
		ArrayList p; string name;
		
		if (la.kind == 58) {

#line  697 "cs.ATG" 
			m.Check(Modifier.Classes); 
			lexer.NextToken();

#line  698 "cs.ATG" 
			TypeDeclaration newType = new TypeDeclaration (partial);
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			
			newType.Type = Types.Class;
			newType.Modifier = m.Modifier;
			newType.Attributes = attributes;
			
			Expect(1);

#line  706 "cs.ATG" 
			newType.Name = t.val; 
			if (la.kind == 9) {
				ClassBase(
#line  707 "cs.ATG" 
out names);

#line  707 "cs.ATG" 
				newType.BaseTypes = names; 
			}

#line  707 "cs.ATG" 
			newType.StartLocation = t.EndLocation; 
			ClassBody();
			if (la.kind == 10) {
				lexer.NextToken();
			}

#line  709 "cs.ATG" 
			newType.EndLocation = t.Location; 
			compilationUnit.BlockEnd();
			
		} else if (StartOf(7)) {

#line  712 "cs.ATG" 
			m.Check(Modifier.StructsInterfacesEnumsDelegates); 
			if (la.kind == 108) {
				lexer.NextToken();

#line  713 "cs.ATG" 
				TypeDeclaration newType = new TypeDeclaration(partial);
				compilationUnit.AddChild(newType);
				compilationUnit.BlockStart(newType);
				newType.Type = Types.Struct; 
				newType.Modifier = m.Modifier;
				newType.Attributes = attributes;
				
				Expect(1);

#line  720 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 9) {
					StructInterfaces(
#line  721 "cs.ATG" 
out names);

#line  721 "cs.ATG" 
					newType.BaseTypes = names; 
				}

#line  721 "cs.ATG" 
				newType.StartLocation = t.EndLocation; 
				StructBody();
				if (la.kind == 10) {
					lexer.NextToken();
				}

#line  723 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else if (la.kind == 82) {
				lexer.NextToken();

#line  727 "cs.ATG" 
				TypeDeclaration newType = new TypeDeclaration(partial);
				compilationUnit.AddChild(newType);
				compilationUnit.BlockStart(newType);
				newType.Type = Types.Interface;
				newType.Attributes = attributes;
				newType.Modifier = m.Modifier;
				Expect(1);

#line  733 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 9) {
					InterfaceBase(
#line  734 "cs.ATG" 
out names);

#line  734 "cs.ATG" 
					newType.BaseTypes = names; 
				}

#line  734 "cs.ATG" 
				newType.StartLocation = t.EndLocation; 
				InterfaceBody();
				if (la.kind == 10) {
					lexer.NextToken();
				}

#line  736 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else if (la.kind == 67) {
				lexer.NextToken();

#line  740 "cs.ATG" 
				if (partial) Error ("partial is not allowed for enum types");
				TypeDeclaration newType = new TypeDeclaration();
				                           compilationUnit.AddChild(newType);
				                           compilationUnit.BlockStart(newType);
				                           newType.Type = Types.Enum;
				                           newType.Attributes = attributes;
				                           newType.Modifier = m.Modifier;
				Expect(1);

#line  747 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 9) {
					lexer.NextToken();
					IntegralType(
#line  748 "cs.ATG" 
out name);

#line  748 "cs.ATG" 
					newType.BaseTypes = new StringCollection(); 
					newType.BaseTypes.Add(name);
					
				}

#line  751 "cs.ATG" 
				newType.StartLocation = t.EndLocation; 
				EnumBody();
				if (la.kind == 10) {
					lexer.NextToken();
				}

#line  753 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else {
				lexer.NextToken();

#line  757 "cs.ATG" 
				if (partial) Error ("partial is not allowed for delegate types");
				DelegateDeclaration delegateDeclr = new DelegateDeclaration();
				                           delegateDeclr.StartLocation = t.Location;
				                           delegateDeclr.Modifier = m.Modifier;
				                           delegateDeclr.Attributes = attributes;
				                        
				if (
#line  763 "cs.ATG" 
NotVoidPointer()) {
					Expect(122);

#line  763 "cs.ATG" 
					delegateDeclr.ReturnType = new TypeReference("void", 0, null); 
				} else if (StartOf(8)) {
					Type(
#line  764 "cs.ATG" 
out type);

#line  764 "cs.ATG" 
					delegateDeclr.ReturnType = type; 
				} else SynErr(130);
				Expect(1);

#line  766 "cs.ATG" 
				delegateDeclr.Name = t.val; 
				Expect(18);
				if (StartOf(9)) {
					FormalParameterList(
#line  767 "cs.ATG" 
out p);

#line  767 "cs.ATG" 
					delegateDeclr.Parameters = p; 
				}
				Expect(19);
				Expect(10);

#line  769 "cs.ATG" 
				delegateDeclr.EndLocation = t.Location;
				compilationUnit.AddChild(delegateDeclr);
				
			}
		} else SynErr(131);
	}
        public override object Visit(TypeDeclaration typeDeclaration, object data)
        {
            VisitAttributes(typeDeclaration.Attributes, data);
            outputFormatter.Indent();
            VisitModifier(typeDeclaration.Modifier);
            switch (typeDeclaration.Type) {
                case Types.Class:
                    outputFormatter.PrintToken(Tokens.Class);
                    break;
                case Types.Enum:
                    outputFormatter.PrintToken(Tokens.Enum);
                    break;
                case Types.Interface:
                    outputFormatter.PrintToken(Tokens.Interface);
                    break;
                case Types.Struct:
                    outputFormatter.PrintToken(Tokens.Struct);
                    break;
            }
            outputFormatter.Space();
            outputFormatter.PrintIdentifier(typeDeclaration.Name);
            if (typeDeclaration.BaseTypes != null && typeDeclaration.BaseTypes.Count > 0) {
                outputFormatter.Space();
                outputFormatter.PrintToken(Tokens.Colon);
                for (int i = 0; i < typeDeclaration.BaseTypes.Count; ++i) {
                    outputFormatter.Space();
                    outputFormatter.PrintIdentifier(typeDeclaration.BaseTypes[i]);
                    if (i + 1 < typeDeclaration.BaseTypes.Count) {
                        outputFormatter.PrintToken(Tokens.Comma);
                        outputFormatter.Space();
                    }
                }
            }

            switch (typeDeclaration.Type) {
                case Types.Class:
                    outputFormatter.BeginBrace(this.prettyPrintOptions.ClassBraceStyle);
                    break;
                case Types.Enum:
                    outputFormatter.BeginBrace(this.prettyPrintOptions.EnumBraceStyle);
                    break;
                case Types.Interface:
                    outputFormatter.BeginBrace(this.prettyPrintOptions.InterfaceBraceStyle);
                    break;
                case Types.Struct:
                    outputFormatter.BeginBrace(this.prettyPrintOptions.StructBraceStyle);
                    break;
            }

            if (typeDeclaration.Type == Types.Enum) {
                VisitEnumMembers(typeDeclaration, data);
            } else {
                typeDeclaration.AcceptChildren(this, data);
            }
            outputFormatter.EndBrace();

            return null;
        }
 object VisitEnumMembers(TypeDeclaration typeDeclaration, object data)
 {
     foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
         VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
         VisitAttributes(fieldDeclaration.Attributes, data);
         outputFormatter.Indent();
         outputFormatter.PrintIdentifier(f.Name);
         if (f.Initializer != null) {
             outputFormatter.Space();
             outputFormatter.PrintToken(Tokens.Assign);
             outputFormatter.Space();
             f.Initializer.AcceptVisitor(this, data);
         }
         outputFormatter.PrintToken(Tokens.Comma);
         outputFormatter.NewLine();
     }
     return null;
 }