Initial run of code formatter

I (Jason Shirk) ran https://github.com/dotnet/codeformatter with the default rules, basically:

    codeformatter /nocopyright "/c:DEBUG,UNIX,CORECLR" @files.rsp

This caused a few problems building, which were fixed up manually.

Notable changes:

`this.` is removed unless needed to disambiguate.
private instance fields are renamed to have a `_` prefix.
private static fields are renamed to have a `s_` prefix.

I left some projects alone (like PackageManagement) and also left some generated code alone.
This commit is contained in:
PowerShell Team authored and Jason Shirk (POWERSHELL) committed 2016-08-01 15:57:03 -07:00
1 parent bc4fe11888
commit 403ae3f53f
953 files changed
+71009 -64819

No files matched your search

@@ -17,7 +17,6 @@ using Microsoft.PowerShell.CoreClr.Stubs;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// helper class to do wildcard matching on MshExpressions
/// </summary>
@@ -27,18 +26,17 @@ namespace Microsoft.PowerShell.Commands
/// construnt the class, using an array of patterns
/// </summary>
/// <param name="wildcardPatternsStrings">array of pattern strings to use</param>
internal MshExpressionFilter (string[] wildcardPatternsStrings)
internal MshExpressionFilter(string[] wildcardPatternsStrings)
{
if (wildcardPatternsStrings == null)
{
throw new ArgumentNullException ("wildcardPatternsStrings");
throw new ArgumentNullException("wildcardPatternsStrings");
}
_wildcardPatterns = new WildcardPattern[wildcardPatternsStrings.Length];
for (int k = 0; k < wildcardPatternsStrings.Length; k++)
{
_wildcardPatterns[k] = WildcardPattern .Get(wildcardPatternsStrings[k], WildcardOptions.IgnoreCase);
_wildcardPatterns[k] = WildcardPattern.Get(wildcardPatternsStrings[k], WildcardOptions.IgnoreCase);
}
}
@@ -48,11 +46,11 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
/// <param name="expression">MshExpression to test against</param>
/// <returns>true if there is a match, else false</returns>
internal bool IsMatch (MshExpression expression)
internal bool IsMatch(MshExpression expression)
{
for (int k = 0; k < _wildcardPatterns.Length; k++)
{
if (_wildcardPatterns[k].IsMatch (expression.ToString ()))
if (_wildcardPatterns[k].IsMatch(expression.ToString()))
return true;
}
return false;
@@ -63,10 +61,10 @@ namespace Microsoft.PowerShell.Commands
internal class SelectObjectExpressionParameterDefinition : CommandParameterDefinition
{
protected override void SetEntries ()
protected override void SetEntries()
{
this.hashEntries.Add (new ExpressionEntryDefinition ());
this.hashEntries.Add (new NameEntryDefinition ());
this.hashEntries.Add(new ExpressionEntryDefinition());
this.hashEntries.Add(new NameEntryDefinition());
}
}
@@ -89,8 +87,8 @@ namespace Microsoft.PowerShell.Commands
set { _inputObject = value; }
get { return _inputObject; }
}
private PSObject _inputObject = AutomationNull.Value;
private PSObject _inputObject = AutomationNull.Value;
/// <summary>
@@ -101,11 +99,11 @@ namespace Microsoft.PowerShell.Commands
[Parameter(Position = 0, ParameterSetName = "SkipLastParameter")]
public object[] Property
{
get { return expr; }
set { expr = value; }
get { return _expr; }
set { _expr = value; }
}
private object[] expr;
private object[] _expr;
/// <summary>
///
@@ -115,10 +113,10 @@ namespace Microsoft.PowerShell.Commands
[Parameter(ParameterSetName = "SkipLastParameter")]
public string[] ExcludeProperty
{
get { return excludeArray; }
set { excludeArray = value; }
get { return _excludeArray; }
set { _excludeArray = value; }
}
private string[] excludeArray = null;
private string[] _excludeArray = null;
/// <summary>
///
@@ -128,10 +126,10 @@ namespace Microsoft.PowerShell.Commands
[Parameter(ParameterSetName = "SkipLastParameter")]
public string ExpandProperty
{
get { return expand; }
set { expand = value; }
get { return _expand; }
set { _expand = value; }
}
private string expand = null;
private string _expand = null;
/// <summary>
///
@@ -140,10 +138,10 @@ namespace Microsoft.PowerShell.Commands
[Parameter]
public SwitchParameter Unique
{
get { return unique; }
set { unique = value; }
get { return _unique; }
set { _unique = value; }
}
private bool unique;
private bool _unique;
/// <summary>
///
@@ -155,10 +153,10 @@ namespace Microsoft.PowerShell.Commands
[ValidateRange(0, int.MaxValue)]
public int Last
{
get { return last; }
set { last = value; firstOrLastSpecified = true; }
get { return _last; }
set { _last = value; _firstOrLastSpecified = true; }
}
private int last = 0;
private int _last = 0;
/// <summary>
///
@@ -170,13 +168,13 @@ namespace Microsoft.PowerShell.Commands
[ValidateRange(0, int.MaxValue)]
public int First
{
get { return first; }
set { first = value; firstOrLastSpecified = true; }
get { return _first; }
set { _first = value; _firstOrLastSpecified = true; }
}
private int first = 0;
private bool firstOrLastSpecified;
private int _first = 0;
private bool _firstOrLastSpecified;
/// <summary>
/// Skips the sepecified number of items from top when used with First,from end when used with Last
/// </summary>
@@ -185,10 +183,10 @@ namespace Microsoft.PowerShell.Commands
[ValidateRange(0, int.MaxValue)]
public int Skip
{
get { return skip; }
set { skip = value; }
get { return _skip; }
set { _skip = value; }
}
private int skip = 0;
private int _skip = 0;
/// <summary>
/// Skip the specified number of items from end.
@@ -197,10 +195,10 @@ namespace Microsoft.PowerShell.Commands
[ValidateRange(0, int.MaxValue)]
public int SkipLast
{
get { return skipLast; }
set { skipLast = value; }
get { return _skipLast; }
set { _skipLast = value; }
}
private int skipLast = 0;
private int _skipLast = 0;
/// <summary>
/// With this switch present, the cmdlet won't "short-circuit"
@@ -209,7 +207,7 @@ namespace Microsoft.PowerShell.Commands
[Parameter(ParameterSetName = "DefaultParameter")]
[Parameter(ParameterSetName = "IndexParameter")]
public SwitchParameter Wait { get; set; }
/// <summary>
/// Used to display the object at specified index
/// </summary>
@@ -221,95 +219,95 @@ namespace Microsoft.PowerShell.Commands
{
get
{
return index;
return _index;
}
set
{
index = value;
indexSpecified = true;
Array.Sort(index);
_index = value;
_indexSpecified = true;
Array.Sort(_index);
}
}
private int[] index;
private bool indexSpecified;
private int[] _index;
private bool _indexSpecified;
#endregion
SelectObjectQueue selectObjectQueue;
private SelectObjectQueue _selectObjectQueue;
private class SelectObjectQueue : Queue<PSObject>
{
internal SelectObjectQueue(int first, int last, int skip, int skipLast, bool firstOrLastSpecified)
{
this.first = first;
this.last = last;
this.skip = skip;
this.skipLast = skipLast;
this.firstOrLastSpecified = firstOrLastSpecified;
_first = first;
_last = last;
_skip = skip;
_skipLast = skipLast;
_firstOrLastSpecified = firstOrLastSpecified;
}
public bool AllRequestedObjectsProcessed
{
get
{
return firstOrLastSpecified && last == 0 && first != 0 && streamedObjectCount >= first;
return _firstOrLastSpecified && _last == 0 && _first != 0 && _streamedObjectCount >= _first;
}
}
new public void Enqueue(PSObject obj)
{
if (last > 0 && this.Count >= (last + skip) && first == 0)
if (_last > 0 && this.Count >= (_last + _skip) && _first == 0)
{
base.Dequeue();
}
else if (last > 0 && this.Count >= last && first != 0)
else if (_last > 0 && this.Count >= _last && _first != 0)
{
base.Dequeue();
}
base.Enqueue(obj);
}
public PSObject StreamingDequeue()
{
//if skip parameter is not mentioned or there are no more objects to skip
if (skip == 0 )
if (_skip == 0)
{
if (skipLast > 0)
if (_skipLast > 0)
{
// We are going to skip some items from end, but it's okay to process
// the early input objects once we have more items in queue than the
// specified 'skipLast' value.
if (this.Count > skipLast)
if (this.Count > _skipLast)
{
return Dequeue();
}
}
else
{
if (streamedObjectCount < first || !firstOrLastSpecified)
if (_streamedObjectCount < _first || !_firstOrLastSpecified)
{
Diagnostics.Assert(this.Count > 0, "Streaming an empty queue");
streamedObjectCount++;
_streamedObjectCount++;
return Dequeue();
}
if (last == 0)
if (_last == 0)
{
Dequeue();
}
}
}
}
else
{
//if last paramater is not mentioned,remove the objects and decrement the skip
if (last == 0)
if (_last == 0)
{
Dequeue();
skip--;
_skip--;
}
else if (first != 0)
else if (_first != 0)
{
skip--;
_skip--;
Dequeue();
}
}
@@ -317,86 +315,84 @@ namespace Microsoft.PowerShell.Commands
return null;
}
private int streamedObjectCount;
private int first, last, skip, skipLast;
private bool firstOrLastSpecified;
private int _streamedObjectCount;
private int _first,_last,_skip,_skipLast;
private bool _firstOrLastSpecified;
}
/// <summary>
/// list of processed parameters obtained from the Expression array
/// </summary>
private List<MshParameter> propertyMshParameterList;
private List<MshParameter> _propertyMshParameterList;
/// <summary>
/// singleton list of process parameters obtained from ExpandProperty
/// </summary>
private List<MshParameter> expandMshParameterList;
private List<MshParameter> _expandMshParameterList;
private MshExpressionFilter exclusionFilter;
private MshExpressionFilter _exclusionFilter;
private class UniquePSObjectHelper
{
internal UniquePSObjectHelper(PSObject o, int notePropertyCount)
{
WrittenObject = o;
this.notePropertyCount = notePropertyCount;
_notePropertyCount = notePropertyCount;
}
internal readonly PSObject WrittenObject;
internal int NotePropertyCount
{
get { return notePropertyCount; }
get { return _notePropertyCount; }
}
private int notePropertyCount;
private int _notePropertyCount;
}
private List<UniquePSObjectHelper> uniques = null;
private List<UniquePSObjectHelper> _uniques = null;
private void ProcessExpressionParameter ()
private void ProcessExpressionParameter()
{
TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
ParameterProcessor processor =
new ParameterProcessor(new SelectObjectExpressionParameterDefinition());
if ((this.expr != null) && (this.expr.Length != 0))
if ((_expr != null) && (_expr.Length != 0))
{
this.propertyMshParameterList = processor.ProcessParameters(this.expr, invocationContext);
_propertyMshParameterList = processor.ProcessParameters(_expr, invocationContext);
}
else
{
this.propertyMshParameterList = new List<MshParameter>();
_propertyMshParameterList = new List<MshParameter>();
}
if (!string.IsNullOrEmpty(expand))
if (!string.IsNullOrEmpty(_expand))
{
this.expandMshParameterList = processor.ProcessParameters(new string[] { this.expand }, invocationContext);
_expandMshParameterList = processor.ProcessParameters(new string[] { _expand }, invocationContext);
}
if (this.excludeArray != null)
if (_excludeArray != null)
{
this.exclusionFilter = new MshExpressionFilter(this.excludeArray);
_exclusionFilter = new MshExpressionFilter(_excludeArray);
}
}
private void ProcessObject(PSObject inputObject)
{
if ((expr == null || expr.Length == 0) && string.IsNullOrEmpty(expand))
if ((_expr == null || _expr.Length == 0) && string.IsNullOrEmpty(_expand))
{
FilteredWriteObject(inputObject, new List<PSNoteProperty>());
return;
}
//If property parameter is mentioned
List<PSNoteProperty> matchedProperties = new List<PSNoteProperty>();
foreach (MshParameter p in this.propertyMshParameterList)
foreach (MshParameter p in _propertyMshParameterList)
{
ProcessParameter(p, inputObject, matchedProperties);
}
if (string.IsNullOrEmpty(this.expand))
if (string.IsNullOrEmpty(_expand))
{
PSObject result = new PSObject();
if (matchedProperties.Count != 0)
@@ -426,17 +422,15 @@ namespace Microsoft.PowerShell.Commands
}
}
FilteredWriteObject(result, matchedProperties);
}
else
{
ProcessExpandParameter(this.expandMshParameterList[0], inputObject, matchedProperties);
ProcessExpandParameter(_expandMshParameterList[0], inputObject, matchedProperties);
}
}
private void ProcessParameter(MshParameter p, PSObject inputObject, List<PSNoteProperty> result)
{
string name = p.GetEntry(NameEntryDefinition.NameEntryKey) as string;
@@ -445,7 +439,7 @@ namespace Microsoft.PowerShell.Commands
List<MshExpressionResult> expressionResults = new List<MshExpressionResult>();
foreach (MshExpression resolvedName in ex.ResolveNames(inputObject))
{
if (exclusionFilter == null || !this.exclusionFilter.IsMatch(resolvedName))
if (_exclusionFilter == null || !_exclusionFilter.IsMatch(resolvedName))
{
List<MshExpressionResult> tempExprResults = resolvedName.GetValues(inputObject);
if (tempExprResults == null) continue;
@@ -487,7 +481,7 @@ namespace Microsoft.PowerShell.Commands
foreach (MshExpressionResult r in expressionResults)
{
// filter the exclusions, if any
if (this.exclusionFilter != null && this.exclusionFilter.IsMatch(r.ResolvedExpression))
if (_exclusionFilter != null && _exclusionFilter.IsMatch(r.ResolvedExpression))
continue;
PSNoteProperty mshProp;
@@ -510,23 +504,21 @@ namespace Microsoft.PowerShell.Commands
else
{
mshProp = new PSNoteProperty(name, r.Result);
}
result.Add(mshProp);
}
}
private void ProcessExpandParameter(MshParameter p, PSObject inputObject,
List<PSNoteProperty> matchedProperties)
{
MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
List<MshExpressionResult> expressionResults = ex.GetValues(inputObject);
if (expressionResults.Count == 0)
if (expressionResults.Count == 0)
{
ErrorRecord errorRecord = new ErrorRecord(
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, this.expand),
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, _expand),
"ExpandPropertyNotFound",
ErrorCategory.InvalidArgument,
inputObject);
@@ -535,7 +527,7 @@ namespace Microsoft.PowerShell.Commands
if (expressionResults.Count > 1)
{
ErrorRecord errorRecord = new ErrorRecord(
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, this.expand),
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, _expand),
"MutlipleExpandProperties",
ErrorCategory.InvalidArgument,
inputObject);
@@ -624,8 +616,8 @@ namespace Microsoft.PowerShell.Commands
private void FilteredWriteObject(PSObject obj, List<PSNoteProperty> addedNoteProperties)
{
Diagnostics.Assert(obj != null, "This command should never write null");
if (!unique)
if (!_unique)
{
if (obj != AutomationNull.Value)
{
@@ -635,10 +627,10 @@ namespace Microsoft.PowerShell.Commands
return;
}
//if only unique is mentioned
else if ((unique))
else if ((_unique))
{
bool isObjUnique = true;
foreach (UniquePSObjectHelper uniqueObj in uniques)
foreach (UniquePSObjectHelper uniqueObj in _uniques)
{
ObjectCommandComparer comparer = new ObjectCommandComparer(true, CultureInfo.CurrentCulture, true);
if ((comparer.Compare(obj.BaseObject, uniqueObj.WrittenObject.BaseObject) == 0) &&
@@ -667,16 +659,16 @@ namespace Microsoft.PowerShell.Commands
}
if (isObjUnique)
{
SetPSCustomObject(obj);
uniques.Add(new UniquePSObjectHelper(obj, addedNoteProperties.Count));
SetPSCustomObject(obj);
_uniques.Add(new UniquePSObjectHelper(obj, addedNoteProperties.Count));
}
}
}
private void SetPSCustomObject(PSObject psObj)
{
if(psObj.ImmediateBaseObject is PSCustomObject)
psObj.TypeNames.Insert(0, "Selected." + _inputObject.BaseObject.GetType().ToString());
if (psObj.ImmediateBaseObject is PSCustomObject)
psObj.TypeNames.Insert(0, "Selected." + _inputObject.BaseObject.GetType().ToString());
}
private void ProcessObjectAndHandleErrors(PSObject pso)
@@ -696,20 +688,20 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
///
/// </summary>
protected override void BeginProcessing ()
protected override void BeginProcessing()
{
ProcessExpressionParameter ();
if (unique)
ProcessExpressionParameter();
if (_unique)
{
uniques = new List<UniquePSObjectHelper>();
_uniques = new List<UniquePSObjectHelper>();
}
selectObjectQueue = new SelectObjectQueue(this.first, this.last, this.skip, this.skipLast, this.firstOrLastSpecified);
_selectObjectQueue = new SelectObjectQueue(_first, _last, _skip, _skipLast, _firstOrLastSpecified);
}
private int indexOfCurrentObject = 0;
private int indexCount = 0;
private int _indexOfCurrentObject = 0;
private int _indexCount = 0;
/// <summary>
///
/// </summary>
@@ -717,15 +709,15 @@ namespace Microsoft.PowerShell.Commands
{
if (_inputObject != AutomationNull.Value && _inputObject != null)
{
if (!indexSpecified)
if (!_indexSpecified)
{
selectObjectQueue.Enqueue(_inputObject);
PSObject streamingInputObject = selectObjectQueue.StreamingDequeue();
_selectObjectQueue.Enqueue(_inputObject);
PSObject streamingInputObject = _selectObjectQueue.StreamingDequeue();
if (streamingInputObject != null)
{
ProcessObjectAndHandleErrors(streamingInputObject);
}
if (selectObjectQueue.AllRequestedObjectsProcessed && !this.Wait)
if (_selectObjectQueue.AllRequestedObjectsProcessed && !this.Wait)
{
this.EndProcessing();
throw new StopUpstreamCommandsException(this);
@@ -733,26 +725,26 @@ namespace Microsoft.PowerShell.Commands
}
else
{
if(indexOfCurrentObject < index.Length)
if (_indexOfCurrentObject < _index.Length)
{
int currentlyRequestedIndex = index[indexOfCurrentObject];
if (indexCount == currentlyRequestedIndex)
int currentlyRequestedIndex = _index[_indexOfCurrentObject];
if (_indexCount == currentlyRequestedIndex)
{
ProcessObjectAndHandleErrors(_inputObject);
while ((indexOfCurrentObject < index.Length) && (index[indexOfCurrentObject] == currentlyRequestedIndex))
while ((_indexOfCurrentObject < _index.Length) && (_index[_indexOfCurrentObject] == currentlyRequestedIndex))
{
indexOfCurrentObject++;
_indexOfCurrentObject++;
}
}
}
if (!this.Wait && indexOfCurrentObject >= index.Length)
if (!this.Wait && _indexOfCurrentObject >= _index.Length)
{
this.EndProcessing();
throw new StopUpstreamCommandsException(this);
}
indexCount++;
_indexCount++;
}
}
}
@@ -767,21 +759,21 @@ namespace Microsoft.PowerShell.Commands
// 2. 'SkipLastParameter' set should have processed all valid input in the ProcessRecord.
if (ParameterSetName == "DefaultParameter")
{
if (first != 0)
if (_first != 0)
{
while ((selectObjectQueue.Count > 0))
while ((_selectObjectQueue.Count > 0))
{
ProcessObjectAndHandleErrors(selectObjectQueue.Dequeue());
ProcessObjectAndHandleErrors(_selectObjectQueue.Dequeue());
}
}
else
{
while ((selectObjectQueue.Count > 0))
while ((_selectObjectQueue.Count > 0))
{
int lenQueue = selectObjectQueue.Count;
if (lenQueue > skip)
int lenQueue = _selectObjectQueue.Count;
if (lenQueue > _skip)
{
ProcessObjectAndHandleErrors(selectObjectQueue.Dequeue());
ProcessObjectAndHandleErrors(_selectObjectQueue.Dequeue());
}
else
{
@@ -791,15 +783,15 @@ namespace Microsoft.PowerShell.Commands
}
}
if (uniques != null)
if (_uniques != null)
{
foreach (UniquePSObjectHelper obj in uniques)
foreach (UniquePSObjectHelper obj in _uniques)
{
if (obj.WrittenObject == null || obj.WrittenObject == AutomationNull.Value)
{
continue;
}
WriteObject(obj.WrittenObject);
}
}
@@ -814,17 +806,17 @@ namespace Microsoft.PowerShell.Commands
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "This exception is internal and never thrown by any public API")]
internal class SelectObjectException : SystemException
{
private ErrorRecord errorRecord;
private ErrorRecord _errorRecord;
internal ErrorRecord ErrorRecord
{
get
{
return this.errorRecord;
return _errorRecord;
}
}
internal SelectObjectException(ErrorRecord errorRecord)
{
this.errorRecord = errorRecord;
_errorRecord = errorRecord;
}
}
}