Browse Source

[WIP] EnvDTE

pull/45/merge
Daniel Grunwald 12 years ago
parent
commit
3609078840
  1. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs
  2. 13
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RefactoringExtensions.cs
  3. 6
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  4. 27
      src/AddIns/Misc/PackageManagement/Project/Src/DocumentNamespaceCreator.cs
  5. 29
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs
  6. 198
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction.cs
  7. 80
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction2.cs
  8. 16
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeGetterFunction.cs
  9. 29
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeGetterOrSetterFunction.cs
  10. 73
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeImport.cs
  11. 24
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs
  12. 16
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeSetterFunction.cs
  13. 20
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs
  14. 10
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs
  15. 134
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModel2.cs
  16. 78
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs
  17. 13
      src/AddIns/Misc/PackageManagement/Project/Src/IDocumentNamespaceCreator.cs
  18. 67
      src/AddIns/Misc/PackageManagement/Project/Src/VirtualMethodUpdater.cs
  19. 1
      src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/vsCMOverrideKind.vb
  20. 5
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/ICSharpCode.Reports.Addin.csproj
  21. 5
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj
  22. 16
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  23. 3
      src/Main/Base/Project/Dom/ITypeDefinitionModel.cs
  24. 6
      src/Main/Base/Project/Refactoring/CodeGenerator.cs
  25. 8
      src/Main/Base/Project/Src/Editor/Commands/SymbolUnderCaretMenuCommand.cs
  26. 6
      src/Main/Base/Project/Util/SimpleCommand.cs
  27. 5
      src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs

10
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs

@ -134,5 +134,15 @@ namespace CSharpBinding.Refactoring @@ -134,5 +134,15 @@ namespace CSharpBinding.Refactoring
// TODO script.ChangeModifiers(...)
throw new NotImplementedException();
}
public override void AddImport(FileName fileName, string namespaceName)
{
var context = RefactoringExtensions.CreateRefactoringContext(new DomRegion(fileName, 0, 0));
var astBuilder = context.CreateTypeSystemAstBuilder();
using (var script = context.StartScript()) {
AstType ns = astBuilder.ConvertNamespace(namespaceName);
UsingHelper.InsertUsing(context, script, ns);
}
}
}
}

13
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RefactoringExtensions.cs

@ -11,6 +11,7 @@ using ICSharpCode.NRefactory.TypeSystem; @@ -11,6 +11,7 @@ using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Project;
namespace CSharpBinding.Refactoring
{
@ -82,17 +83,21 @@ namespace CSharpBinding.Refactoring @@ -82,17 +83,21 @@ namespace CSharpBinding.Refactoring
} else {
region = entity.Region;
}
return CreateRefactoringContext(region, entity.ParentAssembly.GetProject());
}
public static SDRefactoringContext CreateRefactoringContext(DomRegion region, IProject project = null)
{
var view = SD.FileService.OpenFile(new FileName(region.FileName), false);
if (view == null)
return null;
throw new NotSupportedException("Could not open " + region.FileName);
var editor = view.GetService<ITextEditor>();
if (editor == null)
return null;
var project = entity.ParentAssembly.GetProject();
throw new NotSupportedException("Could not find editor for " + region.FileName);
var fileName = FileName.Create(region.FileName);
var parseInfo = SD.ParserService.Parse(fileName, editor.Document, project) as CSharpFullParseInformation;
if (parseInfo == null)
return null;
throw new NotSupportedException("Could not C# parse info for " + region.FileName);
ICompilation compilation;
if (project != null)
compilation = SD.ParserService.GetCompilation(project);

6
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -87,7 +87,6 @@ @@ -87,7 +87,6 @@
<Compile Include="Src\Design\FakeProjectBuilder.cs" />
<Compile Include="Src\Design\FakeSelectedProject.cs" />
<Compile Include="Src\DocumentLoader.cs" />
<Compile Include="Src\DocumentNamespaceCreator.cs" />
<Compile Include="Src\DomRegionExtensions.cs" />
<Compile Include="Src\EnvDTE\CodeAttribute.cs" />
<Compile Include="Src\EnvDTE\CodeAttribute2.cs" />
@ -99,8 +98,6 @@ @@ -99,8 +98,6 @@
<Compile Include="Src\EnvDTE\CodeElementsList.cs" />
<Compile Include="Src\EnvDTE\CodeFunction.cs" />
<Compile Include="Src\EnvDTE\CodeFunction2.cs" />
<Compile Include="Src\EnvDTE\CodeGetterFunction.cs" />
<Compile Include="Src\EnvDTE\CodeGetterOrSetterFunction.cs" />
<Compile Include="Src\EnvDTE\CodeImport.cs" />
<Compile Include="Src\EnvDTE\CodeInterface.cs" />
<Compile Include="Src\EnvDTE\CodeModelContext.cs" />
@ -110,7 +107,6 @@ @@ -110,7 +107,6 @@
<Compile Include="Src\EnvDTE\CodeParameter.cs" />
<Compile Include="Src\EnvDTE\CodeProperty.cs" />
<Compile Include="Src\EnvDTE\CodeProperty2.cs" />
<Compile Include="Src\EnvDTE\CodeSetterFunction.cs" />
<Compile Include="Src\EnvDTE\CodeStruct.cs" />
<Compile Include="Src\EnvDTE\CodeType.cs" />
<Compile Include="Src\EnvDTE\CodeTypeRef.cs" />
@ -145,7 +141,6 @@ @@ -145,7 +141,6 @@
<Compile Include="Src\EnvDTE\TextPoint.cs" />
<Compile Include="Src\EnvDTE\Window.cs" />
<Compile Include="Src\IClassKindUpdater.cs" />
<Compile Include="Src\IDocumentNamespaceCreator.cs" />
<Compile Include="Src\IPackageExtensions.cs" />
<Compile Include="Src\IProjectBuilder.cs" />
<Compile Include="Src\IProjectContentExtensions.cs" />
@ -221,7 +216,6 @@ @@ -221,7 +216,6 @@
<Compile Include="Src\PackageLicenseViewModel.cs" />
<Compile Include="Src\PackageManagementServiceProvider.cs" />
<Compile Include="Src\ProjectBuilder.cs" />
<Compile Include="Src\VirtualMethodUpdater.cs" />
<Compile Include="Src\OpenMSBuildProjects.cs" />
<Compile Include="Src\PackageActionRunner.cs" />
<Compile Include="Src\PackageActionsToRun.cs" />

27
src/AddIns/Misc/PackageManagement/Project/Src/DocumentNamespaceCreator.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop;
//using ICSharpCode.SharpDevelop.Dom;
//using ICSharpCode.SharpDevelop.Editor;
//using ICSharpCode.SharpDevelop.Gui;
//using ICSharpCode.SharpDevelop.Refactoring;
//
//namespace ICSharpCode.PackageManagement
//{
// public class DocumentNamespaceCreator : IDocumentNamespaceCreator
// {
// public void AddNamespace(ICompilationUnit compilationUnit, string newNamespace)
// {
// if (WorkbenchSingleton.InvokeRequired) {
// WorkbenchSingleton.SafeThreadCall(() => AddNamespace(compilationUnit, newNamespace));
// } else {
// IViewContent view = FileService.OpenFile(compilationUnit.FileName);
// var textEditor = view as ITextEditorProvider;
// IDocument document = textEditor.TextEditor.Document;
// NamespaceRefactoringService.AddUsingDeclaration(compilationUnit, document, newNamespace, false);
// }
// }
// }
//}

29
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs

@ -35,8 +35,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -35,8 +35,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{
switch (m.SymbolKind) {
case SymbolKind.Field:
// return new CodeVariable(m);
throw new NotImplementedException();
return new CodeVariable(context, (IFieldModel)m);
case SymbolKind.Property:
case SymbolKind.Indexer:
// return new CodeProperty2(m);
@ -47,8 +46,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -47,8 +46,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
case SymbolKind.Operator:
case SymbolKind.Constructor:
case SymbolKind.Destructor:
// return new CodeFunction2(m);
throw new NotImplementedException();
return new CodeFunction2(context, (IMethodModel)m);
default:
throw new NotSupportedException("Invalid value for SymbolKind");
}
@ -63,12 +61,18 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -63,12 +61,18 @@ namespace ICSharpCode.PackageManagement.EnvDTE
// default is vsCMPart.vsCMPartWholeWithAttributes
public virtual global::EnvDTE.TextPoint GetStartPoint()
{
return null;
if (symbolModel != null)
return TextPoint.CreateStartPoint(context, symbolModel.Region);
else
return null;
}
public virtual global::EnvDTE.TextPoint GetEndPoint()
{
return null;
if (symbolModel != null)
return TextPoint.CreateEndPoint(context, symbolModel.Region);
else
return null;
}
public virtual global::EnvDTE.vsCMInfoLocation InfoLocation {
@ -100,6 +104,19 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -100,6 +104,19 @@ namespace ICSharpCode.PackageManagement.EnvDTE
return context.FilteredFileName == region.FileName;
}
protected CodeElementsList<CodeAttribute2> GetAttributes(IEntityModel entityModel)
{
var list = new CodeElementsList<CodeAttribute2>();
var td = entityModel.Resolve();
if (td != null) {
foreach (var attr in td.Attributes) {
if (IsInFilter(attr.Region))
list.Add(new CodeAttribute2(context, attr));
}
}
return list;
}
protected override bool GetIsDerivedFrom(string fullName)
{
return false;

198
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction.cs

@ -1,98 +1,100 @@ @@ -1,98 +1,100 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeFunction : CodeElement, global::EnvDTE.CodeFunction
// {
// IDocumentLoader documentLoader;
// IVirtualMethodUpdater methodUpdater;
//
// public CodeFunction(IMethod method)
// : this(method, new DocumentLoader(), new VirtualMethodUpdater(method))
// {
// }
//
// public CodeFunction(IMethod method, IDocumentLoader documentLoader, IVirtualMethodUpdater methodUpdater)
// : base(method)
// {
// this.Method = method;
// this.documentLoader = documentLoader;
// this.methodUpdater = methodUpdater;
// }
//
// public CodeFunction()
// {
// }
//
// public CodeFunction(IProperty property)
// : base(property)
// {
// }
//
// protected IMethodOrProperty Method { get; private set; }
//
// public override global::EnvDTE.vsCMElement Kind {
// get { return global::EnvDTE.vsCMElement.vsCMElementFunction; }
// }
//
// public virtual global::EnvDTE.vsCMAccess Access {
// get { return GetAccess(); }
// set { }
// }
//
// public override global::EnvDTE.TextPoint GetStartPoint()
// {
// return new TextPoint(Method.GetStartPosition(), documentLoader);
// }
//
// public override global::EnvDTE.TextPoint GetEndPoint()
// {
// return new TextPoint(Method.GetEndPosition(), documentLoader);
// }
//
// public virtual global::EnvDTE.CodeElements Parameters {
// get { return new CodeParameters(Method.ProjectContent, Method.Parameters); }
// }
//
// public virtual global::EnvDTE.CodeTypeRef2 Type {
// get { return new CodeTypeRef2(Method.ProjectContent, this, Method.ReturnType); }
// }
//
// public virtual global::EnvDTE.CodeElements Attributes {
// get { return new CodeAttributes(Method); }
// }
//
// public virtual bool CanOverride {
// get { return Method.IsOverridable; }
// set {
// if (value) {
// methodUpdater.MakeMethodVirtual();
// }
// }
// }
//
// public virtual global::EnvDTE.vsCMFunction FunctionKind {
// get { return GetFunctionKind(); }
// }
//
// global::EnvDTE.vsCMFunction GetFunctionKind()
// {
// if (Method.IsConstructor()) {
// return global::EnvDTE.vsCMFunction.vsCMFunctionConstructor;
// }
// return global::EnvDTE.vsCMFunction.vsCMFunctionFunction;
// }
//
// public virtual bool IsShared {
// get { return Method.IsStatic; }
// }
//
// public virtual bool MustImplement {
// get { return Method.IsAbstract; }
// }
// }
//}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class CodeFunction : CodeElement, global::EnvDTE.CodeFunction
{
protected readonly IMethodModel methodModel;
public CodeFunction(CodeModelContext context, IMethodModel methodModel)
: base(context, methodModel)
{
}
public CodeFunction()
{
}
public override global::EnvDTE.vsCMElement Kind {
get { return global::EnvDTE.vsCMElement.vsCMElementFunction; }
}
public virtual global::EnvDTE.vsCMAccess Access {
get { return methodModel.Accessibility.ToAccess(); }
set {
var method = methodModel.Resolve();
if (method == null)
throw new NotSupportedException();
context.CodeGenerator.ChangeAccessibility(method, value.ToAccessibility());
}
}
public virtual global::EnvDTE.CodeElements Parameters {
get {
var list = new CodeElementsList<CodeParameter2>();
var method = (IParameterizedMember)methodModel.Resolve();
if (method != null) {
foreach (var p in method.Parameters) {
list.Add(new CodeParameter2(context, p));
}
}
return list;
}
}
public virtual global::EnvDTE.CodeTypeRef2 Type {
get {
var method = methodModel.Resolve();
if (method == null)
return null;
return new CodeTypeRef2(context, this, method.ReturnType);
}
}
public virtual global::EnvDTE.CodeElements Attributes {
get { return GetAttributes(methodModel); }
}
public virtual bool CanOverride {
get { return methodModel.IsOverridable; }
set {
if (value && !methodModel.IsOverridable) {
var method = methodModel.Resolve();
if (method != null) {
context.CodeGenerator.MakeVirtual(method);
}
}
}
}
public virtual global::EnvDTE.vsCMFunction FunctionKind {
get { return GetFunctionKind(); }
}
global::EnvDTE.vsCMFunction GetFunctionKind()
{
switch (methodModel.SymbolKind) {
case SymbolKind.Constructor:
return global::EnvDTE.vsCMFunction.vsCMFunctionConstructor;
//case SymbolKind.Destructor:
//case SymbolKind.Accessor:
//case SymbolKind.Operator:
default:
return global::EnvDTE.vsCMFunction.vsCMFunctionFunction;
}
}
public virtual bool IsShared {
get { return methodModel.IsStatic; }
}
public virtual bool MustImplement {
get { return methodModel.IsAbstract; }
}
}
}

80
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction2.cs

@ -1,40 +1,40 @@ @@ -1,40 +1,40 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeFunction2 : CodeFunction, global::EnvDTE.CodeFunction2
// {
// public CodeFunction2(IMethod method)
// : base(method)
// {
// }
//
// public virtual bool IsGeneric {
// get { return Method.HasTypeParameters(); }
// }
//
// public virtual global::EnvDTE.vsCMOverrideKind OverrideKind {
// get { return GetOverrideKind(); }
// }
//
// global::EnvDTE.vsCMOverrideKind GetOverrideKind()
// {
// if (Method.IsAbstract) {
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindAbstract;
// } else if (Method.IsVirtual) {
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindVirtual;
// } else if (Method.IsOverride) {
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindOverride;
// } else if (Method.IsSealed) {
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindSealed;
// } else if (Method.IsNew) {
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindNew;
// }
// return global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindNone;
// }
// }
//}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class CodeFunction2 : CodeFunction, global::EnvDTE.CodeFunction2
{
public CodeFunction2(CodeModelContext context, IMethodModel methodModel)
: base(context, methodModel)
{
}
public virtual bool IsGeneric {
get { return methodModel.TypeParameterCount > 0; }
}
public virtual global::EnvDTE.vsCMOverrideKind OverrideKind {
get { return GetOverrideKind(); }
}
global::EnvDTE.vsCMOverrideKind GetOverrideKind()
{
global::EnvDTE.vsCMOverrideKind kind = 0;
if (methodModel.IsAbstract)
kind |= global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindAbstract;
if (methodModel.IsOverride)
kind |= global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindOverride;
if (methodModel.IsVirtual && !methodModel.IsAbstract && !methodModel.IsOverride)
kind |= global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindVirtual;
if (methodModel.IsSealed)
kind |= global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindSealed;
if (methodModel.IsShadowing)
kind |= global::EnvDTE.vsCMOverrideKind.vsCMOverrideKindNew;
return kind;
}
}
}

16
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeGetterFunction.cs

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeGetterFunction : CodeGetterOrSetterFunction
// {
// public CodeGetterFunction(IProperty property)
// : base(property, property.GetterModifiers)
// {
// }
// }
//}

29
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeGetterOrSetterFunction.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeGetterOrSetterFunction : CodeFunction
// {
// ModifierEnum modifier;
//
// public CodeGetterOrSetterFunction(IProperty property, ModifierEnum modifier)
// : base(property)
// {
// this.modifier = modifier;
// }
//
// public override global::EnvDTE.vsCMAccess Access {
// get {
// if (modifier == ModifierEnum.None) {
// return base.Access;
// }
// return global::EnvDTE.vsCMAccess.vsCMAccessPrivate;
// }
// set { }
// }
// }
//}

73
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeImport.cs

@ -1,40 +1,33 @@ @@ -1,40 +1,33 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using System.Linq;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeImport : CodeElement, global::EnvDTE.CodeImport
// {
// IUsing import;
//
// public CodeImport()
// {
// }
//
// public CodeImport(IUsing import)
// {
// this.import = import;
// this.Namespace = GetNamespace();
// }
//
// string GetNamespace()
// {
// if (import.Usings.Any()) {
// return import.Usings.First();
// } else if (import.HasAliases) {
// return import.Aliases.Values.First().FullyQualifiedName;
// }
// return String.Empty;
// }
//
// public string Namespace { get; private set; }
//
// public override global::EnvDTE.vsCMElement Kind {
// get { return global::EnvDTE.vsCMElement.vsCMElementImportStmt; }
// }
// }
//}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class CodeImport : CodeElement, global::EnvDTE.CodeImport
{
string namespaceName;
public CodeImport()
{
}
public CodeImport(string namespaceName)
{
this.namespaceName = namespaceName;
}
public string Namespace {
get {
return namespaceName;
}
}
public override global::EnvDTE.vsCMElement Kind {
get { return global::EnvDTE.vsCMElement.vsCMElementImportStmt; }
}
}
}

24
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeNamespace.cs

@ -9,7 +9,8 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -9,7 +9,8 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{
public class CodeNamespace : CodeElement, global::EnvDTE.CodeNamespace
{
readonly INamespaceModel model;
readonly string fullName;
INamespaceModel model;
public CodeNamespace(CodeModelContext context, INamespaceModel model)
: base(context, model)
@ -17,6 +18,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -17,6 +18,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE
this.model = model;
}
public CodeNamespace(CodeModelContext context, string fullName)
: base(context)
{
this.fullName = fullName;
}
public override global::EnvDTE.vsCMElement Kind {
get { return global::EnvDTE.vsCMElement.vsCMElementNamespace; }
}
@ -26,14 +33,21 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -26,14 +33,21 @@ namespace ICSharpCode.PackageManagement.EnvDTE
}
public string FullName {
get { return model.FullName; }
get { return fullName; }
}
CodeElementsList<CodeElement> members;
public virtual global::EnvDTE.CodeElements Members {
get {
IModelCollection<CodeElement> namespaceMembers = model.ChildNamespaces.Select(ns => new CodeNamespace(context, ns));
IModelCollection<CodeElement> typeMembers = model.Types.Select(td => CodeType.Create(context, td));
return namespaceMembers.Concat(typeMembers).AsCodeElements();
if (members == null) {
if (model == null)
throw new NotSupportedException();
IModelCollection<CodeElement> namespaceMembers = model.ChildNamespaces.Select(ns => new CodeNamespace(context, ns));
IModelCollection<CodeElement> typeMembers = model.Types.Select(td => CodeType.Create(context, td));
members = namespaceMembers.Concat(typeMembers).AsCodeElements();
}
return members;
}
}
}

16
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeSetterFunction.cs

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class CodeSetterFunction : CodeGetterOrSetterFunction
// {
// public CodeSetterFunction(IProperty property)
// : base(property, property.SetterModifiers)
// {
// }
// }
//}

20
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeType.cs

@ -66,7 +66,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -66,7 +66,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public virtual global::EnvDTE.vsCMAccess Access {
get { return typeModel.Accessibility.ToAccess(); }
set {
set {
var td = typeModel.Resolve();
if (td != null) {
context.CodeGenerator.ChangeAccessibility(td, value.ToAccessibility());
@ -125,24 +125,16 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -125,24 +125,16 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public virtual global::EnvDTE.CodeElements Attributes {
get {
var list = new CodeElementsList<CodeAttribute2>();
var td = typeModel.Resolve();
if (td != null) {
foreach (var attr in td.Attributes) {
if (IsInFilter(attr.Region))
list.Add(new CodeAttribute2(context, attr));
}
}
return list;
return GetAttributes(typeModel);
}
}
public virtual global::EnvDTE.CodeNamespace Namespace {
get {
throw new NotImplementedException();
// if (context.FilteredFileName != null)
// ...
// else
if (context.FilteredFileName != null)
return new FileCodeModel2(context).GetNamespace(typeModel.Namespace);
else
throw new NotImplementedException();
// return new CodeNamespace(context, typeModel.Namespace);
}
}

10
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs

@ -33,15 +33,5 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -33,15 +33,5 @@ namespace ICSharpCode.PackageManagement.EnvDTE
}
}
}
public override global::EnvDTE.TextPoint GetStartPoint()
{
return TextPoint.CreateStartPoint(context, field.Region);
}
public override global::EnvDTE.TextPoint GetEndPoint()
{
return TextPoint.CreateEndPoint(context, field.Region);
}
}
}

