本文整理汇总了C#中ScintillaNet.WordEndPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaNet.WordEndPosition方法的具体用法?C# ScintillaNet.WordEndPosition怎么用?C# ScintillaNet.WordEndPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet
的用法示例。
在下文中一共展示了ScintillaNet.WordEndPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateDelegateMethods
//.........这里部分代码省略.........
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));
callMethodTemplate += ";";
}
else
{
List<MemberModel> pseudoParamsList = new List<MemberModel>();
pseudoParamsList.Add(new MemberModel("null", null, FlagType.ParameterVar, 0));
pseudoParamsList.Add(new MemberModel("[$(Subarguments)].concat($(Lastsubargument))", null, FlagType.ParameterVar, 0));
MemberModel pseudoParamsOwner = new MemberModel();
pseudoParamsOwner.Parameters = pseudoParamsList;
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Name",
member.Name + "." + m.Name + ".apply");
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Arguments",
TemplateUtils.CallParametersString(pseudoParamsOwner));
callMethodTemplate += ";";
List<MemberModel> arrayParamsList = new List<MemberModel>();
for (int i = 0; i < m.Parameters.Count - 1; i++)
{
MemberModel param = m.Parameters[i];
arrayParamsList.Add(param);
}
pseudoParamsOwner.Parameters = arrayParamsList;
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Subarguments",
TemplateUtils.CallParametersString(pseudoParamsOwner));
callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Lastsubargument",
m.Parameters[m.Parameters.Count - 1].Name.TrimStart(new char[] { '.', ' '}));
}
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Body", callMethodTemplate);
}
methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "BlankLine", NewLine);
result += methodTemplate;
if (m.Parameters != null)
{
for (int i = 0; i < m.Parameters.Count; i++)
{
MemberModel param = m.Parameters[i];
if (param.Type != null)
{
type = ASContext.Context.ResolveType(param.Type, selectedMembers[m].InFile);
importsList.Add(type.QualifiedName);
}
}
}
if (position < 0)
{
MemberModel latest = GetLatestMemberForFunction(inClass, mCopy.Access, mCopy);
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, result);
}
finally { Sci.EndUndoAction(); }
}
示例2: GenerateClass
private static void GenerateClass(ScintillaNet.ScintillaControl Sci, String className, ClassModel inClass)
{
AddLookupPosition(); // remember last cursor position for Shift+F4
List<FunctionParameter> parameters = ParseFunctionParameters(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
List<MemberModel> constructorArgs = new List<MemberModel>();
List<String> constructorArgTypes = new List<String>();
MemberModel paramMember = new MemberModel();
for (int i = 0; i < parameters.Count; i++)
{
FunctionParameter p = parameters[i];
constructorArgs.Add(new MemberModel(p.paramName, p.paramType, FlagType.ParameterVar, 0));
constructorArgTypes.Add(CleanType(getQualifiedType(p.paramQualType, inClass)));
}
paramMember.Parameters = constructorArgs;
IProject project = PluginBase.CurrentProject;
if (String.IsNullOrEmpty(className)) className = "Class";
string projFilesDir = Path.Combine(PathHelper.TemplateDir, "ProjectFiles");
string projTemplateDir = Path.Combine(projFilesDir, project.GetType().Name);
string paramsString = TemplateUtils.ParametersString(paramMember, true);
Hashtable info = new Hashtable();
info["className"] = className;
if (project.Language.StartsWith("as")) info["templatePath"] = Path.Combine(projTemplateDir, "Class.as.fdt");
else if (project.Language.StartsWith("haxe")) info["templatePath"] = Path.Combine(projTemplateDir, "Class.hx.fdt");
else if (project.Language.StartsWith("loom")) info["templatePath"] = Path.Combine(projTemplateDir, "Class.ls.fdt");
info["inDirectory"] = Path.GetDirectoryName(inClass.InFile.FileName);
info["constructorArgs"] = paramsString.Length > 0 ? paramsString : null;
info["constructorArgTypes"] = constructorArgTypes;
DataEvent de = new DataEvent(EventType.Command, "ProjectManager.CreateNewFile", info);
EventManager.DispatchEvent(null, de);
if (de.Handled) return;
}
示例3: GetStatementReturnType
private static StatementReturnType GetStatementReturnType(ScintillaNet.ScintillaControl Sci, ClassModel inClass, string line, int startPos)
{
Regex target = new Regex(@"[;\s\n\r]*", RegexOptions.RightToLeft);
Match m = target.Match(line);
if (!m.Success)
{
return null;
}
line = line.Substring(0, m.Index);
if (line.Length == 0)
{
return null;
}
line = ReplaceAllStringContents(line);
ASResult resolve = null;
int pos = -1;
string word = null;
int stylemask = (1 << Sci.StyleBits) - 1;
ClassModel type = null;
if (line[line.Length - 1] == ')')
{
pos = -1;
int lastIndex = 0;
int bracesBalance = 0;
while (true)
{
int pos1 = line.IndexOf("(", lastIndex);
int pos2 = line.IndexOf(")", lastIndex);
if (pos1 != -1 && pos2 != -1)
{
lastIndex = Math.Min(pos1, pos2);
}
else if (pos1 != -1 || pos2 != -1)
{
lastIndex = Math.Max(pos1, pos2);
}
else
{
break;
}
if (lastIndex == pos1)
{
bracesBalance++;
if (bracesBalance == 1)
{
pos = lastIndex;
}
}
else if (lastIndex == pos2)
{
bracesBalance--;
}
lastIndex++;
}
}
else
{
pos = line.Length;
}
if (pos != -1)
{
line = line.Substring(0, pos);
pos += startPos;
pos -= line.Length - line.TrimEnd().Length + 1;
pos = Sci.WordEndPosition(pos, true);
resolve = ASComplete.GetExpressionType(Sci, pos);
if (resolve.IsNull()) resolve = null;
word = Sci.GetWordFromPosition(pos);
}
IASContext ctx = inClass.InFile.Context;
m = Regex.Match(line, "new\\s+([\\w\\d.<>,_$-]+)+(<[^]]+>)|(<[^]]+>)", RegexOptions.IgnoreCase);
if (m.Success)
{
string m1 = m.Groups[1].Value;
string m2 = m.Groups[2].Value;
string cname;
if (string.IsNullOrEmpty(m1) && string.IsNullOrEmpty(m2))
cname = m.Groups[0].Value;
else
cname = String.Concat(m1, m2);
if (cname.StartsWith("<"))
cname = "Vector." + cname; // literal vector
type = ctx.ResolveType(cname, inClass.InFile);
if (!type.IsVoid()) resolve = null;
}
else
{
char c = (char)Sci.CharAt(pos);
if (c == '"' || c == '\'')
{
type = ctx.ResolveType("String", inClass.InFile);
//.........这里部分代码省略.........
示例4: GenerateVariableJob
private static void GenerateVariableJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member,
bool detach, ClassModel inClass)
{
int position = 0;
MemberModel latest = null;
bool isOtherClass = false;
Visibility varVisi = job.Equals(GeneratorJobType.Variable) ? GetDefaultVisibility() : Visibility.Public;
FlagType ft = job.Equals(GeneratorJobType.Constant) ? FlagType.Constant : FlagType.Variable;
// evaluate, if the variable (or constant) should be generated in other class
ASResult varResult = 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;
}
ASResult returnType = null;
int lineNum = Sci.CurrentLine;
string line = Sci.GetLine(lineNum);
Match m = Regex.Match(line, "\\b" + Regex.Escape(contextToken) + "\\(");
if (m.Success)
{
returnType = new ASResult();
returnType.Type = ASContext.Context.ResolveType("Function", null);
}
else
{
m = Regex.Match(line, @"=\s*[^;\n\r}}]+");
if (m.Success)
{
int posLineStart = Sci.PositionFromLine(lineNum);
if (posLineStart + m.Index >= Sci.CurrentPos)
{
line = line.Substring(m.Index);
StatementReturnType rType = GetStatementReturnType(Sci, inClass, line, posLineStart + m.Index);
if (rType != null)
{
returnType = rType.resolve;
}
}
}
}
if (varResult.RelClass != null && !varResult.RelClass.IsVoid() && !varResult.RelClass.Equals(inClass))
{
AddLookupPosition();
lookupPosition = -1;
ASContext.MainForm.OpenEditableDocument(varResult.RelClass.InFile.FileName, false);
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(varResult.RelClass.QualifiedName))
{
varResult.RelClass = cm;
break;
}
}
inClass = varResult.RelClass;
ASContext.Context.UpdateContext(inClass.LineFrom);
}
latest = GetLatestMemberForVariable(job, inClass, varVisi, isStatic);
// if we generate variable in current class..
if (!isOtherClass && member == null)
{
detach = false;
lookupPosition = -1;
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else // if we generate variable in another class
{
if (latest != null)
{
//.........这里部分代码省略.........
示例5: 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);
}
}
//.........这里部分代码省略.........
示例6: ResolveElement
/// <summary>
/// Using the text under at cursor position, resolve the member/type and call the specified command.
/// </summary>
/// <param name="Sci">Control</param>
/// <returns>Resolved element details</returns>
static public Hashtable ResolveElement(ScintillaNet.ScintillaControl Sci, string eventAction)
{
// get type at cursor position
int position = Sci.WordEndPosition(Sci.CurrentPos, true);
ASResult result = GetExpressionType(Sci, position);
// Open source and show declaration
if (!result.IsNull())
{
ASClass oClass = (result.inClass != null) ? result.inClass : result.Class;
if (oClass.IsVoid() || (oClass.FileName.Length == 0))
return null;
if ((result.Class != null) && (result.Class.Flags == FlagType.Package))
return null;
// details
Hashtable details = new Hashtable();
int p;
// CLASS DETAILS
details.Add("@CLASSFILE", oClass.FileName);
// top-level class is not "searchable"
if (oClass != ASContext.TopLevel)
{
details.Add("@CLASSDECL", ASClass.MemberDeclaration(oClass.ToASMember()));
//
p = oClass.ClassName.LastIndexOf('.');
if (p > 0) {
details.Add("@CLASSPACKAGE", oClass.ClassName.Substring(0,p));
details.Add("@CLASSNAME", oClass.ClassName.Substring(p+1));
}
else {
details.Add("@CLASSPACKAGE", "");
details.Add("@CLASSNAME", oClass.ClassName);
}
details.Add("@CLASSFULLNAME", oClass.ClassName);
}
else {
details.Add("@CLASSDECL", "");
details.Add("@CLASSPACKAGE", "");
details.Add("@CLASSNAME", "");
details.Add("@CLASSFULLNAME", "");
}
// MEMBER DETAILS
if ((result.Class != null) && (result.Member != null))
{
details.Add("@MEMBERNAME", result.Member.Name);
details.Add("@MEMBERDECL", ASClass.MemberDeclaration(result.Member));
//
string kind = "";
if ((result.Member.Flags & FlagType.Function) > 0)
kind = "method";
else if ((result.Member.Flags & FlagType.Variable) > 0)
kind = "property";
else if ((result.Member.Flags & (FlagType.Getter | FlagType.Setter)) > 0)
kind = "property";
details.Add("@MEMBERKIND", kind);
//
p = result.Class.ClassName.LastIndexOf('.');
if (p > 0) {
details.Add("@MEMBERCLASSPACKAGE", result.Class.ClassName.Substring(0,p));
details.Add("@MEMBERCLASSNAME", result.Class.ClassName.Substring(p+1));
}
else {
details.Add("@MEMBERCLASSPACKAGE", "");
details.Add("@MEMBERCLASSNAME", result.Class.ClassName);
}
//
details.Add("@MEMBERCLASSFILE", result.Class.FileName);
details.Add("@MEMBERCLASSDECL", ASClass.MemberDeclaration(result.Class.ToASMember()));
}
else
{
details.Add("@MEMBERKIND", "");
details.Add("@MEMBERNAME", "");
details.Add("@MEMBERDECL", "");
details.Add("@MEMBERCLASSPACKAGE", "");
details.Add("@MEMBERCLASSNAME", "");
details.Add("@MEMBERCLASSFILE", "");
details.Add("@MEMBERCLASSDECL", "");
}
if (eventAction != null)
{
// other plugins may handle the documentation
DataEvent de = new DataEvent(EventType.CustomData, eventAction, details);
ASContext.MainForm.DispatchEvent(de);
if (de.Handled) return details;
// help
if (eventAction == "ShowDocumentation")
{
string cmd = ASContext.HelpCommandPattern;
if ((cmd == null) || (cmd.Length == 0)) return null;
//.........这里部分代码省略.........
示例7: ChangeConstructorDecl
private static void ChangeConstructorDecl(ScintillaNet.ScintillaControl Sci, MemberModel member, ClassModel inClass)
{
int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true);
List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos);
ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
if (funcResult == null || funcResult.Type == null) return;
if (funcResult.Type != null && !funcResult.Type.Equals(inClass))
{
AddLookupPosition();
lookupPosition = -1;
DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.Type.InFile.FileName, true);
Sci = ASContext.CurSciControl;
FileModel fileModel = new FileModel(funcResult.Type.InFile.FileName);
fileModel.Context = ASContext.Context;
ASFileParser parser = new ASFileParser();
parser.ParseSrc(fileModel, Sci.Text);
foreach (ClassModel cm in fileModel.Classes)
{
if (cm.QualifiedName.Equals(funcResult.Type.QualifiedName))
{
funcResult.Type = cm;
break;
}
}
inClass = funcResult.Type;
ASContext.Context.UpdateContext(inClass.LineFrom);
}
foreach (MemberModel m in inClass.Members)
{
if ((m.Flags & FlagType.Constructor) > 0)
{
funcResult.Member = m;
break;
}
}
if (funcResult.Member == null) return;
if (isHaxe) funcResult.Member.Name = "new";
ChangeDecl(Sci, funcResult.Member, functionParameters);
}
示例8: OnMouseHover
private void OnMouseHover(ScintillaNet.ScintillaControl sci, int position)
{
if (ASContext.Locked || !ASContext.Context.IsFileValid())
return;
// get word at mouse position
int style = sci.BaseStyleAt(position);
DebugConsole.Trace("Style="+style);
if (!ASComplete.IsTextStyle(style))
return;
position = sci.WordEndPosition(position, true);
ASResult result = ASComplete.GetExpressionType(sci, position);
// set tooltip
if (!result.IsNull())
{
string text = ASComplete.GetToolTipText(result);
DebugConsole.Trace("SHOW "+text);
if (text == null) return;
// show tooltip
InfoTip.ShowAtMouseLocation(text);
}
}
示例9: EventMetatag
private static void EventMetatag(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
ASResult resolve = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
string line = Sci.GetLine(inClass.LineFrom);
int position = Sci.PositionFromLine(inClass.LineFrom) + (line.Length - line.TrimStart().Length);
string value = resolve.Member.Value;
if (value != null)
{
if (value.StartsWith("\""))
{
value = value.Trim(new char[] { '"' });
}
else if (value.StartsWith("'"))
{
value = value.Trim(new char[] { '\'' });
}
}
else value = resolve.Member.Type;
if (value == "" || value == null)
return;
Regex re1 = new Regex("'(?:[^'\\\\]|(?:\\\\\\\\)|(?:\\\\\\\\)*\\\\.{1})*'");
Regex re2 = new Regex("\"(?:[^\"\\\\]|(?:\\\\\\\\)|(?:\\\\\\\\)*\\\\.{1})*\"");
Match m1 = re1.Match(value);
Match m2 = re2.Match(value);
if (m1.Success || m2.Success)
{
Match m = null;
if (m1.Success && m2.Success) m = m1.Index > m2.Index ? m2 : m1;
else if (m1.Success) m = m1;
else m = m2;
value = value.Substring(m.Index + 1, m.Length - 2);
}
string template = TemplateUtils.GetTemplate("EventMetatag");
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", value);
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", contextParam);
template += "\n$(Boundary)";
AddLookupPosition();
Sci.CurrentPos = position;
Sci.SetSel(position, position);
InsertCode(position, template);
}
示例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
static public void ContextualGenerator(ScintillaNet.ScintillaControl Sci)
{
if (ASContext.Context is ASContext)
(ASContext.Context as ASContext).UpdateCurrentFile(false); // update model
lookupPosition = -1;
int position = Sci.CurrentPos;
if (Sci.BaseStyleAt(position) == 19) // on keyword
return;
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 (!String.IsNullOrEmpty(contextToken) && Char.IsDigit(contextToken[0]))
{
ShowConvertToConst(found);
return;
}
ASResult resolve = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(position, true));
// ignore automatic vars (MovieClip members)
if (resolve.Member != null &&
(((resolve.Member.Flags & FlagType.AutomaticVar) > 0)
|| (resolve.inClass != null && resolve.inClass.QualifiedName == "Object")))
{
resolve.Member = null;
resolve.Type = null;
}
if (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 (resolve.Member == null && resolve.Type == null) // import declaration
{
if (CheckAutoImport(found))
{
return;
}
else
{
int stylemask = (1 << Sci.StyleBits) - 1;
if (ASComplete.IsTextStyle(Sci.StyleAt(position - 1) & stylemask))
{
suggestItemDeclaration = true;
}
}
}
}
if (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;
}
// create property
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
Match m = Regex.Match(text, String.Format(patternEvent, contextToken), RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
return;
//.........这里部分代码省略.........
示例12: GetStatementReturnType
private static StatementReturnType GetStatementReturnType(ScintillaNet.ScintillaControl Sci, ClassModel inClass, string line, int startPos)
{
Regex target = new Regex(@"[;\s\n\r]*", RegexOptions.RightToLeft);
Match m = target.Match(line);
if (!m.Success)
{
return null;
}
line = line.Substring(0, m.Index);
if (line.Length == 0)
{
return null;
}
line = ReplaceAllStringContents(line);
ASResult resolve = null;
int pos = -1;
string word = null;
int stylemask = (1 << Sci.StyleBits) - 1;
ClassModel type = null;
if (line[line.Length - 1] == ')')
{
pos = -1;
int lastIndex = 0;
int bracesBalance = 0;
while (true)
{
int pos1 = line.IndexOf("(", lastIndex);
int pos2 = line.IndexOf(")", lastIndex);
if (pos1 != -1 && pos2 != -1)
{
lastIndex = Math.Min(pos1, pos2);
}
else if (pos1 != -1 || pos2 != -1)
{
lastIndex = Math.Max(pos1, pos2);
}
else
{
break;
}
if (lastIndex == pos1)
{
bracesBalance++;
if (bracesBalance == 1)
{
pos = lastIndex;
}
}
else if (lastIndex == pos2)
{
bracesBalance--;
}
lastIndex++;
}
}
else
{
pos = line.Length;
}
if (pos != -1)
{
line = line.Substring(0, pos);
pos += startPos;
pos -= line.Length - line.TrimEnd().Length + 1;
pos = Sci.WordEndPosition(pos, true);
resolve = ASComplete.GetExpressionType(Sci, pos);
word = Sci.GetWordFromPosition(pos);
}
char c = (char)Sci.CharAt(pos);
if (word != null && Char.IsDigit(word[0]))
{
type = inClass.InFile.Context.ResolveType("Number", inClass.InFile);
}
else if (word != null && (word == "true" || word == "false"))
{
type = inClass.InFile.Context.ResolveType("Boolean", inClass.InFile);
}
else if (!(ASComplete.IsTextStyle(Sci.StyleAt(pos - 1) & stylemask)))
{
type = inClass.InFile.Context.ResolveType("String", inClass.InFile);
}
else if (c == '}')
{
type = inClass.InFile.Context.ResolveType("Object", inClass.InFile);
}
else if (c == '>')
{
type = inClass.InFile.Context.ResolveType("XML", inClass.InFile);
}
else if (c == ']')
{
type = inClass.InFile.Context.ResolveType("Array", inClass.InFile);
}
if (resolve == null)
{
//.........这里部分代码省略.........
示例13: ChangeMethodDecl
private static void ChangeMethodDecl(ScintillaNet.ScintillaControl Sci, MemberModel member, ClassModel inClass)
{
int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true);
List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos);
ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
if (funcResult.Member == null)
{
return;
}
if (funcResult != null && funcResult.inClass != null && !funcResult.inClass.Equals(inClass))
{
AddLookupPosition();
lookupPosition = -1;
DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.inClass.InFile.FileName, true);
Sci = ASContext.CurSciControl;
FileModel fileModel = new FileModel();
ASFileParser parser = new ASFileParser();
parser.ParseSrc(fileModel, Sci.Text);
foreach (ClassModel cm in fileModel.Classes)
{
if (cm.QualifiedName.Equals(funcResult.inClass.QualifiedName))
{
funcResult.inClass = cm;
break;
}
}
inClass = funcResult.inClass;
}
MemberList members = inClass.Members;
foreach (MemberModel m in members)
{
if (m.Name == funcResult.Member.Name)
{
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);
//.........这里部分代码省略.........
示例14: ConvertToConst
private static void ConvertToConst(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach)
{
String suggestion = "NEW_CONST";
String label = TextHelper.GetString("ASCompletion.Label.ConstName");
String title = TextHelper.GetString("ASCompletion.Title.ConvertToConst");
Hashtable info = new Hashtable();
info["suggestion"] = suggestion;
info["label"] = label;
info["title"] = title;
DataEvent de = new DataEvent(EventType.Command, "LineEntryDialog", info);
EventManager.DispatchEvent(null, de);
if (!de.Handled)
{
return;
}
suggestion = (string)info["suggestion"];
int position = Sci.CurrentPos;
MemberModel latest = null;
int wordPosEnd = Sci.WordEndPosition(position, true);
int wordPosStart = Sci.WordStartPosition(position, true);
char cr = (char)Sci.CharAt(wordPosEnd);
if (cr == '.')
{
wordPosEnd = Sci.WordEndPosition(wordPosEnd + 1, true);
}
else
{
cr = (char)Sci.CharAt(wordPosStart - 1);
if (cr == '.')
{
wordPosStart = Sci.WordStartPosition(wordPosStart - 1, true);
}
}
Sci.SetSel(wordPosStart, wordPosEnd);
string word = Sci.SelText;
Sci.ReplaceSel(suggestion);
if (member == null)
{
detach = false;
lookupPosition = -1;
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else
{
latest = FindLatest(FlagType.Constant, GetDefaultVisibility(), inClass)
?? FindLatest(FlagType.Variable, GetDefaultVisibility(), inClass);
if (latest != null)
{
position = FindNewVarPosition(Sci, inClass, latest);
}
else
{
position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
detach = false;
}
if (position <= 0) return;
Sci.SetSel(position, position);
}
contextToken = suggestion + ":Number = " + word + "";
GenerateVariable(
NewMember(contextToken, member, FlagType.Variable | FlagType.Constant | FlagType.Static),
position, detach);
}
示例15: GenerateDefaultHandlerName
private static void GenerateDefaultHandlerName(ScintillaNet.ScintillaControl Sci, int position, int targetPos, string eventName, bool closeBrace)
{
string target = null;
int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(targetPos, true));
if (contextOwnerPos != -1)
{
ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos);
if (contextOwnerResult != null && !contextOwnerResult.IsNull()
&& contextOwnerResult.Member != null)
{
if (contextOwnerResult.Member.Name == "contentLoaderInfo" && Sci.CharAt(contextOwnerPos) == '.')
{
// we want to name the event from the loader var and not from the contentLoaderInfo parameter
contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(contextOwnerPos - 1, true));
if (contextOwnerPos != -1)
{
contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos);
if (contextOwnerResult != null && !contextOwnerResult.IsNull()
&& contextOwnerResult.Member != null)
{
target = contextOwnerResult.Member.Name;
}
}
}
else
{
target = contextOwnerResult.Member.Name;
}
}
}
eventName = Camelize(eventName.Substring(eventName.LastIndexOf('.') + 1));
if (target != null) target = target.TrimStart(new char[] { '_' });
switch (ASContext.CommonSettings.HandlerNamingConvention)
{
case HandlerNamingConventions.handleTargetEventName:
if (target == null) contextToken = "handle" + Capitalize(eventName);
else contextToken = "handle" + Capitalize(target) + Capitalize(eventName);
break;
case HandlerNamingConventions.onTargetEventName:
if (target == null) contextToken = "on" + Capitalize(eventName);
else contextToken = "on" + Capitalize(target) + Capitalize(eventName);
break;
case HandlerNamingConventions.target_eventNameHandler:
if (target == null) contextToken = eventName + "Handler";
else contextToken = target + "_" + eventName + "Handler";
break;
default: //HandlerNamingConventions.target_eventName
if (target == null) contextToken = eventName;
else contextToken = target + "_" + eventName;
break;
}
char c = (char)Sci.CharAt(position - 1);
if (c == ',') InsertCode(position, "$(Boundary) " + contextToken + "$(Boundary)");
else InsertCode(position, contextToken);
position = Sci.WordEndPosition(position + 1, true);
Sci.SetSel(position, position);
c = (char)Sci.CharAt(position);
if (c <= 32) if (closeBrace) Sci.ReplaceSel(");"); else Sci.ReplaceSel(";");
Sci.SetSel(position, position);
}