public GenerateNamespaceImport GetResult (ProjectDom dom, ICompilationUnit unit, IType type, TextEditorData data) { GenerateNamespaceImport result; if (cache.TryGetValue (type.Namespace, out result)) return result; result = new GenerateNamespaceImport (); cache[type.Namespace] = result; result.InsertNamespace = false; DomLocation location = new DomLocation (data.Caret.Line, data.Caret.Column); foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) { if (u.Namespaces.Any (ns => type.Namespace == ns)) { result.GenerateUsing = false; return result; } } result.GenerateUsing = true; string name = type.DecoratedFullName.Substring (type.Namespace.Length + 1); foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) { foreach (string ns in u.Namespaces) { if (dom.SearchType (unit, unit.GetTypeAt (location), unit.GetMemberAt (location), ns + "." + name) != null) { result.GenerateUsing = false; result.InsertNamespace = true; return result; } } } return result; }
void RetrieveRegions(ICompilationUnit cu, ICSharpCode.NRefactory.Parser.SpecialTracker tracker) { for (int i = 0; i < tracker.CurrentSpecials.Count; ++i) { ICSharpCode.NRefactory.PreprocessingDirective directive = tracker.CurrentSpecials[i] as ICSharpCode.NRefactory.PreprocessingDirective; if (directive != null) { if (directive.Cmd == "#region") { int deep = 1; for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j) { ICSharpCode.NRefactory.PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as ICSharpCode.NRefactory.PreprocessingDirective; if (nextDirective != null) { switch (nextDirective.Cmd) { case "#region": ++deep; break; case "#endregion": --deep; if (deep == 0) { cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DomRegion(directive.StartPosition, nextDirective.EndPosition))); goto end; } break; } } } end: ; } } } }
public Class(CompilationUnit cu, ClassType t, Modifier m, IRegion region) { this.cu = cu; classType = t; this.region = region; modifiers = (ModifierEnum)m; }
public ResolveVisitor(BooResolver resolver) { this.resolver = resolver; this.callingClass = resolver.CallingClass; this.projectContent = resolver.ProjectContent; this.cu = resolver.CompilationUnit; }
public void SetUpFixture() { string python = "class Test:\r\n" + "\tdef foo(self):\r\n" + "\t\tpass"; DefaultProjectContent projectContent = new DefaultProjectContent(); PythonParser parser = new PythonParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.py", python); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = python; ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 0) { classFold = folds[0]; } if (folds.Count > 1) { methodFold = folds[1]; } } }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, AssemblyName[] referencedAssemblies, ProjectContentRegistry registry) { if (assemblyFullName == null) throw new ArgumentNullException("assemblyFullName"); if (assemblyLocation == null) throw new ArgumentNullException("assemblyLocation"); if (registry == null) throw new ArgumentNullException("registry"); this.registry = registry; this.assemblyFullName = assemblyFullName; this.referencedAssemblies = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); string fileName = LookupLocalizedXmlDoc(assemblyLocation); // Not found -> look in runtime directory. if (fileName == null) { string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); fileName = LookupLocalizedXmlDoc(Path.Combine(runtimeDirectory, Path.GetFileName(assemblyLocation))); } if (fileName == null) { // still not found -> look in WinFX reference directory string referenceDirectory = WinFXReferenceDirectory; if (!string.IsNullOrEmpty(referenceDirectory)) { fileName = LookupLocalizedXmlDoc(Path.Combine(referenceDirectory, Path.GetFileName(assemblyLocation))); } } if (fileName != null && registry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } }
static IClass CreateMyApplication(ICompilationUnit cu, VBNetProject project, string ns) { DefaultClass c = new DefaultClass(cu, ns + ".MyApplication"); c.ClassType = ClassType.Class; c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic; c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute"))); switch (project.OutputType) { case OutputType.WinExe: c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase")); if (project.GetEvaluatedProperty("MyType") == "WindowsForms") { c.Methods.Add( new DefaultMethod(c, "Main") { Modifiers = ModifierEnum.Internal | ModifierEnum.Static, ReturnType = c.ProjectContent.SystemTypes.Void, Parameters = new[] { new DefaultParameter( "args", new ArrayReturnType(c.ProjectContent, c.ProjectContent.SystemTypes.String, 1), DomRegion.Empty ) } }); } break; case OutputType.Exe: c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase")); break; default: c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase")); break; } return c; }
public static void AddImportedNamespaceContents(ArrayList result, ICompilationUnit cu, IClass callingClass) { IProjectContent projectContent = cu.ProjectContent; projectContent.AddNamespaceContents(result, "", projectContent.Language, true); foreach (IUsing u in cu.GetAllUsings()) { AddUsing(result, u, projectContent); } AddUsing(result, projectContent.DefaultImports, projectContent); if (callingClass != null) { string[] namespaceParts = callingClass.Namespace.Split('.'); for (int i = 1; i <= namespaceParts.Length; i++) { foreach (object member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i))) { if (!result.Contains(member)) result.Add(member); } } IClass currentClass = callingClass; do { foreach (IClass innerClass in currentClass.GetCompoundClass().GetAccessibleTypes(currentClass)) { if (!result.Contains(innerClass)) result.Add(innerClass); } currentClass = currentClass.DeclaringType; } while (currentClass != null); } }
public JavaScriptRegionWalker( JavaScriptAst ast, ICompilationUnit compilationUnit) { this.ast = ast; this.compilationUnit = compilationUnit; }
void AddNames (ICompilationUnit unit, int caretLine, int caretColumn) { foreach (IType cls in unit.Types) { if (cls.BodyRegion.Contains (caretLine, caretColumn)) { // Enclosing namespace: AddName (cls.Namespace, ""); enclosingNamespace = cls.Namespace; // For inner classes: AddName (cls.FullName, ""); } } foreach (IUsing u in unit.Usings) { if (u != null) { foreach (string us in u.Namespaces) AddName (us, ""); } } // Namespace aliases foreach (IUsing u in unit.Usings) { if (u != null) { foreach (KeyValuePair<string, IReturnType> e in u.Aliases) AddName (e.Value.FullName, e.Key); } } }
public ParseInformationEventArgs(string fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ICompilationUnit newCompilationUnit) { this.fileName = fileName; this.projectContent = projectContent; this.oldCompilationUnit = oldCompilationUnit; this.newCompilationUnit = newCompilationUnit; }
void AddDefaultUsings(ICompilationUnit compilationUnit) { AddUsing("System.Web.Mvc", compilationUnit); AddUsing("System.Web.Mvc.Ajax", compilationUnit); AddUsing("System.Web.Mvc.Html", compilationUnit); AddUsing("System.Web.Routing", compilationUnit); }
public void SetUpFixture() { string ruby = "class Test\r\n" + "\tdef initialize\r\n" + "\t\tputs 'test'\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { classFold = folds[0]; methodFold = folds[1]; } } }
bool Initialize(ParseInformation parseInfo, int caretLine, int caretColumn) { if (parseInfo == null) { return false; } this.cu = parseInfo.CompilationUnit; if (cu == null) { return false; } this.pc = cu.ProjectContent; this.caretLine = caretLine; this.caretColumn = caretColumn; this.callingClass = GetCallingClass(pc); callingMember = ResolveCurrentMember(callingClass); if (callingMember == null) { if (cu != parseInfo.CompilationUnit) { IClass olderClass = GetCallingClass(parseInfo.CompilationUnit.ProjectContent); if (olderClass != null && callingClass == null) { this.callingClass = olderClass; } callingMember = ResolveCurrentMember(olderClass); } } if (callingMember != null) { if (caretLine > callingMember.BodyRegion.EndLine) { this.caretLine = callingMember.BodyRegion.EndLine; this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } else if (caretLine == callingMember.BodyRegion.EndLine && caretColumn >= callingMember.BodyRegion.EndColumn) { this.caretColumn = callingMember.BodyRegion.EndColumn - 1; } } return true; }
public void SetUpFixture() { string python = "class"; DefaultProjectContent projectContent = new DefaultProjectContent(); PythonParser parser = new PythonParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.py", python); }
static string GetModelTypeName(ICompilationUnit compilationUnit) { var originalRazorCompilationUnit = compilationUnit as RazorCompilationUnit; if (originalRazorCompilationUnit != null) { return originalRazorCompilationUnit.ModelTypeName; } return String.Empty; }
public void SetUpFixture() { string Ruby = "require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\""; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); }
public void Init() { string python = "from math import *"; DefaultProjectContent projectContent = new DefaultProjectContent(); PythonParser parser = new PythonParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.py", python); import = compilationUnit.UsingScope.Usings[0] as PythonFromImport; }
public CompilationUnitHelper() { CompilationUnit = MockRepository.GenerateStub<ICompilationUnit>(); LanguageProperties language = MockRepository.GenerateStub<LanguageProperties>(StringComparer.InvariantCultureIgnoreCase); language.Stub(lang => lang.CodeGenerator).Return(FakeCodeGenerator); CompilationUnit.Stub(unit => unit.Language).Return(language); CompilationUnit.Stub(unit => unit.Classes).Return(Classes); CompilationUnit.Stub(unit => unit.UsingScope).Return(UsingScopeHelper.UsingScope); }
IClass FindMatchingClass(ICompilationUnit unit) { foreach (IClass c in unit.Classes) { if (c.FullyQualifiedName == Class.FullyQualifiedName) { return c; } } return null; }
public ParseInformation(ICompilationUnit unit) { if (unit == null) throw new ArgumentNullException("unit"); unit.Freeze(); // if (!unit.IsFrozen) // throw new ArgumentException("unit must be frozen for use in ParseInformation"); this.unit = unit; }
public PythonClass(ICompilationUnit compilationUnit, ClassDefinition classDefinition) : base(compilationUnit, String.Empty) { GetFullyQualifiedName(classDefinition); GetClassRegions(classDefinition); AddBaseTypes(classDefinition.Bases); compilationUnit.Classes.Add(this); }
/// <summary> /// Returns the class in which the carret currently is, returns null /// if the carret is outside the class boundaries. /// </summary> IClass GetCurrentClass(TextEditorControl textEditorControl, ICompilationUnit cu, string fileName) { IDocument document = textEditorControl.Document; if (cu != null) { int caretLineNumber = document.GetLineNumberForOffset(textEditorControl.ActiveTextAreaControl.Caret.Offset) + 1; int caretColumn = textEditorControl.ActiveTextAreaControl.Caret.Offset - document.GetLineSegment(caretLineNumber - 1).Offset + 1; return FindClass(cu.Classes, caretLineNumber, caretColumn); } return null; }
public void SetUpFixture() { string ruby = "class Class1\r\n" + " @\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); }
public FilePosition(ICompilationUnit compilationUnit, int line, int column) { this.position = new Location(column, line); this.compilationUnit = compilationUnit; if (compilationUnit != null) { this.filename = compilationUnit.FileName; } else { this.filename = null; } }
public ClassFinder(IClass callingClass, int caretLine, int caretColumn) { this.caretLine = caretLine; this.caretColumn = caretColumn; this.callingClass = callingClass; this.cu = callingClass.CompilationUnit; this.projectContent = cu.ProjectContent; if (projectContent == null) throw new ArgumentException("callingClass must have a project content!"); }
public DefaultClass(ICompilationUnit compilationUnit, string fullyQualifiedName) : base(null) { if (compilationUnit == null) throw new ArgumentNullException("compilationUnit"); if (fullyQualifiedName == null) throw new ArgumentNullException("fullyQualifiedName"); this.compilationUnit = compilationUnit; this.FullyQualifiedName = fullyQualifiedName; this.UsingScope = compilationUnit.UsingScope; }
public RefactoringMenuContext(ITextEditor editor, ExpressionResult expressionResult, ResolveResult resolveResult, bool isDefinition, IProjectContent projectContent, ICompilationUnit compilationUnit) { this.Editor = editor; this.ExpressionResult = expressionResult; this.ResolveResult = resolveResult; this.IsDefinition = isDefinition; this.ProjectContent = projectContent; this.CompilationUnit = compilationUnit; }
public ParseInformationEventArgs(FileName fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ParseInformation newParseInformation) { if (fileName == null) throw new ArgumentNullException("fileName"); if (projectContent == null) throw new ArgumentNullException("projectContent"); this.fileName = fileName; this.projectContent = projectContent; this.oldCompilationUnit = oldCompilationUnit; this.newParseInformation = newParseInformation; }
public void SetUpFixture() { string python = "class Test:\r\n" + "\tpass"; DefaultProjectContent projectContent = new DefaultProjectContent(); PythonParser parser = new PythonParser(); compilationUnit = parser.Parse(projectContent, @"C:\Projects\Test\test.py", python); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; } }
public DomType(ICompilationUnit compilationUnit, ClassType classType, Modifiers modifiers, string name, DomLocation location, string namesp, DomRegion region) { this.compilationUnit = compilationUnit; this.classType = classType; this.Modifiers = modifiers; this.Name = name; this.Namespace = namesp; this.BodyRegion = region; this.Location = location; }
void DoTestClass(IParser parser) { ICompilationUnit unit = parser.Parse(null, "a.cs", @"public partial class TestClass<T, S> : MyBaseClass where T : Constraint { }").CompilationUnit; Assert.AreEqual(1, unit.Types.Count); IType type = unit.Types[0]; Assert.AreEqual(ClassType.Class, type.ClassType); Assert.AreEqual("TestClass", type.Name); Assert.AreEqual("MyBaseClass", type.BaseType.Name); Assert.AreEqual(Modifiers.Partial | Modifiers.Public, type.Modifiers); Assert.AreEqual(2, type.TypeParameters.Count); Assert.AreEqual("T", type.TypeParameters[0].Name); Assert.AreEqual("Constraint", type.TypeParameters[0].Constraints[0].Name); Assert.AreEqual("S", type.TypeParameters[1].Name); }
public static ParseInformation UpdateParseInformation(ICompilationUnit parserOutput, string fileName) { ParseInformation parseInformation = projContentInfo[fileName].ParsedContents; if (parserOutput.ErrorsDuringCompile) { parseInformation.DirtyCompilationUnit = parserOutput; } else { parseInformation.ValidCompilationUnit = parserOutput; parseInformation.DirtyCompilationUnit = null; } projContentInfo[fileName].ParsedContents = parseInformation; return(parseInformation); }
public static IEnumerable <Result> ClassNaming(ICompilationUnit input) { foreach (var type in input.Types) { if (!char.IsUpper(type.Name[0])) { var start = type.Location; var newName = char.ToUpper(type.Name[0]).ToString() + type.Name.Substring(1); yield return(new FixableResult( new DomRegion(start, new DomLocation(start.Line, start.Column + type.Name.Length)), "Type names should begin with an uppercase letter", ResultLevel.Warning, ResultCertainty.High, ResultImportance.Medium, new RenameMemberFix(type, newName))); } } }
public virtual INode Visit(ICompilationUnit unit, string data) { foreach (IUsing u in unit.Usings) { u.AcceptVisitor(this, data + "Usings/"); } foreach (IAttribute a in unit.Attributes) { a.AcceptVisitor(this, data + "Attributes/"); } foreach (IType t in unit.Types) { t.AcceptVisitor(this, data + "Types/"); } return(null); }
void DoTestEvents(IParser parser) { ICompilationUnit unit = parser.Parse(null, "a.cs", @"class AClass { event EventHandler TestEvent; }").CompilationUnit; Assert.AreEqual(1, unit.Types.Count); IType type = unit.Types[0]; Assert.AreEqual(1, type.EventCount); List <IEvent> events = new List <IEvent> (type.Events); Assert.AreEqual("TestEvent", events[0].Name); Assert.AreEqual("EventHandler", events[0].ReturnType.Name); }
public ParseInformationEventArgs(FileName fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ParseInformation newParseInformation, bool isPrimaryParseInfoForFile) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (projectContent == null) { throw new ArgumentNullException("projectContent"); } this.fileName = fileName; this.projectContent = projectContent; this.oldCompilationUnit = oldCompilationUnit; this.newParseInformation = newParseInformation; this.IsPrimaryParseInfoForFile = isPrimaryParseInfoForFile; }
public void UpdateCompilationUnit(ICompilationUnit oldUnit, ICompilationUnit parserOutput, string fileName) { lock (_namespaces) { if (oldUnit != null) { RemoveClasses(oldUnit, parserOutput); } foreach (IClass c in parserOutput.Classes) { AddClassToNamespaceListInternal(c); } } SearchClassReturnType.ClearCache(); }
public static bool IsDesignable(ParseInformation info) { if (info != null) { ICompilationUnit cu = (ICompilationUnit)info.BestCompilationUnit; foreach (IClass c in cu.Classes) { IMethod method = GetInitializeComponents(c); if (method != null) { return(BaseClassIsFormOrControl(c)); } } } return(false); }
public void DefaultConstructorWithExplicitConstructorOnStructTest() { ICompilationUnit cu = Parse("struct X { private X(int a) {} }", SupportedLanguage.CSharp, true); Assert.AreEqual(1, cu.Classes[0].Methods.Count); List <IMethod> ctors = cu.Classes[0].DefaultReturnType.GetMethods().FindAll(m => m.IsConstructor); Assert.AreEqual(2, ctors.Count); Assert.AreEqual(ModifierEnum.Private, ctors[0].Modifiers); Assert.AreEqual(1, ctors[0].Parameters.Count); Assert.AreEqual(ModifierEnum.Public | ModifierEnum.Synthetic, ctors[1].Modifiers); Assert.AreEqual(0, ctors[1].Parameters.Count); }
public void SetUpFixture() { string Ruby = "class Test < Base\r\n" + "\tdef foo(i)\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; } }
public TypeUpdateInformation UpdateFromParseInfo(ICompilationUnit cu) { if (cu == null) { return(new TypeUpdateInformation()); } // TODO dom Get tag comments // UpdateTagComments (cu.TagComments, file); List <IType> resolved; ProjectDomService.ResolveTypes(SourceProjectDom, cu, cu.Types, out resolved); TypeUpdateInformation res = UpdateTypeInformation(resolved, file); Flush(); return(res); }
public void SetUpFixture() { PythonParser parser = new PythonParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.py", GetFormCode()); // Create parse info to return from ParseFile method. parseInfo = new ParseInformation(compilationUnit); // Get the InitializeComponent method from the // compilation unit. expectedInitializeComponentMethod = GetInitializeComponentMethod(compilationUnit); // Find the InitializeComponent method using the designer generator. initializeComponentMethod = PythonDesignerGenerator.GetInitializeComponents(parseInfo); }
public void InitializeComponentsUsedInsteadOfInitializeComponent() { PythonParser parser = new PythonParser(); MockProjectContent mockProjectContent = new MockProjectContent(); string code = GetFormCode().Replace("InitializeComponent", "InitializeComponents"); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.py", code); ParseInformation parseInfo = new ParseInformation(); parseInfo.SetCompilationUnit(compilationUnit); IMethod expectedMethod = GetInitializeComponentMethod(compilationUnit); IMethod method = PythonDesignerGenerator.GetInitializeComponents(parseInfo); Assert.IsNotNull(method); Assert.AreSame(expectedMethod, method); }
protected void EnlistTestFile(string fileName, string code, bool parseFile) { ResourceResolverService.SetFileContentUnitTestOnly(fileName, code); ProjectFileDictionaryService.AddFile(fileName, this.Project); if (parseFile) { IParser parser = ResourceResolverService.GetParser(fileName); Assert.IsNotNull(parser, "Could not get parser for " + fileName + "."); ICompilationUnit cu = parser.Parse(this.DefaultProjectContent, fileName, code); cu.Freeze(); Assert.IsFalse(cu.ErrorsDuringCompile, "Errors while parsing test program."); ParserService.RegisterParseInformation(fileName, cu); this.DefaultProjectContent.UpdateCompilationUnit(null, cu, fileName); } }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, DomAssemblyName[] referencedAssemblies, ProjectContentRegistry registry) { if (assemblyFullName == null) { throw new ArgumentNullException("assemblyFullName"); } if (assemblyLocation == null) { throw new ArgumentNullException("assemblyLocation"); } if (registry == null) { throw new ArgumentNullException("registry"); } this.registry = registry; this.assemblyFullName = assemblyFullName; this.referencedAssemblyNames = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); try { assemblyFileLastWriteTime = File.GetLastWriteTimeUtc(assemblyLocation); } catch (Exception ex) { LoggingService.Warn(ex); } string fileName = LookupLocalizedXmlDoc(assemblyLocation); if (fileName == null) { // Not found -> look in other directories: foreach (string testDirectory in XmlDoc.XmlDocLookupDirectories) { fileName = LookupLocalizedXmlDoc(Path.Combine(testDirectory, Path.GetFileName(assemblyLocation))); if (fileName != null) { break; } } } if (fileName != null && registry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, DomAssemblyName[] referencedAssemblies, ProjectContentRegistry registry) { if (assemblyFullName == null) throw new ArgumentNullException("assemblyFullName"); if (assemblyLocation == null) throw new ArgumentNullException("assemblyLocation"); if (registry == null) throw new ArgumentNullException("registry"); this.registry = registry; this.assemblyFullName = assemblyFullName; this.assemblyName = (assemblyFullName.IndexOf(',') > -1) ? assemblyFullName.Substring(0, assemblyFullName.IndexOf(',')) : assemblyFullName; this.referencedAssemblyNames = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); try { assemblyFileLastWriteTime = File.GetLastWriteTimeUtc(assemblyLocation); } catch (Exception ex) { LoggingService.Warn(ex); } string fileName = null; if (assemblyLocation != typeof(object).Assembly.Location) { // First look in the assembly's directory. // mscorlib is the exception, because it is loaded from the runtime directory (C:\Windows\Microsoft.NET\Framework\v4.0.30319), // but that might contain an outdated version of mscorlib.xml (with less documented members than the mscorlib.xml in the Reference Assemblies) // (at least on my machine, lots of others don't seem to have the v4.0.30319\mscorlib.xml at all). fileName = XmlDoc.LookupLocalizedXmlDoc(assemblyLocation); } if (fileName == null) { // Not found -> look in other directories: foreach (string testDirectory in XmlDoc.XmlDocLookupDirectories) { fileName = XmlDoc.LookupLocalizedXmlDoc(Path.Combine(testDirectory, Path.GetFileName(assemblyLocation))); if (fileName != null) break; } } if (fileName != null) { if (registry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } else { this.XmlDoc = XmlDoc.Load(fileName, null); } } }
List <MonoDevelop.Projects.CodeGeneration.MemberReference> GetReferences(ResolveResult resolveResult) { INode member = null; if (resolveResult is MemberResolveResult) { member = ((MemberResolveResult)resolveResult).ResolvedMember; if (member == null) { member = dom.GetType(resolveResult.ResolvedType); } } if (resolveResult is ParameterResolveResult) { member = ((ParameterResolveResult)resolveResult).Parameter; } if (resolveResult is LocalVariableResolveResult) { member = ((LocalVariableResolveResult)resolveResult).LocalVariable; } if (member != null) { try { ICompilationUnit compUnit = Document.CompilationUnit; if (compUnit == null) { return(null); } NRefactoryResolver resolver = new NRefactoryResolver(dom, compUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, Document.Editor, Document.FileName); if (member is LocalVariable) { resolver.CallingMember = ((LocalVariable)member).DeclaringMember; } FindMemberAstVisitor visitor = new FindMemberAstVisitor(textEditorData.Document, resolver, member); visitor.IncludeXmlDocumentation = true; /* ICSharpCode.NRefactory.Ast.CompilationUnit unit = compUnit.Tag as ICSharpCode.NRefactory.Ast.CompilationUnit; * if (unit == null) * return null;*/ visitor.RunVisitor(); return(visitor.FoundReferences); } catch (Exception e) { LoggingService.LogError("Error in highlight usages extension.", e); } } return(null); }
public void SetUpFixture() { textEditorOptions = new MockTextEditorOptions(); generator = new DerivedPythonDesignerGenerator(textEditorOptions); mockViewContent = new MockTextEditorViewContent(); viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName)); generator.Attach(viewContent); viewContent.DesignerCodeFileContent = GetTextEditorCode(); PythonParser parser = new PythonParser(); ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), fileName, GetTextEditorCode()); ParseInformation parseInfo = new ParseInformation(parserCompilationUnit); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; AfterSetUpFixture(); }
/// <summary> /// ensures that the custom assertions in this test fixture are working properly /// </summary> public void SanityCheckTest() { ICompilationUnit cu = helper.Parse(ITestClass.FileName, ITestClass.FileContent); Assert.That(cu.Classes, Has.Count.EqualTo(1)); IClass c = cu.Classes[0]; Assert.That(c.ClassType, Is.EqualTo(ClassType.Interface)); Assert.That(c.BaseTypes, Has.Count.EqualTo(0)); Assert.That(c.Attributes, Has.Count.EqualTo(0)); Assert.That(c.Events, Has.Count.EqualTo(1)); Assert.That(c.Methods, Has.Count.EqualTo(2)); { IMethod m = c.Methods[0]; Assert.That(m.Name, Is.EqualTo("GetRange")); Assert.That(m.Parameters, Has.Count.EqualTo(1)); Assert.That(m, HasEmpty.MethodBody); m = c.Methods[1]; Assert.That(m.Name, Is.EqualTo("MultiplyBy5")); Assert.That(m.Parameters, Has.Count.EqualTo(2)); Assert.That(m, HasEmpty.MethodBody); } Assert.That(c.Properties, Has.Count.EqualTo(3)); { IProperty p = c.Properties[0]; Assert.That(p.Name, Is.EqualTo("Name")); Assert.That(p.CanGet, Is.True); Assert.That(p, HasEmpty.GetRegion); Assert.That(p.CanSet, Is.False); p = c.Properties[1]; Assert.That(p.Name, Is.EqualTo("Property")); Assert.That(p.CanGet, Is.True); Assert.That(p, HasEmpty.GetRegion); Assert.That(p.CanSet, Is.True); Assert.That(p, HasEmpty.SetRegion); p = c.Properties[2]; Assert.That(p.Name, Is.EqualTo("Configure")); Assert.That(p.CanGet, Is.False); Assert.That(p.CanSet, Is.True); Assert.That(p, HasEmpty.SetRegion); } }
public static ITextEditor OpenDefinitionFile(IMember member, bool switchTo) { IViewContent viewContent = null; ICompilationUnit cu = member.DeclaringType.CompilationUnit; if (cu != null) { string fileName = cu.FileName; if (fileName != null) { viewContent = FileService.OpenFile(fileName, switchTo); } } ITextEditorProvider tecp = viewContent as ITextEditorProvider; return((tecp == null) ? null : tecp.TextEditor); }
void DoTestAttributes(IParser parser) { ICompilationUnit unit = parser.Parse(null, "a.cs", @"[Attr1][Attr2(1,true)][Attr3('c',a=1,b=""hi"")] public class TestClass { }").CompilationUnit; Assert.AreEqual(1, unit.Types.Count); IType type = unit.Types[0]; Assert.AreEqual(ClassType.Class, type.ClassType); Assert.AreEqual("TestClass", type.Name); IEnumerator <IAttribute> e = type.Attributes.GetEnumerator(); Assert.IsTrue(e.MoveNext()); IAttribute att = e.Current; Assert.AreEqual("Attr1", att.Name); Assert.AreEqual(0, att.PositionalArguments.Count); Assert.AreEqual(0, att.NamedArguments.Count); Assert.IsTrue(e.MoveNext()); att = e.Current; Assert.AreEqual("Attr2", att.Name); Assert.AreEqual(2, att.PositionalArguments.Count); Assert.AreEqual(0, att.NamedArguments.Count); Assert.IsTrue(att.PositionalArguments [0] is CodePrimitiveExpression); CodePrimitiveExpression exp = (CodePrimitiveExpression)att.PositionalArguments [0]; Assert.AreEqual(1, exp.Value); exp = (CodePrimitiveExpression)att.PositionalArguments [1]; Assert.AreEqual(true, exp.Value); Assert.IsTrue(e.MoveNext()); att = e.Current; Assert.AreEqual("Attr3", att.Name); Assert.AreEqual(1, att.PositionalArguments.Count); Assert.AreEqual(2, att.NamedArguments.Count); Assert.IsTrue(att.PositionalArguments [0] is CodePrimitiveExpression); exp = (CodePrimitiveExpression)att.PositionalArguments [0]; Assert.AreEqual('c', exp.Value); exp = (CodePrimitiveExpression)att.NamedArguments ["a"]; Assert.AreEqual(1, exp.Value); exp = (CodePrimitiveExpression)att.NamedArguments ["b"]; Assert.AreEqual("hi", exp.Value); Assert.IsFalse(e.MoveNext()); }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); splitContainer1.Panel1.Controls.Add(classcanvas); classcanvas.Dock = DockStyle.Fill; splitContainer2.Panel2.Controls.Add(classeditor); classeditor.Dock = DockStyle.Fill; pc = new ReflectionProjectContent(Assembly.LoadFrom("ClassCanvas.dll"), registry); cu = new DefaultCompilationUnit(pc); classcanvas.CanvasItemSelected += OnItemSelected; classcanvas.LayoutChanged += HandleLayoutChange; }
public override TypeUpdateInformation UpdateFromParseInfo(ICompilationUnit unit) { ProjectCodeCompletionDatabase db = database as ProjectCodeCompletionDatabase; if (db != null) { return(db.UpdateFromParseInfo(unit, unit.FileName)); } SimpleCodeCompletionDatabase sdb = database as SimpleCodeCompletionDatabase; if (sdb != null) { return(sdb.UpdateFromParseInfo(unit)); } return(null); }
public void IndexerNonDefaultNameTest() { ICompilationUnit cu = Parse(@" using System.Runtime.CompilerServices; class X { [IndexerName(""Foo"")] public int this[int index] { get { return 0; } } } ", SupportedLanguage.CSharp, true); IProperty p = cu.Classes[0].Properties[0]; Assert.IsTrue(p.IsIndexer, "IsIndexer must be true"); Assert.AreEqual("Foo", p.Name); Assert.AreEqual(1, p.Parameters.Count); }
public void FindDocumentationComment() { ICompilationUnit cu = Parse(@" using System; namespace X { /// <summary> /// This is the comment /// </summary> public class A { } } "); Assert.AreEqual(SurroundWithSummaryTags("This is the comment"), cu.Classes[0].Documentation); }
public AddUsingAction(ICompilationUnit compilationUnit, ITextEditor editor, string newNamespace) { if (compilationUnit == null) { throw new ArgumentNullException("compilationUnit"); } if (editor == null) { throw new ArgumentNullException("editor"); } if (newNamespace == null) { throw new ArgumentNullException("newNamespace"); } this.CompilationUnit = compilationUnit; this.Editor = editor; this.NewNamespace = newNamespace; }
public virtual INode Visit(ICompilationUnit unit, T data) { CompilationUnit newUnit = CreateInstance(unit, data); foreach (IUsing u in unit.Usings) { newUnit.Add((IUsing)u.AcceptVisitor(this, data)); } foreach (IAttribute a in unit.Attributes) { newUnit.Add((IAttribute)a.AcceptVisitor(this, data)); } foreach (IType t in unit.Types) { newUnit.Add((IType)t.AcceptVisitor(this, data)); } return(newUnit); }
FilePosition GetAssemblyAttributeInsertionPosition(IProjectContent pc) { FilePosition best = FilePosition.Empty; foreach (IAttribute attrib in pc.GetAssemblyAttributes()) { ICompilationUnit cu = attrib.CompilationUnit; if (cu != null && !attrib.Region.IsEmpty) { var newPos = new FilePosition(cu, attrib.Region.BeginLine, attrib.Region.BeginColumn); if (IsBetterAssemblyAttributeInsertionPosition(newPos, best)) { best = newPos; } } } return(best); }
public void TestCompilerOutput(string category, string testName) { ITestContext testContext = TestContextFactory.GetContext(category, testName); ICompilationUnit compilationUnit = CompilationUnitFactory.CreateCompilationUnitBuilder() .WithTestContext(testContext) .Build(); Assert.True(compilationUnit.Compile(out ICompilationUnitResult result), result?.WriteErrors()); string expectedOutput = testContext.GetExpectedOutput(); Assert.Equal(expectedOutput, result.Output, compilerCompliationFixture.FileComparer); if (testContext.GetExpectedMetadata() is string expectedMetadata) { Assert.Equal(expectedMetadata, result.Metadata, compilerCompliationFixture.FileComparer); } }