[11700] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using ICSharpCode.AvalonEdit.CodeCompletion;
|
---|
| 26 | using ICSharpCode.NRefactory.Completion;
|
---|
| 27 | using ICSharpCode.NRefactory.CSharp.Completion;
|
---|
| 28 | using ICSharpCode.NRefactory.TypeSystem;
|
---|
| 29 | using ICompletionData = ICSharpCode.NRefactory.Completion.ICompletionData;
|
---|
| 30 |
|
---|
| 31 | namespace 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("TODO: xml doc creation");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public ICompletionData CreateNamespaceCompletionData(INamespace ns) {
|
---|
| 77 | return new CompletionData(ns.Name) { Image = CompletionImage.NamespaceImage };
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public ICompletionData CreateVariableCompletionData(IVariable variable) {
|
---|
| 81 | return new VariableCompletionData(variable);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public ICompletionData CreateVariableCompletionData(ITypeParameter parameter) {
|
---|
| 85 | return new CompletionData(parameter.Name);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public ICompletionData CreateEventCreationCompletionData(string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType) {
|
---|
| 89 | return new CompletionData("TODO: event creation");
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public ICompletionData CreateNewOverrideCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IMember m) {
|
---|
| 93 | return new CompletionData("TODO: override creation");
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public ICompletionData CreateNewPartialCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m) {
|
---|
| 97 | return new CompletionData("TODO: partial creation");
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public ICompletionData CreateImportCompletionData(IType type, bool useFullName, bool addForTypeCreation) {
|
---|
| 101 | var typeDef = type.GetDefinition();
|
---|
| 102 | if (typeDef != null) return new ImportCompletionData(typeDef, context.TypeResolveContextAtCaret, useFullName);
|
---|
| 103 | throw new InvalidOperationException("Should never happen");
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public IEnumerable<ICompletionData> CreateCodeTemplateCompletionData() {
|
---|
| 107 | yield return new CompletionData("TODO: code template creation"); ;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | public ICompletionData CreateFormatItemCompletionData(string format, string description, object example) {
|
---|
| 111 | return new CompletionData("TODO: format item creation");
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | public IEnumerable<ICompletionData> CreatePreProcessorDefinesCompletionData() {
|
---|
| 115 | yield return new CompletionData("TODO: pre processor creation"); ;
|
---|
| 116 | }
|
---|
| 117 | #endregion
|
---|
| 118 |
|
---|
| 119 | #region IParameterCompletionDataFactory Members
|
---|
| 120 | public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type, ICSharpCode.NRefactory.CSharp.AstNode thisInitializer) {
|
---|
| 121 | return CreateMethodDataProvider(startOffset, type.GetConstructors());
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | public IParameterDataProvider CreateConstructorProvider(int startOffset, IType type) {
|
---|
| 125 | return CreateMethodDataProvider(startOffset, type.GetConstructors());
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public IParameterDataProvider CreateDelegateDataProvider(int startOffset, IType type) {
|
---|
| 129 | return CreateMethodDataProvider(startOffset, new[] { type.GetDelegateInvokeMethod() });
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | public IParameterDataProvider CreateIndexerParameterDataProvider(int startOffset, IType type, IEnumerable<IProperty> accessibleIndexers, ICSharpCode.NRefactory.CSharp.AstNode resolvedNode) {
|
---|
| 133 | throw new NotImplementedException();
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | public IParameterDataProvider CreateMethodDataProvider(int startOffset, IEnumerable<IMethod> methods) {
|
---|
| 137 | return new CSharpOverloadProvider(context, startOffset, from m in methods where m != null select new CSharpInsightItem(m));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | public IParameterDataProvider CreateTypeParameterDataProvider(int startOffset, IEnumerable<IMethod> methods) {
|
---|
| 141 | return CreateMethodDataProvider(startOffset, methods);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | public IParameterDataProvider CreateTypeParameterDataProvider(int startOffset, IEnumerable<IType> types) {
|
---|
| 145 | return null;
|
---|
| 146 | }
|
---|
| 147 | #endregion
|
---|
| 148 | }
|
---|
| 149 | } |
---|