本文整理汇总了C#中ASCompletion.Model.ClassModel.ResolveExtends方法的典型用法代码示例。如果您正苦于以下问题:C# ClassModel.ResolveExtends方法的具体用法?C# ClassModel.ResolveExtends怎么用?C# ClassModel.ResolveExtends使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASCompletion.Model.ClassModel
的用法示例。
在下文中一共展示了ClassModel.ResolveExtends方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateImplementation
private static void GenerateImplementation(ClassModel aType, int position)
{
List<string> typesUsed = new List<string>();
StringBuilder sb = new StringBuilder(TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class", aType.Type));
sb.Append(NewLine);
bool entry = true;
ASResult result = new ASResult();
IASContext context = ASContext.Context;
ClassModel cClass = context.CurrentClass;
ContextFeatures features = context.Features;
bool canGenerate = false;
aType.ResolveExtends(); // resolve inheritance chain
while (!aType.IsVoid() && aType.QualifiedName != "Object")
{
foreach (MemberModel method in aType.Members)
{
if ((method.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) == 0
|| method.Name == aType.Name)
continue;
// check if method exists
ASComplete.FindMember(method.Name, cClass, result, method.Flags, 0);
if (!result.IsNull()) continue;
string decl = entry ? NewLine : "";
if ((method.Flags & FlagType.Getter) > 0)
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Getter"));
else if ((method.Flags & FlagType.Setter) > 0)
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Setter"));
else
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Function"));
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Member", "_" + method.Name);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Void", features.voidKey);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Body", null);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", NewLine);
if (!entry)
{
decl = TemplateUtils.ReplaceTemplateVariable(decl, "EntryPoint", null);
}
decl += NewLine;
entry = false;
sb.Append(decl);
canGenerate = true;
addTypeOnce(typesUsed, getQualifiedType(method.Type, aType));
if (method.Parameters != null && method.Parameters.Count > 0)
foreach (MemberModel param in method.Parameters)
addTypeOnce(typesUsed, getQualifiedType(param.Type, aType));
}
// interface inheritance
aType = aType.Extends;
}
if (!canGenerate)
return;
ScintillaNet.ScintillaControl Sci = ASContext.CurSciControl;
Sci.BeginUndoAction();
try
{
position = Sci.CurrentPos;
if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0)
{
int offset = AddImportsByName(typesUsed, Sci.LineFromPosition(position));
position += offset;
Sci.SetSel(position, position);
}
InsertCode(position, sb.ToString());
}
finally { Sci.EndUndoAction(); }
}
示例2: GenerateDelegateMethods
public static void GenerateDelegateMethods(ScintillaNet.ScintillaControl Sci, MemberModel member,
Dictionary<MemberModel, ClassModel> selectedMembers, ClassModel classModel, ClassModel inClass)
{
Sci.BeginUndoAction();
try
{
string result = TemplateUtils.ReplaceTemplateVariable(
TemplateUtils.GetTemplate("DelegateMethodsHeader"),
"Class",
classModel.Type);
int position = -1;
ClassModel type;
List<string> importsList = new List<string>();
bool isStaticMember = false;
if ((member.Flags & FlagType.Static) > 0)
isStaticMember = true;
inClass.ResolveExtends();
Dictionary<MemberModel, ClassModel>.KeyCollection selectedMemberKeys = selectedMembers.Keys;
foreach (MemberModel m in selectedMemberKeys)
{
MemberModel mCopy = (MemberModel) m.Clone();
string methodTemplate = NewLine;
bool overrideFound = false;
ClassModel baseClassType = inClass;
while (baseClassType != null && !baseClassType.IsVoid())
{
MemberList inClassMembers = baseClassType.Members;
foreach (MemberModel inClassMember in inClassMembers)
{
if ((inClassMember.Flags & FlagType.Function) > 0
&& m.Name.Equals(inClassMember.Name))
{
mCopy.Flags |= FlagType.Override;
overrideFound = true;
break;
}
}
if (overrideFound)
break;
baseClassType = baseClassType.Extends;
}
if (isStaticMember && (m.Flags & FlagType.Static) == 0)
mCopy.Flags |= FlagType.Static;
if ((m.Flags & FlagType.Setter) > 0)
{
methodTemplate += TemplateUtils.GetTemplate("Setter");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Modifiers",
(TemplateUtils.GetStaticExternOverride(m) + TemplateUtils.GetModifiers(m)).Trim());
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Name", m.Name);
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", "");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Type", m.Parameters[0].Type);
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Member", member.Name + "." + m.Name);
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Void", ASContext.Context.Features.voidKey ?? "void");
}
else if ((m.Flags & FlagType.Getter) > 0)
{
methodTemplate += TemplateUtils.GetTemplate("Getter");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Modifiers",
(TemplateUtils.GetStaticExternOverride(m) + TemplateUtils.GetModifiers(m)).Trim());
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Name", m.Name);
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", "");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Type", FormatType(m.Type));
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Member", member.Name + "." + m.Name);
}
else
{
methodTemplate += TemplateUtils.GetTemplate("Function");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Body", "<<$(Return) >>$(Body)");
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", null);
methodTemplate = TemplateUtils.ToDeclarationWithModifiersString(mCopy, methodTemplate);
if (m.Type != null && m.Type.ToLower() != "void")
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Return", "return");
else
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Return", null);
// check for varargs
bool isVararg = false;
if (m.Parameters != null && m.Parameters.Count > 0)
{
MemberModel mm = m.Parameters[m.Parameters.Count - 1];
if (mm.Name.StartsWith("..."))
isVararg = true;
}
string callMethodTemplate = TemplateUtils.GetTemplate("CallFunction");
if (!isVararg)
{
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Name", member.Name + "." + m.Name);
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Arguments",
TemplateUtils.CallParametersString(m));
//.........这里部分代码省略.........
示例3: GenerateToString
private static void GenerateToString(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
MemberModel resultMember = new MemberModel("toString", "String", FlagType.Function, Visibility.Public);
bool isOverride = false;
inClass.ResolveExtends();
if (inClass.Extends != null)
{
ClassModel aType = inClass.Extends;
while (!aType.IsVoid() && aType.QualifiedName != "Object")
{
foreach (MemberModel method in aType.Members)
{
if (method.Name == "toString")
{
isOverride = true;
break;
}
}
if (isOverride)
{
resultMember.Flags |= FlagType.Override;
break;
}
// interface inheritance
aType = aType.Extends;
}
}
MemberList members = inClass.Members;
StringBuilder membersString = new StringBuilder();
StringBuilder oneMembersString;
int len = 0;
int indent = Sci.GetLineIndentation(Sci.CurrentLine);
foreach (MemberModel m in members)
{
if (((m.Flags & FlagType.Variable) > 0 || (m.Flags & FlagType.Getter) > 0)
&& (m.Access & Visibility.Public) > 0
&& (m.Flags & FlagType.Constant) == 0)
{
oneMembersString = new StringBuilder();
oneMembersString.Append(" ").Append(m.Name).Append("=\" + ").Append(m.Name).Append(" + ");
membersString.Append(oneMembersString);
len += oneMembersString.Length;
if (len > 80)
{
len = 0;
membersString.Append("\n\t\t\t\t");
}
membersString.Append("\"");
}
}
string template = TemplateUtils.GetTemplate("ToString");
string result = TemplateUtils.ToDeclarationWithModifiersString(resultMember, template);
result = TemplateUtils.ReplaceTemplateVariable(result, "Body", "\"[" + inClass.Name + membersString.ToString() + "]\"");
InsertCode(Sci.CurrentPos, result);
}
示例4: GenerateImplementation
private static void GenerateImplementation(ClassModel iType, ClassModel inClass, ScintillaControl sci, bool detached)
{
List<string> typesUsed = new List<string>();
StringBuilder sb = new StringBuilder();
string header = TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class",
iType.Type);
header = TemplateUtils.ReplaceTemplateVariable(header, "BlankLine", detached ? BlankLine : null);
sb.Append(header);
sb.Append(NewLine);
bool entry = true;
ASResult result = new ASResult();
IASContext context = ASContext.Context;
ContextFeatures features = context.Features;
bool canGenerate = false;
bool isHaxe = IsHaxe;
FlagType flags = (FlagType.Function | FlagType.Getter | FlagType.Setter);
if (isHaxe) flags |= FlagType.Variable;
iType.ResolveExtends(); // resolve inheritance chain
while (!iType.IsVoid() && iType.QualifiedName != "Object")
{
foreach (MemberModel method in iType.Members)
{
if ((method.Flags & flags) == 0
|| method.Name == iType.Name)
continue;
// check if method exists
ASComplete.FindMember(method.Name, inClass, result, method.Flags, 0);
if (!result.IsNull()) continue;
string decl;
if ((method.Flags & FlagType.Getter) > 0)
{
if (isHaxe)
{
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Property"));
string templateName = null;
string metadata = null;
if (method.Parameters[0].Name == "get")
{
if (method.Parameters[1].Name == "set")
{
templateName = "GetterSetter";
metadata = "@:isVar";
}
else
templateName = "Getter";
}
else if (method.Parameters[1].Name == "set")
{
templateName = "Setter";
}
decl = TemplateUtils.ReplaceTemplateVariable(decl, "MetaData", metadata);
if (templateName != null)
{
var accessor = NewLine + TemplateUtils.ToDeclarationString(method, TemplateUtils.GetTemplate(templateName));
accessor = TemplateUtils.ReplaceTemplateVariable(accessor, "Modifiers", null);
accessor = TemplateUtils.ReplaceTemplateVariable(accessor, "Member", method.Name);
decl += accessor;
}
}
else
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Getter"));
}
else if ((method.Flags & FlagType.Setter) > 0)
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Setter"));
else if ((method.Flags & FlagType.Function) > 0)
decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Function"));
else
decl = NewLine + TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Variable"));
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Member", "_" + method.Name);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Void", features.voidKey);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "Body", null);
decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", NewLine);
if (!entry)
{
decl = TemplateUtils.ReplaceTemplateVariable(decl, "EntryPoint", null);
}
decl += NewLine;
entry = false;
sb.Append(decl);
canGenerate = true;
AddTypeOnce(typesUsed, GetQualifiedType(method.Type, iType));
if (method.Parameters != null && method.Parameters.Count > 0)
foreach (MemberModel param in method.Parameters)
AddTypeOnce(typesUsed, GetQualifiedType(param.Type, iType));
//.........这里部分代码省略.........
示例5: GenerateDelegateMethods
public static void GenerateDelegateMethods(ScintillaNet.ScintillaControl Sci, MemberModel member,
Dictionary<MemberModel, ClassModel> selectedMembers, ClassModel classModel, ClassModel inClass)
{
Sci.BeginUndoAction();
try
{
StringBuilder sb = new StringBuilder(
String.Format(GetTemplate("DelegateMethodsHeader", "$(Boundary)\n\n/* DELEGATE {0} */"), classModel.Type));
MemberModel latest;
int position = -1;
List<MemberModel> methodParams;
ClassModel type;
List<string> importsList = new List<string>();
bool isStaticMember = false;
if ((member.Flags & FlagType.Static) > 0)
{
isStaticMember = true;
}
inClass.ResolveExtends();
Dictionary<MemberModel, ClassModel>.KeyCollection selectedMemberKeys = selectedMembers.Keys;
foreach (MemberModel m in selectedMemberKeys)
{
sb.Append("$(Boundary)\n\n");
bool overrideFound = false;
ClassModel aType = inClass;
while (aType != null && !aType.IsVoid())
{
MemberList inClassMembers = aType.Members;
foreach (MemberModel inClassMember in inClassMembers)
{
if ((inClassMember.Flags & FlagType.Function) > 0
&& m.Name.Equals(inClassMember.Name))
{
sb.Append("override ");
overrideFound = true;
break;
}
}
if (overrideFound)
{
break;
}
aType = aType.Extends;
}
if (isStaticMember)
{
sb.Append("static ");
}
sb.Append(GetDeclaration(m))
.Append(" $(CSLB){\n\t");
if (m.Type != null && m.Type.ToLower() != "void")
{
sb.Append("return ");
}
methodParams = m.Parameters;
// check for varargs
bool isVararg = false;
if (methodParams != null && methodParams.Count > 0)
{
MemberModel mm = methodParams[methodParams.Count - 1];
if (mm.Name.StartsWith("..."))
{
isVararg = true;
}
}
if (!isVararg)
{
sb.Append(member.Name)
.Append(".")
.Append(m.Name)
.Append("(");
if (methodParams != null)
{
for (int i = 0; i < methodParams.Count; i++)
{
MemberModel param = methodParams[i];
sb.Append(param.Name);
if (i + 1 < methodParams.Count)
{
sb.Append(", ");
}
}
}
sb.Append(");");
}
else
//.........这里部分代码省略.........
示例6: GenerateImplementation
private static void GenerateImplementation(ClassModel aType, int position)
{
List<string> typesUsed = new List<string>();
StringBuilder sb = new StringBuilder(String.Format(GetTemplate("ImplementHeader"), aType.Type));
string entry = "$(EntryPoint)";
ASResult result = new ASResult();
IASContext context = ASContext.Context;
ClassModel cClass = context.CurrentClass;
ContextFeatures features = context.Features;
bool canGenerate = false;
string template = GetTemplate("ImplementPart");
aType.ResolveExtends(); // resolve inheritance chain
while (!aType.IsVoid() && aType.QualifiedName != "Object")
{
foreach (MemberModel method in aType.Members)
{
if ((method.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) == 0
|| method.Name == aType.Name)
continue;
// check if method exists
ASComplete.FindMember(method.Name, cClass, result, method.Flags, 0);
if (!result.IsNull()) continue;
string decl = String.Format(template, GetDeclaration(method), entry);
entry = "";
sb.Append(decl);
canGenerate = true;
addTypeOnce(typesUsed, getQualifiedType(method.Type, aType));
if (method.Parameters != null && method.Parameters.Count > 0)
foreach (MemberModel param in method.Parameters)
addTypeOnce(typesUsed, getQualifiedType(param.Type, aType));
}
// interface inheritance
aType = aType.Extends;
}
if (!canGenerate)
return;
ScintillaNet.ScintillaControl Sci = ASContext.CurSciControl;
Sci.BeginUndoAction();
try
{
position = Sci.CurrentPos;
if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0)
{
int offset = AddImportsByName(typesUsed, Sci.LineFromPosition(position));
position += offset;
Sci.SetSel(position, position);
}
InsertCode(position, sb.ToString());
}
finally { Sci.EndUndoAction(); }
}
示例7: GenerateToString
private static void GenerateToString(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
bool isOverride = false;
inClass.ResolveExtends();
if (inClass.Extends != null)
{
ClassModel aType = inClass.Extends;
while (!aType.IsVoid() && aType.QualifiedName != "Object")
{
foreach (MemberModel method in aType.Members)
{
if (method.Name == "toString")
{
isOverride = true;
break;
}
}
if (isOverride)
{
break;
}
// interface inheritance
aType = aType.Extends;
}
}
MemberList members = inClass.Members;
StringBuilder membersString = new StringBuilder();
StringBuilder oneMembersString;
int len = 0;
int indent = Sci.GetLineIndentation(Sci.LineFromPosition(Sci.CurrentPos));
foreach (MemberModel m in members)
{
if (((m.Flags & FlagType.Variable) > 0 || (m.Flags & FlagType.Getter) > 0)
&& (m.Access & Visibility.Public) > 0
&& (m.Flags & FlagType.Constant) == 0)
{
oneMembersString = new StringBuilder();
oneMembersString.Append(" ").Append(m.Name).Append("=\" + ").Append(m.Name).Append(" + ");
membersString.Append(oneMembersString);
len += oneMembersString.Length;
if (len > 80)
{
len = 0;
membersString.Append("\n\t\t\t\t");
}
membersString.Append("\"");
}
}
member = new MemberModel("toString", "String", FlagType.Function, Visibility.Public);
string repl = GetDeclaration(member, true).Replace("()", "($(EntryPoint))");
if (isOverride)
{
repl = "override " + repl;
}
string tmpl = GetTemplate("ToString", "{0} $(CSLB){{\n\treturn {1};\n}}");
string toStringData = "\"[" + inClass.Name + membersString.ToString() + "]\"";
string decl = String.Format(tmpl, repl, toStringData);
InsertCode(Sci.CurrentPos, decl);
}