using System;
using System.Collections;
using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
namespace Microsoft.Build.BuildEngine {
internal class ItemReference {
string itemName;
- string separator;
- OldExpression parent;
- OldExpression transform;
-
- public ItemReference (OldExpression parent)
- {
- if (parent == null)
- throw new Exception ("Parent Expression needed to find project.");
- this.parent = parent;
- this.itemName = null;
- this.separator = ";";
- }
+ Expression transform;
+ Expression separator;
+ int start;
+ int length;
- public void ParseSource (string source)
+ public ItemReference (string itemName, string transform, string separator, int start, int length)
{
- string sourceWithoutParens;
- ApostropheState aState = ApostropheState.Out;
- ItemParsingState iState = ItemParsingState.Name;
- int c = -1;
- int itemNameEnd;
- int transformEnd = -1;
- int separatorStart = -1;
-
- if (source == null)
- throw new ArgumentNullException ("source");
-
- if (source.Length < 3)
- throw new ArgumentException ("Invalid item.");
-
- sourceWithoutParens = source.Substring (2, source.Length - 3);
- itemNameEnd = sourceWithoutParens.Length - 1;
- CharEnumerator it = sourceWithoutParens.GetEnumerator ();
+ this.itemName = itemName;
+ this.start = start;
+ this.length = length;
- while (it.MoveNext ()) {
- c++;
- if (it.Current == '\'') {
- if (aState == ApostropheState.In)
- aState = ApostropheState.Out;
- else
- aState = ApostropheState.In;
- }
- if (it.Current == '-' && iState == ItemParsingState.Name && aState == ApostropheState.Out) {
- iState = ItemParsingState.Transform1;
- itemNameEnd = c - 1;
- } else if (it.Current == '>' && iState == ItemParsingState.Transform1 && aState == ApostropheState.Out) {
- iState = ItemParsingState.Transform2;
- } else if (iState == ItemParsingState.Transform2 && aState == ApostropheState.Out && c == sourceWithoutParens.Length - 1) {
- transformEnd = c;
- } else if (iState == ItemParsingState.Transform2 && aState == ApostropheState.Out && it.Current == ',') {
- transformEnd = c - 1;
- separatorStart = c + 1;
- break;
- } else if (iState == ItemParsingState.Name && aState == ApostropheState.Out && it.Current == ',') {
- separatorStart = c + 1;
- itemNameEnd = c - 1;
- break;
- }
+ if (transform != null) {
+ this.transform = new Expression ();
+ this.transform.Parse (transform);
}
- itemName = sourceWithoutParens.Substring (0, itemNameEnd + 1);
- if (transformEnd != -1) {
- if (separatorStart != -1) {
- separator = sourceWithoutParens.Substring (separatorStart + 1, sourceWithoutParens.Length
- - separatorStart - 2);
- transform = new OldExpression (parent.Project);
- transform.ParseSource (sourceWithoutParens.Substring (itemNameEnd + 4,
- transformEnd - itemNameEnd - 4));
- } else {
- transform = new OldExpression (parent.Project);
- transform.ParseSource (sourceWithoutParens.Substring (itemNameEnd + 4,
- sourceWithoutParens.Length - itemNameEnd - 5));
- }
- } else {
- if (separatorStart != -1) {
- separator = sourceWithoutParens.Substring (separatorStart + 1, sourceWithoutParens.Length
- - separatorStart - 2);
- }
+
+ if (separator != null) {
+ this.separator = new Expression ();
+ this.separator.Parse (separator);
}
}
- public ITaskItem[] ToITaskItemArray ()
+ public string ConvertToString (Project project)
{
- if (itemName != String.Empty) {
- Project p = parent.Project;
- BuildItemGroup big;
- if (p.EvaluatedItemsByName.Contains (itemName)) {
- big = (BuildItemGroup)p.EvaluatedItemsByName [itemName];
- return big.ToITaskItemArray (transform);
- } else
- return null;
- } else
- return null;
+ if (project.EvaluatedItemsByName.ContainsKey (itemName))
+ return project.EvaluatedItemsByName [itemName].ConvertToString (transform, separator);
+ else
+ return String.Empty;
}
- public new string ToString ()
+ public ITaskItem [] ConvertToITaskItemArray (Project project)
{
- if (itemName != String.Empty) {
- Project p = parent.Project;
- BuildItemGroup big;
- if (p.EvaluatedItemsByName.Contains (itemName)) {
- big = (BuildItemGroup)p.EvaluatedItemsByName [itemName];
- return big.ToString (transform, separator);
- } else
- return String.Empty;
- } else
- return String.Empty;
+ if (project.EvaluatedItemsByName.ContainsKey (itemName))
+ return project.EvaluatedItemsByName [itemName].ConvertToITaskItemArray (transform);
+ else
+ return null;
}
-
+
public string ItemName {
get { return itemName; }
}
-
- public string Separator {
+
+ public Expression Transform {
+ get { return transform; }
+ }
+
+ public Expression Separator {
get { return separator; }
}
+
+ public int Start {
+ get { return start; }
+ }
+
+ public int End {
+ get { return start + length - 1; }
+ }
}
}