134
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModel2.cs

@ -1,45 +1,89 @@ @@ -1,45 +1,89 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//using ICSharpCode.SharpDevelop.Project;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// public class FileCodeModel2 : MarshalByRefObject, global::EnvDTE.FileCodeModel2
// {
// Project project;
// FileProjectItem projectItem;
// IDocumentNamespaceCreator namespaceCreator;
//
// public FileCodeModel2(Project project, FileProjectItem projectItem)
// : this(project, projectItem, new DocumentNamespaceCreator())
// {
// }
//
// public FileCodeModel2(
// Project project,
// FileProjectItem projectItem,
// IDocumentNamespaceCreator namespaceCreator)
// {
// this.project = project;
// this.projectItem = projectItem;
// this.namespaceCreator = namespaceCreator;
// }
//
// public global::EnvDTE.CodeElements CodeElements {
// get { return new FileCodeModelCodeElements(GetCompilationUnit()); }
// }
//
// public void AddImport(string name, object position = null, string alias = null)
// {
// namespaceCreator.AddNamespace(GetCompilationUnit(), name);
// }
//
// ICompilationUnit GetCompilationUnit()
// {
// return project.GetCompilationUnit(projectItem.FileName);
// }
// }
//}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class FileCodeModel2 : MarshalByRefObject, global::EnvDTE.FileCodeModel2
{
readonly CodeModelContext context;
CodeElementsList<CodeElement> codeElements = new CodeElementsList<CodeElement>();
Dictionary<string, FileCodeModelCodeNamespace> namespaces = new Dictionary<string, FileCodeModelCodeNamespace>();
public FileCodeModel2(CodeModelContext context)
{
if (context == null || context.FilteredFileName == null)
throw new ArgumentException("context must be restricted to a file");
this.context = context;
var compilation = SD.ParserService.GetCompilation(context.CurrentProject);
var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
if (projectContent != null) {
IUnresolvedFile file = projectContent.GetFile(context.FilteredFileName);
if (file != null) {
var csharpFile = file as CSharpUnresolvedFile;
if (csharpFile != null)
AddUsings(codeElements, csharpFile.RootUsingScope, compilation);
var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly);
AddTypes(file.TopLevelTypeDefinitions
.Select(td => td.Resolve(resolveContext) as ITypeDefinition)
.Where(td => td != null).Distinct());
}
}
}
public global::EnvDTE.CodeElements CodeElements {
get { return codeElements; }
}
void AddTypes(IEnumerable<ITypeDefinition> types)
{
foreach (var td in types) {
var model = td.GetModel();
if (model == null)
continue;
var codeType = CodeType.Create(context, td);
if (string.IsNullOrEmpty(td.Namespace))
codeElements.Add(codeType);
else
GetNamespace(td.Namespace).AddMember(codeType);
}
codeElements.AddRange(types.Select(td => CodeType.Create(context, td)));
}
public static void AddUsings(CodeElementsList<CodeElement> codeElements, UsingScope usingScope, ICompilation compilation)
{
var resolvedUsingScope = usingScope.Resolve(compilation);
foreach (var ns in resolvedUsingScope.Usings) {
codeElements.Add(new CodeImport(ns.FullName));
}
}
public void AddImport(string name, object position = null, string alias = null)
{
context.CodeGenerator.AddImport(FileName.Create(context.FilteredFileName), name);
}
internal FileCodeModelCodeNamespace GetNamespace(string namespaceName)
{
FileCodeModelCodeNamespace ns;
if (!namespaces.TryGetValue(namespaceName, out ns)) {
ns = new FileCodeModelCodeNamespace(context, namespaceName);
namespaces.Add(namespaceName, ns);
codeElements.Add(ns);
}
return null;
}
}
}

