CodeTypeReference ConvTypeRef(TypeReference tr)
		{
			if (tr == null) return null;
			string name = tr.ToString();
			if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name))
				name = BooAmbience.ReverseTypeConversionTable[name];
			return new CodeTypeReference(name);
		}
Example #2
0
 public static IReturnType CreateReturnType(AST.TypeReference reference, IClass callingClass,
                                            IMethodOrProperty callingMember, int caretLine, int caretColumn,
                                            IProjectContent projectContent)
 {
     System.Diagnostics.Debug.Assert(projectContent != null);
     if (reference == null)
     {
         return(GetDefaultReturnType(projectContent));
     }
     if (reference is AST.ArrayTypeReference)
     {
         AST.ArrayTypeReference arr = (AST.ArrayTypeReference)reference;
         return(new ArrayReturnType(projectContent,
                                    CreateReturnType(arr.ElementType, callingClass, callingMember,
                                                     caretLine, caretColumn, projectContent),
                                    (arr.Rank != null) ? (int)arr.Rank.Value : 1));
     }
     else if (reference is AST.SimpleTypeReference)
     {
         string      name = ((AST.SimpleTypeReference)reference).Name;
         IReturnType rt;
         int         typeParameterCount = (reference is AST.GenericTypeReference) ? ((AST.GenericTypeReference)reference).GenericArguments.Count : 0;
         if (name == "duck")
         {
             rt = new BooResolver.DuckClass(new DefaultCompilationUnit(projectContent)).DefaultReturnType;
         }
         else if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name))
         {
             rt = new GetClassReturnType(projectContent, BooAmbience.ReverseTypeConversionTable[name], typeParameterCount);
         }
         else if (callingClass == null)
         {
             rt = new GetClassReturnType(projectContent, name, typeParameterCount);
         }
         else
         {
             rt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn,
                                            name, typeParameterCount);
         }
         if (typeParameterCount > 0)
         {
             AST.TypeReferenceCollection arguments = ((AST.GenericTypeReference)reference).GenericArguments;
             // GenericTypeReference derives from SimpleTypeReference
             IReturnType[] typeArguments = new IReturnType[arguments.Count];
             for (int i = 0; i < typeArguments.Length; i++)
             {
                 typeArguments[i] = CreateReturnType(arguments[i], callingClass, callingMember, caretLine, caretColumn,
                                                     projectContent);
             }
             rt = new ConstructedReturnType(rt, typeArguments);
         }
         return(rt);
     }
     else if (reference is AST.CallableTypeReference)
     {
         AST.CallableTypeReference ctr  = (AST.CallableTypeReference)reference;
         AnonymousMethodReturnType amrt = new AnonymousMethodReturnType(new DefaultCompilationUnit(projectContent));
         if (ctr.ReturnType != null)
         {
             amrt.MethodReturnType = CreateReturnType(ctr.ReturnType, callingClass, callingMember, caretLine, caretColumn, projectContent);
         }
         amrt.MethodParameters = new List <IParameter>();
         AddParameters(ctr.Parameters, amrt.MethodParameters, callingMember, callingClass ?? new DefaultClass(new DefaultCompilationUnit(projectContent), "__Dummy"));
         return(amrt);
     }
     else
     {
         throw new NotSupportedException("unknown reference type: " + reference.ToString());
     }
 }