Browse Source

Improved support for partial classes.

Improved C# new completion.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@247 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
4c1a238309
  1. 20
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs
  2. 97
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs
  3. 7
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  4. 8
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs
  5. 7
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs
  6. 7
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  7. 78
      src/Main/Base/Project/Src/Dom/ClassFinder.cs
  8. 2
      src/Main/Base/Project/Src/Dom/IClass.cs
  9. 4
      src/Main/Base/Project/Src/Dom/IParser.cs
  10. 7
      src/Main/Base/Project/Src/Dom/Implementations/AbstractNamedEntity.cs
  11. 8
      src/Main/Base/Project/Src/Dom/Implementations/CompoundClass.cs
  12. 57
      src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs
  13. 19
      src/Main/Base/Project/Src/Dom/Implementations/GetClassReturnType.cs
  14. 15
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  15. 2
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs
  16. 2
      src/Main/Base/Project/Src/Dom/ReflectionLayer/ReflectionClass.cs
  17. 17
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  18. 98
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs

20
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs

@ -29,7 +29,7 @@ namespace CSharpBinding
{ {
if (!CheckExtension(editor)) if (!CheckExtension(editor))
return false; return false;
CSharpBinding.Parser.ExpressionFinder ef = new CSharpBinding.Parser.ExpressionFinder(); Parser.ExpressionFinder ef = new Parser.ExpressionFinder(editor.FileName);
int cursor = editor.ActiveTextAreaControl.Caret.Offset; int cursor = editor.ActiveTextAreaControl.Caret.Offset;
ExpressionContext context = null; ExpressionContext context = null;
if (ch == '(') { if (ch == '(') {
@ -175,11 +175,25 @@ namespace CSharpBinding
editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' '); editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' ');
return true; return true;
case "new": case "new":
editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.ObjectCreation), ' '); return ShowNewCompletion(editor);
return true; case "override":
// TODO: Suggest list of virtual methods to override
return false;
default: default:
return base.HandleKeyword(editor, word); return base.HandleKeyword(editor, word);
} }
} }
bool ShowNewCompletion(SharpDevelopTextAreaControl editor)
{
Parser.ExpressionFinder ef = new Parser.ExpressionFinder(editor.FileName);
int cursor = editor.ActiveTextAreaControl.Caret.Offset;
ExpressionContext context = ef.FindExpression(editor.Document.GetText(0, cursor) + " T.", cursor + 2).Context;
if (context.IsObjectCreation) {
editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ' ');
return true;
}
return false;
}
} }
} }

