Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2191 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
115 changed files with 7385 additions and 3801 deletions
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace Grunwald.BooBinding.CodeCompletion |
||||
{ |
||||
/// <summary>
|
||||
/// The return type that is the element of an enumerable.
|
||||
/// Used to infer the type in "for x in enumerableVariable" loops.
|
||||
/// </summary>
|
||||
public class ElementReturnType : ProxyReturnType |
||||
{ |
||||
IReturnType listType; |
||||
IProjectContent pc; |
||||
|
||||
public ElementReturnType(IProjectContent pc, IReturnType listType) |
||||
{ |
||||
if (pc == null) |
||||
throw new ArgumentNullException("pc"); |
||||
// listType is probably an InferredReturnType
|
||||
this.listType = listType; |
||||
this.pc = pc; |
||||
} |
||||
|
||||
public override IReturnType BaseType { |
||||
get { |
||||
// get element type from listType
|
||||
if (listType.IsArrayReturnType) |
||||
return listType.CastToArrayReturnType().ArrayElementType; |
||||
|
||||
IClass c = listType.GetUnderlyingClass(); |
||||
if (c == null) |
||||
return null; |
||||
IClass genumerable = pc.GetClass("System.Collections.Generic.IEnumerable", 1); |
||||
if (c.IsTypeInInheritanceTree(genumerable)) { |
||||
return MemberLookupHelper.GetTypeParameterPassedToBaseClass(listType, genumerable, 0); |
||||
} |
||||
IClass enumerable = pc.GetClass("System.Collections.IEnumerable", 0); |
||||
if (c.IsTypeInInheritanceTree(enumerable)) { |
||||
// We can't use the EnumeratorItemType attribute because SharpDevelop
|
||||
// does not store attribute argument values in the cache.
|
||||
|
||||
// HACK: Hacked in support for range(), take out when RangeEnumerator implements IEnumerable<int>
|
||||
if (c.FullyQualifiedName == "Boo.Lang.Builtins.RangeEnumerator") { |
||||
return pc.SystemTypes.Int32; |
||||
} |
||||
|
||||
return pc.SystemTypes.Object; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using Boo.Lang.Compiler; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using B = Boo.Lang.Compiler.Ast; |
||||
|
||||
namespace NRefactoryToBooConverter |
||||
{ |
||||
partial class ConvertVisitor |
||||
{ |
||||
public object VisitQueryExpression(QueryExpression queryExpression, object data) |
||||
{ |
||||
AddError(queryExpression, "QueryExpression is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) |
||||
{ |
||||
AddError(queryExpressionFromClause, "QueryExpressionFromClause is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionFromGenerator(QueryExpressionFromGenerator queryExpressionFromGenerator, object data) |
||||
{ |
||||
AddError(queryExpressionFromGenerator, "QueryExpressionFromGenerator is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) |
||||
{ |
||||
AddError(queryExpressionGroupClause, "QueryExpressionGroupClause is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data) |
||||
{ |
||||
AddError(queryExpressionIntoClause, "QueryExpressionIntoClause is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) |
||||
{ |
||||
AddError(queryExpressionOrdering, "QueryExpressionOrdering is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) |
||||
{ |
||||
AddError(queryExpressionSelectClause, "queryExpressionSelectClause is not supported."); |
||||
return null; |
||||
} |
||||
|
||||
public object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) |
||||
{ |
||||
AddError(queryExpressionWhereClause, "QueryExpressionWhereClause is not supported."); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,67 +0,0 @@
@@ -1,67 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.PrettyPrinter |
||||
{ |
||||
public delegate void InformNode(INode node); |
||||
|
||||
public class NodeTracker |
||||
{ |
||||
IAstVisitor callVisitor; |
||||
|
||||
public IAstVisitor CallVisitor { |
||||
get { |
||||
return callVisitor; |
||||
} |
||||
} |
||||
|
||||
public NodeTracker(IAstVisitor callVisitor) |
||||
{ |
||||
this.callVisitor = callVisitor; |
||||
} |
||||
|
||||
public void BeginNode(INode node) |
||||
{ |
||||
if (NodeVisiting != null) { |
||||
NodeVisiting(node); |
||||
} |
||||
} |
||||
|
||||
public void EndNode(INode node) |
||||
{ |
||||
if (NodeVisited != null) { |
||||
NodeVisited(node); |
||||
} |
||||
} |
||||
|
||||
public object TrackedVisit(INode node, object data) |
||||
{ |
||||
BeginNode(node); |
||||
object ret = node.AcceptVisitor(callVisitor, data); |
||||
EndNode(node); |
||||
return ret; |
||||
} |
||||
|
||||
public object TrackedVisitChildren(INode node, object data) |
||||
{ |
||||
foreach (INode child in node.Children) { |
||||
TrackedVisit(child, data); |
||||
} |
||||
if (NodeChildrenVisited != null) { |
||||
NodeChildrenVisited(node); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public event InformNode NodeVisiting; |
||||
public event InformNode NodeChildrenVisited; |
||||
public event InformNode NodeVisited; |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// This class converts C# constructs to their VB.NET equivalents.
|
||||
/// </summary>
|
||||
public class CSharpToVBNetConvertVisitor : CSharpConstructsVisitor |
||||
{ |
||||
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data) |
||||
{ |
||||
base.VisitCompilationUnit(compilationUnit, data); |
||||
compilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), data); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for the conversion visitors.
|
||||
/// </summary>
|
||||
public class ConvertVisitorBase : AbstractAstTransformer |
||||
{ |
||||
|
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.Visitors |
||||
{ |
||||
class RenameIdentifierVisitor : AbstractAstVisitor |
||||
{ |
||||
protected StringComparer nameComparer; |
||||
protected string from, to; |
||||
|
||||
public RenameIdentifierVisitor(string from, string to, StringComparer nameComparer) |
||||
{ |
||||
this.nameComparer = nameComparer; |
||||
this.from = from; |
||||
this.to = to; |
||||
} |
||||
|
||||
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) |
||||
{ |
||||
if (nameComparer.Equals(identifierExpression.Identifier, from)) { |
||||
identifierExpression.Identifier = to; |
||||
} |
||||
return base.VisitIdentifierExpression(identifierExpression, data); |
||||
} |
||||
} |
||||
|
||||
sealed class RenameLocalVariableVisitor : RenameIdentifierVisitor |
||||
{ |
||||
public RenameLocalVariableVisitor(string from, string to, StringComparer nameComparer) |
||||
: base(from, to, nameComparer) |
||||
{ |
||||
} |
||||
|
||||
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, variableDeclaration.Name)) { |
||||
variableDeclaration.Name = to; |
||||
} |
||||
return base.VisitVariableDeclaration(variableDeclaration, data); |
||||
} |
||||
|
||||
public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, parameterDeclarationExpression.ParameterName)) { |
||||
parameterDeclarationExpression.ParameterName = to; |
||||
} |
||||
return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data); |
||||
} |
||||
|
||||
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, foreachStatement.VariableName)) { |
||||
foreachStatement.VariableName = to; |
||||
} |
||||
return base.VisitForeachStatement(foreachStatement, data); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// Renames local variables if they conflict with other locals, fields or parameters.
|
||||
/// </summary>
|
||||
static class ToVBNetRenameConflictingVariablesVisitor |
||||
{ |
||||
public static void RenameConflicting(ParametrizedNode method) |
||||
{ |
||||
// variable name => case sensitive variable name
|
||||
// value is null if there are multiple casings for the variable -> the variable is conflicting
|
||||
Dictionary<string, string> caseInsensitive = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); |
||||
|
||||
LookupTableVisitor ltv = new LookupTableVisitor(StringComparer.InvariantCulture); |
||||
method.AcceptVisitor(ltv, null); |
||||
|
||||
// add method parameters to caseInsensitive
|
||||
foreach (ParameterDeclarationExpression pde in method.Parameters) { |
||||
AddVariableToDict(caseInsensitive, pde.ParameterName, true); |
||||
} |
||||
|
||||
// add local variables to caseInsensitive
|
||||
foreach (KeyValuePair<string, List<LocalLookupVariable>> var in ltv.Variables) { |
||||
AddVariableToDict(caseInsensitive, var.Key, true); |
||||
} |
||||
|
||||
// add used identifiers to caseInsensitive
|
||||
FindIdentifiersVisitor fvv = new FindIdentifiersVisitor(); |
||||
method.AcceptVisitor(fvv, null); |
||||
|
||||
foreach (KeyValuePair<string, string> pair in fvv.usedIdentifiers) { |
||||
AddVariableToDict(caseInsensitive, pair.Key, false); |
||||
} |
||||
|
||||
int index = 0; |
||||
foreach (ParameterDeclarationExpression pde in method.Parameters) { |
||||
if (caseInsensitive[pde.ParameterName] == null) { |
||||
RenameVariable(method, pde.ParameterName, ref index); |
||||
} |
||||
} |
||||
foreach (KeyValuePair<string, List<LocalLookupVariable>> var in ltv.Variables) { |
||||
if (caseInsensitive[var.Key] == null) { |
||||
RenameVariable(method, var.Key, ref index); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void RenameVariable(INode method, string from, ref int index) |
||||
{ |
||||
index += 1; |
||||
method.AcceptVisitor(new RenameLocalVariableVisitor(from, from + "__" + index, StringComparer.InvariantCulture), null); |
||||
} |
||||
|
||||
static void AddVariableToDict(Dictionary<string, string> caseInsensitive, string varName, bool hasDeclaration) |
||||
{ |
||||
string existing; |
||||
if (caseInsensitive.TryGetValue(varName, out existing)) { |
||||
if (existing != null && existing != varName) { |
||||
caseInsensitive[varName] = null; |
||||
} |
||||
} else { |
||||
if (hasDeclaration) { |
||||
caseInsensitive.Add(varName, varName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
sealed class FindIdentifiersVisitor : AbstractAstVisitor |
||||
{ |
||||
// use dictionary as HashSet to remember used identifiers
|
||||
internal readonly Dictionary<string, string> usedIdentifiers = new Dictionary<string, string>(); |
||||
|
||||
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) |
||||
{ |
||||
usedIdentifiers[identifierExpression.Identifier] = null; |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class LambdaExpressionTests |
||||
{ |
||||
static LambdaExpression Parse(string program) |
||||
{ |
||||
return ParseUtilCSharp.ParseExpression<LambdaExpression>(program); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedExpressionBody() |
||||
{ |
||||
LambdaExpression e = Parse("(x) => x + 1"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedExpressionBodyWithoutParenthesis() |
||||
{ |
||||
LambdaExpression e = Parse("x => x + 1"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedStatementBody() |
||||
{ |
||||
LambdaExpression e = Parse("(x) => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImplicitlyTypedStatementBodyWithoutParenthesis() |
||||
{ |
||||
LambdaExpression e = Parse("x => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExplicitlyTypedStatementBody() |
||||
{ |
||||
LambdaExpression e = Parse("(int x) => { return x + 1; }"); |
||||
Assert.AreEqual("x", e.Parameters[0].ParameterName); |
||||
Assert.AreEqual("int", e.Parameters[0].TypeReference.Type); |
||||
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class QueryExpressionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleExpression() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>( |
||||
"from c in customers where c.City == \"London\" select c" |
||||
); |
||||
Assert.AreEqual(1, qe.FromClause.Generators.Count); |
||||
Assert.AreEqual("c", qe.FromClause.Generators[0].Identifier); |
||||
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Generators[0].InExpression).Identifier); |
||||
Assert.AreEqual(1, qe.FromOrWhereClauses.Count); |
||||
Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[0]); |
||||
QueryExpressionWhereClause wc = (QueryExpressionWhereClause)qe.FromOrWhereClauses[0]; |
||||
Assert.IsInstanceOfType(typeof(BinaryOperatorExpression), wc.Condition); |
||||
Assert.IsInstanceOfType(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
|
||||
[Test] |
||||
public void MultipleGenerators() |
||||
{ |
||||
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(@"
|
||||
from c in customers |
||||
where c.City == ""London"" |
||||
from o in c.Orders |
||||
where o.OrderDate.Year == 2005 |
||||
select new { c.Name, o.OrderID, o.Total }");
|
||||
Assert.AreEqual(1, qe.FromClause.Generators.Count); |
||||
Assert.AreEqual(3, qe.FromOrWhereClauses.Count); |
||||
Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[0]); |
||||
Assert.IsInstanceOfType(typeof(QueryExpressionFromClause), qe.FromOrWhereClauses[1]); |
||||
Assert.IsInstanceOfType(typeof(QueryExpressionWhereClause), qe.FromOrWhereClauses[2]); |
||||
|
||||
Assert.IsInstanceOfType(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,198 @@
@@ -0,0 +1,198 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.NRefactory.PrettyPrinter; |
||||
using ICSharpCode.NRefactory.Visitors; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests advanced code-conversion features that rely on the type system.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class CodeConverterTests |
||||
{ |
||||
#region TestProgram (converting code)
|
||||
ProjectContentRegistry projectContentRegistry = ParserService.DefaultProjectContentRegistry; |
||||
|
||||
void TestProgramCS2VB(string sourceCode, string expectedOutput) |
||||
{ |
||||
TestProgram(SupportedLanguage.CSharp, sourceCode, expectedOutput); |
||||
} |
||||
|
||||
void TestProgramVB2CS(string sourceCode, string expectedOutput) |
||||
{ |
||||
TestProgram(SupportedLanguage.CSharp, sourceCode, expectedOutput); |
||||
} |
||||
|
||||
void TestProgram(SupportedLanguage sourceLanguage, string sourceCode, string expectedOutput) |
||||
{ |
||||
DefaultProjectContent pc = new DefaultProjectContent(); |
||||
pc.ReferencedContents.Add(projectContentRegistry.Mscorlib); |
||||
if (sourceLanguage == SupportedLanguage.VBNet) { |
||||
pc.DefaultImports = new DefaultUsing(pc); |
||||
pc.DefaultImports.Usings.Add("System"); |
||||
pc.DefaultImports.Usings.Add("Microsoft.VisualBasic"); |
||||
} |
||||
pc.Language = sourceLanguage == SupportedLanguage.CSharp ? LanguageProperties.CSharp : LanguageProperties.VBNet; |
||||
HostCallback.GetCurrentProjectContent = delegate { |
||||
return pc; |
||||
}; |
||||
|
||||
ICSharpCode.NRefactory.IParser parser = ParserFactory.CreateParser(sourceLanguage, new StringReader(sourceCode)); |
||||
parser.Parse(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
|
||||
NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc); |
||||
visitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
visitor.Cu.FileName = sourceLanguage == SupportedLanguage.CSharp ? "a.cs" : "a.vb"; |
||||
foreach (IClass c in visitor.Cu.Classes) { |
||||
pc.AddClassToNamespaceList(c); |
||||
} |
||||
|
||||
HostCallback.GetParseInformation = delegate(string fileName) { |
||||
ParseInformation pi = new ParseInformation(); |
||||
pi.ValidCompilationUnit = visitor.Cu; |
||||
return pi; |
||||
}; |
||||
|
||||
if (sourceLanguage == SupportedLanguage.CSharp) { |
||||
CSharpToVBNetConvertVisitor convertVisitor = new CSharpToVBNetConvertVisitor(pc, visitor.Cu.FileName); |
||||
parser.CompilationUnit.AcceptVisitor(convertVisitor, null); |
||||
} else { |
||||
VBNetToCSharpConvertVisitor convertVisitor = new VBNetToCSharpConvertVisitor(); |
||||
parser.CompilationUnit.AcceptVisitor(convertVisitor, null); |
||||
} |
||||
|
||||
IOutputAstVisitor outputVisitor = sourceLanguage == SupportedLanguage.CSharp ? (IOutputAstVisitor)new VBNetOutputVisitor() : new CSharpOutputVisitor(); |
||||
outputVisitor.Options.IndentationChar = ' '; |
||||
outputVisitor.Options.IndentSize = 2; |
||||
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), |
||||
outputVisitor)) { |
||||
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
} |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Trim().Replace("\r", "")); |
||||
} |
||||
#endregion
|
||||
|
||||
#region TestMember/TestStatement/TestExpression
|
||||
string IndentAllLines(string code) |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
using (StringReader r = new StringReader(code)) { |
||||
string line; |
||||
while ((line = r.ReadLine()) != null) { |
||||
b.Append(" "); |
||||
b.AppendLine(line); |
||||
} |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
void TestMemberCS2VB(string sourceCode, string expectedCode) |
||||
{ |
||||
TestProgramCS2VB("using System;\n" + |
||||
"class MyClassName {\n" + |
||||
IndentAllLines(sourceCode) + |
||||
"}", |
||||
|
||||
"Imports System\n" + |
||||
"Class MyClassName\n" + |
||||
IndentAllLines(expectedCode) + |
||||
"End Class"); |
||||
} |
||||
|
||||
void TestMemberVB2CS(string sourceCode, string expectedCode) |
||||
{ |
||||
TestProgramVB2CS("Class MyClassName\n" + |
||||
IndentAllLines(sourceCode) + |
||||
"End Class", |
||||
|
||||
"using System;\n" + |
||||
"using Microsoft.VisualBasic;\n" + |
||||
"class MyClassName {\n" + |
||||
IndentAllLines(expectedCode) + |
||||
"}"); |
||||
} |
||||
|
||||
void TestStatementsCS2VB(string sourceCode, string expectedCode) |
||||
{ |
||||
TestMemberCS2VB("void T() {\n" + |
||||
IndentAllLines(sourceCode) + |
||||
"}", |
||||
|
||||
"Private Sub T()\n" + |
||||
IndentAllLines(expectedCode) + |
||||
"End Sub"); |
||||
} |
||||
#endregion
|
||||
|
||||
[Test] |
||||
public void RaiseEventCS2VB() |
||||
{ |
||||
TestMemberCS2VB("public event EventHandler Click;" + |
||||
"void T() { if (Click != null) { Click(this, EventArgs.Empty); } }", |
||||
"Public Event Click As EventHandler\n" + |
||||
"Private Sub T()\n" + |
||||
" RaiseEvent Click(Me, EventArgs.Empty)\n" + |
||||
"End Sub"); |
||||
|
||||
TestMemberCS2VB("public event EventHandler Click;" + |
||||
"void T() { Click(this, EventArgs.Empty); }", |
||||
"Public Event Click As EventHandler\n" + |
||||
"Private Sub T()\n" + |
||||
" RaiseEvent Click(Me, EventArgs.Empty)\n" + |
||||
"End Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferenceEqualityAndValueEquality() |
||||
{ |
||||
// Reference equality:
|
||||
TestStatementsCS2VB("object a = new object();\n" + |
||||
"object b = new object();\n" + |
||||
"if (a == b) {\n" + |
||||
"}", |
||||
|
||||
"Dim a As New Object()\n" + |
||||
"Dim b As New Object()\n" + |
||||
"If a Is b Then\n" + |
||||
"End If"); |
||||
|
||||
// Value type equality:
|
||||
TestStatementsCS2VB("int a = 3;\n" + |
||||
"int b = 4;\n" + |
||||
"if (a == b) {\n" + |
||||
"}", |
||||
|
||||
"Dim a As Integer = 3\n" + |
||||
"Dim b As Integer = 4\n" + |
||||
"If a = b Then\n" + |
||||
"End If"); |
||||
|
||||
// String equality:
|
||||
TestStatementsCS2VB("string a = \"3\";\n" + |
||||
"string b = \"4\";\n" + |
||||
"if (a == b) {\n" + |
||||
"}", |
||||
|
||||
"Dim a As String = \"3\"\n" + |
||||
"Dim b As String = \"4\"\n" + |
||||
"If a = b Then\n" + |
||||
"End If"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Dom |
||||
{ |
||||
/// <summary>
|
||||
/// A return type that modifies the base return type and is not regarded equal to its base type.
|
||||
/// </summary>
|
||||
public abstract class DecoratingReturnType : ProxyReturnType |
||||
{ |
||||
public abstract override bool Equals(IReturnType other); |
||||
public abstract override int GetHashCode(); |
||||
|
||||
public sealed override bool IsDefaultReturnType { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public abstract override T CastToDecoratingReturnType<T>(); |
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Dom |
||||
{ |
||||
/// <summary>
|
||||
/// The type reference that is the element of an enumerable.
|
||||
/// This class is used in combination with an InferredReturnType to
|
||||
/// represent the implicitly typed loop variable <c>v</c> in
|
||||
/// "<c>foreach (var v in enumerableInstance) {}</c>"
|
||||
/// </summary>
|
||||
public class ElementReturnType : ProxyReturnType |
||||
{ |
||||
IReturnType enumerableType; |
||||
IProjectContent pc; |
||||
|
||||
public ElementReturnType(IProjectContent pc, IReturnType enumerableType) |
||||
{ |
||||
if (pc == null) |
||||
throw new ArgumentNullException("pc"); |
||||
this.enumerableType = enumerableType; |
||||
this.pc = pc; |
||||
} |
||||
|
||||
public override IReturnType BaseType { |
||||
get { |
||||
// get element type from enumerableType
|
||||
if (enumerableType.IsArrayReturnType) |
||||
return enumerableType.CastToArrayReturnType().ArrayElementType; |
||||
|
||||
IClass c = enumerableType.GetUnderlyingClass(); |
||||
if (c == null) |
||||
return null; |
||||
IClass genumerable = pc.GetClass("System.Collections.Generic.IEnumerable", 1); |
||||
if (c.IsTypeInInheritanceTree(genumerable)) { |
||||
return MemberLookupHelper.GetTypeParameterPassedToBaseClass(enumerableType, genumerable, 0); |
||||
} |
||||
IClass enumerable = pc.GetClass("System.Collections.IEnumerable", 0); |
||||
if (c.IsTypeInInheritanceTree(enumerable)) { |
||||
return pc.SystemTypes.Object; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue