private List <NamedTypeBase> GetSiblings(NamedTypeBase type, List <NamedTypeBase> types) { return(types .Where(t => t.Bases.Where(o => o.Name != "Object").Select(x => (NamedTypeBase)x) .Intersect(type.Bases.Where(o => o.Name != "Object").Select(x2 => (NamedTypeBase)x2), new TypeComparer()).Count() > 1) .Except(new List <NamedTypeBase>() { type }, new TypeComparer()).ToList()); }
private NamedTypeBase AreSiblings(NamedTypeBase namedTypeBase1, NamedTypeBase namedTypeBase2) { foreach (var baseType in namedTypeBase1.Bases) { var ancestor = namedTypeBase2.Bases.FirstOrDefault(b => (NamedTypeBase)b == (NamedTypeBase)baseType); if (ancestor != null && (ancestor.Name != "Object" || ancestor.Name != "object")) { return((NamedTypeBase)ancestor); } } return(null); }
private static void BuildBaseList(NamedTypeBase item, List <NamedTypeBase> types, IEnumerable <INamedTypeSymbol> symbols) { //Roslyn szimbólum elkérése var originalSymbol = ((CSharpNamedType)item).SourceSymbol; //Az összes interfész szimbólumának lekérdezése var baseSymbols = originalSymbol.AllInterfaces; //Szimbúlumfeldolgozás foreach (var baseSymbol in baseSymbols) { var interfacetype = types.SingleOrDefault(t => t == originalSymbol.BaseType.ToCSharpNamedType()); //Ha még korábban nem találkoztunk ezzel a típussal if (interfacetype == null) { //létrehozzuk a típust és elátroljuk a modellben var newtype = baseSymbol.ToCSharpNamedType(); types.Add(newtype); //és hozzáadjuk az ősök listájához item.Bases.Add(newtype); } else { //egyébként hozzáadjuk az ősök listájához item.Bases.Add(interfacetype); } } if (originalSymbol.BaseType != null) { var basetype = types.SingleOrDefault(t => t == originalSymbol.BaseType.ToCSharpNamedType()); //Ha még korábban nem találkoztunk ezzel a típussal if (basetype == null) { //létrehozzuk a típust és elátroljuk a modellben var newtype = originalSymbol.BaseType.ToCSharpNamedType(); types.Add(newtype); //és hozzáadjuk az ősök listájához item.Bases.Add(newtype); } else { //egyébként hozzáadjuk az ősök listájához item.Bases.Add(basetype); } } }
private bool DerivesFrom(NamedTypeBase type, string typename) { if (type.Bases.Any(b => b.Name == typename)) { return(true); } foreach (var item in type.Bases) { if (DerivesFrom((NamedTypeBase)item, typename)) { return(true); } } return(false); }
private static List <IMethod> GetDirectlyReturningMethods(ISymbol symbol, NamedTypeBase sType, Dictionary <ISymbol, SemanticModel> models, List <NamedTypeBase> types) { var type = (CSharpNamedType)sType; List <IMethod> methods = new List <IMethod>(); if (type.SourceSymbol.DeclaringSyntaxReferences == null) { logprovider.WriteToLog(string.Format("Cannot find declaring syntax references for symbol {0}", type.SourceSymbol.ToString())); return(methods); } if (type.SourceSymbol.DeclaringSyntaxReferences.Count() > 1) { logprovider.WriteToLog(string.Format("There are more than 1 declaring references for symbol {0}", type.SourceSymbol.ToString())); return(methods); } if (type.SourceSymbol.DeclaringSyntaxReferences.Count() < 1) { logprovider.WriteToLog(string.Format("There are less than 1 declaring references for symbol {0}", type.SourceSymbol.ToString())); return(methods); } if (type.SourceSymbol.DeclaringSyntaxReferences[0].GetSyntax() == null) { logprovider.WriteToLog(string.Format("Cannnot get syntax for declaring syntax reference {0}", type.SourceSymbol.DeclaringSyntaxReferences[0].ToString())); return(methods); } var rets = type.SourceSymbol.DeclaringSyntaxReferences[0].GetSyntax().DescendantNodes().OfType <ReturnStatementSyntax>().Cast <ReturnStatementSyntax>(); var candidaterets = rets.Where(ret => ret.Expression != null && ret.Expression.CSharpKind() != SyntaxKind.NullLiteralExpression && (models[type.SourceSymbol].GetTypeInfo(ret.Expression).Type).ToCSharpNamedType(logprovider) == type); foreach (var ret in rets) { var ids = ret.DescendantNodes().OfType <IdentifierNameSyntax>().ToList(); foreach (var id in ids) { var retsymbol = models[type.SourceSymbol].GetSymbolInfo(id); if (retsymbol.Symbol == null) { logprovider.WriteToLog(string.Format("Could not get symbol info for syntax {0}", retsymbol.ToString())); } if (retsymbol.Symbol != null && retsymbol.Symbol.Name == symbol.Name) { SyntaxNode current = ret; while (!(current.CSharpKind() == SyntaxKind.MethodDeclaration || current.CSharpKind() == SyntaxKind.GetAccessorDeclaration || current.CSharpKind() == SyntaxKind.OperatorDeclaration)) { current = current.Parent; } var cSymbol = models[type.SourceSymbol].GetDeclaredSymbol(current); if (cSymbol == null) { logprovider.WriteToLog(string.Format("Could not get declared symbol symbol info for syntax {0}", cSymbol.ToString())); } if (cSymbol != null) { methods.Add(((IMethodSymbol)cSymbol).ToCSharpMethod(types, models[type.SourceSymbol], type, logprovider)); } } } } return(methods); }