78
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FileCodeModelCodeNamespace.cs

@ -1,36 +1,42 @@ @@ -1,36 +1,42 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement.EnvDTE
//{
// /// <summary>
// /// File code model namespaces take the full name of the namespace that a class
// /// is inside. So for the FileCodeModelNamespace class the CodeNamespace.Name
// /// would be ICSharpCode.PackageManagement.EnvDTE.
// /// This differs from the CodeModel CodeNamespace which breaks up the namespaces into
// /// parts.
// /// </summary>
// public class FileCodeModelCodeNamespace : CodeNamespace
// {
// public FileCodeModelCodeNamespace(IProjectContent projectContent, string namespaceName)
// : base(projectContent, namespaceName)
// {
// }
//
// public override string Name {
// get { return base.FullName; }
// }
//
// public override global::EnvDTE.CodeElements Members {
// get { return members; }
// }
//
// public void AddClass(IProjectContent projectContent, IClass c)
// {
// members.AddClass(projectContent, c);
// }
// }
//}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement.EnvDTE
{
/// <summary>
/// File code model namespaces take the full name of the namespace that a class
/// is inside. So for the FileCodeModelNamespace class the CodeNamespace.Name
/// would be ICSharpCode.PackageManagement.EnvDTE.
/// This differs from the CodeModel CodeNamespace which breaks up the namespaces into
/// parts.
/// </summary>
public class FileCodeModelCodeNamespace : CodeNamespace
{
public FileCodeModelCodeNamespace(CodeModelContext context, string namespaceName)
: base(context, namespaceName)
{
}
public override string Name {
get { return base.FullName; }
}
public override global::EnvDTE.vsCMInfoLocation InfoLocation {
get { return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject; }
}
CodeElementsList<CodeElement> members = new CodeElementsList<CodeElement>();
public override global::EnvDTE.CodeElements Members {
get { return members; }
}
internal void AddMember(CodeElement member)
{
members.Add(member);
}
}
}

