Browse Source

Fixed SD2-1110: Conversion of Microsoft generic sample project between C#<-->VB throws exception.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2102 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
a745c607d5
  1. 6
      src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/ConvertProject.cs
  2. 9
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs
  3. 9
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs
  4. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  5. 4
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  6. 8
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs
  7. 71
      src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs
  8. 25
      src/Main/Base/Project/Src/Project/Items/ProjectItem.cs
  9. 8
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

6
src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/ConvertProject.cs

@ -35,11 +35,7 @@ namespace Grunwald.BooBinding @@ -35,11 +35,7 @@ namespace Grunwald.BooBinding
errors.Clear();
warnings.Clear();
ProjectCreateInformation info = new ProjectCreateInformation();
info.ProjectBasePath = targetProjectDirectory;
info.ProjectName = sourceProject.Name;
info.OutputProjectFileName = Path.Combine(targetProjectDirectory, Path.GetFileNameWithoutExtension(sourceProject.FileName) + ".booproj");
return new BooProject(info);
return base.CreateProject(targetProjectDirectory, sourceProject);
}
protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem)

9
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBToCSharpConverter.cs

@ -44,14 +44,5 @@ namespace CSharpBinding @@ -44,14 +44,5 @@ namespace CSharpBinding
PreprocessingDirective.VBToCSharp(specials);
compilationUnit.AcceptVisitor(new VBNetToCSharpConvertVisitor(), null);
}
protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject)
{
ProjectCreateInformation info = new ProjectCreateInformation();
info.ProjectBasePath = targetProjectDirectory;
info.ProjectName = sourceProject.Name;
info.OutputProjectFileName = Path.Combine(targetProjectDirectory, Path.GetFileNameWithoutExtension(sourceProject.FileName) + ".csproj");
return new CSharpProject(info);
}
}
}

9
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBConverter.cs

@ -44,14 +44,5 @@ namespace VBNetBinding @@ -44,14 +44,5 @@ namespace VBNetBinding
FixProperty((VBNetProject)targetProject, "DefineConstants",
delegate(string v) { return v.Replace(';', ','); });
}
protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject)
{
ProjectCreateInformation info = new ProjectCreateInformation();
info.ProjectBasePath = targetProjectDirectory;
info.ProjectName = sourceProject.Name;
info.OutputProjectFileName = Path.Combine(targetProjectDirectory, Path.GetFileNameWithoutExtension(sourceProject.FileName) + ".vbproj");
return new VBNetProject(info);
}
}
}

