public bool Initialize(string fileName, int caretLineNumber, int caretColumn) { this.caretLine = caretLineNumber; this.caretColumn = caretColumn; ParseInformation parseInfo = HostCallback.GetParseInformation(fileName); if (parseInfo == null) { return(false); } cu = parseInfo.MostRecentCompilationUnit; if (cu != null) { callingClass = cu.GetInnermostClass(caretLine, caretColumn); if (cu.ProjectContent != null) { this.ProjectContent = cu.ProjectContent; } } callingMember = GetCurrentMember(); return(true); }
protected override IProjectContent LoadProjectContent(string itemInclude, string itemFileName) { if (File.Exists(itemFileName)) { return(ParserService.DefaultProjectContentRegistry.GetProjectContentForReference(itemInclude, itemFileName)); } MonoAssemblyName assemblyName = MonoGlobalAssemblyCache.FindAssemblyName(itemInclude); if (assemblyName != null && assemblyName.FileName != null) { return(CecilReader.LoadAssembly(assemblyName.FileName, this)); } else { if (MonoToolLocationHelper.IsMonoInstalled) { HostCallback.ShowAssemblyLoadError(itemFileName, itemInclude, "Could not find assembly in Mono's GAC."); } else { HostCallback.ShowAssemblyLoadError(itemFileName, itemInclude, "Could not find assembly in Mono's GAC - Mono is not installed."); } return(null); } }
static void ShowSourceCodeErrors(IDomProgressMonitor progressMonitor, string errors) { if (progressMonitor != null) { progressMonitor.ShowingDialog = true; } HostCallback.ShowMessage("${res:SharpDevelop.Refactoring.CannotPerformOperationBecauseOfSyntaxErrors}\n" + errors); if (progressMonitor != null) { progressMonitor.ShowingDialog = false; } }
public override PropertyDeclaration CreateProperty(IField field, bool createGetter, bool createSetter) { string propertyName = GetPropertyName(field.Name); if (propertyName == field.Name && GetParameterName(propertyName) != propertyName) { string newName = GetParameterName(propertyName); if (HostCallback.RenameMember(field, newName)) { field = new DefaultField(field.ReturnType, newName, field.Modifiers, field.Region, field.DeclaringType); } } return base.CreateProperty(field, createGetter, createSetter); }
public override PropertyDeclaration CreateProperty(IField field, bool createGetter, bool createSetter) { string propertyName = GetPropertyName(field.Name); if (string.Equals(propertyName, field.Name, StringComparison.InvariantCultureIgnoreCase)) { if (HostCallback.RenameMember(field, "m_" + field.Name)) { field = new DefaultField(field.ReturnType, "m_" + field.Name, field.Modifiers, field.Region, field.DeclaringType); } } return(base.CreateProperty(field, createGetter, createSetter)); }
private static void Main(string[] args) //the EXE's entry point { Console.Title = "Krot console - version " + KrotVersion; Console.WriteLine("Krot has been launched."); try { Console.WriteLine("Loading configuration: krot.ini..."); Kernel.LoadConfiguration(); Console.WriteLine("Loading GUI..."); HostCallback hcb = (string Command, Dictionary <string, object> Arguments, out object Result) => { return(HostEar(Command, Arguments, out Result)); }; PluginManager.UIPlugin = new PluginWrapper(new XwtUI()); PluginManager.UIPlugin.Plugin.Callback = hcb; Console.WriteLine("Load first FS..."); Kernel.krLoadFS(@"..\..\..\KrotLocalFSPlugin\bin\Debug\KrotLocalFSPlugin.dll", "KrotLocalFSPlugin.KrotLocalFSPlugin"); PluginManager.FSPlugins[0].Plugin.Callback = hcb; Kernel.krLoadFS(@"..\..\..\KrotLocalFSPlugin\bin\Debug\KrotLocalFSPlugin.dll", "KrotLocalFSPlugin.KrotLocalFSPlugin"); PluginManager.FSPlugins[1].Plugin.Callback = hcb; PluginManager.Launch("uiSetLayout", null); PluginManager.Launch("uiShow", null); Console.WriteLine("Запущена консоль"); while (true) { CmdPrompt(); } } catch (Exception ex) { Kernel.LogException(ex); } finally { Console.WriteLine("Krot is disposing."); } Console.Title += " [Exiting]"; Console.WriteLine("That's all, press any key to exit."); Console.ReadKey(); }
public ArrayList CtrlSpace(int caretLine, int caretColumn, string fileName, string fileContent, ExpressionContext context) { ArrayList result = new ArrayList(); if (language == NR.SupportedLanguage.VBNet) { foreach (KeyValuePair <string, string> pair in TypeReference.PrimitiveTypesVB) { if ("System." + pair.Key != pair.Value) { result.Add(GetPrimitiveClass(pair.Value, pair.Key)); } } result.Add("Global"); result.Add("New"); } else { foreach (KeyValuePair <string, string> pair in TypeReference.PrimitiveTypesCSharp) { result.Add(GetPrimitiveClass(pair.Value, pair.Key)); } } ParseInformation parseInfo = HostCallback.GetParseInformation(fileName); if (parseInfo == null) { return(null); } this.caretLine = caretLine; this.caretColumn = caretColumn; lookupTableVisitor = new LookupTableVisitor(languageProperties.NameComparer); cu = parseInfo.MostRecentCompilationUnit; if (cu != null) { callingClass = cu.GetInnermostClass(caretLine, caretColumn); } callingMember = GetCurrentMember(); if (callingMember != null) { CompilationUnit parsedCu = ParseCurrentMemberAsCompilationUnit(fileContent); if (parsedCu != null) { lookupTableVisitor.VisitCompilationUnit(parsedCu, null); } } CtrlSpaceResolveHelper.AddContentsFromCalling(result, callingClass, callingMember); foreach (KeyValuePair <string, List <LocalLookupVariable> > pair in lookupTableVisitor.Variables) { if (pair.Value != null && pair.Value.Count > 0) { foreach (LocalLookupVariable v in pair.Value) { if (IsInside(new NR.Location(caretColumn, caretLine), v.StartPos, v.EndPos)) { // convert to a field for display result.Add(CreateLocalVariableField(v, pair.Key)); break; } } } } CtrlSpaceResolveHelper.AddImportedNamespaceContents(result, cu, callingClass); return(result); }
static void ShowSourceCodeErrors(string errors) { HostCallback.ShowMessage("${res:SharpDevelop.Refactoring.CannotPerformOperationBecauseOfSyntaxErrors}\n" + errors); }
public ReflectionClass(ICompilationUnit compilationUnit, Type type, string fullName, IClass declaringType) : base(compilationUnit, declaringType) { if (fullName.Length > 2 && fullName[fullName.Length - 2] == '`') { FullyQualifiedName = fullName.Substring(0, fullName.Length - 2); } else { FullyQualifiedName = fullName; } this.UseInheritanceCache = true; try { AddAttributes(compilationUnit.ProjectContent, this.Attributes, CustomAttributeData.GetCustomAttributes(type)); } catch (Exception ex) { HostCallback.ShowError("Error reading custom attributes", ex); } // set classtype if (type.IsInterface) { this.ClassType = ClassType.Interface; } else if (type.IsEnum) { this.ClassType = ClassType.Enum; } else if (type.IsValueType) { this.ClassType = ClassType.Struct; } else if (IsDelegate(type)) { this.ClassType = ClassType.Delegate; } else { this.ClassType = ClassType.Class; ApplySpecialsFromAttributes(this); } if (type.IsGenericTypeDefinition) { foreach (Type g in type.GetGenericArguments()) { this.TypeParameters.Add(new DefaultTypeParameter(this, g)); } int i = 0; foreach (Type g in type.GetGenericArguments()) { AddConstraintsFromType(this.TypeParameters[i++], g); } } ModifierEnum modifiers = ModifierEnum.None; if (type.IsNestedAssembly) { modifiers |= ModifierEnum.Internal; } if (type.IsSealed) { modifiers |= ModifierEnum.Sealed; } if (type.IsAbstract) { modifiers |= ModifierEnum.Abstract; } if (type.IsNestedPrivate) { // I assume that private is used most and public last (at least should be) modifiers |= ModifierEnum.Private; } else if (type.IsNestedFamily) { modifiers |= ModifierEnum.Protected; } else if (type.IsNestedPublic || type.IsPublic) { modifiers |= ModifierEnum.Public; } else if (type.IsNotPublic) { modifiers |= ModifierEnum.Internal; } else if (type.IsNestedFamORAssem || type.IsNestedFamANDAssem) { modifiers |= ModifierEnum.Protected; modifiers |= ModifierEnum.Internal; } this.Modifiers = modifiers; // set base classes if (type.BaseType != null) { // it's null for System.Object ONLY !!! BaseTypes.Add(ReflectionReturnType.Create(this, type.BaseType, false)); } foreach (Type iface in type.GetInterfaces()) { BaseTypes.Add(ReflectionReturnType.Create(this, iface, false)); } InitMembers(type); }
protected CodeGenerator() { HostCallback.InitializeCodeGeneratorOptions(this); }
ExpressionContext GetCreationContext() { UnGetToken(); if (GetNextNonWhiteSpace() == '=') // was: "= new" { ReadNextToken(); if (curTokenType == Ident) // was: "ident = new" { int typeEnd = offset; ReadNextToken(); int typeStart = -1; while (curTokenType == Ident) { typeStart = offset + 1; ReadNextToken(); if (curTokenType == Dot) { ReadNextToken(); } else { break; } } if (typeStart >= 0) { string className = text.Substring(typeStart, typeEnd - typeStart); int pos = className.IndexOf('<'); string nonGenericClassName, genericPart; int typeParameterCount = 0; if (pos > 0) { nonGenericClassName = className.Substring(0, pos); genericPart = className.Substring(pos); pos = 0; do { typeParameterCount += 1; pos = genericPart.IndexOf(',', pos + 1); } while (pos > 0); } else { nonGenericClassName = className; genericPart = null; } ClassFinder finder = new ClassFinder(fileName, text, typeStart); IReturnType t = finder.SearchType(nonGenericClassName, typeParameterCount); IClass c = (t != null) ? t.GetUnderlyingClass() : null; if (c != null) { ExpressionContext context = ExpressionContext.TypeDerivingFrom(c.BaseType, true); if (context.ShowEntry(c)) { if (genericPart != null) { DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType); genericClass.FullyQualifiedName = c.FullyQualifiedName + genericPart; genericClass.Documentation = c.Documentation; context.SuggestedItem = genericClass; } else { context.SuggestedItem = c; } } return(context); } } } } else { UnGet(); if (ReadIdentifier(GetNextNonWhiteSpace()) == "throw") { return(ExpressionContext.TypeDerivingFrom(HostCallback.GetCurrentProjectContent().GetClass("System.Exception", 1).BaseType, true)); } } return(ExpressionContext.ObjectCreation); }
ExpressionResult CreateResult(string expression, string inText, int offset) { if (expression == null) { return(new ExpressionResult(null)); } if (expression.StartsWith("using ")) { return(new ExpressionResult(expression.Substring(6).TrimStart(), ExpressionContext.Namespace, null)); } if (!hadParenthesis && expression.StartsWith("new ")) { return(new ExpressionResult(expression.Substring(4).TrimStart(), GetCreationContext(), null)); } if (IsInAttribute(inText, offset)) { return(new ExpressionResult(expression, ExpressionContext.GetAttribute(HostCallback.GetCurrentProjectContent()))); } return(new ExpressionResult(expression)); }