public void BasicClassAttributeTest() { var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll"); var testClass = assembly.GetType("FFITarget.TestCSharpAttribute"); var testMethod = testClass.GetMethod("Test"); String code = @"import(""FFITarget.dll"");"; var execMirror = thisTest.RunScriptSource(code); var core =execMirror.MirrorTarget.Core; ClassMirror classMirror = new ClassMirror("TestCSharpAttribute", core); Assert.IsNotNull(classMirror); var classAttributes = classMirror.GetClassAttributes(); Assert.IsNotNull(classAttributes); var ffiClassAttribute = classAttributes as FFIClassAttributes; Assert.IsNotNull(ffiClassAttribute); var classCustomAttributes = ffiClassAttribute.Attributes; Assert.AreEqual(2, classCustomAttributes.Count()); Assert.IsTrue(classCustomAttributes.SequenceEqual(testClass.GetCustomAttributes(false))); MethodMirror methodMirror = classMirror.GetFunctions().FirstOrDefault(m => m.MethodName.Equals("Test")); var methodAttributes = methodMirror.GetMethodAttributes(); Assert.IsNotNull(methodAttributes); var ffiMethodAttributes = methodAttributes as FFIMethodAttributes; Assert.IsNotNull(ffiMethodAttributes); var methodCustomAttributes = ffiMethodAttributes.Attributes; Assert.AreEqual(2, methodCustomAttributes.Count()); Assert.IsTrue(methodCustomAttributes.SequenceEqual(testMethod.GetCustomAttributes(false))); }
//public LibraryMirror(string libName) //{ // LibraryName = libName; //} public LibraryMirror(ProtoCore.Core core, string libName, IList <ProtoCore.DSASM.ClassNode> classNodes) : base(core) { LibraryName = libName; classMirrors = new List <ClassMirror>(); foreach (ProtoCore.DSASM.ClassNode cnode in classNodes) { ClassMirror classMirror = new ClassMirror(core, cnode, this); classMirrors.Add(classMirror); } }
private static string GetShortClassName(ClassMirror mirror, ElementResolver resolver) { var shortName = string.Empty; if (resolver != null) { shortName = resolver.LookupShortName(mirror.ClassName); } return(string.IsNullOrEmpty(shortName) ? mirror.Alias : shortName); }
public IEnumerable <String> GetMembers() { List <string> members = new List <string>(); Validity.Assert(mirrorData != null); ClassMirror type = mirrorData.Class; if (type == null) { return(members); } IEnumerable <ClassMirror> baseClasses = type.GetClassHierarchy(); foreach (var baseClass in baseClasses) { foreach (var method in baseClass.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in baseClass.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } } foreach (var method in type.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in type.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } return(members); }
public void TestClassMemberCompletion() { string ffiTargetClass = "CodeCompletionClass"; // Assert that the class name is indeed a class var type = new ClassMirror(ffiTargetClass, libraryServicesCore); Assert.IsTrue(type != null); var members = type.GetMembers(); var expected = new string[] { "CodeCompletionClass", "StaticFunction", "StaticProp" }; AssertCompletions(members, expected); }
public void TestInstanceMemberCompletion() { string ffiTargetClass = "CodeCompletionClass"; // Assert that the class name is indeed a class var type = new ClassMirror(ffiTargetClass, libraryServicesCore); Assert.IsTrue(type != null); var members = type.GetInstanceMembers(); var expected = new string[] { "AddWithValueContainer", "ClassProperty", "IntVal", "IsEqualTo", "OverloadedAdd" }; AssertCompletions(members, expected); }
public void Constructor_WithIsVisibleFalseAttribute_HiddenFromSearch() { var className = @"FFITarget.DesignScript.Point"; var cm = new ClassMirror(className, libraryServicesCore); var ctors = cm.GetConstructors(); var ctorNames = ctors.Select(x => x.MethodName); var found = false; foreach (var name in ctorNames) { if (name == nameof(FFITarget.DesignScript.Point)) { found = true; } } Assert.False(found); }
public void MethodWithRefOutParams_NoLoad() { string code = @" import(""FFITarget.dll""); "; ExecutionMirror mirror = thisTest.RunScriptSource(code); string ffiTargetClass = "ClassWithRefParams"; // Assert that the class name is indeed a class ClassMirror type = null; Assert.DoesNotThrow(() => type = new ClassMirror(ffiTargetClass, thisTest.GetTestCore())); var members = type.GetMembers(); var expected = new string[] { "ClassWithRefParams" }; var actual = members.OrderBy(n => n.Name).Select(x => x.Name).ToArray(); Assert.AreEqual(expected, actual); }
/// <summary> /// Does typeb derive from typea /// </summary> /// <param name="typea"></param> /// <param name="typeb"></param> /// <param name="core"></param> /// <returns></returns> private bool DerivesFrom(string typea, string typeb, ProtoCore.Core core) { try { //TODO mirrors can be cached until new types are imported... var mirror1 = new ClassMirror(typea, core); var mirror2 = new ClassMirror(typeb, core); //TODO as we do this check we can cache the type distance... if (mirror2.GetClassHierarchy().Any(x => x.ClassName == mirror1.ClassName)) { //this is a derived type return(true); } return(false); } catch { Debug.WriteLine($"failed to create class mirror for either {typea} or {typeb} during node autocomplete operation "); return(false); } }
private WatchViewModel ProcessThing(object value, ProtoCore.Core core, string tag, bool showRawData, WatchHandlerCallback callback) { WatchViewModel node; if (value is IEnumerable) { var list = (value as IEnumerable).Cast <dynamic>().ToList(); node = new WatchViewModel(visualizationManager, list.Count == 0 ? "Empty List" : "List", tag, true); foreach (var e in list.Select((element, idx) => new { element, idx })) { node.Children.Add(callback(e.element, core, tag + ":" + e.idx, showRawData)); } } else if (core != null && value is StackValue) { StackValue stackValue = (StackValue)value; string stringValue = string.Empty; if (stackValue.IsFunctionPointer) { stringValue = StringUtils.GetStringValue(stackValue, core); } else { int typeId = core.TypeSystem.GetType(stackValue); ClassMirror classMirror = new ClassMirror(typeId, core); stringValue = classMirror.ClassName; } node = new WatchViewModel(visualizationManager, stringValue, tag); } else { node = new WatchViewModel(visualizationManager, ToString(value), tag); } return(node); }
public void BasicClassAttributeTest() { var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll"); var testClass = assembly.GetType("FFITarget.TestCSharpAttribute"); var testMethod = testClass.GetMethod("Test"); String code = @"import(""FFITarget.dll"");"; var execMirror = thisTest.RunScriptSource(code); var core = execMirror.MirrorTarget.Core; ClassMirror classMirror = new ClassMirror("TestCSharpAttribute", core); Assert.IsNotNull(classMirror); var classAttributes = classMirror.GetClassAttributes(); Assert.IsNotNull(classAttributes); var ffiClassAttribute = classAttributes as FFIClassAttributes; Assert.IsNotNull(ffiClassAttribute); var classCustomAttributes = ffiClassAttribute.Attributes; Assert.AreEqual(2, classCustomAttributes.Count()); Assert.IsTrue(classCustomAttributes.SequenceEqual(testClass.GetCustomAttributes(false))); MethodMirror methodMirror = classMirror.GetFunctions().FirstOrDefault(m => m.MethodName.Equals("Test")); var methodAttributes = methodMirror.GetMethodAttributes(); Assert.IsNotNull(methodAttributes); var ffiMethodAttributes = methodAttributes as FFIMethodAttributes; Assert.IsNotNull(ffiMethodAttributes); var methodCustomAttributes = ffiMethodAttributes.Attributes; Assert.AreEqual(2, methodCustomAttributes.Count()); Assert.IsTrue(methodCustomAttributes.SequenceEqual(testMethod.GetCustomAttributes(false))); }
public IList <MethodMirror> GetMethods(string className, string methodName) { ClassMirror classMirror = new ClassMirror(className, testCore); return(classMirror.GetOverloads(methodName).ToList()); }
public void TestClassMemberCompletion() { string ffiTargetClass = "CodeCompletionClass"; // Assert that the class name is indeed a class var type = new ClassMirror(ffiTargetClass, libraryServicesCore); Assert.IsTrue(type != null); var members = type.GetMembers(); var expected = new string[] { "CodeCompletionClass", "StaticFunction", "StaticProp" }; AssertCompletions(members, expected); }
public void TestHiddenConflictingClassCompletionWhenTyping() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); // "SecondNamespace.AnotherClassWithNameConflict" is defined in FFITarget library with "IsVisibleInDynamoLibrary" // attribute set to false. We verify that this class does not appear in code completion results // and that only "FirstNamespace.AnotherClassWithNameConflict" appears in code completion results with // fully qualified name so that it can be resolved against "SecondNamespace.AnotherClassWithNameConflict" string code = "ano"; var completions = codeCompletionServices.SearchCompletions(code, Guid.Empty); // Expected 1 completion items Assert.AreEqual(1, completions.Count()); string[] expected = { "AnotherClassWithNameConflict" }; var actual = completions.Select(x => x.Text).OrderBy(x => x); Assert.AreEqual(expected, actual); // Assert that the class name is indeed a class ClassMirror type = null; Assert.DoesNotThrow(() => type = new ClassMirror("FirstNamespace.AnotherClassWithNameConflict", libraryServicesCore)); var members = type.GetMembers(); expected = new[] { "AnotherClassWithNameConflict", "PropertyA", "PropertyB", "PropertyC" }; AssertCompletions(members, expected); }
public void TestCodeCompletionForFullyQualifiedVariableType() { string code = "a : FFITarget.FirstNamespace.ClassWithNameConflict;"; string variableName = "a"; string type1 = CodeCompletionParser.GetVariableType(code, variableName); Assert.AreEqual("FFITarget.FirstNamespace.ClassWithNameConflict", type1); // Assert that the class name is indeed a class ClassMirror type = null; Assert.DoesNotThrow(() => type = new ClassMirror(type1, libraryServicesCore)); var members = type.GetInstanceMembers(); var expected = new[] { "PropertyA", "PropertyB", "PropertyC" }; AssertCompletions(members, expected); code = @"b : FFITarget.SecondNamespace.ClassWithNameConflict;"; variableName = "b"; string type2 = CodeCompletionParser.GetVariableType(code, variableName); Assert.AreEqual("FFITarget.SecondNamespace.ClassWithNameConflict", type2); // Assert that the class name is indeed a class Assert.DoesNotThrow(() => type = new ClassMirror(type2, libraryServicesCore)); members = type.GetInstanceMembers(); expected = new[] { "PropertyD", "PropertyE", "PropertyF" }; AssertCompletions(members, expected); }
public void TestInstanceMemberCompletion() { string ffiTargetClass = "CodeCompletionClass"; // Assert that the class name is indeed a class ClassMirror type = null; Assert.DoesNotThrow(() => type = new ClassMirror(ffiTargetClass, libraryServicesCore)); var members = type.GetInstanceMembers(); var expected = new[] { "AddWithValueContainer", "ClassProperty", "IntVal", "IsEqualTo", "OverloadedAdd" }; AssertCompletions(members, expected); }
private static string GetShortClassName(ClassMirror mirror, ElementResolver resolver) { var shortName = string.Empty; if (resolver != null) { shortName = resolver.LookupShortName(mirror.ClassName); } return string.IsNullOrEmpty(shortName) ? mirror.Alias : shortName; }
public LibraryMirror(ProtoCore.Core core, string libName, IList<ProtoCore.DSASM.ClassNode> classNodes) : base(core, libName) { LibraryName = libName; classMirrors = new List<ClassMirror>(); foreach (ProtoCore.DSASM.ClassNode cnode in classNodes) { ClassMirror classMirror = new ClassMirror(core, cnode, this); classMirrors.Add(classMirror); } }
private void ProcessClassItem(ClassMirror classMirror, LibraryItem classItem) { classItem.Assembly = classMirror.GetAssembly().LibraryName; foreach (MethodMirror constructorMirror in classMirror.GetConstructors()) { LibraryItem constructorItem = new LibraryItem(NodeType.Function, constructorMirror.MethodName, constructorMirror); constructorItem.ArgumentTypes = GetArgumentTypes(constructorMirror.GetArgumentTypes()); constructorItem.Assembly = classMirror.GetAssembly().LibraryName; constructorItem.Type = LibraryItem.MemberType.Constructor; classItem.AddChildItem(constructorItem); } foreach (MethodMirror methodMirror in classMirror.GetFunctions()) { if (!methodMirror.IsStatic) continue; LibraryItem staticMethodItem = new LibraryItem(NodeType.Function, methodMirror.MethodName, methodMirror); staticMethodItem.ArgumentTypes = GetArgumentTypes(methodMirror.GetArgumentTypes()); staticMethodItem.Assembly = classMirror.GetAssembly().LibraryName; staticMethodItem.Type = LibraryItem.MemberType.StaticMethod; classItem.AddChildItem(staticMethodItem); } GroupOverloadedItem(classItem); foreach (PropertyMirror propertyMirror in classMirror.GetProperties()) { if (!propertyMirror.IsStatic) continue; LibraryItem staticPropertyItem = new LibraryItem(NodeType.Function, propertyMirror.PropertyName, propertyMirror); staticPropertyItem.ArgumentTypes = string.Empty;//GetArgumentTypes(propertyMirror. staticPropertyItem.Type = LibraryItem.MemberType.StaticProperty; if (propertyMirror.IsSetter) staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextSetter; else staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextGetter; classItem.AddChildItem(staticPropertyItem); } }
public void MethodWithRefOutParams_NoLoad() { string code = @" import(""FFITarget.dll""); "; ExecutionMirror mirror = thisTest.RunScriptSource(code); string ffiTargetClass = "ClassWithRefParams"; // Assert that the class name is indeed a class ClassMirror type = null; Assert.DoesNotThrow(() => type = new ClassMirror(ffiTargetClass, thisTest.GetTestCore())); var members = type.GetMembers(); var expected = new string[] { "ClassWithRefParams" }; var actual = members.OrderBy(n => n.Name).Select(x => x.Name).ToArray(); Assert.AreEqual(expected, actual); }
/// <summary> /// Used to reflect on static data such as classes and class members /// </summary> /// <param name="varName"></param> /// <returns></returns> protected ClassMirror GetClassMirror(string className) { ProtoCore.Core core = GetModel().EngineController.LiveRunnerCore; var classMirror = new ClassMirror(className, core); return classMirror; }