public NativeTypeRef(IDeclarationContext parent, Type type, bool external = false, Type redirectbase = null) : base(parent, type) { if(null == type) { throw new ArgumentNullException("type"); } if(external) { SetExternal(); } if(type.IsSubclassOf(typeof(Delegate))) { _isdelegate = true; } else if (!type.IsValueType) { var rbase = redirectbase ?? type.BaseType; if (null != rbase) { _lbase = parent.TranslateRType(rbase, TranslateOptions.Add); //_typedependencies.Add(lbase); AddDepdendency(_lbase, DependencyLevel.Constructor); _isdelegate = _lbase.IsDelegate; } } parent.RegisterType(this); }
public LogInfoViewModel(Authentication authentication, ITypeItem typeItem, LogInfo logInfo) { this.authentication = authentication; this.typeItem = typeItem; this.LogInfo = logInfo; this.Target = typeItem; }
public void TriggerItemReferenced(ITypeItem d) { if(null != OnItemReferenced) { OnItemReferenced(d); } }
private bool PredicateFunc(ITypeItem typeItem) { if (this.Type != null && this.Type.IsAssignableFrom(typeItem.GetType()) == false) { return(false); } if (this.HasParent == true && typeItem.Parent == null) { return(false); } if (this.HasChilds == true && typeItem.Childs.Any() == false) { return(false); } if (this.IsLeaf == true && typeItem.Childs.Any() == true) { return(false); } if (this.TargetToMove != null && CanMove(this.TargetToMove, typeItem.Path) == false) { return(false); } if (this.ExcludedItems != null && this.ExcludedItems.Contains(typeItem) == true) { return(false); } if (this.Predicate != null && this.Predicate(typeItem) == false) { return(false); } return(true); }
public LogViewModel(Authentication authentication, ITypeItem typeItem) { this.authentication = authentication; this.typeItem = typeItem; this.DisplayName = Resources.Title_ViewLog; this.PreviewCommand = new DelegateCommand(async(p) => await this.PreviewAsync(), (p) => this.CanPreview); this.Initialize(); }
public static string GetAccessInfoPath(this ITypeItem typeItem, string categoryPath) { var typeContext = GetTypeContext(typeItem); var uriString = UriUtility.Combine(typeContext.BasePath, categoryPath.TrimStart(PathUtility.SeparatorChar) + typeItem.Name + extension); var uri = new Uri(uriString); return(uri.LocalPath); }
public static ExpressionSyntax WithLTypeAnnotation(this ExpressionSyntax node, ITypeItem ltype) { if (null != ltype) { return node.WithAdditionalAnnotations(new SyntaxAnnotation("ltype", ltype.ID)); } else { return node; } }
public void InvokeTypeItemDelete(Authentication authentication, ITypeItem typeItem) { if (typeItem.AccessInfo.Path == typeItem.Path) { var accessInfoPath = typeItem.GetAccessInfoPath(); if (File.Exists(accessInfoPath) == true) { this.repository.Delete(accessInfoPath); } } }
public void InvokeTypeItemMove(Authentication authentication, ITypeItem typeItem, string newCategoryPath) { if (typeItem.AccessInfo.Path == typeItem.Path) { var accessInfoPath1 = typeItem.GetAccessInfoPath(); var accessInfoPath2 = typeItem.GetAccessInfoPath(newCategoryPath); if (File.Exists(accessInfoPath1) == true) { this.repository.Move(accessInfoPath1, accessInfoPath2); } } }
private static void ValidateNotNull(ITypeItem typeItem) { if (IsExceptionOccurred == false) { return; } if (typeItem == null) { throw new ArgumentNullException(); } }
public void InvokeTypeItemRename(Authentication authentication, ITypeItem typeItem, string newName) { if (typeItem.AccessInfo.Path == typeItem.Path) { var accessInfoPath1 = typeItem.GetAccessInfoPath(); var directoryName = Path.GetDirectoryName(accessInfoPath1); var extension = Path.GetExtension(accessInfoPath1); var accessInfoPath2 = Path.Combine(directoryName, newName + extension); if (File.Exists(accessInfoPath1) == true && accessInfoPath1 != accessInfoPath2) { this.repository.Move(accessInfoPath1, accessInfoPath2); } } }
private static TypeContext GetTypeContext(this ITypeItem typeItem) { if (typeItem is Type type) { return(type.Context); } else if (typeItem is TypeCategory category) { return(category.Context); } else { throw new NotImplementedException(); } }
public static void WriteAccessInfo(this ITypeItem typeItem, string accessInfoPath, AccessInfo accessInfo) { if (typeItem is Type type) { WriteAccessInfo(accessInfoPath, accessInfo); } else if (typeItem is TypeCategory category) { WriteAccessInfo(accessInfoPath, accessInfo); } else { throw new NotImplementedException(); } }
public static void ClassInit(TestContext context) { app = new CremaBootstrapper(); app.Initialize(context, nameof(ITypeItem_DispatcherTest)); cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost; cremaHost.Dispatcher.Invoke(() => { authentication = cremaHost.Start(); dataBase = cremaHost.DataBases.Random(); dataBase.Load(authentication); dataBase.Enter(authentication); dataBase.TypeContext.AddRandomItems(authentication); typeItem = dataBase.TypeContext.Random(); }); }
private static bool CanMove(ITypeItem typeItem, string parentPath) { if (typeItem.Parent == null) { return(false); } if (typeItem.Parent.Path == parentPath) { return(false); } if (NameValidator.VerifyCategoryPath(parentPath) == false) { return(false); } return(parentPath.StartsWith(typeItem.Path) == false); }
public void InvokeTypeItemRemoveAccessMember(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo, string memberID) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemRemoveAccessMember), typeItem, memberID); var accessInfoPath = typeItem.GetAccessInfoPath(); try { accessInfo.Remove(authentication.SignatureDate, memberID); typeItem.WriteAccessInfo(accessInfoPath, accessInfo); } catch (Exception e) { this.CremaHost.Error(e); this.repository.Revert(); throw e; } }
public void InvokeTypeItemSetPublic(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemSetPrivate), typeItem); var accessInfoPath = typeItem.GetAccessInfoPath(); try { accessInfo.SetPublic(); this.repository.Delete(accessInfoPath); } catch (Exception e) { this.CremaHost.Error(e); this.repository.Revert(); throw e; } }
public void InvokeTypeItemSetPrivate(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemSetPrivate), typeItem); var accessInfoPath = typeItem.GetAccessInfoPath(); try { accessInfo.SetPrivate(typeItem.GetType().Name, authentication.SignatureDate); typeItem.WriteAccessInfo(accessInfoPath, accessInfo); this.repository.Add(accessInfoPath); } catch (Exception e) { this.CremaHost.Error(e); this.repository.Revert(); throw e; } }
public static void ReadAccessInfo(this ITypeItem typeItem, string accessInfoPath) { if (typeItem is Type type) { if (ReadAccessInfo(accessInfoPath, out var accessInfo)) { type.SetAccessInfo(accessInfo); } } else if (typeItem is TypeCategory category) { if (ReadAccessInfo(accessInfoPath, out var accessInfo)) { category.SetAccessInfo(accessInfo); } } else { throw new NotImplementedException(); } }
public void InvokeTypeItemSetPublic(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo) { }
public void RegisterType(ITypeItem ltype) { throw Failure(); }
public Field(IVariableContext parent, string id, ITypeItem type) : base(parent, id, type) { }
public GenericTypeRef(IDeclarationContext parent, ITypeItem generic, Type instance) : base(parent, instance.GetRName()) { _ltype = generic; _rtype = instance; }
public Method(IVariableContext parent, string id, ITypeItem ltype) : base(parent, id, ltype) { }
public void RegisterType(ITypeItem ltype) { Trace("[RegisterType] <{0}> {1}", this.ID, ltype); Types.AddItem(ltype); }
public void AddVariable(ITypeItem item) { _variables.AddItem(item); }
public void InvokeTypeItemUnlock(Authentication authentication, ITypeItem typeItem) { }
public void InvokeTypeItemLock(Authentication authentication, ITypeItem typeItem, string comment) { }
public void LoadProfile(XmlReader reader) { reader.MoveToContent(); State s = State.initial; while (reader.NodeType != XmlNodeType.None) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "profile") { if (s == State.initial) { s = State.profile; ScriptAssemblyName = reader.GetAttribute("script-assembly"); ScriptPath = reader.GetAttribute("script-path"); } else { throw new MalformedConfigurationException("unexpected 'profile' element."); } } else if (reader.LocalName == "source") { if (s == State.profile) { Namespace = reader.GetAttribute("namespace"); AssemblyName = reader.GetAttribute("assembly") ?? "mscorlib"; BaseTypeName = reader.GetAttribute("base"); s = State.source; } else { throw new MalformedConfigurationException("unexpected 'source' element."); } } else if (reader.LocalName == "type") { if (s == State.source) { TypeName = reader.GetAttribute("name"); var oldbase = BaseTypeName; var z = reader.GetAttribute("base"); if (null != z) { BaseTypeName = z; } InstallType(); BaseTypeName = oldbase; if (reader.IsStartElement() && !reader.IsEmptyElement) { s = State.type; } else { InstallTypeScript(); LType = null; } } else { throw new MalformedConfigurationException("unexpected 'type' element."); } } else if (reader.LocalName == "script") { if (s == State.type) { InstallScript(reader.GetAttribute("name"), true); } else if(s == State.source) { InstallScript(reader.GetAttribute("name"), true); } else { throw new MalformedConfigurationException("unexpected '" + reader.LocalName + "' element."); } } else { throw new MalformedConfigurationException("unexpected '" + reader.LocalName + "' element."); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (s == State.profile) { s = State.initial; } else if (s == State.source) { s = State.profile; } else if (s == State.type) { InstallTypeScript(); LType = null; s = State.source; } else { throw new MalformedConfigurationException("unexpected end element."); } } reader.Read(); } }
public void RegisterType(ITypeItem ltype) { throw new NotImplementedException("unable to register a type within a method context."); }
private void InstallType() { var rtype = Lookup(TypeName); Trace("constructing {0} ...", rtype.FullName); Type rbase = null; if(null != BaseTypeName) { rbase = Lookup(BaseTypeName); } if(null != rbase && rbase.FullName == rtype.FullName) { rbase = null; } // registers itself LType = new NativeTypeRef(Context, rtype, true, rbase); }
public Dependency(ITypeItem target, DependencyLevel level) { Target = target; Level = level; }
/// <summary> /// Creates an types item based on a variable context. /// </summary> /// <param name="parent">The variable context.</param> /// <param name="id">The identifier of the item.</param> /// <param name="type">The type of the item.</param> public ItemWithType(IVariableContext parent, string id, ITypeItem type) : base(parent.GetTypeDeclarationContext(), id) { _container = parent; _type = type; }
public void InvokeTypeItemRemoveAccessMember(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo, string memberID) { }
private void ExtractBaseType() { var type = _rtype; var basetype = type.BaseType; if (null != basetype) { if (basetype == typeof(object) || basetype.IsValueType) { basetype = null; } } if (null != basetype) { _baseclass = ParentTypes.TranslateRType(basetype, TranslateOptions.Add); _lbase = _baseclass as IVariableContext; if (null == _lbase) { throw new Exception("base type [" + basetype.GetRName() + "] is not defined."); } AddDepdendency(_baseclass, DependencyLevel.Constructor); } }
public Method(IDeclarationContext parent, string id, ITypeItem ltype) : base(parent, id, ltype) { }
public void InvokeTypeItemChange(Authentication authentication, ITypeItem typeItem) { }
public void AddVariable(string name, ITypeItem type) { _variables.AddVariable(name, type); }
public Property(IVariableContext parent, string id, ITypeItem type) : base(parent, id, type) { }
protected void AddTypeItem(ITypeItem item) { _types.AddItem(item); }
public virtual void AddDepdendency(ITypeItem target, DependencyLevel level) { if (target.ID != ID) { var d = new Dependency(target, level); if (!_dependencies.Contains(d)) { _dependencies.Add(d); } } }
public void AddVariable(string name, ITypeItem type) { throw new NotImplementedException(); }
private ITypeItem ResolveType(ITypeItem container, Type rtype) { return null; }
public void AddDepdendency(ITypeItem dependent, ITypeItem target) { throw Failure(); }
/// <summary> /// Queues the specified ltype for code generation and associates dependencies. /// </summary> /// <param name="ltype">The type item to enqueue.</param> public void ItemReferenced(ITypeItem ltype) { if(null != CurrentClass) { } if(ltype.GStatus == TypeGenerationStatus.initial || ltype.GStatus == TypeGenerationStatus.source) { // later return; } ClassToQueue(ltype); if(!_classesref.Contains(ltype.ID)) { _classesref.Add(ltype.ID); foreach (var dependency in ltype.Dependencies.Select(e => e.Target)) { ItemReferenced(dependency); } } }
public void AddVariable(string name, ITypeItem type) { throw Failure(); }
/// <summary> /// Generates code for a given class type and associates it with the type item. /// </summary> /// <param name="ltype">The class type item to generate.</param> /// <remarks> /// <para>The DeclarationEmitContext will be set as the EmitContext.</para></remarks> private void EmitClass(ITypeItem ltype) { if (Log.ShowClassDependencies || Log.ShowCodeGeneration) { Log.Trace("generate class [{0}] ...", ltype.ID); } if(null != ltype.EmitContext) { throw new InvalidOperationException("item " + ltype + " already has an emit context."); } try { CurrentClass = ltype; var dsc = (DeclarationSourceContext)ltype.SourceNode; var cls = (ClassDeclarationSyntax)dsc.ClassDeclaration; // create emit context var dgc = new DeclarationEmitContext(ltype, dsc); ltype.SetEmitContext(dgc); dgc.OnItemReferenced = ItemReferenced; dgc.AddItemReferences(); // look for automatic properties var autoprops = cls.Members .OfType<PropertyDeclarationSyntax>() .Where(IsAutomaticProperty) .Select(ap => ap.Identifier.ToString()); EmitConstructor(dgc, autoprops); var classmembers = ltype as IVariableContext; // add member methods and properties ... foreach (var member in cls.Members) { if (member is MethodDeclarationSyntax) { var method = member as MethodDeclarationSyntax; var name = method.Identifier.ToString(); var v = classmembers.GetVariable(name); if (!v.DoNotGenerate) { EmitMethod(dgc, method); } } else if (member is PropertyDeclarationSyntax) { var prop = (PropertyDeclarationSyntax)member; var propname = prop.Identifier.ToString(); /*Trace("property {0}:", propname); SyntaxTreeHelper.PrintTree(prop);*/ if (IsAutomaticProperty(prop)) { // automatic property EmitAutomaticPropertyAccessors(dgc, prop); } else { // emit property accessors foreach (var acc in member.DescendantNodes().OfType<AccessorDeclarationSyntax>()) { if (acc.Keyword.ToString() == "get") { EmitGetAccessor(dgc, "get_" + propname, acc.Body); } else { EmitSetAccessor(dgc, "set_" + propname, acc.Body); } } } } else if (member is EventFieldDeclarationSyntax) { // done LMGMELDMQ7 } else if (member is FieldDeclarationSyntax) { // done LN4NL4H5PI } else if (member is ConstructorDeclarationSyntax) { // handled before } else if (member is EnumDeclarationSyntax) { // skip nested } else if (member is ClassDeclarationSyntax) { // skip nested } else { Log.Warning("skipped production [{0}] while generating class code.", member.GetType().Name); SyntaxTreeHelper.PrintTree(member); } } } finally { CurrentClass = null; } }
public void InvokeTypeItemLock(Authentication authentication, ITypeItem typeItem, string comment) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemLock), typeItem, comment); }
public ItemWithType(IDeclarationContext parent, string id, ITypeItem type) : base(parent, id) { _container = parent; _type = type; }
private string GetPrototypeClause(ITypeItem typeinfo, string id) { return typeinfo.CodeName + ".prototype." + id; }
public void InvokeTypeItemUnlock(Authentication authentication, ITypeItem typeItem) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemUnlock), typeItem); }
private void EmitNativeScripts(ITypeItem ltype) { if(Log.ShowCodeGeneration) { Log.Trace("emit native [" + ltype.ID + "] ..."); } foreach(var script in ltype.ScriptReferences) { if(!_nativescripts.Contains(script.Key)) { _nativescripts.Add(script.Key); EmitNativeScript(script); } } }
public void InvokeTypeItemSetPublic(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemSetPrivate), typeItem); }
private void ClassToQueue(ITypeItem ltype) { if (!_classes.ContainsKey(ltype.ID)) { _classes.Add(ltype.ID, ltype); _classqueue.Enqueue(ltype); } }
public void InvokeTypeItemRemoveAccessMember(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo, string memberID) { this.CremaHost.DebugMethod(authentication, this, nameof(InvokeTypeItemRemoveAccessMember), typeItem, memberID); }
private static bool DefaultPredicate(ITypeItem _) => true;
public void InvokeTypeItemSetAccessMember(Authentication authentication, ITypeItem typeItem, AccessInfo accessInfo, string memberID, AccessType accessType) { }