2
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -148,10 +148,10 @@ out u); @@ -148,10 +148,10 @@ out u);
}
void GlobalAttributeSection() {
Expect(27);
#line 2029 "VBNET.ATG"
Location startPos = t.Location;
Expect(27);
if (la.kind == 49) {
lexer.NextToken();
} else if (la.kind == 121) {

4
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -2026,8 +2026,8 @@ TypeArgumentList<List<TypeReference> typeArguments> @@ -2026,8 +2026,8 @@ TypeArgumentList<List<TypeReference> typeArguments>
.
GlobalAttributeSection =
(. Location startPos = t.Location; .)
"<" ("Assembly" | "Module")
"<" (. Location startPos = t.Location; .)
("Assembly" | "Module")
(. string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture);
List<ASTAttribute> attributes = new List<ASTAttribute>();
ASTAttribute attribute;

8
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs

@ -39,9 +39,13 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -39,9 +39,13 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
{
public static void AddProject(ISolutionFolderNode solutionFolderNode, string fileName)
{
IProject newProject = LanguageBindingService.LoadProject(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName));
AddProject(solutionFolderNode, LanguageBindingService.LoadProject(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName)));
}
public static void AddProject(ISolutionFolderNode solutionFolderNode, IProject newProject)
{
if (newProject != null) {
newProject.Location = FileUtility.GetRelativePath(solutionFolderNode.Solution.Directory, fileName);
newProject.Location = FileUtility.GetRelativePath(solutionFolderNode.Solution.Directory, newProject.FileName);
ProjectService.AddProject(solutionFolderNode, newProject);
NodeBuilders.AddProjectNode((TreeNode)solutionFolderNode, newProject).EnsureVisible();
solutionFolderNode.Solution.ApplySolutionConfigurationAndPlatformToProjects();

71
src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs

@ -16,6 +16,8 @@ using ICSharpCode.NRefactory; @@ -16,6 +16,8 @@ using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.SharpDevelop.Project.Commands;
using MSBuild = Microsoft.Build.BuildEngine;
using ICSharpCode.SharpDevelop.Internal.Templates;
namespace ICSharpCode.SharpDevelop.Project.Converter
{
@ -24,11 +26,27 @@ namespace ICSharpCode.SharpDevelop.Project.Converter @@ -24,11 +26,27 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
/// </summary>
public abstract class LanguageConverter : AbstractMenuCommand
{
protected abstract IProject CreateProject(string targetProjectDirectory, IProject sourceProject);
protected virtual void AfterConversion(IProject targetProject) {}
public abstract string TargetLanguageName { get; }
protected virtual IProject CreateProject(string targetProjectDirectory, IProject sourceProject)
{
ProjectCreateInformation info = new ProjectCreateInformation();
info.Solution = sourceProject.ParentSolution;
info.ProjectBasePath = targetProjectDirectory;
info.ProjectName = sourceProject.Name + ".Converted";
info.RootNamespace = sourceProject.RootNamespace;
LanguageBindingDescriptor descriptor = LanguageBindingService.GetCodonPerLanguageName(TargetLanguageName);
if (descriptor == null || descriptor.Binding == null)
throw new InvalidOperationException("Cannot get Language Binding for " + TargetLanguageName);
info.OutputProjectFileName = Path.Combine(targetProjectDirectory, info.ProjectName + descriptor.ProjectFileExtension);
return descriptor.Binding.CreateProject(info);
}
protected virtual void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem)
{
if (!File.Exists(targetItem.FileName)) {
@ -41,39 +59,36 @@ namespace ICSharpCode.SharpDevelop.Project.Converter @@ -41,39 +59,36 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
MSBuildBasedProject sp = sourceProject as MSBuildBasedProject;
MSBuildBasedProject tp = targetProject as MSBuildBasedProject;
if (sp != null && tp != null) {
// TODO: Language converter
/*tp.Configurations.Clear();
tp.UserConfigurations.Clear();
foreach (KeyValuePair<string, PropertyGroup> pair in sp.Configurations) {
tp.Configurations.Add(pair.Key, pair.Value.Clone());
}
foreach (KeyValuePair<string, PropertyGroup> pair in sp.UserConfigurations) {
tp.UserConfigurations.Add(pair.Key, pair.Value.Clone());
lock (sp.SyncRoot) {
lock (tp.SyncRoot) {
tp.MSBuildProject.RemoveAllPropertyGroups();
foreach (MSBuild.BuildPropertyGroup spg in sp.MSBuildProject.PropertyGroups) {
if (spg.IsImported) continue;
MSBuild.BuildPropertyGroup tpg = tp.MSBuildProject.AddNewPropertyGroup(false);
tpg.Condition = spg.Condition;
foreach (MSBuild.BuildProperty sprop in spg) {
MSBuild.BuildProperty tprop = tpg.AddNewProperty(sprop.Name, sprop.Value);
tprop.Condition = sprop.Condition;
}
}
// use the newly created IdGuid instead of the copied one
tp.SetProperty(MSBuildBasedProject.ProjectGuidPropertyName, tp.IdGuid);
}
}
tp.BaseConfiguration.Merge(sp.BaseConfiguration);
tp.UserBaseConfiguration.Merge(sp.UserBaseConfiguration);*/
}
}
/// <summary>
/// Changes a property in the <paramref name="project"/> by applying a method to its value.
/// Changes all instances of a property in the <paramref name="project"/> by applying a method to its value.
/// </summary>
protected void FixProperty(MSBuildBasedProject project, string propertyName, Converter<string, string> method)
{
// TODO: Language converter
/*if (project.BaseConfiguration.IsSet(propertyName))
project.BaseConfiguration[propertyName] = method(project.BaseConfiguration[propertyName]);
if (project.UserBaseConfiguration.IsSet(propertyName))
project.UserBaseConfiguration[propertyName] = method(project.UserBaseConfiguration[propertyName]);
foreach (PropertyGroup pg in project.Configurations.Values) {
if (pg.IsSet(propertyName))
pg[propertyName] = method(pg[propertyName]);
lock (project.SyncRoot) {
foreach (MSBuild.BuildProperty p in project.GetAllProperties(propertyName)) {
p.Value = method(p.Value);
}
}
foreach (PropertyGroup pg in project.UserConfigurations.Values) {
if (pg.IsSet(propertyName))
pg[propertyName] = method(pg[propertyName]);
}*/
}
protected virtual void FixExtensionOfExtraProperties(FileProjectItem item, string sourceExtension, string targetExtension)
@ -117,9 +132,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter @@ -117,9 +132,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
}
targetProjectItems.AddProjectItem(targetItem);
} else {
// Adding the same item to two projects is only allowed because we will save and reload
// the target project.
targetProjectItems.AddProjectItem(item);
targetProjectItems.AddProjectItem(item.CloneFor(targetProject));
}
}
}
@ -174,7 +187,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter @@ -174,7 +187,7 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
}
}
}
public abstract class NRefactoryLanguageConverter : LanguageConverter
{
protected abstract void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials);

