private LinqQueryExpression RemoveTransparentIdentifiers(LinqQueryExpression originalQuery) { LinqQueryExpression linqQuery = (LinqQueryExpression)originalQuery.Clone(); List <VariableReference> identifiers = new List <VariableReference>(); TransparentIdentifierCleaner cleaner = new TransparentIdentifierCleaner(); HashSet <VariableReference> transparentIdentifiers = new HashSet <VariableReference>(); for (int i = 0; i < linqQuery.Clauses.Count; i++) { linqQuery.Clauses[i] = (QueryClause)cleaner.Visit(linqQuery.Clauses[i]); QueryClause currentClause = linqQuery.Clauses[i]; if (currentClause.CodeNodeType == CodeNodeType.FromClause) { identifiers.Add(GetVariableReference((currentClause as FromClause).Identifier)); } else if (currentClause.CodeNodeType == CodeNodeType.JoinClause) { if (linqQuery.Clauses[i + 1].CodeNodeType != CodeNodeType.IntoClause) { identifiers.Add(GetVariableReference((currentClause as JoinClause).InnerIdentifier)); } else { identifiers.Add(((IntoClause)linqQuery.Clauses[i + 1]).Identifier.Variable); i++; } } else if (currentClause.CodeNodeType == CodeNodeType.SelectClause && i != linqQuery.Clauses.Count - 1) { VariableReference intoIdentifier = ((IntoClause)linqQuery.Clauses[i + 1]).Identifier.Variable; if (IsTransparentIdentifier(intoIdentifier)) { Dictionary <PropertyDefinition, Expression> propertyToValueMap = GetPropertyToValueMap((currentClause as SelectClause).Expression); if (propertyToValueMap == null) { return(originalQuery); } if (identifiers.Count == 2) { if (!RemoveIdentifier(propertyToValueMap, identifiers)) { return(originalQuery); } linqQuery.Clauses.RemoveAt(i); linqQuery.Clauses.RemoveAt(i); i--; } else if (identifiers.Count == 1) { LetClause letClause = GenerateLetClause(propertyToValueMap, identifiers[0]); if (letClause == null) { return(originalQuery); } linqQuery.Clauses[i] = letClause; linqQuery.Clauses.RemoveAt(i + 1); } else { return(originalQuery); } this.methodContext.VariablesToRename.Add(intoIdentifier.Resolve()); transparentIdentifiers.Add(intoIdentifier); identifiers.Clear(); identifiers.Add(intoIdentifier); UpdateCleaner(cleaner, intoIdentifier, propertyToValueMap); } } else if (currentClause.CodeNodeType == CodeNodeType.IntoClause) { identifiers.Clear(); identifiers.Add(((IntoClause)currentClause).Identifier.Variable); } } TransparentIdentifierFinder finder = new TransparentIdentifierFinder(transparentIdentifiers); if (finder.ContainsTransparentIdentifiers(linqQuery)) { return(originalQuery); } return(linqQuery); }
private LinqQueryExpression RemoveTransparentIdentifiers(LinqQueryExpression originalQuery) { V_0 = (LinqQueryExpression)originalQuery.Clone(); V_1 = new List <VariableReference>(); V_2 = new RebuildLinqQueriesStep.LinqQueriesRebuilder.TransparentIdentifierCleaner(); V_3 = new HashSet <VariableReference>(); V_4 = 0; while (V_4 < V_0.get_Clauses().get_Count()) { V_0.get_Clauses().set_Item(V_4, (QueryClause)V_2.Visit(V_0.get_Clauses().get_Item(V_4))); V_5 = V_0.get_Clauses().get_Item(V_4); if (V_5.get_CodeNodeType() != 73) { if (V_5.get_CodeNodeType() != 78) { if (V_5.get_CodeNodeType() != 74 || V_4 == V_0.get_Clauses().get_Count() - 1) { if (V_5.get_CodeNodeType() == 80) { V_1.Clear(); V_1.Add(((IntoClause)V_5).get_Identifier().get_Variable()); } } else { V_6 = ((IntoClause)V_0.get_Clauses().get_Item(V_4 + 1)).get_Identifier().get_Variable(); if (this.IsTransparentIdentifier(V_6)) { V_7 = this.GetPropertyToValueMap((V_5 as SelectClause).get_Expression()); if (V_7 == null) { return(originalQuery); } if (V_1.get_Count() != 2) { if (V_1.get_Count() != 1) { return(originalQuery); } V_8 = this.GenerateLetClause(V_7, V_1.get_Item(0)); if (V_8 == null) { return(originalQuery); } V_0.get_Clauses().set_Item(V_4, V_8); V_0.get_Clauses().RemoveAt(V_4 + 1); } else { if (!this.RemoveIdentifier(V_7, V_1)) { return(originalQuery); } V_0.get_Clauses().RemoveAt(V_4); V_0.get_Clauses().RemoveAt(V_4); V_4 = V_4 - 1; } dummyVar0 = this.methodContext.get_VariablesToRename().Add(V_6.Resolve()); dummyVar1 = V_3.Add(V_6); V_1.Clear(); V_1.Add(V_6); this.UpdateCleaner(V_2, V_6, V_7); } } } else { if (V_0.get_Clauses().get_Item(V_4 + 1).get_CodeNodeType() == 80) { V_1.Add(((IntoClause)V_0.get_Clauses().get_Item(V_4 + 1)).get_Identifier().get_Variable()); V_4 = V_4 + 1; } else { V_1.Add(this.GetVariableReference((V_5 as JoinClause).get_InnerIdentifier())); } } } else { V_1.Add(this.GetVariableReference((V_5 as FromClause).get_Identifier())); } V_4 = V_4 + 1; } if ((new RebuildLinqQueriesStep.LinqQueriesRebuilder.TransparentIdentifierFinder(V_3)).ContainsTransparentIdentifiers(V_0)) { return(originalQuery); } return(V_0); }