97
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Text; using System.Text;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
namespace CSharpBinding.Parser namespace CSharpBinding.Parser
@ -16,6 +17,13 @@ namespace CSharpBinding.Parser
/// </summary> /// </summary>
public class ExpressionFinder : IExpressionFinder public class ExpressionFinder : IExpressionFinder
{ {
string fileName;
public ExpressionFinder(string fileName)
{
this.fileName = fileName;
}
#region Capture Context #region Capture Context
ExpressionResult CreateResult(string expression, string inText, int offset) ExpressionResult CreateResult(string expression, string inText, int offset)
{ {
@ -23,13 +31,60 @@ namespace CSharpBinding.Parser
return new ExpressionResult(null); return new ExpressionResult(null);
if (expression.StartsWith("using ")) if (expression.StartsWith("using "))
return new ExpressionResult(expression.Substring(6).TrimStart(), ExpressionContext.Namespace, null); return new ExpressionResult(expression.Substring(6).TrimStart(), ExpressionContext.Namespace, null);
if (!hadParenthesis && expression.StartsWith("new ")) if (!hadParenthesis && expression.StartsWith("new ")) {
return new ExpressionResult(expression.Substring(4).TrimStart(), ExpressionContext.ObjectCreation, null); return new ExpressionResult(expression.Substring(4).TrimStart(), GetCreationContext(), null);
}
if (IsInAttribute(inText, offset)) if (IsInAttribute(inText, offset))
return new ExpressionResult(expression, ExpressionContext.Attribute); return new ExpressionResult(expression, ExpressionContext.Attribute);
return new ExpressionResult(expression); return new ExpressionResult(expression);
} }
ExpressionContext GetCreationContext()
{
UnGetToken();
if (GetNextNonWhiteSpace() == '=') { // was: "= new"
ReadNextToken();
if (curTokenType == Ident) { // was: "ident = new"
int typeEnd = offset;
ReadNextToken();
int typeStart = -1;
while (curTokenType == Ident) {
typeStart = offset + 1;
ReadNextToken();
if (curTokenType == Dot) {
ReadNextToken();
} else {
break;
}
}
if (typeStart >= 0) {
string className = text.Substring(typeStart, typeEnd - typeStart);
int pos = className.IndexOf('<');
string nonGenericClassName;
if (pos > 0)
nonGenericClassName = className.Substring(0, pos);
else
nonGenericClassName = className;
ClassFinder finder = new ClassFinder(fileName, text, typeStart);
IClass c = finder.SearchClass(nonGenericClassName);
if (c != null) {
ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true);
if (context.ShowEntry(c))
context.SuggestedItem = c;
return context;
}
}
}
} else {
UnGet();
ReadNextToken();
if (curTokenType == Ident && lastIdentifier == "throw") {
return ExpressionContext.TypeDerivingFrom(ProjectContentRegistry.Mscorlib.GetClass("System.Exception"), true);
}
}
return ExpressionContext.ObjectCreation;
}
bool IsInAttribute(string txt, int offset) bool IsInAttribute(string txt, int offset)
{ {
// Get line start: // Get line start:
@ -93,6 +148,7 @@ namespace CSharpBinding.Parser
lastAccept = this.offset; lastAccept = this.offset;
} }
if (state == ACCEPTNOMORE) { if (state == ACCEPTNOMORE) {
lastExpressionStartPosition = offset + 1;
return this.text.Substring(this.offset + 1, offset - this.offset); return this.text.Substring(this.offset + 1, offset - this.offset);
} }
} }
@ -100,12 +156,16 @@ namespace CSharpBinding.Parser
if (lastAccept < 0) if (lastAccept < 0)
return null; return null;
lastExpressionStartPosition = lastAccept + 1;
return this.text.Substring(this.lastAccept + 1, offset - this.lastAccept); return this.text.Substring(this.lastAccept + 1, offset - this.lastAccept);
} }
int lastExpressionStartPosition;
internal int LastExpressionStartPosition { internal int LastExpressionStartPosition {
get { get {
return ((state == ACCEPTNOMORE) ? offset : lastAccept) + 1; return lastExpressionStartPosition;
} }
} }
#endregion #endregion
@ -421,6 +481,15 @@ namespace CSharpBinding.Parser
return '\0'; return '\0';
} }
char GetNextNonWhiteSpace()
{
char ch;
do {
ch = GetNext();
} while (char.IsWhiteSpace(ch));
return ch;
}
char Peek(int n) char Peek(int n)
{ {
if (offset - n >= 0) { if (offset - n >= 0) {
@ -442,6 +511,13 @@ namespace CSharpBinding.Parser
++offset; ++offset;
} }
void UnGetToken()
{
do {
UnGet();
} while (char.IsLetterOrDigit(Peek()));
}
// tokens for our lexer // tokens for our lexer
static int Err = 0; static int Err = 0;
static int Dot = 1; static int Dot = 1;
@ -470,17 +546,17 @@ namespace CSharpBinding.Parser
/// </summary> /// </summary>
bool hadParenthesis; bool hadParenthesis;
string lastIdentifier;
void ReadNextToken() void ReadNextToken()
{ {
char ch;
curTokenType = Err; curTokenType = Err;
do { char ch = GetNextNonWhiteSpace();
ch = GetNext(); if (ch == '\0') {
if (ch == '\0') { return;
return; }
}
} while (Char.IsWhiteSpace(ch));
switch (ch) { switch (ch) {
@ -537,6 +613,7 @@ namespace CSharpBinding.Parser
break; break;
default: default:
curTokenType = Ident; curTokenType = Ident;
lastIdentifier = ident;
break; break;
} }
} }

7
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -32,10 +32,9 @@ namespace CSharpBinding.Parser
} }
} }
public IExpressionFinder ExpressionFinder { public IExpressionFinder CreateExpressionFinder(string fileName)
get { {
return new ExpressionFinder(); return new ExpressionFinder(fileName);
}
} }
public bool CanParse(string fileName) public bool CanParse(string fileName)

8
src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs

@ -114,8 +114,14 @@ namespace VBNetBinding
public override List<IProperty> Properties { public override List<IProperty> Properties {
get { get {
List<IProperty> properties = new List<IProperty>(); List<IProperty> properties = new List<IProperty>();
IProjectContent pc = ProjectContentRegistry.GetExistingProjectContent(new System.Reflection.AssemblyName("System.Windows.Forms"));
if (pc == null)
return properties;
IClass formClass = pc.GetClass("System.Windows.Forms.Form");
if (formClass == null)
return properties;
foreach (IClass c in this.ProjectContent.Classes) { foreach (IClass c in this.ProjectContent.Classes) {
if (c.BaseTypes.Contains("System.Windows.Forms.Form")) { if (c.BaseClass == formClass) {
properties.Add(new DefaultProperty(c.Name, properties.Add(new DefaultProperty(c.Name,
new GetClassReturnType(this.ProjectContent, c.FullyQualifiedName), new GetClassReturnType(this.ProjectContent, c.FullyQualifiedName),
ModifierEnum.Public | ModifierEnum.Static, ModifierEnum.Public | ModifierEnum.Static,

7
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs

@ -35,12 +35,9 @@ namespace VBNetBinding.Parser
} }
} }
public IExpressionFinder ExpressionFinder public IExpressionFinder CreateExpressionFinder(string fileName)
{ {
get return new ExpressionFinder();
{
return new ExpressionFinder();
}
} }
public bool CanParse(string fileName) public bool CanParse(string fileName)

7
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -183,7 +183,7 @@
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\CommonAboutDialog.cs"> <Compile Include="Src\Gui\Dialogs\CommonAboutDialog.cs">
<SubType>Form</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\DirtyFilesDialog.cs" /> <Compile Include="Src\Gui\Dialogs\DirtyFilesDialog.cs" />
<Compile Include="Src\Gui\Dialogs\FolderDialog.cs" /> <Compile Include="Src\Gui\Dialogs\FolderDialog.cs" />
@ -202,7 +202,7 @@
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\TreeViewOptions.cs"> <Compile Include="Src\Gui\Dialogs\TreeViewOptions.cs">
<SubType>Component</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\ViewGPLDialog.cs"> <Compile Include="Src\Gui\Dialogs\ViewGPLDialog.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@ -267,7 +267,7 @@
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Pads\FileScout.cs"> <Compile Include="Src\Gui\Pads\FileScout.cs">
<SubType>UserControl</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Pads\OpenTaskView.cs" /> <Compile Include="Src\Gui\Pads\OpenTaskView.cs" />
<Compile Include="Src\Gui\Pads\PropertyPad\PropertyPad.cs" /> <Compile Include="Src\Gui\Pads\PropertyPad\PropertyPad.cs" />
@ -682,6 +682,7 @@
<Compile Include="Src\TextEditor\Gui\OptionPanels\CodeCompletionPanel.cs" /> <Compile Include="Src\TextEditor\Gui\OptionPanels\CodeCompletionPanel.cs" />
<Compile Include="Src\Dom\CodeCompletionOptions.cs" /> <Compile Include="Src\Dom\CodeCompletionOptions.cs" />
<Compile Include="Src\Services\Debugger\CurrentLineBookmark.cs" /> <Compile Include="Src\Services\Debugger\CurrentLineBookmark.cs" />
<Compile Include="Src\Dom\ClassFinder.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj"> <ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj">

78
src/Main/Base/Project/Src/Dom/ClassFinder.cs

@ -0,0 +1,78 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Dom
{
/// <summary>
/// Interface for objects that can find classes.
/// </summary>
public class ClassFinder
{
int caretLine, caretColumn;
ICompilationUnit cu;
IClass callingClass;
IProjectContent projectContent;
public ClassFinder(string fileName, string fileContent, int offset)
{
caretLine = 0;
caretColumn = 0;
for (int i = 0; i < offset; i++) {
if (fileContent[i] == '\n') {
caretLine++;
caretColumn = 0;
} else {
caretColumn++;
}
}
Init(fileName);
}
public ClassFinder(string fileName, int caretLineNumber, int caretColumn)
{
this.caretLine = caretLineNumber;
this.caretColumn = caretColumn;
Init(fileName);
}
void Init(string fileName)
{
ParseInformation parseInfo = ParserService.GetParseInformation(fileName);
if (parseInfo == null) {
return;
}
cu = parseInfo.MostRecentCompilationUnit;
if (cu != null) {
callingClass = cu.GetInnermostClass(caretLine, caretColumn);
projectContent = cu.ProjectContent;
} else {
projectContent = ParserService.CurrentProjectContent;
}
}
public IClass GetClass(string fullName)
{
return projectContent.GetClass(fullName);
}
public IClass SearchClass(string name)
{
return projectContent.SearchType(name, callingClass, cu, caretLine, caretColumn);
}
public string SearchNamespace(string name)
{
return projectContent.SearchNamespace(name, callingClass, cu, caretLine, caretColumn);
}
}
}

2
src/Main/Base/Project/Src/Dom/IClass.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.SharpDevelop.Dom
get; get;
} }
IEnumerable ClassInheritanceTree { IEnumerable<IClass> ClassInheritanceTree {
get; get;
} }

4
src/Main/Base/Project/Src/Dom/IParser.cs

@ -21,9 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom
set; set;
} }
IExpressionFinder ExpressionFinder { IExpressionFinder CreateExpressionFinder(string fileName);
get;
}
/// <summary> /// <summary>
/// Gets if the parser can parse the specified file. /// Gets if the parser can parse the specified file.

7
src/Main/Base/Project/Src/Dom/Implementations/AbstractNamedEntity.cs

@ -27,12 +27,19 @@ namespace ICSharpCode.SharpDevelop.Dom
return fullyQualifiedName; return fullyQualifiedName;
} }
set { set {
if (fullyQualifiedName == value)
return;
fullyQualifiedName = value; fullyQualifiedName = value;
name = null; name = null;
nspace = null; nspace = null;
OnFullyQualifiedNameChanged(EventArgs.Empty);
} }
} }
protected virtual void OnFullyQualifiedNameChanged(EventArgs e)
{
}
public virtual string DotNetName { public virtual string DotNetName {
get { get {
if (this.DeclaringType != null) { if (this.DeclaringType != null) {

8
src/Main/Base/Project/Src/Dom/Implementations/CompoundClass.cs

@ -61,6 +61,14 @@ namespace ICSharpCode.SharpDevelop.Dom
this.Modifiers = modifier; this.Modifiers = modifier;
} }
/// <summary>
/// CompoundClass has a normal return type even though IsPartial is set.
/// </summary>
protected override IReturnType CreateDefaultReturnType()
{
return new DefaultReturnType(this);
}
public override List<IClass> InnerClasses { public override List<IClass> InnerClasses {
get { get {
List<IClass> l = new List<IClass>(); List<IClass> l = new List<IClass>();

57
src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs

@ -64,7 +64,20 @@ namespace ICSharpCode.SharpDevelop.Dom
protected virtual IReturnType CreateDefaultReturnType() protected virtual IReturnType CreateDefaultReturnType()
{ {
return new DefaultReturnType(this); if (IsPartial) {
return new GetClassReturnType(ProjectContent, FullyQualifiedName);
} else {
return new DefaultReturnType(this);
}
}
protected override void OnFullyQualifiedNameChanged(EventArgs e)
{
base.OnFullyQualifiedNameChanged(e);
GetClassReturnType rt = defaultReturnType as GetClassReturnType;
if (rt != null) {
rt.SetFullyQualifiedName(FullyQualifiedName);
}
} }
public ICompilationUnit CompilationUnit { public ICompilationUnit CompilationUnit {
@ -207,16 +220,23 @@ namespace ICSharpCode.SharpDevelop.Dom
return CompareTo((IClass)o); return CompareTo((IClass)o);
} }
// TODO: Cache ClassInheritanceTree as it is called many times (for GetFields(), GetProperties() etc.) List<IClass> inheritanceTreeCache;
// and it is expensive to execute SearchType so often.
// ReflectionClass should cache it forever; DefaultClass only as long as no new CompilationUnits public IEnumerable<IClass> ClassInheritanceTree {
// are created.
public IEnumerable ClassInheritanceTree {
get { get {
return new ClassInheritanceEnumerator(this); if (UseInheritanceCache) {
if (inheritanceTreeCache == null) {
inheritanceTreeCache = new List<IClass>(new ClassInheritanceEnumerator(this));
}
return inheritanceTreeCache;
} else {
return new ClassInheritanceEnumerator(this);
}
} }
} }
protected bool UseInheritanceCache = false;
protected override bool CanBeSubclass { protected override bool CanBeSubclass {
get { get {
return true; return true;
@ -238,13 +258,19 @@ namespace ICSharpCode.SharpDevelop.Dom
} }
} }
IClass cachedBaseClass;
public IClass BaseClass { public IClass BaseClass {
get { get {
Debug.Assert(ProjectContent != null); Debug.Assert(ProjectContent != null);
if (BaseTypes.Count > 0) { if (BaseTypes.Count > 0) {
if (UseInheritanceCache && cachedBaseClass != null)
return cachedBaseClass;
IClass baseClass = GetBaseClass(0); IClass baseClass = GetBaseClass(0);
if (baseClass != null && baseClass.ClassType != ClassType.Interface) { if (baseClass != null && baseClass.ClassType != ClassType.Interface) {
if (UseInheritanceCache)
cachedBaseClass = baseClass;
return baseClass; return baseClass;
} }
} }
@ -397,7 +423,7 @@ namespace ICSharpCode.SharpDevelop.Dom
return members; return members;
} }
public class ClassInheritanceEnumerator : IEnumerator, IEnumerable public class ClassInheritanceEnumerator : IEnumerator<IClass>, IEnumerable<IClass>
{ {
IClass topLevelClass; IClass topLevelClass;
IClass currentClass = null; IClass currentClass = null;
@ -423,7 +449,12 @@ namespace ICSharpCode.SharpDevelop.Dom
baseTypeQueue.Enqueue(new BaseType(null, "System.Object")); baseTypeQueue.Enqueue(new BaseType(null, "System.Object"));
} }
public IEnumerator GetEnumerator() public IEnumerator<IClass> GetEnumerator()
{
return this;
}
IEnumerator IEnumerable.GetEnumerator()
{ {
return this; return this;
} }
@ -494,6 +525,14 @@ namespace ICSharpCode.SharpDevelop.Dom
PutBaseClassesOnStack(topLevelClass); PutBaseClassesOnStack(topLevelClass);
baseTypeQueue.Enqueue(new BaseType(null, "System.Object")); baseTypeQueue.Enqueue(new BaseType(null, "System.Object"));
} }
public void Dispose()
{
baseTypeQueue = null;
finishedClasses = null;
topLevelClass = null;
currentClass = null;
}
} }
} }
} }

19
src/Main/Base/Project/Src/Dom/Implementations/GetClassReturnType.cs

@ -24,12 +24,7 @@ namespace ICSharpCode.SharpDevelop.Dom
public GetClassReturnType(IProjectContent content, string fullName) public GetClassReturnType(IProjectContent content, string fullName)
{ {
this.content = content; this.content = content;
this.fullName = fullName; SetFullyQualifiedName(fullName);
int pos = fullName.LastIndexOf('.');
if (pos < 0)
shortName = fullName;
else
shortName = fullName.Substring(pos + 1);
} }
public override bool IsDefaultReturnType { public override bool IsDefaultReturnType {
@ -70,6 +65,18 @@ namespace ICSharpCode.SharpDevelop.Dom
} }
} }
public void SetFullyQualifiedName(string fullName)
{
if (fullName == null)
throw new ArgumentNullException("fullName");
this.fullName = fullName;
int pos = fullName.LastIndexOf('.');
if (pos < 0)
shortName = fullName;
else
shortName = fullName.Substring(pos + 1);
}
public override string Name { public override string Name {
get { get {
return shortName; return shortName;

15
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -134,7 +134,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (cu != null) { if (cu != null) {
callingClass = cu.GetInnermostClass(caretLine, caretColumn); callingClass = cu.GetInnermostClass(caretLine, caretColumn);
cu.FileName = fileName;
} }
Expression expr = null; Expression expr = null;
@ -195,12 +194,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{ {
if (name == null) if (name == null)
return null; return null;
IClass c = SearchType(name); IClass c = SearchClass(name);
if (c != null) { if (c != null) {
if (c.IsTypeInInheritanceTree(ProjectContentRegistry.Mscorlib.GetClass("System.Attribute"))) if (c.IsTypeInInheritanceTree(ProjectContentRegistry.Mscorlib.GetClass("System.Attribute")))
return c; return c;
} }
return SearchType(name + "Attribute"); return SearchClass(name + "Attribute");
} }
ResolveResult ResolveAttribute(Expression expr) ResolveResult ResolveAttribute(Expression expr)
@ -443,7 +442,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
ResolveResult result2 = null; ResolveResult result2 = null;
IClass c = SearchType(identifier); IClass c = SearchClass(identifier);
if (c != null) { if (c != null) {
result2 = new TypeResolveResult(callingClass, callingMember, c); result2 = new TypeResolveResult(callingClass, callingMember, c);
} else { } else {
@ -643,10 +642,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return projectContent.SearchNamespace(name, callingClass, cu, caretLine, caretColumn); return projectContent.SearchNamespace(name, callingClass, cu, caretLine, caretColumn);
} }
public IClass GetClass(string fullName)
{
return projectContent.GetClass(fullName);
}
/// <remarks> /// <remarks>
/// use the usings and the name of the namespace to find a class /// use the usings and the name of the namespace to find a class
/// </remarks> /// </remarks>
public IClass SearchType(string name) public IClass SearchClass(string name)
{ {
return projectContent.SearchType(name, callingClass, cu, caretLine, caretColumn); return projectContent.SearchType(name, callingClass, cu, caretLine, caretColumn);
} }
@ -869,7 +873,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (cu != null) { if (cu != null) {
callingClass = cu.GetInnermostClass(caretLine, caretColumn); callingClass = cu.GetInnermostClass(caretLine, caretColumn);
cu.FileName = fileName;
} }
callingMember = GetCurrentMember(); callingMember = GetCurrentMember();

2
src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

@ -290,7 +290,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (name != null && name.Length > 0) { if (name != null && name.Length > 0) {
return new NamespaceReturnType(name); return new NamespaceReturnType(name);
} }
IClass c = resolver.SearchType(identifierExpression.Identifier); IClass c = resolver.SearchClass(identifierExpression.Identifier);
if (c != null) { if (c != null) {
return c.DefaultReturnType; return c.DefaultReturnType;
} }

2
src/Main/Base/Project/Src/Dom/ReflectionLayer/ReflectionClass.cs

@ -182,6 +182,8 @@ namespace ICSharpCode.SharpDevelop.Dom
FullyQualifiedName = name; FullyQualifiedName = name;
} }
this.UseInheritanceCache = true;
try { try {
AddAttributes(compilationUnit.ProjectContent, this.Attributes, CustomAttributeData.GetCustomAttributes(type)); AddAttributes(compilationUnit.ProjectContent, this.Attributes, CustomAttributeData.GetCustomAttributes(type));
} catch (Exception ex) { } catch (Exception ex) {

17
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -399,7 +399,7 @@ namespace ICSharpCode.Core
{ {
IParser parser = GetParser(fileName); IParser parser = GetParser(fileName);
if (parser != null) { if (parser != null) {
return parser.ExpressionFinder; return parser.CreateExpressionFinder(fileName);
} }
return null; return null;
} }
@ -434,15 +434,24 @@ namespace ICSharpCode.Core
return null; return null;
} }
public static IResolver CreateResolver(string fileName)
{
IParser parser = GetParser(fileName);
if (parser != null) {
return parser.CreateResolver();
}
return null;
}
public static ResolveResult Resolve(ExpressionResult expressionResult, public static ResolveResult Resolve(ExpressionResult expressionResult,
int caretLineNumber, int caretLineNumber,
int caretColumn, int caretColumn,
string fileName, string fileName,
string fileContent) string fileContent)
{ {
IParser parser = GetParser(fileName); IResolver resolver = CreateResolver(fileName);
if (parser != null) { if (resolver != null) {
return parser.CreateResolver().Resolve(expressionResult, caretLineNumber, caretColumn, fileName, fileContent); return resolver.Resolve(expressionResult, caretLineNumber, caretColumn, fileName, fileContent);
} }
return null; return null;
} }

98
src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
object item; object item;
string text; string text;
int iconIndex; int iconIndex;
bool isInCurrentPart;
public int IconIndex { public int IconIndex {
get { get {
@ -44,6 +45,12 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
} }
} }
public bool IsInCurrentPart {
get {
return isInCurrentPart;
}
}
public IRegion ItemRegion { public IRegion ItemRegion {
get { get {
IClass classItem = item as IClass; IClass classItem = item as IClass;
@ -86,15 +93,18 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
} }
} }
public ComboBoxItem(object item, string text, int iconIndex) public ComboBoxItem(object item, string text, int iconIndex, bool isInCurrentPart)
{ {
this.item = item; this.item = item;
this.text = text; this.text = text;
this.iconIndex = iconIndex; this.iconIndex = iconIndex;
this.isInCurrentPart = isInCurrentPart;
} }
public bool IsInside(int lineNumber) public bool IsInside(int lineNumber)
{ {
if (!isInCurrentPart)
return false;
IClass classItem = item as IClass; IClass classItem = item as IClass;
if (classItem != null) { if (classItem != null) {
if (classItem.Region == null) if (classItem.Region == null)
@ -224,7 +234,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
UpdateClassComboBox(); UpdateClassComboBox();
UpdateMembersComboBox(); UpdateMembersComboBox();
} }
} catch (Exception) {} } catch (Exception ex) {
MessageService.ShowError(ex);
}
} }
bool membersComboBoxSelectedMember = false; bool membersComboBoxSelectedMember = false;
@ -323,51 +335,62 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
return false; return false;
} }
IClass lastClassInMembersComboBox;
void FillMembersComboBox() void FillMembersComboBox()
{ {
IClass c = GetCurrentSelectedClass(); IClass c = GetCurrentSelectedClass();
if (c != null) { if (c != null && lastClassInMembersComboBox != c) {
lastClassInMembersComboBox = c;
ArrayList items = new ArrayList(); ArrayList items = new ArrayList();
bool partialMode = false;
IClass currentPart = c;
if (c.IsPartial) {
CompoundClass cc = c.ProjectContent.GetClass(c.FullyQualifiedName) as CompoundClass;
if (cc != null && cc.Parts.Count > 0) {
partialMode = true;
c = cc;
}
}
int lastIndex = 0; int lastIndex = 0;
IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture); IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
foreach (IMethod m in c.Methods) { foreach (IMethod m in c.Methods) {
items.Add(new ComboBoxItem(m, m.Name, ClassBrowserIconService.GetIcon(m))); items.Add(new ComboBoxItem(m, m.Name, ClassBrowserIconService.GetIcon(m), partialMode ? currentPart.Methods.Contains(m) : true));
} }
items.Sort(lastIndex, c.Methods.Count, comparer); items.Sort(lastIndex, c.Methods.Count, comparer);
lastIndex = items.Count; lastIndex = items.Count;
foreach (IProperty p in c.Properties) { foreach (IProperty p in c.Properties) {
items.Add(new ComboBoxItem(p, p.Name, ClassBrowserIconService.GetIcon(p))); items.Add(new ComboBoxItem(p, p.Name, ClassBrowserIconService.GetIcon(p), partialMode ? currentPart.Properties.Contains(p) : true));
} }
items.Sort(lastIndex, c.Properties.Count, comparer); items.Sort(lastIndex, c.Properties.Count, comparer);
lastIndex = items.Count; lastIndex = items.Count;
foreach (IIndexer indexer in c.Indexer) { foreach (IIndexer indexer in c.Indexer) {
items.Add(new ComboBoxItem(indexer, indexer.Name, ClassBrowserIconService.GetIcon(indexer))); items.Add(new ComboBoxItem(indexer, indexer.Name, ClassBrowserIconService.GetIcon(indexer), partialMode ? currentPart.Indexer.Contains(indexer) : true));
} }
items.Sort(lastIndex, c.Indexer.Count, comparer); items.Sort(lastIndex, c.Indexer.Count, comparer);
lastIndex = items.Count; lastIndex = items.Count;
foreach (IField f in c.Fields) { foreach (IField f in c.Fields) {
items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f))); items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true));
} }
items.Sort(lastIndex, c.Fields.Count, comparer); items.Sort(lastIndex, c.Fields.Count, comparer);
lastIndex = items.Count; lastIndex = items.Count;
foreach (IEvent evt in c.Events) { foreach (IEvent evt in c.Events) {
items.Add(new ComboBoxItem(evt, evt.Name, ClassBrowserIconService.GetIcon(evt))); items.Add(new ComboBoxItem(evt, evt.Name, ClassBrowserIconService.GetIcon(evt), partialMode ? currentPart.Events.Contains(evt) : true));
} }
items.Sort(lastIndex, c.Events.Count, comparer); items.Sort(lastIndex, c.Events.Count, comparer);
lastIndex = items.Count; lastIndex = items.Count;
if (NeedtoUpdate(items, membersComboBox)) { membersComboBox.BeginUpdate();
membersComboBox.BeginUpdate(); membersComboBox.Items.Clear();
membersComboBox.Items.Clear(); membersComboBox.Items.AddRange(items.ToArray());
membersComboBox.Items.AddRange(items.ToArray()); membersComboBox.EndUpdate();
membersComboBox.EndUpdate(); UpdateMembersComboBox();
UpdateMembersComboBox();
}
} else { } else {
if (membersComboBox.Items.Count > 0) { if (membersComboBox.Items.Count > 0) {
membersComboBox.Items.Clear(); membersComboBox.Items.Clear();
@ -377,9 +400,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
void AddClasses(ArrayList items, ICollection classes) void AddClasses(ArrayList items, ICollection classes)
{ {
foreach (IClass c in classes) { foreach (IClass c in classes) {
items.Add(new ComboBoxItem(c, c.FullyQualifiedName, ClassBrowserIconService.GetIcon(c))); items.Add(new ComboBoxItem(c, c.FullyQualifiedName, ClassBrowserIconService.GetIcon(c), true));
AddClasses(items, c.InnerClasses); AddClasses(items, c.InnerClasses);
} }
} }
@ -388,17 +410,23 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
{ {
ArrayList items = new ArrayList(); ArrayList items = new ArrayList();
AddClasses(items, currentCompilationUnit.Classes); AddClasses(items, currentCompilationUnit.Classes);
if (NeedtoUpdate(items, classComboBox)) { if (isUpdateRequired) {
if (isUpdateRequired) { classComboBox.BeginUpdate();
classComboBox.BeginUpdate(); }
} classComboBox.Items.Clear();
classComboBox.Items.Clear(); classComboBox.Items.AddRange(items.ToArray());
classComboBox.Items.AddRange(items.ToArray()); if (items.Count == 1) {
if (isUpdateRequired) { try {
classComboBox.EndUpdate(); autoselect = false;
classComboBox.SelectedIndex = 0;
} finally {
autoselect = true;
} }
UpdateClassComboBox();
} }
if (isUpdateRequired) {
classComboBox.EndUpdate();
}
UpdateClassComboBox();
} }
@ -462,9 +490,17 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
if (comboBox.SelectedIndex < 0) { if (comboBox.SelectedIndex < 0) {
membersComboBox.Items.Clear(); membersComboBox.Items.Clear();
} else if (autoselect) { } else if (autoselect) {
textAreaControl.ActiveTextAreaControl.Caret.Position = new Point(((ComboBoxItem)comboBox.Items[comboBox.SelectedIndex]).Column, ComboBoxItem item = (ComboBoxItem)comboBox.Items[comboBox.SelectedIndex];
((ComboBoxItem)comboBox.Items[comboBox.SelectedIndex]).Line); if (item.IsInCurrentPart) {
textAreaControl.ActiveTextAreaControl.TextArea.Focus(); textAreaControl.ActiveTextAreaControl.Caret.Position = new Point(item.Column, item.Line);
textAreaControl.ActiveTextAreaControl.TextArea.Focus();
} else {
IMember m = item.Item as IMember;
if (m != null) {
string fileName = m.DeclaringType.CompilationUnit.FileName;
FileService.JumpToFilePosition(fileName, item.Line, item.Column);
}
}
} }
} }
@ -493,7 +529,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
drawItemBrush = SystemBrushes.HighlightText; drawItemBrush = SystemBrushes.HighlightText;
} }
if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) { if (!item.IsInCurrentPart) {
drawItemBrush = SystemBrushes.ControlDark;
} else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) {
drawItemBrush = SystemBrushes.ControlDark; drawItemBrush = SystemBrushes.ControlDark;
} }
e.Graphics.DrawString(item.ToString(), e.Graphics.DrawString(item.ToString(),

Loading…
Cancel
Save