Merge remote-tracking branch 'joncham/sgen-msvc2'
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / ItemReference.cs
1 //
2 // ItemReference.cs: Represents "@(Reference)" in expression.
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //   Ankit Jain (jankit@novell.com)
7 // 
8 // (C) 2005 Marek Sieradzki
9 // Copyright 2009 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 using System;
31 using System.Collections;
32 using Microsoft.Build.Framework;
33
34 namespace Microsoft.Build.BuildEngine {
35         internal class ItemReference : IReference {
36         
37                 string          itemName;
38                 Expression      transform;
39                 Expression      separator;
40                 int             start;
41                 int             length;
42                 string          original_string;
43                 
44                 public ItemReference (string original_string, string itemName, string transform, string separator, int start, int length)
45                 {
46                         this.itemName = itemName;
47                         this.start = start;
48                         this.length = length;
49                         this.original_string = original_string;
50
51                         // Transform and separator are never expanded for item refs
52                         if (transform != null) {
53                                 this.transform = new Expression ();
54                                 this.transform.Parse (transform, ParseOptions.AllowMetadata | ParseOptions.Split);
55                         }
56
57                         if (separator != null) {
58                                 this.separator = new Expression ();
59                                 this.separator.Parse (separator, ParseOptions.Split);
60                         }
61                 }
62                 
63                 // when evaluating property, allowItems=false, so,
64                 // ItemRef will _not_ get created, so this wont get hit
65                 // when evaluating items, expand: true
66                 // other cases, expand: true
67                 public string ConvertToString (Project project, ExpressionOptions options)
68                 {
69                         BuildItemGroup group;
70                         if (project.TryGetEvaluatedItemByNameBatched (itemName, out group))
71                                 return group.ConvertToString (transform, separator, options);
72                         else
73                                 return String.Empty;
74                 }
75                 
76                 public ITaskItem [] ConvertToITaskItemArray (Project project, ExpressionOptions options)
77                 {
78                         BuildItemGroup group;
79                         if (project.TryGetEvaluatedItemByNameBatched (itemName, out group))
80                                 return group.ConvertToITaskItemArray (transform, separator, options);
81                         else
82                                 return null;
83                 }
84
85                 public string ItemName {
86                         get { return itemName; }
87                 }
88
89                 public Expression Transform {
90                         get { return transform; }
91                 }
92
93                 public Expression Separator {
94                         get { return separator; }
95                 }
96
97                 public string OriginalString {
98                         get { return original_string; }
99                 }
100
101                 public int Start {
102                         get { return start; }
103                 }
104
105                 public int End {
106                         get { return start + length - 1; }
107                 }
108
109                 public override string ToString ()
110                 {
111                         return original_string;
112                 }
113         }
114 }