/// <summary> /// Gets the return type of an entity. /// </summary> /// <param name="withNamespace">If true, the namespace of the type will be included.</param> /// <returns>Type (and possibly namespace) of the return type, as a string.</returns> public string GetReturnType(bool withNamespace = false) { if (entity == null) { return(null); } // The problem is that a lot - but not all - of the entity types defined by NRefactory (e.g. AbstractResolvedMember, // ReducedExtensionMethod, etc) contain a property called ReturnType. If it exists, this property is exactly what we want. // This property is not inherited from a base class or interface, so the best way to check if it exists is via reflection. try { System.Reflection.PropertyInfo returnType = entity.GetType().GetProperty("ReturnType"); if (returnType != null) { IType returnTypeValue = returnType.GetValue(entity) as IType; if (returnTypeValue != null) { return(GetTypeName(returnTypeValue, withNamespace)); } } } catch { } if (entity is DefaultResolvedTypeDefinition) { DefaultResolvedTypeDefinition resolvedMember = this.entity as DefaultResolvedTypeDefinition; return(withNamespace ? resolvedMember?.Kind.ToString() ?? "" : resolvedMember?.Kind.ToString() ?? ""); } return("Unknown"); }
protected virtual string GetCastCode(Expression expression, AstType astType, out bool isInline) { var resolveResult = this.Emitter.Resolver.ResolveNode(astType, this.Emitter) as TypeResolveResult; var exprResolveResult = this.Emitter.Resolver.ResolveNode(expression, this.Emitter); string inline = null; isInline = false; var method = this.GetCastMethod(exprResolveResult.Type, resolveResult.Type, out inline); if (method == null && (NullableType.IsNullable(exprResolveResult.Type) || NullableType.IsNullable(resolveResult.Type))) { method = this.GetCastMethod(NullableType.IsNullable(exprResolveResult.Type) ? NullableType.GetUnderlyingType(exprResolveResult.Type) : exprResolveResult.Type, NullableType.IsNullable(resolveResult.Type) ? NullableType.GetUnderlyingType(resolveResult.Type) : resolveResult.Type, out inline); } if (inline != null) { this.InlineMethod = method; isInline = true; return(inline); } if (resolveResult != null) { IEnumerable <IAttribute> attributes = null; DefaultResolvedTypeDefinition type = resolveResult.Type as DefaultResolvedTypeDefinition; if (type != null) { attributes = type.Attributes; } else { ParameterizedType paramType = resolveResult.Type as ParameterizedType; if (paramType != null) { attributes = paramType.GetDefinition().Attributes; } } if (attributes != null) { var attribute = this.Emitter.GetAttribute(attributes, Translator.Bridge_ASSEMBLY + ".CastAttribute"); if (attribute != null) { return(attribute.PositionalArguments[0].ConstantValue.ToString()); } } } return(null); }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition (GetContext (treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve (treeBuilder, method, dt); label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); if (method.IsPrivate || method.IsInternal) label = DomMethodNodeBuilder.FormatPrivate (label); icon = ImageService.GetPixbuf (resolved.GetStockIcon (), Gtk.IconSize.Menu); }
protected static ClassType GetClassType(DefaultResolvedTypeDefinition resolvedType) { switch (resolvedType.Kind) { case TypeKind.Class: return(ClassType.Class); case TypeKind.Interface: return(ClassType.Interface); default: throw new ArgumentOutOfRangeException(); } }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition(GetContext(treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve(treeBuilder, method, dt); label = Ambience.GetString(resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); if (method.IsPrivate || method.IsInternal) { label = DomMethodNodeBuilder.FormatPrivate(label); } icon = ImageService.GetPixbuf(resolved.GetStockIcon(), Gtk.IconSize.Menu); }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition (GetContext (treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve (treeBuilder, method, dt); try { nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); } catch (Exception) { nodeInfo.Label = method.Name; } if (method.IsPrivate || method.IsInternal) nodeInfo.Label = DomMethodNodeBuilder.FormatPrivate (nodeInfo.Label); nodeInfo.Icon = Context.GetIcon (resolved.GetStockIcon ()); }
public virtual int EnumEmitMode(DefaultResolvedTypeDefinition type) { string enumAttr = Translator.Bridge_ASSEMBLY + ".EnumAttribute"; int result = -1; type.Attributes.Any(attr => { if (attr.Constructor != null && attr.Constructor.DeclaringType.FullName == enumAttr && attr.PositionalArguments.Count > 0) { result = (int)attr.PositionalArguments.First().ConstantValue; return(true); } return(false); }); return(result); }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition (GetContext (treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve (treeBuilder, method, dt); var ambience = new CSharpAmbience (); try { nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (ambience.ConvertSymbol (resolved)); } catch (Exception) { nodeInfo.Label = method.Name; } if (method.IsPrivate || method.IsInternal) nodeInfo.Label = DomMethodNodeBuilder.FormatPrivate (nodeInfo.Label); nodeInfo.Icon = Context.GetIcon (resolved.GetStockIcon ()); }
public ITypeDefinition GetTypeDefinition(IUnresolvedTypeDefinition unresolved) { if (unresolved.DeclaringTypeDefinition == null) { return(GetTypeDefinition(unresolved.Namespace, unresolved.Name, unresolved.TypeParameters.Count)); } else { lock (nestedTypeDict) { ITypeDefinition typeDef; if (nestedTypeDict.TryGetValue(unresolved, out typeDef)) { return(typeDef); } ITypeDefinition parentType = GetTypeDefinition(unresolved.DeclaringTypeDefinition); if (parentType == null) { return(null); } List <IUnresolvedTypeDefinition> parts = new List <IUnresolvedTypeDefinition>(); foreach (var parentPart in parentType.Parts) { foreach (var nestedPart in parentPart.NestedTypes) { if (nestedPart.Name == unresolved.Name && nestedPart.TypeParameters.Count == unresolved.TypeParameters.Count) { parts.Add(nestedPart); } } } typeDef = new DefaultResolvedTypeDefinition(new SimpleTypeResolveContext(parentType), parts.ToArray()); foreach (var part in parts) { // TODO: Fix that hack ! if (nestedTypeDict.ContainsKey(part)) { continue; } nestedTypeDict.Add(part, typeDef); } return(typeDef); } } }
ICodeContext CreateContext(ITextEditor editor) { var compilation = SD.ParserService.GetCompilationForFile(editor.FileName); var project = SD.ProjectService.FindProjectContainingFile(editor.FileName); var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly); var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName)); ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1); baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { FindModelType(editor) }); currentTypeDefinition.BaseTypes.Add(baseTypeReference); var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__"); currentMethod.ReturnType = KnownTypeReference.Void; currentTypeDefinition.Members.Add(currentMethod); var currentResolvedTypeDef = new DefaultResolvedTypeDefinition(resolveContext, currentTypeDefinition); var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; var currentFile = new CSharpUnresolvedFile(); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Ajax"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Html"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Routing"); currentFile.TopLevelTypeDefinitions.Add(currentTypeDefinition); if (projectContent != null) { compilation = projectContent.AddOrUpdateFiles(currentFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot()); } var context = new CSharpTypeResolveContext(compilation.MainAssembly, currentFile.RootUsingScope.Resolve(compilation), currentResolvedTypeDef, currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef))); return(new CSharpResolver(context)); }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition(GetContext(treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve(treeBuilder, method, dt); try { nodeInfo.Label = Ambience.GetString(resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); } catch (Exception) { nodeInfo.Label = method.Name; } if (method.IsPrivate || method.IsInternal) { nodeInfo.Label = DomMethodNodeBuilder.FormatPrivate(nodeInfo.Label); } nodeInfo.Icon = Context.GetIcon(resolved.GetStockIcon()); }
public static IList<IMethod> getClassConstructors(DefaultResolvedTypeDefinition classDef) { IList<IMethod> results = new List<IMethod>(); foreach (IMethod methodDef in classDef.Methods) { //string mName = methodDef.Name; if (methodDef.IsConstructor) { // Check the class is being exported //ITypeDefinition classDef = getClassDefinition( methodDef. results.Add(methodDef); } } if (results.Count > 0) { return results; } return null; }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition(GetContext(treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve(treeBuilder, method, dt); var ambience = new CSharpAmbience(); try { nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText(ambience.ConvertSymbol(resolved)); } catch (Exception) { nodeInfo.Label = method.Name; } if (method.IsPrivate || method.IsInternal) { nodeInfo.Label = DomMethodNodeBuilder.FormatPrivate(nodeInfo.Label); } nodeInfo.Icon = Context.GetIcon(resolved.GetStockIcon()); }
public static IList<IMethod> getClassMethodsByAttribute(DefaultResolvedTypeDefinition classDef, string reflectionName) { IList<IMethod> results = new List<IMethod>(); foreach (IMethod methodDef in classDef.Methods) { string mName = methodDef.Name; if (!methodDef.IsConstructor) { IAttribute attribute = getAttributeByName(methodDef.Attributes, reflectionName); if (attribute != null) { results.Add(methodDef); } } } if (results.Count > 0) { return results; } return null; }
public InjectionPointsFunctionBuilder(DefaultResolvedTypeDefinition arg1, JsUnit arg2) { this.cSharpDef = arg1; this.jsEntity = arg2; }
public virtual bool IsStringNameEnum(DefaultResolvedTypeDefinition type) { return(this.EnumEmitMode(type) == 3); }
public virtual bool IsNameEnum(DefaultResolvedTypeDefinition type) { var enumEmitMode = this.EnumEmitMode(type); return(enumEmitMode == 1 || enumEmitMode > 6); }
public virtual bool IsValueEnum(DefaultResolvedTypeDefinition type) { return(this.EnumEmitMode(type) == 2); }
public ObservablePropertiesBuilder(DefaultResolvedTypeDefinition arg1) { this.cSharpEntity = arg1; }
// creates injectionPoints function // ex: randori.formatters.AbstractFormatter.injectionPoints = function(t) { ... } protected void insertInjectionPoints( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef ) { if (cSharpDef != null && jsDef != null) { InjectionPointsFunctionBuilder ipBuilder = new InjectionPointsFunctionBuilder(cSharpDef, jsDef); JsExpressionStatement injectionPoints = ipBuilder.getInjectionPointsExpression(); if (injectionPoints != null) { jsDef.Statements.Add(injectionPoints); } } }
// inserts static className property in JSFile // ex: randori.attributes.HtmlMergedFile.className = "randori.attributes.HtmlMergedFile"; protected void insertClassNameProperty( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef ) { if ( cSharpDef != null && jsDef != null ) { JsExpressionStatement classNameStatement = AstUtils.getStaticPropertyStatement( OutputNameConstants.PROPERTY_CLASS_NAME, cSharpDef.FullName ); if ( classNameStatement != null ) { jsDef.Statements.Add( classNameStatement ); } } }
public JsNodeVisitorBase( DefaultResolvedTypeDefinition arg1, JsNode arg2 ) { this.cSharpDef = arg1; this.jsEntity = arg2; }
JsFunction getInjectionPointsFunction(DefaultResolvedTypeDefinition arg1) { IList<IMethod> constructors = IEntityUtils.getClassConstructors(arg1); IList<IField> fields = IEntityUtils.getFieldsByAttribute( arg1, RandoriClassNames.metadataInject ); IList<IProperty> properties = IEntityUtils.getPropertiesByAttribute( arg1, RandoriClassNames.metadataInject ); IList<IField> views = IEntityUtils.getFieldsByAttribute( arg1, RandoriClassNames.metadataView ); IList<IMethod> methods = IEntityUtils.getClassMethodsByAttribute( arg1, RandoriClassNames.metadataInject ); JsFunction result = new JsFunction(); result.Parameters = new List<string>(); result.Parameters.Add(InjectionPointVariableConstants.INJECTION_POINT_PARAMETER_NAME); // function contents JsBlock resultsBlock = new JsBlock(); resultsBlock.Statements = new List<JsStatement>(); // add the block result.Block = resultsBlock; // Determine what the super class is in the event we need to call the super class's injectionPoints method string superClassPath = null; foreach (IType type in arg1.DirectBaseTypes) { // Careful, type.FullName could be all sorts of stuff, like interfaces if (type.Kind == TypeKind.Class) { bool initArray = GuiceUtils.shouldExcludeBasedOnNamespace(type.Namespace); if (!initArray) { superClassPath = type.FullName; } } } JsSwitchStatement injectionPoints = getInjectionSwitchStatement( InjectionPointVariableConstants.INJECTION_POINT_PARAMETER_NAME, constructors, fields, methods, views, properties, superClassPath ); if (injectionPoints != null) { resultsBlock.Statements.Add( AstUtils.getJsVariableDeclarationStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ) ); resultsBlock.Statements.Add(injectionPoints); // return the result variable resultsBlock.Statements.Add( AstUtils.getJsReturnStatement( InjectionPointVariableConstants.SWITCH_RETURN_VARIABLE_NAME ) ); } else { JsInvocationExpression initer = AstUtils.getEmptyArrayInvocationExpression(); resultsBlock.Statements.Add(AstUtils.getJsReturnStatement(initer)); } return result; }
protected virtual string GetCastCode(Expression expression, AstType astType, out bool isInline) { var resolveResult = this.Emitter.Resolver.ResolveNode(astType, this.Emitter) as TypeResolveResult; var exprResolveResult = this.Emitter.Resolver.ResolveNode(expression, this.Emitter); string inline = null; isInline = false; var method = exprResolveResult.Type.GetMethods().FirstOrDefault(m => { if (m.IsOperator && m.Name == "op_Explicit" && m.Parameters.Count == 1 && m.ReturnType.ReflectionName == resolveResult.Type.ReflectionName && m.Parameters[0].Type.ReflectionName == exprResolveResult.Type.ReflectionName ) { string tmpInline = this.Emitter.GetInline(m); if (!string.IsNullOrWhiteSpace(tmpInline)) { inline = tmpInline; return(true); } } return(false); }); if (inline != null) { isInline = true; return(inline); } if (resolveResult != null) { IEnumerable <IAttribute> attributes = null; DefaultResolvedTypeDefinition type = resolveResult.Type as DefaultResolvedTypeDefinition; if (type != null) { attributes = type.Attributes; } else { ParameterizedType paramType = resolveResult.Type as ParameterizedType; if (paramType != null) { attributes = paramType.GetDefinition().Attributes; } } if (attributes != null) { var attribute = this.Emitter.GetAttribute(attributes, Translator.Bridge_ASSEMBLY + ".CastAttribute"); if (attribute != null) { return(attribute.PositionalArguments[0].ConstantValue.ToString()); } } } return(null); }
public ClassDependencyVisitor(DefaultResolvedTypeDefinition arg1, JsNode arg2) : base(arg1, arg2) { dependencyList = new List<string>(); buildDependencyList(); }
public ITypeDefinition GetTypeDefinition(IUnresolvedTypeDefinition unresolved) { if (unresolved.DeclaringTypeDefinition == null) { return GetTypeDefinition(unresolved.Namespace, unresolved.Name, unresolved.TypeParameters.Count); } else { lock (nestedTypeDict) { ITypeDefinition typeDef; if (nestedTypeDict.TryGetValue(unresolved, out typeDef)) return typeDef; ITypeDefinition parentType = GetTypeDefinition(unresolved.DeclaringTypeDefinition); if (parentType == null) return null; List<IUnresolvedTypeDefinition> parts = new List<IUnresolvedTypeDefinition>(); foreach (var parentPart in parentType.Parts) { foreach (var nestedPart in parentPart.NestedTypes) { if (nestedPart.Name == unresolved.Name && nestedPart.TypeParameters.Count == unresolved.TypeParameters.Count) { parts.Add(nestedPart); } } } typeDef = new DefaultResolvedTypeDefinition(new SimpleTypeResolveContext(parentType), parts.ToArray()); foreach (var part in parts) { // TODO: Fix that hack ! if (nestedTypeDict.ContainsKey (part)) continue; nestedTypeDict.Add(part, typeDef); } return typeDef; } } }
public static IList<IField> getFieldsByAttribute(DefaultResolvedTypeDefinition classDef, string reflectionName) { IList<IField> results = new List<IField>(); foreach (IField field in classDef.Fields) { IAttribute attribute = getAttributeByName(field.Attributes, reflectionName); if (attribute != null) { results.Add(field); } } if (results.Count > 0) { return results; } return null; }
// processes [Bindable] tagged items protected void insertBindableMetadata(DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef) { if (cSharpDef != null && jsDef != null) { ObservablePropertiesBuilder bpb = new ObservablePropertiesBuilder(cSharpDef); List<JsExpressionStatement> propertyStatements = bpb.getEncapsulateBindableProperties(); if (propertyStatements != null) { foreach (JsExpressionStatement propertyStatement in propertyStatements) { jsDef.Statements.Add(propertyStatement); } } } }
public virtual int EnumEmitMode(DefaultResolvedTypeDefinition type) { string enumAttr = Translator.Bridge_ASSEMBLY + ".EnumAttribute"; int result = -1; type.Attributes.Any(attr => { if (attr.Constructor != null && attr.Constructor.DeclaringType.FullName == enumAttr && attr.PositionalArguments.Count > 0) { result = (int)attr.PositionalArguments.First().ConstantValue; return true; } return false; }); return result; }
// inserts a list of other dependencies this class needs in order to run. Guice will load protected void insertDependencyList( DefaultResolvedTypeDefinition cSharpDef, JsUnit jsDef ) { if ( cSharpDef != null && jsDef != null ) { ClassDependencyFunctionBuilder dependencyBuilder = new ClassDependencyFunctionBuilder( cSharpDef, jsDef ); JsExpressionStatement classDependencyStatement = dependencyBuilder.getDependencyExpression(); if (classDependencyStatement != null) { jsDef.Statements.Add(classDependencyStatement); } } }
public virtual bool IsStringNameEnum(DefaultResolvedTypeDefinition type) { return this.EnumEmitMode(type) == 3; }
public static IList<IProperty> getPropertiesByAttribute(DefaultResolvedTypeDefinition classDef, string reflectionName) { IList<IProperty> results = new List<IProperty>(); foreach (IProperty property in classDef.Properties) { IAttribute attribute = getAttributeByName(property.Attributes, reflectionName); if (attribute != null) { results.Add(property); } } if (results.Count > 0) { return results; } return null; }
public virtual bool IsValueEnum(DefaultResolvedTypeDefinition type) { return this.EnumEmitMode(type) == 2; }
public ClassDependencyFunctionBuilder(DefaultResolvedTypeDefinition arg1, JsUnit arg2) { this.cSharpDef = arg1; this.jsEntity = arg2; }
ICodeContext CreateContext(ITextEditor editor) { var compilation = SD.ParserService.GetCompilationForFile(editor.FileName); var project = SD.ProjectService.FindProjectContainingFile(editor.FileName); var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly); var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName)); ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1); baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { FindModelType(editor) }); currentTypeDefinition.BaseTypes.Add(baseTypeReference); var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__"); currentMethod.ReturnType = KnownTypeReference.Void; currentTypeDefinition.Members.Add(currentMethod); var currentResolvedTypeDef = new DefaultResolvedTypeDefinition(resolveContext, currentTypeDefinition); var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; var currentFile = new CSharpUnresolvedFile(); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Ajax"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Html"); currentFile.RootUsingScope.AddSimpleUsing("System.Web.Routing"); currentFile.TopLevelTypeDefinitions.Add(currentTypeDefinition); if (projectContent != null) { compilation = projectContent.AddOrUpdateFiles(currentFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot()); } var context = new CSharpTypeResolveContext(compilation.MainAssembly, currentFile.RootUsingScope.Resolve(compilation), currentResolvedTypeDef, currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef))); return new CSharpResolver(context); }