13
src/AddIns/Misc/PackageManagement/Project/Src/IDocumentNamespaceCreator.cs

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.PackageManagement
//{
// public interface IDocumentNamespaceCreator
// {
// void AddNamespace(ICompilationUnit compilationUnit, string newNamespace);
// }
//}

67
src/AddIns/Misc/PackageManagement/Project/Src/VirtualMethodUpdater.cs

@ -1,67 +0,0 @@ @@ -1,67 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using ICSharpCode.SharpDevelop.Dom;
//using ICSharpCode.SharpDevelop.Dom.Refactoring;
//
//namespace ICSharpCode.PackageManagement
//{
// public class VirtualMethodUpdater : IVirtualMethodUpdater
// {
// public VirtualMethodUpdater(IMethod method)
// : this(method, new DocumentLoader())
// {
// }
//
// public VirtualMethodUpdater(IMethod method, IDocumentLoader documentLoader)
// {
// this.Method = method;
// this.DocumentLoader = documentLoader;
// }
//
// IMethod Method { get; set; }
// IDocumentLoader DocumentLoader { get; set; }
// IRefactoringDocument Document { get; set; }
//
// public void MakeMethodVirtual()
// {
// if (Method.IsVirtual)
// return;
//
// OpenFileContainingMethod();
// int offset = GetVirtualKeywordInsertOffset();
// InsertVirtualKeyword(offset);
// }
//
// void OpenFileContainingMethod()
// {
// Document = DocumentLoader.LoadRefactoringDocument(Method.CompilationUnit.FileName);
// }
//
// int GetVirtualKeywordInsertOffset()
// {
// IRefactoringDocumentLine line = Document.GetLine(Method.Region.BeginLine);
// int offset = line.Text.IndexOf("public ", StringComparison.OrdinalIgnoreCase);
// if (offset >= 0) {
// int publicKeywordLength = 6;
// return offset + line.Offset + publicKeywordLength + 1;
// }
// throw new ApplicationException("Unable to find 'method' declaration.");
// }
//
// void InsertVirtualKeyword(int offset)
// {
// string virtualKeyword = GetLanguageSpecificVirtualKeyword();
// Document.Insert(offset, virtualKeyword + " ");
// }
//
// string GetLanguageSpecificVirtualKeyword()
// {
// if (Method.ProjectContent.Language == LanguageProperties.VBNet) {
// return "Overridable";
// }
// return "virtual";
// }
// }
//}

1
src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/vsCMOverrideKind.vb

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
' This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
Namespace EnvDTE
<Flags>
Public Enum vsCMOverrideKind
vsCMOverrideKindNone = 0
vsCMOverrideKindAbstract = 1

5
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/ICSharpCode.Reports.Addin.csproj

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>125829120</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
@ -58,9 +58,6 @@ @@ -58,9 +58,6 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="itextsharp">
<HintPath>..\Libraries\itextsharp.dll</HintPath>

