source: branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionDataFactory.cs @ 11722

Last change on this file since 11722 was 11722, checked in by jkarder, 6 years ago

#2077:

  • added completion image for templates
  • cleaned CSharpCodeCompletionDataFactory
  • sorted foldings by start offset
File size: 6.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using ICSharpCode.AvalonEdit.CodeCompletion;
26using ICSharpCode.NRefactory.Completion;
27using ICSharpCode.NRefactory.CSharp.Completion;
28using ICSharpCode.NRefactory.TypeSystem;
29using ICompletionData = ICSharpCode.NRefactory.Completion.ICompletionData;
30
31namespace HeuristicLab.CodeEditor {
32  internal class CSharpCodeCompletionDataFactory : ICompletionDataFactory, IParameterCompletionDataFactory {
33    private readonly CSharpCodeCompletionContext context;
34
35    public CSharpCodeCompletionDataFactory(CSharpCodeCompletionContext context) {
36      this.context = context;
37    }
38
39    #region ICompletionDataFactory Members
40    public ICompletionData CreateEntityCompletionData(IEntity entity) {
41      return new EntityCompletionData(entity);
42    }
43
44    public ICompletionData CreateEntityCompletionData(IEntity entity, string text) {
45      return new EntityCompletionData(entity) { CompletionText = text, DisplayText = text };
46    }
47
48    public ICompletionData CreateTypeCompletionData(IType type, bool fullName, bool isInAttributeContext, bool addForTypeCreation) {
49      var typeDef = type.GetDefinition();
50      if (typeDef != null) { return new EntityCompletionData(typeDef); }
51
52      string name = fullName ? type.FullName : type.Name;
53      if (isInAttributeContext && name.EndsWith("Attribute", StringComparison.Ordinal) && name.Length > "Attribute".Length) {
54        name = name.Substring(0, name.Length - "Attribute".Length);
55      }
56      return new CompletionData(name);
57    }
58
59    public ICompletionData CreateMemberCompletionData(IType type, IEntity member) {
60      return new EntityCompletionData(member);
61    }
62
63    public ICompletionData CreateLiteralCompletionData(string title, string description = null, string insertText = null) {
64      return new CompletionData(title) {
65        Description = description,
66        CompletionText = insertText ?? title,
67        Image = CompletionImage.Literal.BaseImage,
68        Priority = 2
69      };
70    }
71
72    public ICompletionData CreateXmlDocCompletionData(string title, string description = null, string insertText = null) {
73      return new CompletionData(title) {
74        Description = description,
75        CompletionText = insertText ?? title,
76        Image = CompletionImage.Template.BaseImage,
77      };
78    }
79
80    public ICompletionData CreateNamespaceCompletionData(INamespace ns) {
81      return new CompletionData(ns.Name) { Image = CompletionImage.NamespaceImage };
82    }
83
84    public ICompletionData CreateVariableCompletionData(IVariable variable) {
85      return new VariableCompletionData(variable);
86    }
87
88    public ICompletionData CreateVariableCompletionData(ITypeParameter parameter) {
89      return new CompletionData(parameter.Name);
90    }
91
92    public ICompletionData CreateEventCreationCompletionData(string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType) {
93      return new CompletionData(varName);
94    }
95
96    public ICompletionData CreateNewOverrideCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IMember m) {
97      return new CompletionData(m.Name);
98    }
99
100    public ICompletionData CreateNewPartialCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m) {
101      return new CompletionData(m.Name);
102    }
103
104    public ICompletionData CreateImportCompletionData(IType type, bool useFullName, bool addForTypeCreation) {
105      var typeDef = type.GetDefinition();
106      return new ImportCompletionData(typeDef, context.TypeResolveContextAtCaret, useFullName);
107    }
108
109    public IEnumerable<ICompletionData> CreateCodeTemplateCompletionData() {
110      yield break;
111    }
112
113    public ICompletionData CreateFormatItemCompletionData(string format, string description, object example) {
114      return null;
115    }
116
117    public IEnumerable<ICompletionData> CreatePreProcessorDefinesCompletionData() {
118      yield break;
119    }
120    #endregion
121
122    #region IParameterCompletionDataFactory Members
123    public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type, ICSharpCode.NRefactory.CSharp.AstNode thisInitializer) {
124      return CreateMethodDataProvider(startOffset, type.GetConstructors());
125    }
126
127    public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type) {
128      return CreateMethodDataProvider(startOffset, type.GetConstructors());
129    }
130
131    public IParameterDataProvider CreateDelegateDataProvider(int startOffset, IType type) {
132      return CreateMethodDataProvider(startOffset, new[] { type.GetDelegateInvokeMethod() });
133    }
134
135    public IParameterDataProvider CreateIndexerParameterDataProvider(int startOffset, IType type, IEnumerable<IProperty> accessibleIndexers, ICSharpCode.NRefactory.CSharp.AstNode resolvedNode) {
136      return null;
137    }
138
139    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));
141    }
142
143    public IParameterDataProvider CreateTypeParameterDataProvider(int startOffset, IEnumerable<IMethod> methods) {
144      return CreateMethodDataProvider(startOffset, methods);
145    }
146
147    public IParameterDataProvider CreateTypeParameterDataProvider(int startOffset, IEnumerable<IType> types) {
148      return null;
149    }
150    #endregion
151  }
152}
Note: See TracBrowser for help on using the repository browser.