25
src/Main/Base/Project/Src/Project/Items/ProjectItem.cs

@ -312,17 +312,30 @@ namespace ICSharpCode.SharpDevelop.Project @@ -312,17 +312,30 @@ namespace ICSharpCode.SharpDevelop.Project
public virtual ProjectItem Clone()
{
if (this.Project != null) {
// use CreateProjectItem to ensure the clone has the same class
// (derived from ProjectItem)
ProjectItem copy = this.Project.CreateProjectItem(CloneBuildItem());
// remove reference to cloned item, leaving an unbound project item
copy.BuildItem = null;
return copy;
return CloneFor(this.Project);
} else {
throw new NotSupportedException();
}
}
/// <summary>
/// Clones this project item by cloning the underlying
/// MSBuild item and creating a new project item in the target project for it.
/// </summary>
public ProjectItem CloneFor(IProject targetProject)
{
if (targetProject == null)
throw new ArgumentNullException("project");
// use CreateProjectItem to ensure the clone has the same class
// (derived from ProjectItem)
ProjectItem copy = targetProject.CreateProjectItem(CloneBuildItem());
// remove reference to cloned item, leaving an unbound project item
copy.BuildItem = null;
return copy;
}
BuildItem CloneBuildItem()
{
lock (SyncRoot) {

8
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -119,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Project
IdGuid = "{" + Guid.NewGuid().ToString().ToUpperInvariant() + "}";
MSBuild.BuildPropertyGroup group = project.AddNewPropertyGroup(false);
group.AddNewProperty("ProjectGuid", IdGuid, true);
group.AddNewProperty(ProjectGuidPropertyName, IdGuid, true);
group.AddNewProperty("Configuration", "Debug", true).Condition = " '$(Configuration)' == '' ";
group.AddNewProperty("Platform", "AnyCPU", true).Condition = " '$(Platform)' == '' ";
@ -127,6 +127,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -127,6 +127,8 @@ namespace ICSharpCode.SharpDevelop.Project
this.ActivePlatform = "AnyCPU";
}
public const string ProjectGuidPropertyName = "ProjectGuid";
/// <summary>
/// Adds a guarded property:
/// &lt;<paramref name="name"/> Condition=" '$(<paramref name="name"/>)' == '' "
@ -828,11 +830,11 @@ namespace ICSharpCode.SharpDevelop.Project @@ -828,11 +830,11 @@ namespace ICSharpCode.SharpDevelop.Project
CreateItemsListFromMSBuild();
LoadConfigurationPlatformNamesFromMSBuild();
IdGuid = GetEvaluatedProperty("ProjectGuid");
IdGuid = GetEvaluatedProperty(ProjectGuidPropertyName);
if (IdGuid == null) {
// Fix projects that have nb GUID
IdGuid = Guid.NewGuid().ToString();
SetPropertyInternal(null, null, "ProjectGuid", IdGuid, PropertyStorageLocations.Base, true);
SetPropertyInternal(null, null, ProjectGuidPropertyName, IdGuid, PropertyStorageLocations.Base, true);
try {
// save fixed project
project.Save(fileName);

Loading…
Cancel
Save