5
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>123731968</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
@ -55,9 +55,6 @@ @@ -55,9 +55,6 @@
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Irony">
<HintPath>..\Libraries\Irony.dll</HintPath>

16
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs

@ -338,7 +338,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -338,7 +338,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
AstType ConvertNamespace(string ns)
public AstType ConvertNamespace(string namespaceName)
{
if (resolver != null) {
// Look if there's an alias to the target namespace
@ -346,27 +346,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -346,27 +346,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
for (ResolvedUsingScope usingScope = resolver.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent) {
foreach (var pair in usingScope.UsingAliases) {
NamespaceResolveResult nrr = pair.Value as NamespaceResolveResult;
if (nrr != null && nrr.NamespaceName == ns)
if (nrr != null && nrr.NamespaceName == namespaceName)
return new SimpleType(pair.Key);
}
}
}
}
int pos = ns.LastIndexOf('.');
int pos = namespaceName.LastIndexOf('.');
if (pos < 0) {
if (IsValidNamespace(ns)) {
return new SimpleType(ns);
if (IsValidNamespace(namespaceName)) {
return new SimpleType(namespaceName);
} else {
return new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = ns
MemberName = namespaceName
};
}
} else {
string parentNamespace = ns.Substring(0, pos);
string localNamespace = ns.Substring(pos + 1);
string parentNamespace = namespaceName.Substring(0, pos);
string localNamespace = namespaceName.Substring(pos + 1);
return new MemberType {
Target = ConvertNamespace(parentNamespace),
MemberName = localNamespace

3
src/Main/Base/Project/Dom/ITypeDefinitionModel.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Parser;
@ -18,6 +19,8 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -18,6 +19,8 @@ namespace ICSharpCode.SharpDevelop.Dom
IModelCollection<ITypeDefinitionModel> NestedTypes { get; }
IModelCollection<IMemberModel> Members { get; }
IEnumerable<DomRegion> GetPartRegions();
/// <summary>
/// Resolves the type definition in the current solution snapshot.
/// Returns null if the type definition could not be resolved.

6
src/Main/Base/Project/Refactoring/CodeGenerator.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project;
@ -86,5 +87,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -86,5 +87,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
throw new NotSupportedException("Feature not supported!");
}
public virtual void AddImport(FileName fileName, string namespaceName)
{
throw new NotSupportedException("Feature not supported!");
}
}
}

8
src/Main/Base/Project/Src/Editor/Commands/SymbolUnderCaretMenuCommand.cs

@ -16,24 +16,24 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands @@ -16,24 +16,24 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands
/// <summary>
/// A menu command that operates on a <see cref="ResolveResult"/>.
///
/// Supports the following types as <see cref="Owner"/>:
/// Supports the following types as <c>parameter</c>:
/// - ResolveResult
/// - IEntityModel
///
/// If the owner isn't one of the types above, the command operates on the caret position in the current editor.
/// If the parameter isn't one of the types above, the command operates on the caret position in the current editor.
/// </summary>
public abstract class ResolveResultMenuCommand : ICommand
{
public virtual event EventHandler CanExecuteChanged { add {} remove {} }
public bool CanExecute(object parameter)
bool ICommand.CanExecute(object parameter)
{
ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>();
ResolveResult resolveResult = GetResolveResult(editor, parameter);
return CanExecute(resolveResult);
}
public void Execute(object parameter)
void ICommand.Execute(object parameter)
{
ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>();
ResolveResult resolveResult = GetResolveResult(editor, parameter);

6
src/Main/Base/Project/Util/SimpleCommand.cs

@ -7,13 +7,13 @@ using System.Windows.Input; @@ -7,13 +7,13 @@ using System.Windows.Input;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// Base class for simple ICommand implementation that always returns true from CanExecute.
/// Base class for ICommand implementations.
/// </summary>
public abstract class SimpleCommand : ICommand
{
event EventHandler ICommand.CanExecuteChanged { add {} remove {} }
public virtual event EventHandler CanExecuteChanged { add {} remove {} }
bool ICommand.CanExecute(object parameter)
public virtual bool CanExecute(object parameter)
{
return true;
}

5
src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs

@ -334,5 +334,10 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -334,5 +334,10 @@ namespace ICSharpCode.SharpDevelop.Dom
public bool IsShadowing {
get { return parts.Any(p => p.IsShadowing); }
}
public IEnumerable<DomRegion> GetPartRegions()
{
return parts.Select(p => p.Region);
}
}
}

Loading…
Cancel
Save