Traverse() public method

public Traverse ( IEnumerable arguments ) : void
arguments IEnumerable
return void
Example #1
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    protected string WriteCSharpFromAST(IExpression expression) {
      Contract.Requires(expression != null);

      SourceEmitterOutputString sourceEmitterOutput = new SourceEmitterOutputString();
      SourceEmitter CSSourceEmitter = new SourceEmitter(sourceEmitterOutput);
      ExpressionSimplifier es = new ExpressionSimplifier();
      expression = es.Rewrite(expression);
      CSSourceEmitter.Traverse(expression);
      return sourceEmitterOutput.Data;
    }
Example #2
0
    //private string WriteCSharpFromAST(IExpression expression) {
    //  SourceEmitterOutputString sourceEmitterOutput = new SourceEmitterOutputString();
    //  SourceEmitter CSSourceEmitter = new SourceEmitter(sourceEmitterOutput);
    //  ExpressionSimplifier es = new ExpressionSimplifier();
    //  expression = es.Rewrite(expression);
    //  CSSourceEmitter.Traverse(expression);
    //  return sourceEmitterOutput.Data;
    //}

    //private string WriteVBFromAST(IExpression expression) {
    //  var sourceEmitterOutput = new VBSourceEmitter.SourceEmitterOutputString();
    //  var VBSourceEmitter = new VBSourceEmitter.SourceEmitter(this.host, sourceEmitterOutput);
    //  var es = new ExpressionSimplifier();
    //  expression = es.Rewrite(expression);
    //  VBSourceEmitter.Traverse(expression);
    //  return sourceEmitterOutput.Data;
    //}

    /// <summary>
    /// Writes the exception thrown by this IPrecondition into an "exception" xml element.
    /// </summary>
    public void WriteExceptionTo(XmlWriter writer) {

      if (String.IsNullOrEmpty(this.exception)) return;
      writer.WriteStartElement("exception");
      writer.WriteAttributeString("cref", this.exception);
      if (!String.IsNullOrEmpty(this.precondition.OriginalSource))
        writer.WriteString(BooleanExpressionHelper.NegatePredicate(this.precondition.OriginalSource));
      else {
        this.docTracker.WriteLine("Warning: Writing exception, but no OriginalSource found.");
        //Emit the condition instead of the OriginalSource
        SourceEmitterOutputString sourceEmitterOutput = new SourceEmitterOutputString();
        SourceEmitter CSSourceEmitter = new SourceEmitter(sourceEmitterOutput);
        ExpressionSimplifier es = new ExpressionSimplifier();
        LogicalNot logicalNot = new LogicalNot();
        logicalNot.Operand = this.precondition.Condition;
        var condition = es.Rewrite(logicalNot);
        CSSourceEmitter.Traverse(condition);
        writer.WriteString(sourceEmitterOutput.Data);
      }
      writer.WriteEndElement();
    }
 public static string PrintIndexer(IMethodDefinition method, bool isGetter) {
   Contract.Requires(method != null);
   
   var sourceEmitterOutput = new SourceEmitterOutputString();
   var csSourceEmitter = new SourceEmitter(sourceEmitterOutput);
   var indexerSignatureBuilder = new StringBuilder();
   csSourceEmitter.Traverse(method.Type);
   indexerSignatureBuilder.Append(sourceEmitterOutput.Data);
   sourceEmitterOutput.ClearData();
   indexerSignatureBuilder.Append(" ");
   // Indexers are always identified with a 'this' keyword, but might have an interface prefix
   string id = method.Name.Value;
   int lastDot = id.LastIndexOf('.');
   if (lastDot != -1)
     indexerSignatureBuilder.Append(id.Substring(0, lastDot + 1));
   indexerSignatureBuilder.Append("this");
   indexerSignatureBuilder.Append("[");
   bool fFirstParameter = true;
   var parms = method.Parameters;
   if (!isGetter)
   {
     // Use the setter's names except for the final 'value' parameter
     var l = new List<IParameterDefinition>(method.Parameters);
     if (l.Count > 0)
     {
       l.RemoveAt(l.Count - 1);
     }
     parms = l;
   }
   foreach (IParameterDefinition parameterDefinition in parms) {
     if (!fFirstParameter)
       indexerSignatureBuilder.Append(", ");
     Contract.Assume(parameterDefinition != null);
     csSourceEmitter.Traverse(parameterDefinition);
     indexerSignatureBuilder.Append(sourceEmitterOutput.Data);
     sourceEmitterOutput.ClearData();
     fFirstParameter = false;
   }
   indexerSignatureBuilder.Append("]");
   return indexerSignatureBuilder.ToString();
 }