예제 #1
0
        /// <summary>
        /// Returns true if the short name of a type is valid in the given context.
        /// Returns false for primitive types because they should be passed around using their
        /// fully qualified names to allow the ambience or output visitor to use the intrinsic
        /// type name.
        /// </summary>
        public static bool CanUseShortTypeName(IReturnType returnType, ClassFinder context)
        {
            int         typeArgumentCount   = (returnType.IsConstructedReturnType) ? returnType.CastToConstructedReturnType().TypeArguments.Count : 0;
            IReturnType typeInTargetContext = context.SearchType(returnType.Name, typeArgumentCount);

            return(typeInTargetContext != null && typeInTargetContext.FullyQualifiedName == returnType.FullyQualifiedName);
        }
예제 #2
0
        /// <summary>
        /// Returns true if the short name of a type is valid in the given context.
        /// Returns false for primitive types because they should be passed around using their
        /// fully qualified names to allow the ambience or output visitor to use the intrinsic
        /// type name.
        /// </summary>
        public static bool CanUseShortTypeName(IReturnType returnType, ClassFinder context)
        {
            switch (returnType.FullyQualifiedName)
            {
            case "System.Void":
            case "System.String":
            case "System.Char":
            case "System.Boolean":
            case "System.Single":
            case "System.Double":
            case "System.Decimal":
            case "System.Byte":
            case "System.SByte":
            case "System.Int16":
            case "System.Int32":
            case "System.Int64":
            case "System.UInt16":
            case "System.UInt32":
            case "System.UInt64":
                // don't use short name -> output visitor will use the instrinsic name
                return(false);
            }
            int         typeArgumentCount   = (returnType.IsConstructedReturnType) ? returnType.CastToConstructedReturnType().TypeArguments.Count : 0;
            IReturnType typeInTargetContext = context.SearchType(returnType.Name, typeArgumentCount);

            return(typeInTargetContext != null && typeInTargetContext.FullyQualifiedName == returnType.FullyQualifiedName);
        }
        /// <summary>
        /// Returns true if the short name of a type is valid in the given context.
        /// Returns false for primitive types because they should be passed around using their
        /// fully qualified names to allow the ambience or output visitor to use the intrinsic
        /// type name.
        /// </summary>
        public static bool CanUseShortTypeName(IReturnType returnType, ClassFinder context)
        {
            if (returnType == null || context == null)
            {
                return(false);
            }
            IReturnType typeInTargetContext = context.SearchType(returnType.Name, returnType.TypeArgumentCount);

            return(typeInTargetContext != null &&
                   typeInTargetContext.FullyQualifiedName == returnType.FullyQualifiedName &&
                   typeInTargetContext.TypeArgumentCount == returnType.TypeArgumentCount);
        }
 ExpressionContext GetCreationContext()
 {
     UnGetToken();
     if (GetNextNonWhiteSpace() == '=')               // was: "= new"
     {
         ReadNextToken();
         if (curTokenType == Ident)                       // was: "ident = new"
         {
             int typeEnd = offset;
             ReadNextToken();
             int typeStart = -1;
             while (curTokenType == Ident)
             {
                 typeStart = offset + 1;
                 ReadNextToken();
                 if (curTokenType == Dot)
                 {
                     ReadNextToken();
                 }
                 else
                 {
                     break;
                 }
             }
             if (typeStart >= 0)
             {
                 string className = text.Substring(typeStart, typeEnd - typeStart);
                 int    pos = className.IndexOf('<');
                 string nonGenericClassName, genericPart;
                 int    typeParameterCount = 0;
                 if (pos > 0)
                 {
                     nonGenericClassName = className.Substring(0, pos);
                     genericPart         = className.Substring(pos);
                     pos = 0;
                     do
                     {
                         typeParameterCount += 1;
                         pos = genericPart.IndexOf(',', pos + 1);
                     } while (pos > 0);
                 }
                 else
                 {
                     nonGenericClassName = className;
                     genericPart         = null;
                 }
                 ClassFinder finder = new ClassFinder(fileName, text, typeStart);
                 IReturnType t      = finder.SearchType(nonGenericClassName, typeParameterCount);
                 IClass      c      = (t != null) ? t.GetUnderlyingClass() : null;
                 if (c != null)
                 {
                     ExpressionContext context = ExpressionContext.TypeDerivingFrom(c.BaseType, true);
                     if (context.ShowEntry(c))
                     {
                         if (genericPart != null)
                         {
                             DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType);
                             genericClass.FullyQualifiedName = c.FullyQualifiedName + genericPart;
                             genericClass.Documentation      = c.Documentation;
                             context.SuggestedItem           = genericClass;
                         }
                         else
                         {
                             context.SuggestedItem = c;
                         }
                     }
                     return(context);
                 }
             }
         }
     }
     else
     {
         UnGet();
         if (ReadIdentifier(GetNextNonWhiteSpace()) == "throw")
         {
             return(ExpressionContext.TypeDerivingFrom(HostCallback.GetCurrentProjectContent().GetClass("System.Exception", 1).BaseType, true));
         }
     }
     return(ExpressionContext.ObjectCreation);
 }
 ExpressionContext GetCreationContext()
 {
     UnGetToken();
     if (GetNextNonWhiteSpace() == '=') { // was: "= new"
         ReadNextToken();
         if (curTokenType == Ident) {     // was: "ident = new"
             int typeEnd = offset;
             ReadNextToken();
             int typeStart = -1;
             while (curTokenType == Ident) {
                 typeStart = offset + 1;
                 ReadNextToken();
                 if (curTokenType == Dot) {
                     ReadNextToken();
                 } else {
                     break;
                 }
             }
             if (typeStart >= 0) {
                 string className = text.Substring(typeStart, typeEnd - typeStart);
                 int pos = className.IndexOf('<');
                 string nonGenericClassName, genericPart;
                 int typeParameterCount = 0;
                 if (pos > 0) {
                     nonGenericClassName = className.Substring(0, pos);
                     genericPart = className.Substring(pos);
                     pos = 0;
                     do {
                         typeParameterCount += 1;
                         pos = genericPart.IndexOf(',', pos + 1);
                     } while (pos > 0);
                 } else {
                     nonGenericClassName = className;
                     genericPart = null;
                 }
                 ClassFinder finder = new ClassFinder(fileName, text, typeStart);
                 IReturnType t = finder.SearchType(nonGenericClassName, typeParameterCount);
                 IClass c = (t != null) ? t.GetUnderlyingClass() : null;
                 if (c != null) {
                     ExpressionContext context = ExpressionContext.TypeDerivingFrom(c.BaseType, true);
                     if (context.ShowEntry(c)) {
                         if (genericPart != null) {
                             DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType);
                             genericClass.FullyQualifiedName = c.FullyQualifiedName + genericPart;
                             genericClass.Documentation = c.Documentation;
                             context.SuggestedItem = genericClass;
                         } else {
                             context.SuggestedItem = c;
                         }
                     }
                     return context;
                 }
             }
         }
     } else {
         UnGet();
         if (ReadIdentifier(GetNextNonWhiteSpace()) == "throw") {
             return ExpressionContext.TypeDerivingFrom(HostCallback.GetCurrentProjectContent().GetClass("System.Exception", 1).BaseType, true);
         }
     }
     return ExpressionContext.ObjectCreation;
 }