public static GetSyntaxFromType ( ClassOrInterfaceType type, bool addI = false ) : Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax | ||
type | ClassOrInterfaceType | |
addI | bool | |
Résultat | Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax |
private static ClassDeclarationSyntax VisitClassDeclaration(ConversionContext context, ClassOrInterfaceDeclaration javac, bool isNested = false) { string name = javac.getName(); if (!isNested) { context.RootTypeName = name; } context.LastTypeName = name; var classSyntax = SyntaxFactory.ClassDeclaration(name); var typeParams = javac.getTypeParameters().ToList <TypeParameter>(); if (typeParams != null && typeParams.Count > 0) { classSyntax = classSyntax.AddTypeParameterListParameters(typeParams.Select(i => SyntaxFactory.TypeParameter(i.getName())).ToArray()); } var mods = javac.getModifiers(); if (mods.HasFlag(Modifier.PRIVATE)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PUBLIC)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.ABSTRACT)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AbstractKeyword)); } if (mods.HasFlag(Modifier.FINAL)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.SealedKeyword)); } var extends = javac.getExtends().ToList <ClassOrInterfaceType>(); if (extends != null) { foreach (var extend in extends) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(extend))); } } var implements = javac.getImplements().ToList <ClassOrInterfaceType>(); if (implements != null) { foreach (var implement in implements) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(implement, true))); } } var members = javac.getMembers().ToList <BodyDeclaration>(); foreach (var member in members) { if (member is ClassOrInterfaceDeclaration) { var childc = (ClassOrInterfaceDeclaration)member; if (childc.isInterface()) { var childInt = VisitInterfaceDeclaration(context, childc, true); classSyntax = classSyntax.AddMembers(childInt); } else { var childClass = VisitClassDeclaration(context, childc, true); classSyntax = classSyntax.AddMembers(childClass); } } else { var syntax = BodyDeclarationVisitor.VisitBodyDeclarationForClass(context, classSyntax, member); classSyntax = classSyntax.AddMembers(syntax); } while (context.PendingAnonymousTypes.Count > 0) { var anon = context.PendingAnonymousTypes.Dequeue(); classSyntax = classSyntax.AddMembers(anon); } } return(classSyntax); }
private static InterfaceDeclarationSyntax VisitInterfaceDeclaration(ConversionContext context, ClassOrInterfaceDeclaration javai, bool isNested = false) { string name = "I" + javai.getName(); if (!isNested) { context.RootTypeName = name; } context.LastTypeName = name; var classSyntax = SyntaxFactory.InterfaceDeclaration(name); var typeParams = javai.getTypeParameters().ToList <TypeParameter>(); if (typeParams != null && typeParams.Count > 0) { classSyntax = classSyntax.AddTypeParameterListParameters(typeParams.Select(i => SyntaxFactory.TypeParameter(i.getName())).ToArray()); } var mods = javai.getModifiers(); if (mods.HasFlag(Modifier.PRIVATE)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); } if (mods.HasFlag(Modifier.PROTECTED)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); } if (mods.HasFlag(Modifier.PUBLIC)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); } if (mods.HasFlag(Modifier.FINAL)) { classSyntax = classSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.SealedKeyword)); } var implements = javai.getImplements().ToList <ClassOrInterfaceType>(); if (implements != null) { foreach (var implement in implements) { classSyntax = classSyntax.AddBaseListTypes(SyntaxFactory.SimpleBaseType(TypeHelper.GetSyntaxFromType(implement))); } } var members = javai.getMembers().ToList <BodyDeclaration>(); foreach (var member in members) { var syntax = BodyDeclarationVisitor.VisitBodyDeclarationForInterface(context, classSyntax, member); classSyntax = classSyntax.AddMembers(syntax); } return(classSyntax); }