@ -21,12 +21,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -21,12 +21,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
{
ICompilationUnit cu ;
IClass callingClass ;
IMember callingMember ;
ICSharpCode . NRefactory . Parser . LookupTableVisitor lookupTableVisitor ;
IProjectContent projectContent = null ;
bool showStatic = false ;
bool inNew = false ;
bool caseSensitive = true ;
SupportedLanguages language = SupportedLanguages . CSharp ;
@ -60,16 +58,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -60,16 +58,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
public bool ShowStatic {
get {
return showStatic ;
}
set {
showStatic = value ;
}
}
public NRefactoryResolver ( SupportedLanguages language )
{
this . language = language ;
@ -103,21 +91,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -103,21 +91,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
expression = expression . ToLower ( ) ;
}
// disable the code completion for numbers like 3.47
if ( IsNumber ( expression ) ) {
return null ;
}
if ( expression . StartsWith ( "new " ) ) {
inNew = true ;
expression = expression . Substring ( 4 ) ;
} else {
inNew = false ;
}
if ( expression . StartsWith ( GetUsingString ( ) ) ) {
return UsingResolve ( expression ) ;
}
this . caretLine = caretLineNumber ;
this . caretColumn = caretColumn ;
@ -156,40 +129,147 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -156,40 +129,147 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if ( cu ! = null ) {
callingClass = cu . GetInnermostClass ( caretLine , caretColumn ) ;
}
callingMember = GetCurrentMember ( ) ;
TypeVisitor typeVisitor = new TypeVisitor ( this ) ;
if ( expr is InvocationExpression ) {
IMethod method = typeVisitor . GetMethod ( ( InvocationExpression ) expr , null ) ;
if ( method ! = null )
return new MemberResolveResult ( callingClass , callingMember , method ) ;
} else if ( expr is FieldReferenceExpression ) {
FieldReferenceExpression fieldReferenceExpression = ( FieldReferenceExpression ) expr ;
IReturnType returnType = fieldReferenceExpression . TargetObject . AcceptVisitor ( typeVisitor , null ) as IReturnType ;
if ( returnType ! = null ) {
string name = SearchNamespace ( returnType . FullyQualifiedName , this . CompilationUnit ) ;
if ( name ! = null ) {
name + = "." + fieldReferenceExpression . FieldName ;
string n = SearchNamespace ( name , null ) ;
if ( n ! = null ) {
return new NamespaceResolveResult ( callingClass , callingMember , n ) ;
}
IClass c = SearchType ( name , this . CallingClass , this . CompilationUnit ) ;
if ( c ! = null ) {
return new TypeResolveResult ( callingClass , callingMember , new ReturnType ( c . FullyQualifiedName ) , c ) ;
}
return null ;
}
IMember member = GetMember ( returnType , fieldReferenceExpression . FieldName ) ;
if ( member ! = null )
return new MemberResolveResult ( callingClass , callingMember , member ) ;
ResolveResult result = ResolveMethod ( returnType , fieldReferenceExpression . FieldName ) ;
if ( result ! = null )
return result ;
}
} else if ( expr is IdentifierExpression ) {
ResolveResult result = ResolveIdentifier ( ( ( IdentifierExpression ) expr ) . Identifier ) ;
if ( result ! = null )
return result ;
}
IReturnType type = expr . AcceptVisitor ( typeVisitor , null ) as IReturnType ;
if ( type = = null | | type . FullyQualifiedName = = "" | | type . PointerNestingLevel ! = 0 ) {
return null ;
}
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 ) {
type = new ReturnType ( "System.Array" ) ;
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 )
return new ResolveResult ( callingClass , callingMember , new ReturnType ( "System.Array" ) ) ;
else {
return new ResolveResult ( callingClass , callingMember , FixType ( type ) ) ;
}
}
IReturnType FixType ( IReturnType type )
{
IClass returnClass = SearchType ( type . FullyQualifiedName , callingClass , cu ) ;
if ( returnClass = = null ) {
return TryNamespace ( type ) ;
if ( returnClass ! = null & & returnClass . FullyQualifiedName ! = type . FullyQualifiedName )
return new ReturnType ( returnClass . FullyQualifiedName ) ;
else
return type ;
}
#region Resolve Identifier
ResolveResult ResolveIdentifier ( string identifier )
{
string name = SearchNamespace ( identifier , this . CompilationUnit ) ;
if ( name ! = null & & name ! = "" ) {
return new NamespaceResolveResult ( callingClass , callingMember , name ) ;
}
IClass c = SearchType ( identifier , this . CallingClass , this . CompilationUnit ) ;
if ( c ! = null ) {
return new TypeResolveResult ( callingClass , callingMember , new ReturnType ( c . FullyQualifiedName ) , c ) ;
}
LocalLookupVariable var = SearchVariable ( identifier ) ;
if ( var ! = null ) {
IReturnType type = GetVariableType ( var ) ;
IField field = new LocalVariableField ( type , identifier , null , callingClass ) ;
return new LocalResolveResult ( callingClass , callingMember , field , false ) ;
}
IParameter para = SearchMethodParameter ( identifier ) ;
if ( para ! = null ) {
IField field = new LocalVariableField ( para . ReturnType , para . Name , para . Region , callingClass ) ;
return new LocalResolveResult ( callingClass , callingMember , field , true ) ;
}
IMember member = GetMember ( callingClass , identifier ) ;
if ( member ! = null ) {
return new MemberResolveResult ( callingClass , callingMember , member ) ;
}
ResolveResult result = ResolveMethod ( callingClass , identifier ) ;
if ( result ! = null )
return result ;
// try if there exists a static member in outer classes named typeName
List < IClass > classes = cu . GetOuterClasses ( caretLine , caretColumn ) ;
foreach ( IClass c2 in classes ) {
member = GetMember ( c2 , identifier ) ;
if ( member ! = null & & member . IsStatic ) {
return new MemberResolveResult ( callingClass , callingMember , member ) ;
}
}
return null ;
}
private class LocalVariableField : AbstractField
{
public LocalVariableField ( IReturnType type , string name , IRegion region , IClass declaringType ) : base ( declaringType )
{
this . returnType = type ;
this . FullyQualifiedName = name ;
this . region = region ;
this . modifiers = ModifierEnum . Private ;
}
}
#endregion
#region ResolveMethod
ResolveResult ResolveMethod ( IReturnType type , string identifier )
{
if ( type = = null | | type . PointerNestingLevel ! = 0 ) {
return null ;
}
if ( inNew ) {
return new ResolveResult ( returnClass , returnClass . GetAccessibleTypes ( callingClass ) ) ;
IClass curType ;
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 ) {
curType = SearchType ( "System.Array" , null , null ) ;
} else {
ArrayList result = returnClass . GetAccessibleMembers ( callingClass , showStatic ) ;
if ( ! showStatic & & language = = SupportedLanguages . VBNet ) {
result . AddRange ( returnClass . GetAccessibleMembers ( callingClass , true ) . ToArray ( ) ) ;
curType = SearchType ( type . FullyQualifiedName , null , null ) ;
if ( curType = = null ) {
return null ;
}
return new ResolveResult ( returnClass , result ) ;
}
return ResolveMethod ( curType , identifier ) ;
}
bool IsNumber ( string expression )
ResolveResult ResolveMethod ( IClass c , string identifier )
{
try {
int . Parse ( expression ) ;
return true ;
} catch ( Exception ) {
return false ;
foreach ( IClass curType in c . ClassInheritanceTree ) {
foreach ( IMethod method in c . Methods ) {
if ( IsSameName ( identifier , method . Name ) )
return new MethodResolveResult ( callingClass , callingMember , c , identifier ) ;
}
}
return null ;
}
#endregion
Expression WithResolve ( )
{
@ -208,121 +288,107 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -208,121 +288,107 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return expr ;
}
string GetUsingString ( )
{
switch ( language ) {
case SupportedLanguages . CSharp :
return "using " ;
case SupportedLanguages . VBNet :
return "imports " ;
default :
throw new NotSupportedException ( "The language " + language + " is not supported in the resolver" ) ;
}
}
ResolveResult ImportsResolve ( string expression )
Expression SpecialConstructs ( string expression )
{
// expression[expression.Length - 1] != '.'
// the period that causes this Resove() is not part of the expression
if ( expression [ expression . Length - 1 ] = = '.' ) {
return null ;
}
int i ;
for ( i = expression . Length - 1 ; i > = 0 ; - - i ) {
if ( ! ( Char . IsLetterOrDigit ( expression [ i ] ) | | expression [ i ] = = '_' | | expression [ i ] = = '.' ) ) {
break ;
}
if ( language = = SupportedLanguages . VBNet ) {
// MyBase and MyClass are no expressions, only MyBase.Identifier and MyClass.Identifier
if ( expression = = "mybase" ) {
return new BaseReferenceExpression ( ) ;
} else if ( expression = = "myclass" ) {
return new ClassReferenceExpression ( ) ;
}
// no Identifier before the period
if ( i = = expression . Length - 1 ) {
return null ;
}
string t = expression . Substring ( i + 1 ) ;
string [ ] namespaces = projectContent . GetNamespaceList ( t ) ;
if ( namespaces = = null | | namespaces . Length < = 0 ) {
return null ;
}
return new ResolveResult ( namespaces ) ;
}
ResolveResult UsingResolve ( string expression )
bool IsSameName ( string name1 , string name2 )
{
if ( language = = SupportedLanguages . VBNet ) {
return ImportsResolve ( expression ) ;
if ( IsCaseSensitive ( language ) ) {
return name1 = = name2 ;
} else {
return name1 . ToLower ( ) = = name2 . ToLower ( ) ;
}
// expression[expression.Length - 1] != '.'
// the period that causes this Resove() is not part of the expression
if ( expression [ expression . Length - 1 ] = = '.' ) {
return null ;
}
int i ;
for ( i = expression . Length - 1 ; i > = 0 ; - - i ) {
if ( ! ( Char . IsLetterOrDigit ( expression [ i ] ) | | expression [ i ] = = '_' | | expression [ i ] = = '.' ) ) {
break ;
bool IsInside ( Point between , Point start , Point end )
{
if ( between . Y < start . Y | | between . Y > end . Y ) {
return false ;
}
if ( between . Y > start . Y ) {
if ( between . Y < end . Y ) {
return true ;
}
// no Identifier before the period
if ( i = = expression . Length - 1 ) {
return null ;
// between.Y == end.Y
return between . X < = end . X ;
}
string t = expression . Substring ( i + 1 ) ;
string [ ] namespaces = projectContent . GetNamespaceList ( t ) ;
if ( namespaces = = null | | namespaces . Length < = 0 ) {
return null ;
// between.Y == start.Y
if ( between . X < start . X ) {
return false ;
}
return new ResolveResult ( namespaces ) ;
// start is OK and between.Y <= end.Y
return between . Y < end . Y | | between . X < = end . X ;
}
Expression SpecialConstructs ( string expression )
IMember GetCurrentMember ( )
{
if ( language = = SupportedLanguages . VBNet ) {
// MyBase and MyClass are no expressions, only MyBase.Identifier and MyClass.Identifier
if ( expression = = "mybase" ) {
return new BaseReferenceExpression ( ) ;
} else if ( expression = = "myclass" ) {
return new ClassReferenceExpression ( ) ;
foreach ( IProperty property in callingClass . Properties ) {
if ( property . BodyRegion ! = null & & property . BodyRegion . IsInside ( caretLine , caretColumn ) ) {
return property ;
}
}
foreach ( IMethod method in callingClass . Methods ) {
if ( method . BodyRegion ! = null & & method . BodyRegion . IsInside ( caretLine , caretColumn ) ) {
return method ;
}
}
return null ;
}
ResolveResult TryNamespace ( IReturnType type )
/// <remarks>
/// use the usings to find the correct name of a namespace
/// </remarks>
public string SearchNamespace ( string name , ICompilationUnit unit )
{
string n = SearchNamespace ( type . FullyQualifiedName , cu ) ;
if ( n = = null ) {
return null ;
}
ArrayList content = projectContent . GetNamespaceContents ( n ) ;
ArrayList classes = new ArrayList ( ) ;
for ( int i = 0 ; i < content . Count ; + + i ) {
if ( content [ i ] is IClass ) {
if ( inNew ) {
IClass c = ( IClass ) content [ i ] ;
if ( ( c . ClassType = = ClassType . Class ) | | ( c . ClassType = = ClassType . Struct ) ) {
classes . Add ( c ) ;
/ * if ( projectContent . NamespaceExists ( name ) ) {
return name ;
}
} else {
classes . Add ( ( IClass ) content [ i ] ) ;
if ( CallingClass ! = null ) {
string callspace = this . CallingClass . Namespace ;
for ( int split = callspace . Length ; split > 0 ; split = callspace . LastIndexOf ( '.' , split - 1 ) ) {
string fullname = callspace . Substring ( 0 , split ) + "." + name ;
if ( projectContent . NamespaceExists ( fullname ) ) {
return fullname ;
}
}
}
string [ ] namespaces = projectContent . GetNamespaceList ( n ) ;
return new ResolveResult ( namespaces , classes ) ;
* /
// TODO: look if all the stuff before is nessessary
return projectContent . SearchNamespace ( name , unit , caretLine , caretColumn ) ;
}
bool InStatic ( )
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType ( string name , IClass curType )
{
IProperty property = GetProperty ( ) ;
if ( property ! = null ) {
return property . IsStatic ;
}
IMethod method = GetMethod ( caretLine , caretColumn ) ;
if ( method ! = null ) {
return method . IsStatic ;
return projectContent . SearchType ( name , curType , caretLine , caretColumn ) ;
}
return false ;
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType ( string name , IClass curType , ICompilationUnit unit )
{
return projectContent . SearchType ( name , curType , unit , caretLine , caretColumn ) ;
}
#region Helper for TypeVisitor
#region SearchMethod
/// <summary>
/// Gets the list of methods on the return type that have the specified name.
/// </summary>
public ArrayList SearchMethod ( IReturnType type , string memberName )
{
if ( type = = null | | type . PointerNestingLevel ! = 0 ) {
@ -340,22 +406,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -340,22 +406,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return SearchMethod ( new ArrayList ( ) , curType , memberName ) ;
}
bool IsSameName ( string name1 , string name2 )
{
if ( IsCaseSensitive ( language ) ) {
return name1 = = name2 ;
} else {
return name1 . ToLower ( ) = = name2 . ToLower ( ) ;
}
}
ArrayList SearchMethod ( ArrayList methods , IClass curType , string memberName )
{
bool isClassInInheritanceTree = callingClass . IsTypeInInheritanceTree ( curType ) ;
foreach ( IMethod m in curType . Methods ) {
if ( IsSameName ( m . Name , memberName ) & &
m . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) & &
m . MustBeShown ( callingClass , true , isClassInInheritanceTree ) & &
! ( ( m . Modifiers & ModifierEnum . Override ) = = ModifierEnum . Override ) ) {
methods . Add ( m ) ;
}
@ -364,10 +421,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -364,10 +421,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if ( baseClass ! = null ) {
return SearchMethod ( methods , baseClass , memberName ) ;
}
showStatic = false ;
return methods ;
}
#endregion
#region SearchIndexer
public ArrayList SearchIndexer ( IReturnType type )
{
IClass curType = SearchType ( type . FullyQualifiedName , null , null ) ;
@ -377,11 +435,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -377,11 +435,11 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return new ArrayList ( 1 ) ;
}
public ArrayList SearchIndexer ( ArrayList indexer , IClass curType )
ArrayList SearchIndexer ( ArrayList indexer , IClass curType )
{
bool isClassInInheritanceTree = callingClass . IsTypeInInheritanceTree ( curType ) ;
foreach ( IIndexer i in curType . Indexer ) {
if ( i . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) & & ! ( ( i . Modifiers & ModifierEnum . Override ) = = ModifierEnum . Override ) ) {
if ( i . MustBeShown ( callingClass , true , isClassInInheritanceTree ) & & ! ( ( i . Modifiers & ModifierEnum . Override ) = = ModifierEnum . Override ) ) {
indexer . Add ( i ) ;
}
}
@ -389,131 +447,104 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -389,131 +447,104 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if ( baseClass ! = null ) {
return SearchIndexer ( indexer , baseClass ) ;
}
showStatic = false ;
return indexer ;
}
#endregion
#region SearchMember
// no methods or indexer
public IReturnType SearchMember ( IReturnType type , string memberName )
{
// TODO: use SearchMember from ParserService
if ( type = = null | | memberName = = null | | memberName = = "" ) {
return null ;
}
IClass curType = SearchType ( type . FullyQualifiedName , callingClass , cu ) ;
bool isClassInInheritanceTree = callingClass . IsTypeInInheritanceTree ( curType ) ;
if ( type . PointerNestingLevel ! = 0 ) {
return null ;
}
IClass curType ;
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 ) {
curType = SearchType ( "System.Array" , null , null ) ;
} else {
curType = SearchType ( type . FullyQualifiedName , callingClass , cu ) ;
}
if ( curType = = null )
return null ;
else
return SearchMember ( curType , memberName ) ;
}
if ( curType = = null ) {
public IMember GetMember ( IReturnType type , string memberName )
{
if ( type = = null | | memberName = = null | | memberName = = "" ) {
return null ;
}
if ( type . PointerNestingLevel ! = 0 ) {
return null ;
}
IClass curType ;
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 ) {
curType = SearchType ( "System.Array" , null , null ) ;
} else {
curType = SearchType ( type . FullyQualifiedName , callingClass , cu ) ;
}
if ( curType . ClassType = = ClassType . Enum ) {
foreach ( IField f in curType . Fields ) {
if ( IsSameName ( f . Name , memberName ) & & f . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) ) {
showStatic = false ;
return type ; // enum members have the type of the enum
}
}
if ( curType = = null )
return null ;
else
return GetMember ( curType , memberName ) ;
}
if ( showStatic ) {
public IReturnType SearchMember ( IClass curType , string memberName )
{
bool isClassInInheritanceTree = false ;
if ( callingClass ! = null )
isClassInInheritanceTree = callingClass . IsTypeInInheritanceTree ( curType ) ;
foreach ( IClass c in curType . InnerClasses ) {
if ( IsSameName ( c . Name , memberName ) & & c . IsAccessible ( callingClass , isClassInInheritanceTree ) ) {
return new ReturnType ( c . FullyQualifiedName ) ;
}
}
}
foreach ( IProperty p in curType . Properties ) {
if ( IsSameName ( p . Name , memberName ) & & p . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) ) {
showStatic = false ;
return p . ReturnType ;
}
}
foreach ( IField f in curType . Fields ) {
if ( IsSameName ( f . Name , memberName ) & & f . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) ) {
showStatic = false ;
return f . ReturnType ;
}
}
foreach ( IEvent e in curType . Events ) {
if ( IsSameName ( e . Name , memberName ) & & e . MustBeShown ( callingClass , showStatic , isClassInInheritanceTree ) ) {
showStatic = false ;
return e . ReturnType ;
}
}
foreach ( string baseType in curType . BaseTypes ) {
IClass c = SearchType ( baseType , curType ) ;
if ( c ! = null ) {
IReturnType erg = SearchMember ( new ReturnType ( c . FullyQualifiedName ) , memberName ) ;
if ( erg ! = null ) {
return erg ;
}
}
}
IMember member = GetMember ( curType , memberName ) ;
if ( member = = null )
return null ;
else
return member . ReturnType ;
}
bool IsInside ( Point between , Point start , Point end )
private IMember GetMember ( IClass c , string memberName )
{
if ( between . Y < start . Y | | between . Y > end . Y ) {
return false ;
}
if ( between . Y > start . Y ) {
if ( between . Y < end . Y ) {
return true ;
}
// between.Y == end.Y
return between . X < = end . X ;
bool isClassInInheritanceTree = false ;
if ( callingClass ! = null )
isClassInInheritanceTree = callingClass . IsTypeInInheritanceTree ( c ) ;
foreach ( IClass curType in c . ClassInheritanceTree ) {
foreach ( IProperty p in curType . Properties ) {
if ( IsSameName ( p . Name , memberName ) & & p . MustBeShown ( callingClass , true , isClassInInheritanceTree ) ) {
return p ;
}
// between.Y == start.Y
if ( between . X < start . X ) {
return false ;
}
// start is OK and between.Y <= end.Y
return between . Y < end . Y | | between . X < = end . X ;
foreach ( IField f in curType . Fields ) {
if ( IsSameName ( f . Name , memberName ) & & f . MustBeShown ( callingClass , true , isClassInInheritanceTree ) ) {
return f ;
}
LocalLookupVariable SearchVariable ( string name )
{
ArrayList variables = ( ArrayList ) lookupTableVisitor . variables [ IsCaseSensitive ( language ) ? name : name . ToLower ( ) ] ;
if ( variables = = null | | variables . Count < = 0 ) {
return null ;
}
foreach ( LocalLookupVariable v in variables ) {
if ( IsInside ( new Point ( caretColumn , caretLine ) , v . StartPos , v . EndPos ) ) {
return v ;
foreach ( IEvent e in curType . Events ) {
if ( IsSameName ( e . Name , memberName ) & & e . MustBeShown ( callingClass , true , isClassInInheritanceTree ) ) {
return e ;
}
}
return null ;
}
IReturnType GetVariableType ( LocalLookupVariable v )
{
if ( v = = null ) {
return null ;
}
IClass c = SearchType ( v . TypeRef . SystemType , callingClass , cu ) ;
if ( c ! = null ) {
return new ReturnType ( c . FullyQualifiedName , v . TypeRef . RankSpecifier , v . TypeRef . PointerNestingLevel ) ;
} else {
return new ReturnType ( v . TypeRef ) ;
}
}
#endregion
#region DynamicLookup
/// <remarks>
/// does the dynamic lookup for the typeName
/// does the dynamic lookup for the identifier
/// </remarks>
public IReturnType DynamicLookup ( string typeName )
{
// try if it exists a variable named typeName
IReturnType variable = GetVariableType ( SearchVariable ( typeName ) ) ;
if ( variable ! = null ) {
showStatic = false ;
return variable ;
}
@ -524,85 +555,29 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -524,85 +555,29 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
// try if typeName is a method parameter
IParameter parameter = SearchMethodParameter ( typeName ) ;
if ( parameter ! = null ) {
showStatic = false ;
return parameter . ReturnType ;
}
// check if typeName == value in set method of a property
if ( typeName = = "value" ) {
IProperty property = GetProperty ( ) ;
IProperty property = callingMember as IProperty ;
if ( property ! = null & & property . SetterRegion ! = null & & property . SetterRegion . IsInside ( caretLine , caretColumn ) ) {
showStatic = false ;
return property . ReturnType ;
}
}
// try if there exists a nonstatic member named typeName
showStatic = false ;
IReturnType t = SearchMember ( callingClass = = null ? null : new ReturnType ( callingClass . FullyQualifiedName ) , typeName ) ;
IReturnType t = SearchMember ( callingClass , typeName ) ;
if ( t ! = null ) {
return t ;
}
// try if there exists a static member named typeName
showStatic = true ;
t = SearchMember ( callingClass = = null ? null : new ReturnType ( callingClass . FullyQualifiedName ) , typeName ) ;
if ( t ! = null ) {
showStatic = false ;
return t ;
}
// try if there exists a static member in outer classes named typeName
List < IClass > classes = cu . GetOuterClasses ( caretLine , caretColumn ) ;
foreach ( IClass c in classes ) {
t = SearchMember ( callingClass = = null ? null : new ReturnType ( c . FullyQualifiedName ) , typeName ) ;
if ( t ! = null ) {
showStatic = false ;
return t ;
}
}
// Alex: look in namespaces
// Alex: look inside namespaces
string [ ] innamespaces = projectContent . GetNamespaceList ( "" ) ;
foreach ( string ns in innamespaces ) {
ArrayList objs = projectContent . GetNamespaceContents ( ns ) ;
if ( objs = = null ) continue ;
foreach ( object o in objs ) {
if ( o is IClass ) {
IClass oc = ( IClass ) o ;
if ( IsSameName ( oc . Name , typeName ) | | IsSameName ( oc . FullyQualifiedName , typeName ) ) {
//Debug.WriteLine(((IClass)o).Name);
/// now we can set completion data
objs . Clear ( ) ;
objs = null ;
return new ReturnType ( oc . FullyQualifiedName ) ;
}
}
}
if ( objs = = null ) {
break ;
}
}
innamespaces = null ;
return null ;
}
IProperty GetProperty ( )
{
foreach ( IProperty property in callingClass . Properties ) {
if ( property . BodyRegion ! = null & & property . BodyRegion . IsInside ( caretLine , caretColumn ) ) {
return property ;
}
}
return null ;
}
IMethod GetMethod ( int caretLine , int caretColumn )
{
foreach ( IMethod method in callingClass . Methods ) {
if ( method . BodyRegion ! = null & & method . BodyRegion . IsInside ( caretLine , caretColumn ) ) {
return method ;
IMember member = GetMember ( c , typeName ) ;
if ( member ! = null & & member . IsStatic ) {
return member . ReturnType ;
}
}
return null ;
@ -610,7 +585,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -610,7 +585,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
IParameter SearchMethodParameter ( string parameter )
{
IMethod method = GetMethod ( caretLine , caretColumn ) ;
IMethod method = callingMember as IMethod ;
if ( method = = null ) {
return null ;
}
@ -622,116 +597,37 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -622,116 +597,37 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return null ;
}
/// <remarks>
/// use the usings to find the correct name of a namespace
/// </remarks>
public string SearchNamespace ( string name , ICompilationUnit unit )
{
if ( projectContent . NamespaceExists ( name ) ) {
return name ;
}
if ( CallingClass ! = null ) {
string callspace = this . CallingClass . Namespace ;
for ( int split = callspace . Length ; split > 0 ; split = callspace . LastIndexOf ( '.' , split - 1 ) ) {
string fullname = callspace . Substring ( 0 , split ) + "." + name ;
if ( projectContent . NamespaceExists ( fullname ) ) {
return fullname ;
}
}
}
// TODO: look if all the stuff before is nessessary
return projectContent . SearchNamespace ( name , unit , caretLine , caretColumn ) ;
}
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType ( string name , IClass curType )
{
return projectContent . SearchType ( name , curType , caretLine , caretColumn ) ;
}
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType ( string name , IClass curType , ICompilationUnit unit )
{
return projectContent . SearchType ( name , curType , unit , caretLine , caretColumn ) ;
}
public FilePosition SearchDefinition ( string expression ,
int caretLineNumber ,
int caretColumn ,
string fileName )
IReturnType GetVariableType ( LocalLookupVariable v )
{
this . caretLine = caretLineNumber ;
this . caretColumn = caretColumn ;
ICSharpCode . NRefactory . Parser . IParser p = ICSharpCode . NRefactory . Parser . ParserFactory . CreateParser ( language , new System . IO . StringReader ( expression ) ) ;
Expression expr = p . ParseExpression ( ) ;
ParseInformation parseInfo = ParserService . GetParseInformation ( fileName ) ;
if ( parseInfo = = null ) {
if ( v = = null ) {
return null ;
}
NRefactoryASTConvertVisitor cSharpVisitor = new NRefactoryASTConvertVisitor ( parseInfo . MostRecentCompilationUnit ! = null ? parseInfo . MostRecentCompilationUnit . ProjectContent : null ) ;
ICSharpCode . NRefactory . Parser . AST . CompilationUnit fileCompilationUnit = parseInfo . MostRecentCompilationUnit . Tag as ICSharpCode . NRefactory . Parser . AST . CompilationUnit ;
cu = ( ICompilationUnit ) cSharpVisitor . Visit ( fileCompilationUnit , null ) ;
if ( cu ! = null ) {
callingClass = cu . GetInnermostClass ( caretLine , caretColumn ) ;
}
if ( callingClass = = null ) {
return null ;
IClass c = SearchType ( v . TypeRef . SystemType , callingClass , cu ) ;
if ( c ! = null ) {
return new ReturnType ( c . FullyQualifiedName , v . TypeRef . RankSpecifier , v . TypeRef . PointerNestingLevel ) ;
} else {
return new ReturnType ( v . TypeRef ) ;
}
if ( expr is IdentifierExpression ) {
lookupTableVisitor = new LookupTableVisitor ( ) ;
lookupTableVisitor . Visit ( fileCompilationUnit , null ) ;
// try if it exists a variable named typeName
LocalLookupVariable variable = SearchVariable ( expression ) ;
if ( variable ! = null ) {
return new FilePosition ( fileName , variable . StartPos ) ;
}
// try if typeName is a method parameter
IParameter parameter = SearchMethodParameter ( expression ) ;
if ( parameter ! = null ) {
return new FilePosition ( fileName , new Point ( parameter . Region . BeginColumn , parameter . Region . BeginLine ) ) ;
}
LocalLookupVariable SearchVariable ( string name )
{
ArrayList variables = ( ArrayList ) lookupTableVisitor . variables [ IsCaseSensitive ( language ) ? name : name . ToLower ( ) ] ;
if ( variables = = null | | variables . Count < = 0 ) {
return null ;
}
string target = expression . Substring ( 0 , expression . LastIndexOf ( '.' ) ) ;
string member = expression . Substring ( expression . LastIndexOf ( '.' ) + 1 ) ;
p = ICSharpCode . NRefactory . Parser . ParserFactory . CreateParser ( language , new System . IO . StringReader ( target ) ) ;
Expression targetExpr = p . ParseExpression ( ) ;
TypeVisitor typeVisitor = new TypeVisitor ( this ) ;
IReturnType type = expr . AcceptVisitor ( typeVisitor , null ) as IReturnType ;
if ( type = = null | | type . FullyQualifiedName = = "" | | type . PointerNestingLevel ! = 0 ) {
return null ;
}
if ( type . ArrayDimensions ! = null & & type . ArrayDimensions . Length > 0 ) {
type = new ReturnType ( "System.Array" ) ;
}
IClass returnClass = SearchType ( type . FullyQualifiedName , callingClass , cu ) ;
if ( returnClass = = null ) {
string n = SearchNamespace ( type . FullyQualifiedName , cu ) ;
if ( n = = null ) {
return null ;
}
returnClass = SearchType ( n + '.' + member , callingClass , cu ) ;
if ( returnClass ! = null ) {
return new FilePosition ( fileName , new Point ( returnClass . Region . BeginColumn , returnClass . Region . BeginLine ) ) ;
foreach ( LocalLookupVariable v in variables ) {
if ( IsInside ( new Point ( caretColumn , caretLine ) , v . StartPos , v . EndPos ) ) {
return v ;
}
return null ;
}
return null ;
}
#endregion
#endregion
/ *
public ArrayList NewCompletion ( int caretLine , int caretColumn , string fileName )
{
if ( ! IsCaseSensitive ( language ) ) {
@ -764,7 +660,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -764,7 +660,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
}
return result ;
}
} * /
public ArrayList CtrlSpace ( int caretLine , int caretColumn , string fileName )
{
@ -785,14 +681,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@@ -785,14 +681,16 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if ( cu ! = null ) {
callingClass = cu . GetInnermostClass ( caretLine , caretColumn ) ;
if ( callingClass ! = null ) {
IMethod method = GetMethod ( caretLine , caretColumn ) ;
IMethod method = callingMember as IMethod ;
if ( method ! = null ) {
foreach ( IParameter p in method . Parameters ) {
result . Add ( new Field ( new ReturnType ( p . ReturnType . Name , p . ReturnType . ArrayDimensions , p . ReturnType . PointerNestingLevel ) , p . Name , Modifier . None , method . Region , callingClass ) ) ;
}
}
result . AddRange ( projectContent . GetNamespaceContents ( callingClass . Namespace ) ) ;
bool inStatic = InStatic ( ) ;
bool inStatic = true ;
if ( callingMember ! = null )
inStatic = callingMember . IsStatic ;
result . AddRange ( callingClass . GetAccessibleMembers ( callingClass , inStatic ) . ToArray ( ) ) ;
if ( inStatic = = false ) {
result . AddRange ( callingClass . GetAccessibleMembers ( callingClass , ! inStatic ) . ToArray ( ) ) ;