本文整理汇总了C#中ScintillaNet.PositionFromLine方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaNet.PositionFromLine方法的具体用法?C# ScintillaNet.PositionFromLine怎么用?C# ScintillaNet.PositionFromLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet
的用法示例。
在下文中一共展示了ScintillaNet.PositionFromLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAsParameter
private static void AddAsParameter(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach)
{
if (!RemoveLocalDeclaration(Sci, contextMember)) return;
StringBuilder sb = new StringBuilder();
int position = Sci.PositionFromLine(member.LineFrom);
Sci.SetSel(position, Sci.LineEndPosition(member.LineTo));
string body = Sci.SelText;
int bracePos = body.IndexOf(')') + position;
if (member.Parameters != null && member.Parameters.Count > 0)
{
sb.Append(", ");
}
sb.Append(contextMember.Name);
if (contextMember.Type != null)
{
sb.Append(":")
.Append(contextMember.Type);
}
Sci.SetSel(bracePos, bracePos);
Sci.CurrentPos = bracePos;
InsertCode(bracePos, sb.ToString());
Sci.SetSel(lookupPosition, lookupPosition);
}
示例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
//.........这里部分代码省略.........
}
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)
{
contextMatch = m;
ShowDelegateList(found);
return;
}
// suggest delegate
if (ASContext.Context.Features.hasDelegates)
{
m = Regex.Match(text, @"([a-z0-9_.]+)\s*\+=\s*" + contextToken, RegexOptions.IgnoreCase);
if (m.Success)
{
int offset = Sci.PositionFromLine(Sci.LineFromPosition(position))
+ m.Groups[1].Index + m.Groups[1].Length;
resolve = ASComplete.GetExpressionType(Sci, offset);
if (resolve.Member != null)
contextMember = ResolveDelegate(resolve.Member.Type, resolve.InFile);
contextMatch = m;
ShowDelegateList(found);
return;
}
}
}
else
{
// insert a default handler name, then "generate event handlers" suggestion
Match m = Regex.Match(text, String.Format(patternEvent, ""), RegexOptions.IgnoreCase);
if (m.Success)
{
int regexIndex = m.Index + Sci.PositionFromLine(Sci.CurrentLine);
GenerateDefaultHandlerName(Sci, position, regexIndex, m.Groups["event"].Value, true);
resolve = ASComplete.GetExpressionType(Sci, Sci.CurrentPos);
if (resolve.Member == null || (resolve.Member.Flags & FlagType.AutomaticVar) > 0)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
}
return;
}
// insert default delegate name, then "generate delegate" suggestion
if (ASContext.Context.Features.hasDelegates)
{
m = Regex.Match(text, @"([a-z0-9_.]+)\s*\+=\s*", RegexOptions.IgnoreCase);
示例4: FindNewVarPosition
private static int FindNewVarPosition(ScintillaNet.ScintillaControl Sci, ClassModel inClass, MemberModel latest)
{
firstVar = false;
// found a var?
if ((latest.Flags & FlagType.Variable) > 0)
return Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
// add as first member
int line = 0;
int maxLine = Sci.LineCount;
if (inClass != null)
{
line = inClass.LineFrom;
maxLine = inClass.LineTo;
}
else if (ASContext.Context.InPrivateSection) line = ASContext.Context.CurrentModel.PrivateSectionIndex;
else maxLine = ASContext.Context.CurrentModel.PrivateSectionIndex;
while (line < maxLine)
{
string text = Sci.GetLine(line++);
if (text.IndexOf('{') >= 0)
{
firstVar = true;
return Sci.PositionFromLine(line) - ((Sci.EOLMode == 0) ? 2 : 1);
}
}
return -1;
}
示例5: MakePrivate
public static bool MakePrivate(ScintillaNet.ScintillaControl Sci, MemberModel member)
{
ContextFeatures features = ASContext.Context.Features;
string visibility = GetPrivateKeyword();
if (features.publicKey == null || visibility == null) return false;
Regex rePublic = new Regex(String.Format(@"\s*({0})\s+", features.publicKey));
string line;
Match m;
int index, position;
for (int i = member.LineFrom; i <= member.LineTo; i++)
{
line = Sci.GetLine(i);
m = rePublic.Match(line);
if (m.Success)
{
index = Sci.MBSafeTextLength(line.Substring(0, m.Groups[1].Index));
position = Sci.PositionFromLine(i) + index;
Sci.SetSel(position, position + features.publicKey.Length);
Sci.ReplaceSel(visibility);
UpdateLookupPosition(position, features.publicKey.Length - visibility.Length);
return true;
}
}
return false;
}
示例6: 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;
}
示例7: GenerateFunctionJob
private static void GenerateFunctionJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member,
bool detach, ClassModel inClass)
{
int position = 0;
MemberModel latest = null;
bool isOtherClass = false;
Visibility funcVisi = job.Equals(GeneratorJobType.FunctionPublic) ? Visibility.Public : GetDefaultVisibility();
int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true);
List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos);
// evaluate, if the function should be generated in other class
ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(Sci.CurrentPos, true));
MemberModel isStatic = new MemberModel();
if (contextOwnerPos != -1)
{
ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos);
if (contextOwnerResult != null)
{
if (contextOwnerResult.Member == null && contextOwnerResult.Type != null)
{
isStatic.Flags |= FlagType.Static;
}
}
}
else if (member != null && (member.Flags & FlagType.Static) > 0)
{
isStatic.Flags |= FlagType.Static;
}
if (funcResult.RelClass != null && !funcResult.RelClass.IsVoid() && !funcResult.RelClass.Equals(inClass))
{
AddLookupPosition();
lookupPosition = -1;
DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.RelClass.InFile.FileName, true);
Sci = ASContext.CurSciControl;
isOtherClass = true;
FileModel fileModel = new FileModel();
fileModel.Context = ASContext.Context;
ASFileParser parser = new ASFileParser();
parser.ParseSrc(fileModel, Sci.Text);
foreach (ClassModel cm in fileModel.Classes)
{
if (cm.QualifiedName.Equals(funcResult.RelClass.QualifiedName))
{
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);
}
}
//.........这里部分代码省略.........
示例8: 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)
{
if (varname.Length == 1)
{
varname = varname + "1";
}
else
{
varname = varname[0] + "";
}
}
if (type != null)
{
cleanType = FormatType(GetShortType(type));
}
StringBuilder sb = new StringBuilder();
sb.Append("var ");
if (varname != null)
{
sb.Append(varname);
sb.Append(":");
}
if (cleanType != null)
{
sb.Append(cleanType);
}
else
{
sb.Append("$(EntryPoint)");
}
sb.Append(" = $(Boundary)");
int indent = Sci.GetLineIndentation(lineNum);
pos = Sci.PositionFromLine(lineNum) + indent / Sci.Indent;
Sci.CurrentPos = pos;
Sci.SetSel(pos, pos);
InsertCode(pos, sb.ToString());
if (type != null)
{
ClassModel inClassForImport = null;
if (resolve.inClass != null)
{
inClassForImport = resolve.inClass;
}
else if (resolve.relClass != null)
//.........这里部分代码省略.........
示例9: AddSquiggles
private void AddSquiggles(ScintillaNet.ScintillaControl sci, int line, int start, int end)
{
if (sci == null) return;
fileWithSquiggles = CurrentFile;
int position = sci.PositionFromLine(line) + start;
int es = sci.EndStyled;
int mask = 1 << sci.StyleBits;
sci.SetIndicStyle(0, (int)ScintillaNet.Enums.IndicatorStyle.Squiggle);
sci.SetIndicFore(0, 0x000000ff);
sci.StartStyling(position, mask);
sci.SetStyling(end - start, mask);
sci.StartStyling(es, mask - 1);
}
示例10: GenerateDelegateMethods
//.........这里部分代码省略.........
.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
{
sb.Append(member.Name)
.Append(".")
.Append(m.Name)
.Append(".apply(null, [");
for (int i = 0; i < methodParams.Count; i++)
{
MemberModel param = methodParams[i];
if (i + 1 < methodParams.Count)
{
sb.Append(param.Name);
if (i + 2 < methodParams.Count)
{
sb.Append(", ");
}
}
else
{
sb.Append("].concat(")
.Append(param.Name.Substring(3))
.Append(")");
}
}
sb.Append(");");
}
sb.Append("\n}");
if (methodParams != null)
{
for (int i = 0; i < methodParams.Count; i++)
{
MemberModel param = methodParams[i];
if (param.Type != null)
{
type = ASContext.Context.ResolveType(param.Type, selectedMembers[m].InFile);
importsList.Add(type.QualifiedName);
}
}
}
if (position < 0)
{
latest = FindLatest(FlagType.Function, inClass);
if (latest == null)
{
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else
{
position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
Sci.SetSel(position, position);
}
}
else
{
position = Sci.CurrentPos;
}
if (m.Type != null)
{
type = ASContext.Context.ResolveType(m.Type, selectedMembers[m].InFile);
importsList.Add(type.QualifiedName);
}
}
if (importsList.Count > 0 && position > -1)
{
int o = AddImportsByName(importsList, Sci.LineFromPosition(position));
position += o;
Sci.SetSel(position, position);
}
InsertCode(position, sb.ToString());
}
finally { Sci.EndUndoAction(); }
}
示例11: ContextualGenerator
//.........这里部分代码省略.........
return;
}
m = Regex.Match(text, String.Format(patternDelegate, contextToken), RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
ShowDelegateList(found);
return;
}
}
}
// "Generate fields from parameters" suggestion
if (found.member != null
&& (found.member.Flags & FlagType.Function) > 0
&& (found.member.Flags & FlagType.Static) == 0
&& found.member.Parameters != null && (found.member.Parameters.Count > 0)
&& resolve.Member != null && (resolve.Member.Flags & FlagType.ParameterVar) > 0)
{
contextMember = resolve.Member;
ShowFieldFromParameter(found);
return;
}
// "add to interface" suggestion
if (resolve.Member != null &&
resolve.Member.Name == found.member.Name &&
(found.member.Flags & FlagType.Function) > 0 &&
found.inClass != null &&
found.inClass.Implements != null &&
found.inClass.Implements.Count > 0)
{
string funcName = found.member.Name;
int classPosStart = Sci.PositionFromLine(found.inClass.LineFrom);
bool skip = false;
foreach (string interf in found.inClass.Implements)
{
if (skip)
{
break;
}
ClassModel cm = ASContext.Context.ResolveType(interf, ASContext.Context.CurrentModel);
contextParam = cm.Type;
MemberList members = cm.Members;
foreach (MemberModel m in members)
{
if (m.Name.Equals(funcName))
{
skip = true;
break;
}
}
}
if (!skip && contextParam != null)
{
ShowAddInterfaceDefList(found);
return;
}
}
// "assign var to statement" siggestion
int curLine = Sci.LineFromPosition(Sci.CurrentPos);
string ln = Sci.GetLine(curLine);
if (ln.Trim().Length > 0 && ln.TrimEnd().Length <= Sci.CurrentPos - Sci.PositionFromLine(curLine))
示例12: 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);
}
//.........这里部分代码省略.........
示例13: 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();
}
示例14: 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;
}
示例15: 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);
}