本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper.AddCustom方法的典型用法代码示例。如果您正苦于以下问题:C# CompletionDataWrapper.AddCustom方法的具体用法?C# CompletionDataWrapper.AddCustom怎么用?C# CompletionDataWrapper.AddCustom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Completion.CompletionDataWrapper
的用法示例。
在下文中一共展示了CompletionDataWrapper.AddCustom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddKeywords
void AddKeywords(CompletionDataWrapper wrapper, IEnumerable<string> keywords)
{
if (!IncludeKeywordsInCompletionList)
return;
foreach (string keyword in keywords) {
if (wrapper.Result.Any(data => data.DisplayText == keyword))
continue;
wrapper.AddCustom(keyword);
}
}
示例2: AddTypesAndNamespaces
//.........这里部分代码省略.........
var a = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a2 = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
}
for (var n = scope; n != null; n = n.Parent) {
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint && IncludeKeywordsInCompletionList) {
wrapper.AddCustom("new()");
}
if (AutomaticallyAddImports) {
state = GetState();
ICompletionData[] importData;
var namespaces = new List<INamespace>();
for (var n = ctx.CurrentUsingScope; n != null; n = n.Parent) {
namespaces.Add(n.Namespace);
foreach (var u in n.Usings)
namespaces.Add(u);
}
if (this.CompletionEngineCache != null && ListEquals(namespaces, CompletionEngineCache.namespaces)) {
importData = CompletionEngineCache.importCompletion;
} else {
// flatten usings
var importList = new List<ICompletionData>();
var dict = new Dictionary<string, Dictionary<string, ICompletionData>>();
foreach (var type in Compilation.GetAllTypeDefinitions ()) {
if (!lookup.IsAccessible(type, false))
continue;
if (namespaces.Any(n => n.FullName == type.Namespace))
continue;
bool useFullName = false;
foreach (var ns in namespaces) {
if (ns.GetTypeDefinition(type.Name, type.TypeParameterCount) != null) {
useFullName = true;
break;
}
}
if (onlyAddConstructors) {
if (!type.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
var data = factory.CreateImportCompletionData(type, useFullName, onlyAddConstructors);
Dictionary<string, ICompletionData> createdDict;
if (!dict.TryGetValue(type.Name, out createdDict)) {
createdDict = new Dictionary<string, ICompletionData>();
dict.Add(type.Name, createdDict);
}
ICompletionData oldData;
if (!createdDict.TryGetValue(type.Namespace, out oldData)) {
importList.Add(data);
createdDict.Add(type.Namespace, data);
} else {
oldData.AddOverload(data);
}
}
importData = importList.ToArray();
if (CompletionEngineCache != null) {
CompletionEngineCache.namespaces = namespaces;
CompletionEngineCache.importCompletion = importData;
}
}
foreach (var data in importData) {
wrapper.Result.Add(data);
}
}
}
示例3: HandleKeywordCompletion
//.........这里部分代码省略.........
case "override":
// Look for modifiers, in order to find the beginning of the declaration
int firstMod = wordStart;
int i = wordStart;
for (int n = 0; n < 3; n++) {
string mod = GetPreviousToken(ref i, true);
if (mod == "public" || mod == "protected" || mod == "private" || mod == "internal" || mod == "sealed") {
firstMod = i;
} else if (mod == "static") {
// static methods are not overridable
return null;
} else {
break;
}
}
if (!IsLineEmptyUpToEol()) {
return null;
}
if (currentType != null && (currentType.Kind == TypeKind.Class || currentType.Kind == TypeKind.Struct)) {
string modifiers = document.GetText(firstMod, wordStart - firstMod);
return GetOverrideCompletionData(currentType, modifiers);
}
return null;
case "partial":
// Look for modifiers, in order to find the beginning of the declaration
firstMod = wordStart;
i = wordStart;
for (int n = 0; n < 3; n++) {
string mod = GetPreviousToken(ref i, true);
if (mod == "public" || mod == "protected" || mod == "private" || mod == "internal" || mod == "sealed") {
firstMod = i;
} else if (mod == "static") {
// static methods are not overridable
return null;
} else {
break;
}
}
if (!IsLineEmptyUpToEol()) {
return null;
}
var state = GetState();
if (state.CurrentTypeDefinition != null && (state.CurrentTypeDefinition.Kind == TypeKind.Class || state.CurrentTypeDefinition.Kind == TypeKind.Struct)) {
string modifiers = document.GetText(firstMod, wordStart - firstMod);
return GetPartialCompletionData(state.CurrentTypeDefinition, modifiers);
}
return null;
case "public":
case "protected":
case "private":
case "internal":
case "sealed":
case "static":
var accessorContext = HandleAccessorContext();
if (accessorContext != null) {
return accessorContext;
}
return null;
case "new":
int j = offset - 4;
// string token = GetPreviousToken (ref j, true);
IType hintType = null;
var expressionOrVariableDeclaration = GetNewExpressionAt(j);
if (expressionOrVariableDeclaration == null)
return null;
var astResolver = CompletionContextProvider.GetResolver(GetState(), expressionOrVariableDeclaration.Node.Ancestors.FirstOrDefault(n => n is EntityDeclaration || n is SyntaxTree));
hintType = TypeGuessing.GetValidTypes(
astResolver,
expressionOrVariableDeclaration.Node
).FirstOrDefault();
return CreateConstructorCompletionData(hintType);
case "yield":
var yieldDataList = new CompletionDataWrapper(this);
DefaultCompletionString = "return";
if (IncludeKeywordsInCompletionList) {
yieldDataList.AddCustom("break");
yieldDataList.AddCustom("return");
}
return yieldDataList.Result;
case "in":
var inList = new CompletionDataWrapper(this);
var expr = GetExpressionAtCursor();
if (expr == null)
return null;
var rr = ResolveExpression(expr);
AddContextCompletion(
inList,
rr != null ? rr.Resolver : GetState(),
expr.Node
);
return inList.Result;
}
return null;
}
示例4: HandleAccessorContext
IEnumerable<ICompletionData> HandleAccessorContext()
{
var unit = ParseStub("get; }", false);
var node = unit.GetNodeAt(location, cn => !(cn is CSharpTokenNode));
if (node is Accessor) {
node = node.Parent;
}
var contextList = new CompletionDataWrapper(this);
if (node is PropertyDeclaration || node is IndexerDeclaration) {
if (IncludeKeywordsInCompletionList) {
contextList.AddCustom("get");
contextList.AddCustom("set");
AddKeywords(contextList, accessorModifierKeywords);
}
} else if (node is CustomEventDeclaration) {
if (IncludeKeywordsInCompletionList) {
contextList.AddCustom("add");
contextList.AddCustom("remove");
}
} else {
return null;
}
return contextList.Result;
}
示例5: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node)
{
int i = offset - 1;
var isInGlobalDelegate = node == null && state.CurrentTypeDefinition == null && GetPreviousToken(ref i, true) == "delegate";
if (state != null && !(node is AstType)) {
foreach (var variable in state.LocalVariables) {
if (variable.Region.IsInside(location.Line, location.Column - 1)) {
continue;
}
wrapper.AddVariable(variable);
}
}
if (state.CurrentMember is IParameterizedMember && !(node is AstType)) {
var param = (IParameterizedMember)state.CurrentMember;
foreach (var p in param.Parameters) {
wrapper.AddVariable(p);
}
}
if (state.CurrentMember is IMethod) {
var method = (IMethod)state.CurrentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
Func<IType, IType> typePred = null;
if (IsAttributeContext(node)) {
var attribute = Compilation.FindType(KnownTypeCode.Attribute);
typePred = t => t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null;
}
if (node != null && node.Role == Roles.BaseType) {
typePred = t => {
var def = t.GetDefinition();
if (def != null && t.Kind != TypeKind.Interface && (def.IsSealed || def.IsStatic))
return null;
return t;
};
}
if (node != null && !(node is NamespaceDeclaration) || state.CurrentTypeDefinition != null || isInGlobalDelegate) {
AddTypesAndNamespaces(wrapper, state, node, typePred);
wrapper.Result.Add(factory.CreateLiteralCompletionData("global"));
}
if (!(node is AstType)) {
if (currentMember != null || node is Expression) {
AddKeywords(wrapper, statementStartKeywords);
if (LanguageVersion.Major >= 5)
AddKeywords(wrapper, new [] { "await" });
AddKeywords(wrapper, expressionLevelKeywords);
if (node == null || node is TypeDeclaration)
AddKeywords(wrapper, typeLevelKeywords);
} else if (currentType != null) {
AddKeywords(wrapper, typeLevelKeywords);
} else {
if (!isInGlobalDelegate && !(node is Attribute))
AddKeywords(wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside(location)) {
wrapper.AddCustom("value");
}
if (currentMember is IUnresolvedEvent) {
wrapper.AddCustom("value");
}
if (IsInSwitchContext(node)) {
if (IncludeKeywordsInCompletionList)
wrapper.AddCustom("case");
}
} else {
if (((AstType)node).Parent is ParameterDeclaration) {
AddKeywords(wrapper, parameterTypePredecessorKeywords);
}
}
if (node != null || state.CurrentTypeDefinition != null || isInGlobalDelegate)
AddKeywords(wrapper, primitiveTypesKeywords);
if (currentMember != null && (node is IdentifierExpression || node is SimpleType) && (node.Parent is ExpressionStatement || node.Parent is ForeachStatement || node.Parent is UsingStatement)) {
if (IncludeKeywordsInCompletionList) {
wrapper.AddCustom("var");
wrapper.AddCustom("dynamic");
}
}
wrapper.Result.AddRange(factory.CreateCodeTemplateCompletionData());
if (node != null && node.Role == Roles.Argument) {
var resolved = ResolveExpression(node.Parent);
var invokeResult = resolved != null ? resolved.Result as CSharpInvocationResolveResult : null;
if (invokeResult != null) {
int argNum = 0;
foreach (var arg in node.Parent.Children.Where (c => c.Role == Roles.Argument)) {
if (arg == node) {
break;
}
argNum++;
}
//.........这里部分代码省略.........
示例6: AddDelegateHandlers
string AddDelegateHandlers(CompletionDataWrapper completionList, IType delegateType, bool addSemicolon = true, bool addDefault = true, string optDelegateName = null)
{
IMethod delegateMethod = delegateType.GetDelegateInvokeMethod();
PossibleDelegates.Add(delegateMethod);
var thisLineIndent = GetLineIndent(location.Line);
string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : "");
//bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate("));
if (addDefault && !completionList.AnonymousDelegateAdded) {
completionList.AnonymousDelegateAdded = true;
var oldDelegate = completionList.Result.FirstOrDefault(cd => cd.DisplayText == "delegate");
if (oldDelegate != null)
completionList.Result.Remove(oldDelegate);
completionList.AddCustom(
"delegate",
"Creates anonymous delegate.",
"delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate",
"Creates anonymous async delegate.",
"async delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
}
}
var sb = new StringBuilder("(");
var sbWithoutTypes = new StringBuilder("(");
var state = GetState();
var builder = new TypeSystemAstBuilder(state);
for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
if (k > 0) {
sb.Append(", ");
sbWithoutTypes.Append(", ");
}
var convertedParameter = builder.ConvertParameter(delegateMethod.Parameters [k]);
if (convertedParameter.ParameterModifier == ParameterModifier.Params)
convertedParameter.ParameterModifier = ParameterModifier.None;
sb.Append(convertedParameter.ToString(FormattingPolicy));
sbWithoutTypes.Append(delegateMethod.Parameters [k].Name);
}
sb.Append(")");
sbWithoutTypes.Append(")");
var signature = sb.ToString();
if (!completionList.HasAnonymousDelegateAdded(signature)) {
completionList.AddAnonymousDelegateAdded(signature);
completionList.AddCustom(
"delegate" + signature,
"Creates anonymous delegate.",
"delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate" + signature,
"Creates anonymous async delegate.",
"async delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
).DisplayFlags |= DisplayFlags.MarkedBold;
}
if (!completionList.Result.Any(data => data.DisplayText == sb.ToString())) {
completionList.AddCustom(
signature,
"Creates typed lambda expression.",
signature + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + signature,
"Creates typed async lambda expression.",
"async " + signature + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
}
if (!delegateMethod.Parameters.Any(p => p.IsOut || p.IsRef) && !completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) {
completionList.AddCustom(
sbWithoutTypes.ToString(),
"Creates lambda expression.",
sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + sbWithoutTypes,
"Creates async lambda expression.",
"async " + sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
).DisplayFlags |= DisplayFlags.MarkedBold;
}
}
}
}
string varName = optDelegateName ?? "Handle" + delegateType.Name;
var ecd = factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType);
ecd.DisplayFlags |= DisplayFlags.MarkedBold;
completionList.Add(ecd);
return sb.ToString();
//.........这里部分代码省略.........
示例7: AddDelegateHandlers
string AddDelegateHandlers(CompletionDataWrapper completionList, IType delegateType, bool addSemicolon = true, bool addDefault = true)
{
IMethod delegateMethod = delegateType.GetDelegateInvokeMethod();
var thisLineIndent = GetLineIndent(location.Line);
string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : "");
//bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate("));
if (addDefault) {
var oldDelegate = completionList.Result.FirstOrDefault(cd => cd.DisplayText == "delegate");
if (oldDelegate != null)
completionList.Result.Remove(oldDelegate);
completionList.AddCustom(
"delegate",
"Creates anonymous delegate.",
"delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
}
var sb = new StringBuilder("(");
var sbWithoutTypes = new StringBuilder("(");
for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
if (k > 0) {
sb.Append(", ");
sbWithoutTypes.Append(", ");
}
var parameterType = delegateMethod.Parameters [k].Type;
sb.Append(GetShortType(parameterType, GetState()));
sb.Append(" ");
sb.Append(delegateMethod.Parameters [k].Name);
sbWithoutTypes.Append(delegateMethod.Parameters [k].Name);
}
sb.Append(")");
sbWithoutTypes.Append(")");
completionList.AddCustom(
"delegate" + sb,
"Creates anonymous delegate.",
"delegate" + sb + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
if (!completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) {
completionList.AddCustom(
sbWithoutTypes.ToString(),
"Creates lambda expression.",
sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
);
}
/* TODO:Make factory method out of it.
// It's needed to temporarly disable inserting auto matching bracket because the anonymous delegates are selectable with '('
// otherwise we would end up with () => )
if (!containsDelegateData) {
var savedValue = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket;
MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = false;
completionList.Result.CompletionListClosed += delegate {
MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = savedValue;
};
}*/
return sb.ToString();
}
示例8: AddKeywords
static void AddKeywords(CompletionDataWrapper wrapper, IEnumerable<string> keywords)
{
foreach (string keyword in keywords) {
wrapper.AddCustom(keyword);
}
}
示例9: DefaultControlSpaceItems
IEnumerable<ICompletionData> DefaultControlSpaceItems(ExpressionResult xp = null, bool controlSpace = true)
{
var wrapper = new CompletionDataWrapper(this);
if (offset >= document.TextLength) {
offset = document.TextLength - 1;
}
while (offset > 1 && char.IsWhiteSpace (document.GetCharAt (offset))) {
offset--;
}
location = document.GetLocation(offset);
if (xp == null) {
xp = GetExpressionAtCursor();
}
AstNode node;
CompilationUnit unit;
Tuple<ResolveResult, CSharpResolver> rr;
if (xp != null) {
node = xp.Node;
rr = ResolveExpression(node, xp.Unit);
unit = xp.Unit;
} else {
unit = ParseStub("foo", false);
node = unit.GetNodeAt(
location.Line,
location.Column + 2,
n => n is Expression || n is AstType
);
rr = ResolveExpression(node, unit);
}
if (node is Identifier && node.Parent is ForeachStatement) {
var foreachStmt = (ForeachStatement)node.Parent;
foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) {
if (possibleName.Length > 0) {
wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
}
}
AutoSelect = false;
AutoCompleteEmptyMatch = false;
return wrapper.Result;
}
if (node is Identifier && node.Parent is ParameterDeclaration) {
if (!controlSpace) {
return null;
}
// Try Parameter name case
var param = node.Parent as ParameterDeclaration;
if (param != null) {
foreach (var possibleName in GenerateNameProposals (param.Type)) {
if (possibleName.Length > 0) {
wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
}
}
AutoSelect = false;
AutoCompleteEmptyMatch = false;
return wrapper.Result;
}
}
if (Unit != null && (node == null || node is TypeDeclaration)) {
var constructor = Unit.GetNodeAt<ConstructorDeclaration>(
location.Line,
location.Column - 3
);
if (constructor != null && !constructor.ColonToken.IsNull && constructor.Initializer.IsNull) {
wrapper.AddCustom("this");
wrapper.AddCustom("base");
return wrapper.Result;
}
}
var initializer = node != null ? node.Parent as ArrayInitializerExpression : null;
if (initializer != null) {
var result = HandleObjectInitializer(unit, initializer);
if (result != null)
return result;
}
CSharpResolver csResolver = null;
if (rr != null) {
csResolver = rr.Item2;
}
if (csResolver == null) {
if (node != null) {
csResolver = GetState();
//var astResolver = new CSharpAstResolver (csResolver, node, xp != null ? xp.Item1 : CSharpParsedFile);
try {
//csResolver = astResolver.GetResolverStateBefore (node);
Console.WriteLine(csResolver.LocalVariables.Count());
} catch (Exception e) {
Console.WriteLine("E!!!" + e);
}
} else {
csResolver = GetState();
}
}
AddContextCompletion(wrapper, csResolver, node, unit);
//.........这里部分代码省略.........
示例10: AddTypesAndNamespaces
//.........这里部分代码省略.........
}
if (!lookup.IsAccessible(member, isProtectedAllowed)) {
continue;
}
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
if (ctx.CurrentTypeDefinition != null) {
foreach (var p in ctx.CurrentTypeDefinition.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
}
var scope = ctx.CurrentUsingScope;
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddAlias(pair.Key);
}
foreach (var alias in n.ExternAliases) {
wrapper.AddAlias(alias);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (onlyAddConstructors && addType != null) {
if (!addType.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
if (addType != null) {
var a2 = onlyAddConstructors ? wrapper.AddConstructors(addType, false, IsAttributeContext(node)) : wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint && IncludeKeywordsInCompletionList) {
wrapper.AddCustom ("new()");
}
if (AutomaticallyAddImports) {
state = GetState();
foreach (var type in Compilation.GetAllTypeDefinitions ()) {
if (!lookup.IsAccessible (type, false))
continue;
var resolveResult = state.LookupSimpleNameOrTypeName(type.Name, type.TypeArguments, NameLookupMode.Expression);
if (resolveResult.Type.GetDefinition () == type)
continue;
if (onlyAddConstructors) {
if (!type.GetConstructors().Any(c => lookup.IsAccessible(c, true)))
continue;
}
wrapper.AddTypeImport(type, !resolveResult.IsError, onlyAddConstructors);
}
}
}
示例11: AddTypesAndNamespaces
//.........这里部分代码省略.........
wrapper.AddType(nestedType, false, IsAttributeContext(node));
continue;
}
var type = typePred(nestedType);
if (type != null) {
var a2 = wrapper.AddType(type, false, IsAttributeContext(node));
if (a2 != null && callback != null) {
callback(a2, type);
}
}
continue;
}
}
if (this.currentMember != null && !(node is AstType)) {
var def = ctx.CurrentTypeDefinition;
if (def == null && currentType != null)
def = Compilation.MainAssembly.GetTypeDefinition(currentType.FullTypeName);
if (def != null) {
bool isProtectedAllowed = true;
foreach (var member in def.GetMembers (m => currentMember.IsStatic ? m.IsStatic : true)) {
if (member is IMethod && ((IMethod)member).FullName == "System.Object.Finalize") {
continue;
}
if (member.EntityType == EntityType.Operator) {
continue;
}
if (member.IsExplicitInterfaceImplementation) {
continue;
}
if (!lookup.IsAccessible(member, isProtectedAllowed)) {
continue;
}
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
if (memberPred == null || memberPred(member)) {
wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
if (ctx.CurrentTypeDefinition != null) {
foreach (var p in ctx.CurrentTypeDefinition.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
}
var scope = ctx.CurrentUsingScope;
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
wrapper.AddAlias(pair.Key);
}
foreach (var alias in n.ExternAliases) {
wrapper.AddAlias(alias);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
var a = wrapper.AddType(addType, false, IsAttributeContext(node));
if (a != null && callback != null) {
callback(a, type);
}
}
}
}
foreach (var type in n.Namespace.Types) {
if (!lookup.IsAccessible(type, false))
continue;
IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
var a2 = wrapper.AddType(addType, false);
if (a2 != null && callback != null) {
callback(a2, type);
}
}
}
foreach (var curNs in n.Namespace.ChildNamespaces) {
wrapper.AddNamespace(lookup, curNs);
}
}
if (node is AstType && node.Parent is Constraint) {
wrapper.AddCustom ("new()");
}
}
示例12: AddDelegateHandlers
string AddDelegateHandlers(CompletionDataWrapper completionList, IType delegateType, bool addSemicolon = true, bool addDefault = true, string optDelegateName = null)
{
IMethod delegateMethod = delegateType.GetDelegateInvokeMethod();
PossibleDelegates.Add(delegateMethod);
var thisLineIndent = GetLineIndent(location.Line);
string delegateEndString = EolMarker + thisLineIndent + "}" + (addSemicolon ? ";" : "");
//bool containsDelegateData = completionList.Result.Any(d => d.DisplayText.StartsWith("delegate("));
if (addDefault && !completionList.AnonymousDelegateAdded) {
completionList.AnonymousDelegateAdded = true;
var oldDelegate = completionList.Result.FirstOrDefault(cd => cd.DisplayText == "delegate");
if (oldDelegate != null)
completionList.Result.Remove(oldDelegate);
completionList.AddCustom(
"delegate",
"Creates anonymous delegate.",
"delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate",
"Creates anonymous async delegate.",
"async delegate {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
}
}
var sb = new StringBuilder("(");
var sbWithoutTypes = new StringBuilder("(");
var state = GetState();
var builder = new TypeSystemAstBuilder(state);
for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
if (k > 0) {
sb.Append(", ");
sbWithoutTypes.Append(", ");
}
var convertedParameter = builder.ConvertParameter(delegateMethod.Parameters [k]);
if (convertedParameter.ParameterModifier == ParameterModifier.Params)
convertedParameter.ParameterModifier = ParameterModifier.None;
sb.Append(convertedParameter.ToString(FormattingPolicy));
sbWithoutTypes.Append(delegateMethod.Parameters [k].Name);
}
sb.Append(")");
sbWithoutTypes.Append(")");
var signature = sb.ToString();
if (!completionList.HasAnonymousDelegateAdded(signature)) {
completionList.AddAnonymousDelegateAdded(signature);
completionList.AddCustom(
"delegate" + signature,
"Creates anonymous delegate.",
"delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async delegate" + signature,
"Creates anonymous async delegate.",
"async delegate" + signature + " {" + EolMarker + thisLineIndent + IndentString + "|" + delegateEndString
);
}
if (!completionList.Result.Any(data => data.DisplayText == sb.ToString())) {
completionList.AddCustom(
signature,
"Creates typed lambda expression.",
signature + " => |" + (addSemicolon ? ";" : "")
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + signature,
"Creates typed async lambda expression.",
"async " + signature + " => |" + (addSemicolon ? ";" : "")
);
}
if (!delegateMethod.Parameters.Any(p => p.IsOut || p.IsRef) && !completionList.Result.Any(data => data.DisplayText == sbWithoutTypes.ToString())) {
completionList.AddCustom(
sbWithoutTypes.ToString(),
"Creates lambda expression.",
sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
);
if (LanguageVersion.Major >= 5) {
completionList.AddCustom(
"async " + sbWithoutTypes,
"Creates async lambda expression.",
"async " + sbWithoutTypes + " => |" + (addSemicolon ? ";" : "")
);
}
}
}
}
string varName = "Handle" + delegateType.Name + optDelegateName;
completionList.Add(factory.CreateEventCreationCompletionData(varName, delegateType, null, signature, currentMember, currentType));
/* TODO:Make factory method out of it.
// It's needed to temporarly disable inserting auto matching bracket because the anonymous delegates are selectable with '('
// otherwise we would end up with () => )
//.........这里部分代码省略.........
示例13: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node, CompilationUnit unit)
{
if (state != null && !(node is AstType)) {
foreach (var variable in state.LocalVariables) {
if (variable.Region.IsInside(location.Line, location.Column - 1)) {
continue;
}
wrapper.AddVariable(variable);
}
}
if (currentMember is IUnresolvedParameterizedMember && !(node is AstType)) {
var param = (IParameterizedMember)currentMember.CreateResolved(ctx);
foreach (var p in param.Parameters) {
wrapper.AddVariable(p);
}
}
if (currentMember is IUnresolvedMethod) {
var method = (IUnresolvedMethod)currentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter(p);
}
}
Func<IType, IType> typePred = null;
if (IsAttributeContext(node)) {
var attribute = Compilation.FindType(KnownTypeCode.Attribute);
typePred = t => {
return t.GetAllBaseTypeDefinitions().Any(bt => bt.Equals(attribute)) ? t : null;
};
}
AddTypesAndNamespaces(wrapper, state, node, typePred);
wrapper.Result.Add(factory.CreateLiteralCompletionData("global"));
if (!(node is AstType)) {
if (currentMember != null || node is Expression) {
AddKeywords(wrapper, statementStartKeywords);
AddKeywords(wrapper, expressionLevelKeywords);
if (node is TypeDeclaration)
AddKeywords(wrapper, typeLevelKeywords);
} else if (currentType != null) {
AddKeywords(wrapper, typeLevelKeywords);
} else {
AddKeywords(wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter != null && prop.Setter.Region.IsInside(location)) {
wrapper.AddCustom("value");
}
if (currentMember is IUnresolvedEvent) {
wrapper.AddCustom("value");
}
if (IsInSwitchContext(node)) {
wrapper.AddCustom("case");
}
} else {
if (((AstType)node).Parent is ParameterDeclaration) {
AddKeywords(wrapper, parameterTypePredecessorKeywords);
}
}
AddKeywords(wrapper, primitiveTypesKeywords);
if (currentMember != null) {
wrapper.AddCustom("var");
}
wrapper.Result.AddRange(factory.CreateCodeTemplateCompletionData());
if (node != null && node.Role == Roles.Argument) {
var resolved = ResolveExpression(node.Parent, unit);
var invokeResult = resolved != null ? resolved.Item1 as CSharpInvocationResolveResult : null;
if (invokeResult != null) {
int argNum = 0;
foreach (var arg in node.Parent.Children.Where (c => c.Role == Roles.Argument)) {
if (arg == node) {
break;
}
argNum++;
}
var param = argNum < invokeResult.Member.Parameters.Count ? invokeResult.Member.Parameters [argNum] : null;
if (param != null && param.Type.Kind == TypeKind.Enum) {
AddEnumMembers(wrapper, param.Type, state);
}
}
}
if (node is Expression) {
var astResolver = new CSharpAstResolver(state, unit, CSharpParsedFile);
foreach (var type in CreateFieldAction.GetValidTypes(astResolver, (Expression)node)) {
if (type.Kind == TypeKind.Enum) {
AddEnumMembers(wrapper, type, state);
} else if (type.Kind == TypeKind.Delegate) {
AddDelegateHandlers(wrapper, type, true, true);
AutoSelect = false;
AutoCompleteEmptyMatch = false;
}
}
}
//.........这里部分代码省略.........
示例14: MagicKeyCompletion
//.........这里部分代码省略.........
if (identifierStart == null && !string.IsNullOrEmpty(token) && !IsInsideCommentStringOrDirective() && (prevToken2 == ";" || prevToken2 == "{" || prevToken2 == "}")) {
char last = token [token.Length - 1];
if (char.IsLetterOrDigit(last) || last == '_' || token == ">") {
return HandleKeywordCompletion(tokenIndex, token);
}
}
if (identifierStart == null) {
var accCtx = HandleAccessorContext();
if (accCtx != null) {
return accCtx;
}
return DefaultControlSpaceItems(ref isComplete, null, controlSpace);
}
CSharpResolver csResolver;
AstNode n = identifierStart.Node;
if (n.Parent is NamedArgumentExpression)
n = n.Parent;
if (n != null && n.Parent is AnonymousTypeCreateExpression) {
AutoSelect = false;
}
// new { b$ }
if (n is IdentifierExpression && n.Parent is AnonymousTypeCreateExpression)
return null;
// Handle foreach (type name _
if (n is IdentifierExpression) {
var prev = n.GetPrevNode() as ForeachStatement;
while (prev != null && prev.EmbeddedStatement is ForeachStatement)
prev = (ForeachStatement)prev.EmbeddedStatement;
if (prev != null && prev.InExpression.IsNull) {
if (IncludeKeywordsInCompletionList)
contextList.AddCustom("in");
return contextList.Result;
}
}
// Handle object/enumerable initialzer expressions: "new O () { P$"
if (n is IdentifierExpression && n.Parent is ArrayInitializerExpression && !(n.Parent.Parent is ArrayCreateExpression)) {
var result = HandleObjectInitializer(identifierStart.Unit, n);
if (result != null)
return result;
}
if (n != null && n.Parent is InvocationExpression ||
n.Parent is ParenthesizedExpression && n.Parent.Parent is InvocationExpression) {
if (n.Parent is ParenthesizedExpression)
n = n.Parent;
var invokeParent = (InvocationExpression)n.Parent;
var invokeResult = ResolveExpression(
invokeParent.Target
);
var mgr = invokeResult != null ? invokeResult.Result as MethodGroupResolveResult : null;
if (mgr != null) {
int idx = 0;
foreach (var arg in invokeParent.Arguments) {
if (arg == n) {
break;
}
idx++;
}
foreach (var method in mgr.Methods) {
if (idx < method.Parameters.Count && method.Parameters [idx].Type.Kind == TypeKind.Delegate) {
AutoSelect = false;
AutoCompleteEmptyMatch = false;
示例15: AddContextCompletion
void AddContextCompletion(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node)
{
if (state != null) {
foreach (var variable in state.LocalVariables) {
wrapper.AddVariable (variable);
}
}
if (ctx.CurrentMember is IParameterizedMember) {
var param = (IParameterizedMember)ctx.CurrentMember;
foreach (var p in param.Parameters) {
wrapper.AddVariable (p);
}
}
if (currentMember is IUnresolvedMethod) {
var method = (IUnresolvedMethod)currentMember;
foreach (var p in method.TypeParameters) {
wrapper.AddTypeParameter (p);
}
}
Predicate<IType> typePred = null;
if (node is Attribute) {
var attribute = Compilation.FindType (typeof (System.Attribute));
typePred = t => {
return t.GetAllBaseTypeDefinitions ().Any (bt => bt.Equals (attribute));
};
}
AddTypesAndNamespaces (wrapper, state, node, typePred);
wrapper.Result.Add (factory.CreateLiteralCompletionData ("global"));
if (state.CurrentMember != null) {
AddKeywords (wrapper, statementStartKeywords);
AddKeywords (wrapper, expressionLevelKeywords);
} else if (state.CurrentTypeDefinition != null) {
AddKeywords (wrapper, typeLevelKeywords);
} else {
AddKeywords (wrapper, globalLevelKeywords);
}
var prop = currentMember as IUnresolvedProperty;
if (prop != null && prop.Setter.Region.IsInside (location))
wrapper.AddCustom ("value");
if (currentMember is IUnresolvedEvent)
wrapper.AddCustom ("value");
if (IsInSwitchContext (node)) {
wrapper.AddCustom ("case");
wrapper.AddCustom ("default");
}
AddKeywords (wrapper, primitiveTypesKeywords);
wrapper.Result.AddRange (factory.CreateCodeTemplateCompletionData ());
}