Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/15 16:33:53 (8 years ago)
Author:
jkarder
Message:

#2077:

  • do not offer completion for inaccessible protected members
  • fixed go to line logic
  • fixed comment in CSharpScriptTemplate
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionDataFactory.cs

    r11722 r11825  
    2525using ICSharpCode.AvalonEdit.CodeCompletion;
    2626using ICSharpCode.NRefactory.Completion;
     27using ICSharpCode.NRefactory.CSharp;
    2728using ICSharpCode.NRefactory.CSharp.Completion;
     29using ICSharpCode.NRefactory.CSharp.Resolver;
    2830using ICSharpCode.NRefactory.TypeSystem;
    2931using ICompletionData = ICSharpCode.NRefactory.Completion.ICompletionData;
     
    121123
    122124    #region IParameterCompletionDataFactory Members
    123     public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type, ICSharpCode.NRefactory.CSharp.AstNode thisInitializer) {
    124       return CreateMethodDataProvider(startOffset, type.GetConstructors());
     125    public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type, AstNode thisInitializer) {
     126      return CreateConstructorProvider(startOffset, type);
    125127    }
    126128
    127129    public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type) {
    128       return CreateMethodDataProvider(startOffset, type.GetConstructors());
     130      var constructors = FilterMethodsForAccessibility(type, type.GetConstructors());
     131      return CreateMethodDataProvider(startOffset, constructors);
    129132    }
    130133
    131134    public IParameterDataProvider CreateDelegateDataProvider(int startOffset, IType type) {
    132       return CreateMethodDataProvider(startOffset, new[] { type.GetDelegateInvokeMethod() });
     135      var delegates = FilterMethodsForAccessibility(type, new[] { type.GetDelegateInvokeMethod() });
     136      return CreateMethodDataProvider(startOffset, delegates);
    133137    }
    134138
     
    138142
    139143    public IParameterDataProvider CreateMethodDataProvider(int startOffset, IEnumerable<IMethod> methods) {
    140       return new CSharpOverloadProvider(context, startOffset, from m in methods where m != null select new CSharpInsightItem(m));
     144      return new CSharpOverloadProvider(context, startOffset, methods.Where(x => x != null).Select(x => new CSharpInsightItem(x)));
    141145    }
    142146
     
    149153    }
    150154    #endregion
     155
     156    private IEnumerable<IMethod> FilterMethodsForAccessibility(IType type, IEnumerable<IMethod> methods) {
     157      var typeResolveContext = context.TypeResolveContextAtCaret;
     158      var lookup = new MemberLookup(typeResolveContext.CurrentTypeDefinition, typeResolveContext.Compilation.MainAssembly);
     159      bool protectedAccessAllowed = lookup.IsProtectedAccessAllowed(type);
     160      return protectedAccessAllowed ? methods : methods.Where(x => !x.IsProtected);
     161    }
    151162  }
    152163}
Note: See TracChangeset for help on using the changeset viewer.