本文整理汇总了C#中ScintillaNet.LineFromPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaNet.LineFromPosition方法的具体用法?C# ScintillaNet.LineFromPosition怎么用?C# ScintillaNet.LineFromPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet
的用法示例。
在下文中一共展示了ScintillaNet.LineFromPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignStatementToVar
private static void AssignStatementToVar(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
int lineNum = Sci.LineFromPosition(Sci.CurrentPos);
string line = Sci.GetLine(lineNum);
StatementReturnType returnType = GetStatementReturnType(Sci, inClass, line, Sci.PositionFromLine(lineNum));
if (returnType == null)
{
return;
}
IASContext cntx = inClass.InFile.Context;
bool isAs3 = cntx.Settings.LanguageId == "AS3";
string voidWord = isAs3 ? "void" : "Void";
string type = null;
string varname = null;
string cleanType = null;
ASResult resolve = returnType.resolve;
int pos = returnType.position;
string word = returnType.word;
if (resolve != null && !resolve.IsNull())
{
if (resolve.Member != null && resolve.Member.Type != null)
{
type = resolve.Member.Type;
}
else if (resolve.Type != null && resolve.Type.Name != null)
{
type = returnType.resolve.Type.QualifiedName;
}
if (resolve.Member != null && resolve.Member.Name != null)
{
varname = GuessVarName(resolve.Member.Name, type);
}
}
if (word != null && Char.IsDigit(word[0])) word = null;
if (type == voidWord) type = null;
if (varname == null) varname = GuessVarName(word, type);
if (varname != null && varname == word)
varname = varname.Length == 1 ? varname + "1" : varname[0] + "";
if (type != null) cleanType = FormatType(GetShortType(type));
string template = TemplateUtils.GetTemplate("AssignVariable");
if (varname != null)
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", varname);
else
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", null);
if (cleanType != null)
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", cleanType);
else
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", null);
int indent = Sci.GetLineIndentation(lineNum);
pos = Sci.PositionFromLine(lineNum) + indent / Sci.Indent;
Sci.CurrentPos = pos;
Sci.SetSel(pos, pos);
InsertCode(pos, template);
if (type != null)
{
ClassModel inClassForImport = null;
if (resolve.InClass != null)
{
inClassForImport = resolve.InClass;
}
else if (resolve.RelClass != null)
{
inClassForImport = resolve.RelClass;
}
else
{
inClassForImport = inClass;
}
List<string> l = new List<string>();
l.Add(getQualifiedType(type, inClassForImport));
pos += AddImportsByName(l, Sci.LineFromPosition(pos));
}
}
示例2: GenerateOverride
static public void GenerateOverride(ScintillaNet.ScintillaControl Sci, ClassModel ofClass, MemberModel member, int position)
{
ContextFeatures features = ASContext.Context.Features;
List<string> typesUsed = new List<string>();
bool isProxy = (member.Namespace == "flash_proxy");
if (isProxy) typesUsed.Add("flash.utils.flash_proxy");
bool isAS2Event = ASContext.Context.Settings.LanguageId == "AS2" && member.Name.StartsWith("on");
bool isObjectMethod = ofClass.QualifiedName == "Object";
int line = Sci.LineFromPosition(position);
string currentText = Sci.GetLine(line);
int startPos = currentText.Length;
GetStartPos(currentText, ref startPos, features.privateKey);
GetStartPos(currentText, ref startPos, features.protectedKey);
GetStartPos(currentText, ref startPos, features.internalKey);
GetStartPos(currentText, ref startPos, features.publicKey);
GetStartPos(currentText, ref startPos, features.staticKey);
GetStartPos(currentText, ref startPos, features.overrideKey);
startPos += Sci.PositionFromLine(line);
FlagType flags = member.Flags;
string acc = "";
string decl = "";
if (features.hasNamespaces && !string.IsNullOrEmpty(member.Namespace) && member.Namespace != "internal")
acc = member.Namespace;
else if ((member.Access & Visibility.Public) > 0) acc = features.publicKey;
else if ((member.Access & Visibility.Internal) > 0) acc = features.internalKey;
else if ((member.Access & Visibility.Protected) > 0) acc = features.protectedKey;
else if ((member.Access & Visibility.Private) > 0 && features.methodModifierDefault != Visibility.Private)
acc = features.privateKey;
bool isStatic = (flags & FlagType.Static) > 0;
if (isStatic) acc = features.staticKey + " " + acc;
if (!isAS2Event && !isObjectMethod)
acc = features.overrideKey + " " + acc;
acc = Regex.Replace(acc, "[ ]+", " ").Trim();
if ((flags & (FlagType.Getter | FlagType.Setter)) > 0)
{
string type = member.Type;
string name = member.Name;
if (member.Parameters != null && member.Parameters.Count == 1)
type = member.Parameters[0].Type;
type = FormatType(type);
if (type == null && !features.hasInference) type = features.objectKey;
bool genGetter = ofClass.Members.Search(name, FlagType.Getter, 0) != null;
bool genSetter = ofClass.Members.Search(name, FlagType.Setter, 0) != null;
if (isHaxe)
{
// property is public but not the methods
acc = features.overrideKey;
}
if (genGetter)
{
string tpl = TemplateUtils.GetTemplate("OverrideGetter", "Getter");
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Modifiers", acc);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Name", name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Type", type);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Member", "super." + name);
decl += tpl;
}
if (genSetter)
{
string tpl = TemplateUtils.GetTemplate("OverrideSetter", "Setter");
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Modifiers", acc);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Name", name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Type", type);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Member", "super." + name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Void", ASContext.Context.Features.voidKey ?? "void");
if (decl.Length > 0)
{
tpl = "\n\n" + tpl.Replace("$(EntryPoint)", "");
}
decl += tpl;
}
decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", "");
}
else
{
string type = FormatType(member.Type);
//if (type == null) type = features.objectKey;
decl = acc + features.functionKey + " ";
bool noRet = type == null || type.Equals("void", StringComparison.OrdinalIgnoreCase);
type = (noRet && type != null) ? ASContext.Context.Features.voidKey : type;
if (!noRet)
{
string qType = getQualifiedType(type, ofClass);
typesUsed.Add(qType);
if (qType == type)
{
ClassModel rType = ASContext.Context.ResolveType(type, ofClass.InFile);
if (!rType.IsVoid()) type = rType.Name;
}
}
//.........这里部分代码省略.........
示例3: ContextualGenerator
static public void ContextualGenerator(ScintillaNet.ScintillaControl Sci)
{
if (ASContext.Context is ASContext) (ASContext.Context as ASContext).UpdateCurrentFile(false); // update model
if ((ASContext.Context.CurrentClass.Flags & (FlagType.Enum | FlagType.TypeDef)) > 0) return;
lookupPosition = -1;
int position = Sci.CurrentPos;
if (Sci.BaseStyleAt(position) == 19) // on keyword
return;
bool isNotInterface = (ASContext.Context.CurrentClass.Flags & FlagType.Interface) == 0;
int line = Sci.LineFromPosition(position);
contextToken = Sci.GetWordFromPosition(position);
contextMatch = null;
FoundDeclaration found = GetDeclarationAtLine(Sci, line);
string text = Sci.GetLine(line);
bool suggestItemDeclaration = false;
if (isNotInterface && !String.IsNullOrEmpty(contextToken) && Char.IsDigit(contextToken[0]))
{
ShowConvertToConst(found);
return;
}
ASResult resolve = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(position, true));
contextResolved = resolve;
// ignore automatic vars (MovieClip members)
if (isNotInterface
&& resolve.Member != null
&& (((resolve.Member.Flags & FlagType.AutomaticVar) > 0) || (resolve.InClass != null && resolve.InClass.QualifiedName == "Object")))
{
resolve.Member = null;
resolve.Type = null;
}
if (isNotInterface && found.inClass != ClassModel.VoidClass && contextToken != null)
{
if (resolve.Member == null && resolve.Type != null
&& (resolve.Type.Flags & FlagType.Interface) > 0) // implement interface
{
contextParam = resolve.Type.Type;
ShowImplementInterface(found);
return;
}
if (resolve.Member != null && !ASContext.Context.CurrentClass.IsVoid()
&& (resolve.Member.Flags & FlagType.LocalVar) > 0) // promote to class var
{
contextMember = resolve.Member;
ShowPromoteLocalAndAddParameter(found);
return;
}
}
if (contextToken != null && resolve.Member == null) // import declaration
{
if ((resolve.Type == null || resolve.Type.IsVoid() || !ASContext.Context.IsImported(resolve.Type, line)) && CheckAutoImport(found)) return;
if (resolve.Type == null)
{
int stylemask = (1 << Sci.StyleBits) - 1;
suggestItemDeclaration = ASComplete.IsTextStyle(Sci.StyleAt(position - 1) & stylemask);
}
}
if (isNotInterface && found.member != null)
{
// private var -> property
if ((found.member.Flags & FlagType.Variable) > 0 && (found.member.Flags & FlagType.LocalVar) == 0)
{
// maybe we just want to import the member's non-imported type
Match m = Regex.Match(text, String.Format(patternVarDecl, found.member.Name, contextToken));
if (m.Success)
{
contextMatch = m;
ClassModel type = ASContext.Context.ResolveType(contextToken, ASContext.Context.CurrentModel);
if (type.IsVoid() && CheckAutoImport(found))
return;
}
ShowGetSetList(found);
return;
}
// inside a function
else if ((found.member.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) > 0
&& resolve.Member == null && resolve.Type == null)
{
if (contextToken != null)
{
// "generate event handlers" suggestion
string re = String.Format(patternEvent, contextToken);
Match m = Regex.Match(text, re, RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
return;
}
m = Regex.Match(text, String.Format(patternAS2Delegate, contextToken), RegexOptions.IgnoreCase);
if (m.Success)
//.........这里部分代码省略.........
示例4: GetBodyStart
public static int GetBodyStart(int lineFrom, int lineTo, ScintillaNet.ScintillaControl Sci, int pos)
{
int posStart = Sci.PositionFromLine(lineFrom);
int posEnd = Sci.LineEndPosition(lineTo);
Sci.SetSel(posStart, posEnd);
List<char> characterClass = new List<char>(new char[] { ' ', '\r', '\n', '\t' });
string currentMethodBody = Sci.SelText;
int nCount = 0;
int funcBodyStart = pos;
int extraLine = 0;
if (pos == -1)
{
funcBodyStart = posStart + currentMethodBody.IndexOf('{');
extraLine = 1;
}
while (funcBodyStart <= posEnd)
{
char c = (char)Sci.CharAt(++funcBodyStart);
if (c == '}')
{
int ln = Sci.LineFromPosition(funcBodyStart);
int indent = Sci.GetLineIndentation(ln);
if (lineFrom == lineTo || lineFrom == ln)
{
Sci.InsertText(funcBodyStart, Sci.NewLineMarker);
Sci.SetLineIndentation(ln + 1, indent);
ln++;
}
Sci.SetLineIndentation(ln, indent + Sci.Indent);
Sci.InsertText(funcBodyStart, Sci.NewLineMarker);
Sci.SetLineIndentation(ln + 1, indent);
Sci.SetLineIndentation(ln, indent + Sci.Indent);
funcBodyStart = Sci.LineEndPosition(ln);
break;
}
else if (!characterClass.Contains(c))
{
break;
}
else if (Sci.EOLMode == 1 && c == '\r' && (++nCount) > extraLine)
{
break;
}
else if (c == '\n' && (++nCount) > extraLine)
{
if (Sci.EOLMode != 2)
{
funcBodyStart--;
}
break;
}
}
return funcBodyStart;
}
示例5: GenerateFunctionJob
//.........这里部分代码省略.........
funcResult.RelClass = cm;
break;
}
}
inClass = funcResult.RelClass;
ASContext.Context.UpdateContext(inClass.LineFrom);
}
string blockTmpl = null;
if ((isStatic.Flags & FlagType.Static) > 0)
{
blockTmpl = TemplateUtils.GetBoundary("StaticMethods");
}
else if ((funcVisi & Visibility.Public) > 0)
{
blockTmpl = TemplateUtils.GetBoundary("PublicMethods");
}
else
{
blockTmpl = TemplateUtils.GetBoundary("PrivateMethods");
}
latest = TemplateUtils.GetTemplateBlockMember(Sci, blockTmpl);
if (latest == null || (!isOtherClass && member == null))
{
latest = GetLatestMemberForFunction(inClass, funcVisi, isStatic);
// if we generate function in current class..
if (!isOtherClass)
{
MethodsGenerationLocations location = ASContext.CommonSettings.MethodsGenerationLocations;
if (member == null)
{
detach = false;
lookupPosition = -1;
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else if (latest != null && location == MethodsGenerationLocations.AfterSimilarAccessorMethod)
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
Sci.SetSel(position, position);
}
else
{
position = Sci.PositionFromLine(member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
Sci.SetSel(position, position);
}
}
else // if we generate function in another class..
{
if (latest != null)
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
}
else
{
position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
detach = false;
}
Sci.SetSel(position, position);
}
}
else
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
Sci.SetSel(position, position);
}
// add imports to function argument types
if (functionParameters.Count > 0)
{
List<string> l = new List<string>();
foreach (FunctionParameter fp in functionParameters)
{
try
{
l.Add(fp.paramQualType);
}
catch (Exception) { }
}
int o = AddImportsByName(l, Sci.LineFromPosition(position));
position += o;
if (latest == null)
Sci.SetSel(position, Sci.WordEndPosition(position, true));
else
Sci.SetSel(position, position);
}
List<MemberModel> parameters = new List<MemberModel>();
for (int i = 0; i < functionParameters.Count; i++)
{
string name = functionParameters[i].paramName;
string type = functionParameters[i].paramType;
parameters.Add(new MemberModel(name, type, FlagType.ParameterVar, 0));
}
MemberModel newMember = NewMember(contextToken, isStatic, FlagType.Function, funcVisi);
newMember.Parameters = parameters;
GenerateFunction(newMember, position, detach, inClass);
}
示例6: AssignStatementToVar
private static void AssignStatementToVar(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
int lineNum = Sci.CurrentLine;
string line = Sci.GetLine(lineNum);
StatementReturnType returnType = GetStatementReturnType(Sci, inClass, line, Sci.PositionFromLine(lineNum));
if (returnType == null) return;
string type = null;
string varname = null;
ASResult resolve = returnType.resolve;
string word = returnType.word;
if (resolve != null && !resolve.IsNull())
{
if (resolve.Member != null && resolve.Member.Type != null)
{
type = resolve.Member.Type;
}
else if (resolve.Type != null && resolve.Type.Name != null)
{
type = resolve.Type.QualifiedName;
}
if (resolve.Member != null && resolve.Member.Name != null)
{
varname = GuessVarName(resolve.Member.Name, type);
}
}
if (!string.IsNullOrEmpty(word) && Char.IsDigit(word[0])) word = null;
if (!string.IsNullOrEmpty(word) && (string.IsNullOrEmpty(type) || Regex.IsMatch(type, "(<[^]]+>)")))
word = null;
if (!string.IsNullOrEmpty(type) && type.Equals("void", StringComparison.OrdinalIgnoreCase))
type = null;
if (varname == null) varname = GuessVarName(word, type);
if (varname != null && varname == word)
varname = varname.Length == 1 ? varname + "1" : varname[0] + "";
string cleanType = null;
if (type != null) cleanType = FormatType(GetShortType(type));
string template = TemplateUtils.GetTemplate("AssignVariable");
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", varname);
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", cleanType);
int indent = Sci.GetLineIndentation(lineNum);
int pos = Sci.PositionFromLine(lineNum) + indent / Sci.Indent;
Sci.CurrentPos = pos;
Sci.SetSel(pos, pos);
InsertCode(pos, template);
if (type != null)
{
ClassModel inClassForImport = null;
if (resolve.InClass != null)
{
inClassForImport = resolve.InClass;
}
else if (resolve.RelClass != null)
{
inClassForImport = resolve.RelClass;
}
else
{
inClassForImport = inClass;
}
List<string> l = new List<string>();
l.Add(getQualifiedType(type, inClassForImport));
pos += AddImportsByName(l, Sci.LineFromPosition(pos));
}
}
示例7: AddInterfaceDefJob
private static void AddInterfaceDefJob(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, string interf)
{
ClassModel aType = ASContext.Context.ResolveType(interf, ASContext.Context.CurrentModel);
if (aType.IsVoid()) return;
FileModel fileModel = ASFileParser.ParseFile(ASContext.Context.CreateFileModel(aType.InFile.FileName));
foreach (ClassModel cm in fileModel.Classes)
{
if (cm.QualifiedName.Equals(aType.QualifiedName))
{
aType = cm;
break;
}
}
string template = TemplateUtils.GetTemplate("IFunction");
if ((member.Flags & FlagType.Getter) > 0)
{
template = TemplateUtils.GetTemplate("IGetter");
}
else if ((member.Flags & FlagType.Setter) > 0)
{
template = TemplateUtils.GetTemplate("ISetter");
}
DockContent dc = ASContext.MainForm.OpenEditableDocument(aType.InFile.FileName, true);
Sci = ASContext.CurSciControl;
MemberModel latest = GetLatestMemberForFunction(aType, Visibility.Default, new MemberModel());
int position;
if (latest == null)
{
position = GetBodyStart(aType.LineFrom, aType.LineTo, Sci);
}
else
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
template = NewLine + template;
}
Sci.SetSel(position, position);
Sci.CurrentPos = position;
IASContext context = ASContext.Context;
ContextFeatures features = context.Features;
template = TemplateUtils.ToDeclarationString(member, template);
template = TemplateUtils.ReplaceTemplateVariable(template, "BlankLine", NewLine);
template = TemplateUtils.ReplaceTemplateVariable(template, "Void", features.voidKey);
List<string> importsList = new List<string>();
string t;
List<MemberModel> parms = member.Parameters;
if (parms != null && parms.Count > 0)
{
for (int i = 0; i < parms.Count; i++)
{
if (parms[i].Type != null)
{
t = getQualifiedType(parms[i].Type, inClass);
importsList.Add(t);
}
}
}
if (member.Type != null)
{
t = getQualifiedType(member.Type, inClass);
importsList.Add(t);
}
if (importsList.Count > 0)
{
int o = AddImportsByName(importsList, Sci.LineFromPosition(position));
position += o;
}
Sci.SetSel(position, position);
Sci.CurrentPos = position;
InsertCode(position, template);
}
示例8: 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);
}
示例9: GenerateOverride
static public void GenerateOverride(ScintillaNet.ScintillaControl Sci, ClassModel ofClass, MemberModel member, int position)
{
ContextFeatures features = ASContext.Context.Features;
List<string> typesUsed = new List<string>();
bool isProxy = (member.Namespace == "flash_proxy");
if (isProxy) typesUsed.Add("flash.utils.flash_proxy");
bool isAS2Event = ASContext.Context.Settings.LanguageId == "AS2" && member.Name.StartsWith("on");
bool isObjectMethod = ofClass.QualifiedName == "Object";
int line = Sci.LineFromPosition(position);
string currentText = Sci.GetLine(line);
int startPos = currentText.Length;
GetStartPos(currentText, ref startPos, features.privateKey);
GetStartPos(currentText, ref startPos, features.protectedKey);
GetStartPos(currentText, ref startPos, features.internalKey);
GetStartPos(currentText, ref startPos, features.publicKey);
GetStartPos(currentText, ref startPos, features.staticKey);
GetStartPos(currentText, ref startPos, features.overrideKey);
startPos += Sci.PositionFromLine(line);
FlagType flags = member.Flags;
string acc = "";
string decl = "";
if (features.hasNamespaces && member.Namespace != null
&& member.Namespace.Length > 0 && member.Namespace != "internal")
acc = member.Namespace;
else if ((member.Access & Visibility.Public) > 0) acc = features.publicKey;
else if ((member.Access & Visibility.Internal) > 0) acc = features.internalKey;
else if ((member.Access & Visibility.Protected) > 0) acc = features.protectedKey;
else if ((member.Access & Visibility.Private) > 0) acc = features.privateKey;
bool isStatic = (flags & FlagType.Static) > 0;
if (isStatic) acc = features.staticKey + " " + acc;
if (!isAS2Event && !isObjectMethod)
acc = features.overrideKey + " " + acc;
if ((flags & (FlagType.Getter | FlagType.Setter)) > 0)
{
string type = member.Type;
string name = member.Name;
if (member.Parameters != null && member.Parameters.Count > 0)
type = member.Parameters[0].Type;
type = FormatType(type);
if (type == null)
{
string message = String.Format(TextHelper.GetString("Info.TypeDeclMissing"), member.Name);
ErrorManager.ShowInfo(message);
return;
}
if (ofClass.Members.Search(name, FlagType.Getter, 0) != null)
{
decl += String.Format(GetTemplate("Getter"),
acc, name, type, "super." + name);
}
if (ofClass.Members.Search(name, FlagType.Setter, 0) != null)
{
string tpl = GetTemplate("Setter");
if (decl.Length > 0)
{
decl += "\n\n";
tpl = tpl.Replace("$(EntryPoint)", "");
}
decl += String.Format(tpl,
acc, name, type, "super." + name, ASContext.Context.Features.voidKey ?? "void");
}
}
else
{
string type = FormatType(member.Type);
if (type == null)
{
string message = String.Format(TextHelper.GetString("Info.TypeDeclMissing"), member.Name);
ErrorManager.ShowInfo(message);
return;
}
if (acc.Length > 0) acc += " ";
decl = acc + features.functionKey + " ";
bool noRet = type.Equals("void", StringComparison.OrdinalIgnoreCase);
type = (noRet) ? ASContext.Context.Features.voidKey : type;
if (!noRet) typesUsed.Add(getQualifiedType(type, ofClass));
string action = (isProxy || isAS2Event) ? "" : GetSuperCall(member, typesUsed, ofClass);
decl += member.Name
+ String.Format(GetTemplate("MethodOverride"), member.ParametersString(true), type, action);
}
Sci.BeginUndoAction();
try
{
if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0)
{
int offset = AddImportsByName(typesUsed, line);
position += offset;
startPos += offset;
}
Sci.SetSel(startPos, position + member.Name.Length);
InsertCode(startPos, decl);
}
//.........这里部分代码省略.........
示例10: AddInterfaceDefJob
private static void AddInterfaceDefJob(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
ClassModel aType = ASContext.Context.ResolveType(contextParam, ASContext.Context.CurrentModel);
if (aType.IsVoid()) return;
FileModel fileModel = ASFileParser.ParseFile(aType.InFile.FileName, ASContext.Context);
foreach (ClassModel cm in fileModel.Classes)
{
if (cm.QualifiedName.Equals(aType.QualifiedName))
{
aType = cm;
break;
}
}
StringBuilder snippet = new StringBuilder();
DockContent dc = ASContext.MainForm.OpenEditableDocument(aType.InFile.FileName, true);
Sci = ASContext.CurSciControl;
MemberModel latest = FindLatest(FlagType.Function, aType);
int position;
if (latest == null)
{
position = GetBodyStart(aType.LineFrom, aType.LineTo, Sci);
}
else
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 1 : 0);
snippet.Append(NewLine);
}
Sci.SetSel(position, position);
Sci.CurrentPos = position;
List<MemberModel> parms = member.Parameters;
snippet.Append("function ")
.Append(member.ToDeclarationString())
.Append(";");
List<string> importsList = new List<string>();
string t;
if (parms != null && parms.Count > 0)
{
for (int i = 0; i < parms.Count; i++)
{
if (parms[i].Type != null)
{
t = getQualifiedType(parms[i].Type, inClass);
importsList.Add(t);
}
}
}
if (member.Type != null)
{
t = getQualifiedType(member.Type, inClass);
importsList.Add(t);
}
if (importsList.Count > 0)
{
int o = AddImportsByName(importsList, Sci.LineFromPosition(position));
position += o;
Sci.SetSel(position, position);
}
InsertCode(position, snippet.ToString());
Sci.CurrentPos = position;
}
示例11: GenerateFieldFromParameter
private static void GenerateFieldFromParameter(ScintillaNet.ScintillaControl Sci, MemberModel member, ClassModel inClass)
{
int funcBodyStart = GetBodyStart(member.LineFrom, member.LineTo, Sci);
Sci.SetSel(funcBodyStart, Sci.LineEndPosition(member.LineTo));
string body = Sci.SelText;
string trimmed = body.TrimStart();
Regex re = new Regex("^super\\s*[\\(|\\.]");
Match m = re.Match(trimmed);
if (m.Success)
{
if (m.Index == 0)
{
int p = funcBodyStart + (body.Length - trimmed.Length);
int l = Sci.LineFromPosition(p);
p = Sci.PositionFromLine(l + 1);
funcBodyStart = GetBodyStart(member.LineFrom, member.LineTo, Sci, p);
}
}
Sci.SetSel(funcBodyStart, funcBodyStart);
Sci.CurrentPos = funcBodyStart;
bool isVararg = false;
string paramName = contextMember.Name;
if (paramName.StartsWith("..."))
{
paramName = paramName.TrimStart(new char[] { ' ', '.' });
isVararg = true;
}
string varName = paramName;
bool addThis = true;
if (ASContext.CommonSettings.PrefixFields.Length > 0 && !paramName.StartsWith(ASContext.CommonSettings.PrefixFields))
{
varName = ASContext.CommonSettings.PrefixFields + varName;
addThis = ASContext.CommonSettings.GenerateScope;
}
StringBuilder sb = new StringBuilder();
if (addThis) sb.Append("this.");
sb.Append(varName)
.Append(" = ")
.Append(paramName)
.Append(";")
.Append(NewLine)
.Append("$(Boundary)");
SnippetHelper.InsertSnippetText(Sci, funcBodyStart, sb.ToString());
MemberList classMembers = inClass.Members;
foreach (MemberModel classMember in classMembers)
{
if (classMember.Name.Equals(varName))
{
return;
}
}
MemberModel latest = FindLatest(FlagType.Variable | FlagType.Constant, GetDefaultVisibility(), inClass);
if (latest == null) return;
int position = FindNewVarPosition(Sci, inClass, latest);
if (position <= 0) return;
Sci.SetSel(position, position);
Sci.CurrentPos = position;
MemberModel mem = NewMember(varName, member, FlagType.Variable, GetDefaultVisibility());
if (isVararg)
{
mem.Type = "Array";
}
else
{
mem.Type = contextMember.Type;
}
GenerateVariable(mem, position, true);
ASContext.Panel.RestoreLastLookupPosition();
}
示例12: ChangeMethodDecl
//.........这里部分代码省略.........
{
funcResult.Member = m;
}
}
bool paramsDiffer = false;
if (funcResult.Member.Parameters != null)
{
// check that parameters have one and the same type
if (funcResult.Member.Parameters.Count == functionParameters.Count)
{
if (functionParameters.Count > 0)
{
List<MemberModel> parameters = funcResult.Member.Parameters;
for (int i = 0; i < parameters.Count; i++)
{
MemberModel p = parameters[i];
if (p.Type != functionParameters[i].paramType)
{
paramsDiffer = true;
break;
}
}
}
}
else
{
paramsDiffer = true;
}
}
// check that parameters count differs
else if (functionParameters.Count != 0)
{
paramsDiffer = true;
}
if (paramsDiffer)
{
int app = 0;
List<MemberModel> newParameters = new List<MemberModel>();
List<MemberModel> existingParameters = funcResult.Member.Parameters;
for (int i = 0; i < functionParameters.Count; i++)
{
FunctionParameter p = functionParameters[i];
if (existingParameters != null
&& existingParameters.Count > (i - app)
&& existingParameters[i - app].Type == p.paramType)
{
newParameters.Add(existingParameters[i - app]);
}
else
{
if (existingParameters != null && existingParameters.Count < functionParameters.Count)
{
app++;
}
newParameters.Add(new MemberModel(p.param, p.paramType, FlagType.ParameterVar, 0));
}
}
funcResult.Member.Parameters = newParameters;
int posStart = Sci.PositionFromLine(funcResult.Member.LineFrom);
int posEnd = Sci.LineEndPosition(funcResult.Member.LineTo);
Sci.SetSel(posStart, posEnd);
string selectedText = Sci.SelText;
Regex rStart = new Regex(String.Format(@"\s+{0}\s*\(([^\)]*)\)(\s*:\s*([^({{|\n|\r|\s|;)]+))?", funcResult.Member.Name));
Match mStart = rStart.Match(selectedText);
if (!mStart.Success)
{
return;
}
int start = mStart.Index + posStart;
int end = start + mStart.Length;
Sci.SetSel(start, end);
string decl = funcResult.Member.ToDeclarationString();
Sci.ReplaceSel(" " + decl);
// add imports to function argument types
if (functionParameters.Count > 0)
{
List<string> l = new List<string>();
foreach (FunctionParameter fp in functionParameters)
{
try
{
l.Add(fp.paramQualType);
}
catch (Exception)
{
}
}
start += AddImportsByName(l, Sci.LineFromPosition(end));
}
Sci.SetSel(start, start);
}
}
示例13: 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.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("\"");
}
}
string template = TemplateUtils.GetTemplate("ToString");
string result = TemplateUtils.ToDeclarationWithModifiersString(resultMember, template);
result = TemplateUtils.ReplaceTemplateVariable(result, "Body", "\"[" + inClass.Name + membersString.ToString() + "]\"");
InsertCode(Sci.CurrentPos, result);
}
示例14: AddAsParameter
private static void AddAsParameter(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach)
{
if (!RemoveLocalDeclaration(Sci, contextMember)) return;
int currLine = Sci.LineFromPosition(Sci.CurrentPos);
int posStart = Sci.PositionFromLine(member.LineFrom);
int posEnd = Sci.LineEndPosition(member.LineTo);
Sci.SetSel(posStart, posEnd);
string selectedText = Sci.SelText;
Regex rStart = new Regex(@"\s{1}" + member.Name + @"\s*\(([^\)]*)\)(\s*:\s*([^({{|\n|\r|\s|;)]+))?");
Match mStart = rStart.Match(selectedText);
if (!mStart.Success)
return;
int start = mStart.Index + posStart + 1;
int end = mStart.Index + posStart + mStart.Length;
Sci.SetSel(start, end);
MemberModel memberCopy = (MemberModel) member.Clone();
if (memberCopy.Parameters == null)
memberCopy.Parameters = new List<MemberModel>();
memberCopy.Parameters.Add(contextMember);
string template = TemplateUtils.ToDeclarationString(memberCopy, TemplateUtils.GetTemplate("MethodDeclaration"));
InsertCode(start, template);
int currPos = Sci.LineEndPosition(currLine);
Sci.SetSel(currPos, currPos);
Sci.CurrentPos = currPos;
}
示例15: OnCompletionInsert
public override bool OnCompletionInsert(ScintillaNet.ScintillaControl sci, int position, string text, char trigger)
{
if (text == "Dictionary")
{
string insert = null;
string line = sci.GetLine(sci.LineFromPosition(position));
Match m = Regex.Match(line, @"\svar\s+(?<varname>.+)\s*:\s*Dictionary\.<(?<indextype>.+)(?=(>\s*=))");
if (m.Success)
{
insert = String.Format(".<{0}>", m.Groups["indextype"].Value);
}
else
{
m = Regex.Match(line, @"\s*=\s*new");
if (m.Success)
{
ASResult result = ASComplete.GetExpressionType(sci, sci.PositionFromLine(sci.LineFromPosition(position)) + m.Index);
if (result != null && !result.IsNull() && result.Member != null && result.Member.Type != null)
{
m = Regex.Match(result.Member.Type, @"(?<=<).+(?=>)");
if (m.Success)
{
insert = String.Format(".<{0}>", m.Value);
}
}
}
if (insert == null)
{
if (trigger == '.' || trigger == '(') return true;
insert = ".<>";
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + 2;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
ASComplete.HandleAllClassesCompletion(sci, "", false, true);
return true;
}
}
if (insert == null) return false;
if (trigger == '.')
{
sci.InsertText(position + text.Length, insert.Substring(1));
sci.CurrentPos = position + text.Length;
}
else
{
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + insert.Length;
}
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
return true;
}
return base.OnCompletionInsert(sci, position, text, trigger);
}