Skip to content

Commit

Permalink
Merge branch 'upstream_master'
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-kallen committed Nov 14, 2013
2 parents 2aa17da + 50733f5 commit 0640c66
Show file tree
Hide file tree
Showing 151 changed files with 5,511 additions and 3,497 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sln -crlf
*.csproj -crlf
*.cs text diff=csharp
*.sln text eol=crlf
*.csproj text eol=crlf
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace>
<AssemblyName>AstVerifier</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace>
<AssemblyName>AstVerifier</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Debug\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_5_Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,13 @@ bool SameNode(INode expr1, INode expr2)
return m.Success;
}

ForeachStatement GetForeachStatement (RefactoringContext context)
static ForeachStatement GetForeachStatement (RefactoringContext context)
{
var foreachStatement = context.GetNode();
if (foreachStatement == null) {
var foreachStatement = context.GetNode<ForeachStatement>();
if (foreachStatement == null || !foreachStatement.ForeachToken.Contains(context.Location))
return null;
}

return foreachStatement.GetParent<ForeachStatement> ();
return foreachStatement;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
}, varInit);
}, selectedNode);
}

var idntf = context.GetNode<Identifier>();
Expand All @@ -97,7 +97,7 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
}, paramDec);
}, paramDec.NameToken);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Semantics;
using System.Linq;

namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
Expand All @@ -35,52 +37,87 @@ public class GenerateSwitchLabelsAction : CodeActionProvider
{
public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
var switchStatement = GetSwitchStatement(context);
if (switchStatement == null) {
var switchStatement = context.GetNode<SwitchStatement> ();

if (switchStatement == null || !switchStatement.SwitchToken.Contains(context.Location))
yield break;
}
var result = context.Resolve(switchStatement.Expression);
if (result.Type.Kind != TypeKind.Enum) {
if (result.Type.Kind != TypeKind.Enum)
yield break;
}
yield return new CodeAction (context.TranslateString("Create switch labels"), script => {
var type = result.Type;
var newSwitch = (SwitchStatement)switchStatement.Clone();

var target = context.CreateShortType(result.Type);
foreach (var field in type.GetFields ()) {
if (field.IsSynthetic || !field.IsConst) {
continue;

if (switchStatement.SwitchSections.Count == 0) {
yield return new CodeAction(context.TranslateString("Create switch labels"), script => {
var type = result.Type;
var newSwitch = (SwitchStatement)switchStatement.Clone();

var target = context.CreateShortType(result.Type);
foreach (var field in type.GetFields ()) {
if (field.IsSynthetic || !field.IsConst)
continue;
newSwitch.SwitchSections.Add(new SwitchSection() {
CaseLabels = {
new CaseLabel(new MemberReferenceExpression(target.Clone(), field.Name))
},
Statements = {
new BreakStatement()
}
});
}
newSwitch.SwitchSections.Add(new SwitchSection () {

newSwitch.SwitchSections.Add(new SwitchSection() {
CaseLabels = {
new CaseLabel (new MemberReferenceExpression (target.Clone(), field.Name))
new CaseLabel()
},
Statements = {
new BreakStatement ()
new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "ArgumentOutOfRangeException")))
}
});

script.Replace(switchStatement, newSwitch);
}, switchStatement);
} else {
var missingFields = new List<IField>();
foreach (var field in result.Type.GetFields ()) {
if (field.IsSynthetic || !field.IsConst)
continue;
if (!IsHandled(context, switchStatement, field)) {
missingFields.Add(field);
}
}

newSwitch.SwitchSections.Add(new SwitchSection () {
CaseLabels = {
new CaseLabel ()
},
Statements = {
new ThrowStatement (new ObjectCreateExpression (context.CreateShortType("System", "ArgumentOutOfRangeException")))
if (missingFields.Count == 0)
yield break;
yield return new CodeAction(context.TranslateString("Create missing switch labels"), script => {
var type = result.Type;
//var newSwitch = (SwitchStatement)switchStatement.Clone();
var insertNode = (AstNode)switchStatement.SwitchSections.LastOrDefault(s => !s.CaseLabels.Any(label => label.Expression.IsNull)) ?? switchStatement.LBraceToken;

var target = context.CreateShortType(result.Type);
foreach (var field in missingFields) {
script.InsertAfter(insertNode, new SwitchSection() {
CaseLabels = {
new CaseLabel(new MemberReferenceExpression(target.Clone(), field.Name))
},
Statements = {
new BreakStatement()
}
});
}
});

script.Replace(switchStatement, newSwitch);
}, switchStatement);
}, switchStatement);
}
}
static SwitchStatement GetSwitchStatement (RefactoringContext context)

static bool IsHandled(RefactoringContext context, SwitchStatement switchStatement, IField field)
{
var switchStatment = context.GetNode<SwitchStatement> ();
if (switchStatment != null && switchStatment.SwitchSections.Count == 0)
return switchStatment;
return null;
foreach (var sect in switchStatement.SwitchSections) {
foreach (var caseLabel in sect.CaseLabels) {
var resolveCase = context.Resolve(caseLabel.Expression) as MemberResolveResult;
if (resolveCase == null)
continue;
if (field == resolveCase.Member)
return true;
}
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,29 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
)
, type);
}

static void RemoveConstraints(EntityDeclaration decl)
{
foreach (var child in decl.GetChildrenByRole(Roles.Constraint).ToArray()) {
child.Remove();
}
}

public static IEnumerable<AstNode> GenerateImplementation(RefactoringContext context, IEnumerable<Tuple<IMember, bool>> toImplement, bool generateRegion)
{
var service = (CodeGenerationService)context.GetService(typeof(CodeGenerationService));
if (service == null)
yield break;
var nodes = new Dictionary<IType, List<AstNode>>();
var nodes = new Dictionary<IType, List<EntityDeclaration>>();

foreach (var member in toImplement) {
if (!nodes.ContainsKey(member.Item1.DeclaringType))
nodes [member.Item1.DeclaringType] = new List<AstNode>();
nodes [member.Item1.DeclaringType].Add(service.GenerateMemberImplementation(context, member.Item1, member.Item2));
nodes [member.Item1.DeclaringType] = new List<EntityDeclaration>();
var decl = service.GenerateMemberImplementation(context, member.Item1, member.Item2);
if (member.Item2 || member.Item1.DeclaringType.Kind != TypeKind.Interface)
RemoveConstraints(decl);

nodes[member.Item1.DeclaringType].Add(decl);
}

foreach (var kv in nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
CodeAction ActionFromUsingStatement(RefactoringContext context)
{
var initializer = context.GetNode<VariableInitializer>();
if (initializer == null)
if (initializer == null || !initializer.NameToken.Contains(context.Location))
return null;
var initializerRR = context.Resolve(initializer) as LocalResolveResult;
if (initializerRR == null)
Expand Down Expand Up @@ -82,7 +82,7 @@ CodeAction ActionFromUsingStatement(RefactoringContext context)
CodeAction ActionFromVariableInitializer(RefactoringContext context)
{
var initializer = context.GetNode<VariableInitializer>();
if (initializer == null || initializer.Parent.Parent is ForStatement)
if (initializer == null || initializer.Parent.Parent is ForStatement || !initializer.NameToken.Contains(context.Location))
return null;
var initializerRR = context.Resolve(initializer) as LocalResolveResult;
if (initializerRR == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
if (entryNode == null)
yield break;
var selectedInitializer = context.GetNode<VariableInitializer>();
if (selectedInitializer != null && selectedInitializer.Contains(context.Location)) {
if (selectedInitializer != null) {
if (!selectedInitializer.NameToken.Contains(context.Location))
yield break;
if (HasDependency(context, entryNode, selectedInitializer)) {
yield return MoveDeclarationAction(context, entryNode, variableDeclaration, selectedInitializer);
} else {
Expand Down
Loading

0 comments on commit 0640c66

Please sign in to comment.